LargeInteger.st
author Stefan Vogel <sv@exept.de>
Tue, 13 Jul 2004 15:10:20 +0200
changeset 8447 9bdea3431846
parent 8334 4466f66d1f9a
child 8628 38dc3601e16b
permissions -rw-r--r--
EncodedStream inherts from PeekableStream
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
345
claus
parents: 250
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5382
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
    13
"{ Package: 'stx:libbasic' }"
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
Integer subclass:#LargeInteger
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	instanceVariableNames:'sign digitByteArray'
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	classVariableNames:''
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    18
	poolDictionaries:''
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    19
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
    22
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
 COPYRIGHT (c) 1994 by Claus Gittinger
345
claus
parents: 250
diff changeset
    27
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    38
documentation
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    39
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    40
    This class provides arbitrary precision integers. These are represented as:
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    41
      sign (-1/0/+1) and, if sign ~~ 0
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    42
      a ByteArray of digits with 8 bits per element; 
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    43
      least significant 8 bits at index 1 ...
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    44
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    45
    The implementation is not completely tuned for high performance
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    46
    (more key-methods should be rewritten as primitives), although the
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    47
    common operations have been pretty tuned for some architectures.
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    48
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    49
    LargeIntegers are usually not created explicitely, but result from 
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    50
    SmallInteger arithmetic (overflowing the SmallInteger range).
357
claus
parents: 345
diff changeset
    51
    Also, results of LargeInteger operations are converted to back to 
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    52
    SmallIntegers, when possible (see #compressed).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    53
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    54
    In contrast to ST-80, there is only one class for LargeIntegers, keeping
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    55
    the sign as an instance variable (ST-80 has LargePositiveInteger and
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    56
    LargeNegativeInteger). This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    57
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    58
    [author:]
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
    59
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    60
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    61
    [see also:]
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
    62
	Number
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
    63
	Float Fraction FixedPoint 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
    64
	SmallInteger
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    65
"
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    66
!
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    67
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    68
testing
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    69
"
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    70
   test largeInt multiplication & division 
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    71
   (at least, test if they have not both errors which anull each other ;-)
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    72
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    73
   |last v|
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    74
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    75
   v := last := 1.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    76
   2 to:3000 do:[:i |
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    77
       i printCR.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    78
       v := v * i.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    79
       (v / i) ~= last ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
    80
	   self halt
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    81
       ].
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    82
       last := v.
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    83
   ]
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    84
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    85
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    86
   test addition, subtraction:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    87
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    88
   SmallInteger maxVal                -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    89
   SmallInteger maxVal + 1            -> 1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    90
   SmallInteger maxVal + 2            -> 1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    91
   (SmallInteger maxVal + 2) - 2      -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    92
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    93
   SmallInteger minVal                -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    94
   SmallInteger minVal - 1            -> -1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    95
   SmallInteger minVal - 2            -> -1073741826
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    96
   (SmallInteger minVal - 2) + 2      -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    97
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    98
   1234567890 + 10                    -> 1234567900
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    99
   1111111111 + 1111111111            -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   100
   1111111111 - 1111111111            -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   101
   1111111111 - 2222222222            -> -1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   102
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   103
   1111111111 * 2                     -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   104
   1111111111 * -2                    -> -2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   105
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   106
   1111111111 * 1111111111            -> 1234567900987654321
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   107
   1234567900987654321 // 1111111111  -> 1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   108
   1234567900987654321 \\ 1111111111  -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   109
   1234567900987654322 \\ 1111111111  -> 1
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   110
   1234567900987654421 \\ 1111111111  -> 100
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   112
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   113
   addition:
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   114
   (16rFFFFFFF0 + 1          ) hexPrintString -> 'FFFFFFF1'     
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   115
   (16rFFFFFFFF + 1          ) hexPrintString -> '100000000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   116
   (16rFFFFFFFF + 2          ) hexPrintString -> '100000001'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   117
   (16rFFFFFFFF + 16rFFFFFF  ) hexPrintString -> '100FFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   118
   (16rFFFFFFFF + 16rFFFFFFFF) hexPrintString -> '1FFFFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   119
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   120
   20 factorial         -> 2432902008176640000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   121
   20 factorial + 10000 -> 2432902008176650000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   122
   20 factorial               hexPrintString -> '21C3677C82B40000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   123
   (20 factorial + 16rFFFF)   hexPrintString -> '21C3677C82B4FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   124
   (20 factorial + 16rFFFFFF) hexPrintString -> '21C3677C83B3FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   125
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   126
   test comparison:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   127
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   128
   -1234567890 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   129
   -1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   130
   -1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   131
   -1234567890 <= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   132
   -1234567890 =  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   133
   -1234567890 ~= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   134
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   135
   -1234567890 >  -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   136
   -1234567890 >= -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   137
   -1234567890 <  -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   138
   -1234567890 <= -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   139
   -1234567890 =  -1234567891         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   140
   -1234567890 ~= -1234567891         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   141
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   142
   -1234567891 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   143
   -1234567891 >= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   144
   -1234567891 <  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   145
   -1234567891 <= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   146
   -1234567891 =  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   147
   -1234567891 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   148
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   149
    1234567890 >  -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   150
    1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   151
    1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   152
    1234567890 <= -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   153
    1234567890 =  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   154
    1234567890 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   155
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   156
   -1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   157
   -1234567890 >= 1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   158
   -1234567890 <  1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   159
   -1234567890 <= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   160
   -1234567890 =  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   161
   -1234567890 ~= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   162
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   163
    1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   164
    1234567890 >= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   165
    1234567890 <  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   166
    1234567890 <= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   167
    1234567890 =  1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   168
    1234567890 ~= 1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   169
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   170
   -1234567890 >  -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   171
   -1234567890 >= -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   172
   -1234567890 <  -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   173
   -1234567890 <= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   174
   -1234567890 =  -10                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   175
   -1234567890 ~= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   176
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   177
   -1234567890 >  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   178
   -1234567890 >= 10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   179
   -1234567890 <  10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   180
   -1234567890 <= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   181
   -1234567890 =  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   182
   -1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   183
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   184
   -10 >  -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   185
   -10 >= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   186
   -10 <  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   187
   -10 <= -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   188
   -10 =  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   189
   -10 ~= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   190
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   191
    10 >  -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   192
    10 >= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   193
    10 <  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   194
    10 <= -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   195
    10 =  -1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   196
    10 ~= -1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   197
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   198
    1234567890 >  -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   199
    1234567890 >= -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   200
    1234567890 <  -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   201
    1234567890 <= -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   202
    1234567890 =  -10                 false  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   203
    1234567890 ~= -10                 true  
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   204
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   205
    1234567890 >  10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   206
    1234567890 >= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   207
    1234567890 <  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   208
    1234567890 <= 10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   209
    1234567890 =  10                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   210
    1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   211
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   212
   -10 >   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   213
   -10 >=  1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   214
   -10 <   1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   215
   -10 <=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   216
   -10 =   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   217
   -10 ~=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   218
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   219
    10 >   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   220
    10 >=  1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   221
    10 <   1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   222
    10 <=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   223
    10 =   1234567890                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   224
    10 ~=  1234567890                 true
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
   225
"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   226
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   227
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   228
!LargeInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   229
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   230
digitBytes:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   231
    "create and return a new LargeInteger with digits (lsb-first)
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   232
     from the argument, aByteArray.
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   233
     Experimental interface - May change/be removed without notice."
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   234
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   235
    ^ self basicNew setDigits:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   236
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   237
    "
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   238
     LargeInteger digitBytes:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]
4806
1b48e7420cfe comment
Claus Gittinger <cg@exept.de>
parents: 4794
diff changeset
   239
     (LargeInteger digitBytes:#[16r12 16r34 16r56 16r78 16r90]) hexPrintString
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   240
    "
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   241
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   242
    "Modified: / 8.5.1998 / 21:40:41 / cg"
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   243
!
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   244
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   245
digitBytes:aByteArrayOfDigits MSB:msb
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   246
    "create and return a new LargeInteger with digits (which may be in either msb/lsb order)
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   247
     from the argument, aByteArray."
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   248
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   249
    |digits|
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   250
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   251
    msb == false ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   252
	digits := aByteArrayOfDigits
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   253
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   254
	digits := aByteArrayOfDigits copy reverse
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   255
    ].
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   256
    ^ self basicNew setDigits:digits
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   257
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   258
    "
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   259
     (LargeInteger digitBytes:#[16r10 16r20 16r30 16r00] MSB:false) hexPrintString  
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   260
     (LargeInteger digitBytes:#[16r10 16r20 16r30 16r00] MSB:true) hexPrintString   
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   261
    "
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   262
!
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   263
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
new
4299
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   265
    "catch creation message.
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   266
     LargeIntegers are only created by system code, which 
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   267
     uses basicNew and cares for correct initialization."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   268
a27a279701f8 Initial revision
claus
parents:
diff changeset
   269
    self error:'LargeIntegers cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   271
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   272
new:numberOfDigits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   273
    "catch creation message"
2
claus
parents: 1
diff changeset
   274
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   275
    self error:'LargeIntegers cannot be created with new'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   277
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   278
value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   279
    "create and return a new LargeInteger with value taken from
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   280
     the argument, aSmallInteger.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   281
     Notice: 
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   282
	this should be only used internally, since such small
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   283
	largeIntegers do not normally occur in the system.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   284
	(They are used by myself)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   285
     May change/be removed without notice."
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   286
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
    ^ self basicNew value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   289
    "LargeInteger value:3689"
3438
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   290
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   291
    "Modified: / 8.5.1998 / 21:40:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   292
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   294
!LargeInteger class methodsFor:'queries'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   297
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   298
     Here, true is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   301
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   302
    "Modified: 23.4.1996 / 15:59:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   303
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   304
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   305
!LargeInteger methodsFor:'arithmetic'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   306
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   309
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   310
    |otherSign numberClass|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
    (sign == 0) ifTrue:[^ 0].  "cannot happen if correctly normalized"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   314
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
     this is the common case, multiplying with SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   316
     Use a special method for this case ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   318
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   319
	^ self productFromInteger:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
     if the argument is not a largeInteger, coerce
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   325
    (numberClass == self class) ifFalse:[
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   326
	^ self retry:#* coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   327
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   328
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   329
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
    (sign == otherSign) ifTrue:[^ self absMul:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   331
    (otherSign == 0) ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   332
    ^ (self absMul:aNumber) sign:-1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   333
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   334
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   335
+ aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   336
    "return the sum of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   337
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   338
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   339
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   340
    (sign == 0) ifTrue:[^ aNumber].  "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   341
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   342
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   343
     this is the common case, adding a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   344
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   345
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   346
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   347
	^ self sumFromInteger:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   348
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   349
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   350
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   351
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   352
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   353
    (numberClass == self class) ifFalse:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   354
	^ self retry:#+ coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   355
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   356
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   357
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   358
    (sign > 0) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   359
	"I am positive"
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   360
	(otherSign > 0) ifTrue:[^ self absPlus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   361
	(otherSign < 0) ifTrue:[^ self absMinus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   362
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   363
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   364
    "I am negative"
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
   365
    (otherSign > 0) ifTrue:[^ aNumber absMinus:self sign:1].
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
   366
    (otherSign < 0) ifTrue:[^ self absPlus:aNumber sign:-1].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   367
    ^ self
357
claus
parents: 345
diff changeset
   368
claus
parents: 345
diff changeset
   369
    "
claus
parents: 345
diff changeset
   370
     SmallInteger maxVal 
claus
parents: 345
diff changeset
   371
     SmallInteger maxVal + 1  
claus
parents: 345
diff changeset
   372
     SmallInteger maxVal + 2 
claus
parents: 345
diff changeset
   373
     SmallInteger minVal    
claus
parents: 345
diff changeset
   374
     SmallInteger minVal - 1
claus
parents: 345
diff changeset
   375
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   376
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   377
    "Modified: / 9.1.1998 / 13:26:28 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   378
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   379
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   380
- aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   381
    "return the difference of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   382
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   383
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   384
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   385
    (sign == 0) ifTrue:[^ aNumber negated].     "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   386
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   387
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   388
     this is the common case, subtracting a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   389
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   390
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   391
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   392
	sign > 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   393
	    aNumber > 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   394
		^ self absFastMinus:aNumber sign:1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   395
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   396
	    ^ self absFastPlus:aNumber sign:1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   397
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   398
	aNumber > 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   399
	    ^ self absFastPlus:aNumber sign:-1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   400
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   401
	^ self absFastMinus:aNumber sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   402
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   403
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   404
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   405
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   406
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   407
    (numberClass == self class) ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   408
	^ self retry:#- coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   409
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   410
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   411
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   412
    (sign > 0) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   413
	"I am positive"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   414
	(otherSign > 0) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   415
	    "+large - +large"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   416
	    ^ self absMinus:aNumber sign:1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   417
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   418
	(otherSign < 0) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   419
	    "+large - -large"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   420
	    ^ self absPlus:aNumber sign:1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   421
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   422
	"should not happen"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   423
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   424
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   425
    "I am negative"
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   426
    (otherSign > 0) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   427
	"-large - +large"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   428
	^ self absPlus:aNumber sign:-1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   429
    ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   430
    (otherSign < 0) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   431
	"-large - -large"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   432
	^ self absMinus:aNumber sign:-1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   433
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   434
    ^ self
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   435
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   436
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   437
     12345678901234567890 - 0     
357
claus
parents: 345
diff changeset
   438
     12345678901234567890 - 1      
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   439
     12345678901234567890 - -1    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   440
     -12345678901234567890 - 1     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   441
     -12345678901234567890 - -1    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   442
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   443
     12345678901234567890 - 12345678901234567880     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   444
     12345678901234567890 - 12345000000000000000     
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   445
     12345678901234567890 - -87654321098765432110    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   446
     -12345678901234567890 - 87654321098765432110    
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   447
     -12345678901234567890 - -12345678901234567880   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   448
     -12345678901234567890 - -12345678901234567980   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   449
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   450
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   451
    "Modified: 20.10.1996 / 18:42:16 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   452
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   453
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   454
/ aNumber
1065
77b25fb9f9d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   455
    "return the quotient of the receiver and the argument, aNumber"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   456
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   457
    aNumber isInteger ifTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   458
	^ Fraction numerator:self
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   459
		  denominator:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   460
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   461
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   462
    "this is a q&d hack - we loose lots of precision here ..."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   463
    ^ (self asFloat / aNumber asFloat)
2793
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   464
e40dedf51177 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2788
diff changeset
   465
    "Modified: 28.7.1997 / 19:07:55 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   466
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   467
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   468
// aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   469
    "return the quotient of the receiver and the argument, aNumber.
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   470
     The result is truncated toward negative infinity and negative,
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   471
     if the operands signs differ.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   472
     The following is always true:
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   473
	(receiver // aNumber) * aNumber + (receiver \\ aNUmber) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   474
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   475
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   476
    |cls divMod quo abs "{ Class: SmallInteger }" n|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   477
5382
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
   478
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   479
    cls := aNumber class.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   480
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   481
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   482
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   483
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   484
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   485
    (cls == SmallInteger) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   486
	abs := aNumber.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   487
	abs := abs abs.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   488
	(abs between:1 and:16r00ffffff) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   489
	    divMod := self absFastDivMod:abs.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   490
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   491
	    n := abs asLargeInteger.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   492
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   493
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   494
	"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   495
	 if the argument is not a largeInteger, coerce
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   496
	"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   497
	(cls == self class) ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   498
	    ^ self retry:#// coercing:aNumber
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   499
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   500
	n := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   501
    ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   502
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   503
    divMod isNil ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   504
	divMod := self absDivMod:n.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   505
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   506
    quo := divMod at:1.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   507
    (sign == aNumber sign) ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   508
	"/ adjust for truncation if negative and there is a remainder ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   509
	quo := quo sign:-1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   510
	(divMod at:2) == 0 ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   511
	    ^ quo - 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   512
	].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   513
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   514
    ^ quo
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   515
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   516
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   517
     (9000000000 // 4000000000)   =   (900 // 400)   ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   518
     (-9000000000 // 4000000000)  =   (-900 // 400)  ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   519
     (9000000000 // -4000000000)  =   (900 // -400)  ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   520
     (-9000000000 // -4000000000) =   (-900 // -400) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   521
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   522
     16rfffffffff // 16r01ffffff  =   2048 ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   523
     16rfffffffff // 16r00ffffff  =   4096 ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   524
     16rfffffffff // 16r001fffff  =  32768 ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   525
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   526
     900 quo: 400   
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   527
     -900 quo: 400                   
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   528
     900 quo: -400                   
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   529
     -900 quo: -400 
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   530
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   531
     9000000000 quo: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   532
     -9000000000 quo: 4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   533
     9000000000 quo: -4000000000  
5382
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
   534
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
   535
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
   536
     0 // 40000000000000000        
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   537
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   538
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   539
    "Modified: / 5.11.1996 / 16:39:36 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   540
    "Modified: / 27.4.1999 / 19:50:26 / stefan"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   541
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   542
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   543
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   544
    "Answer the integer remainder m defined by division with truncation toward
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   545
     negative infinity. The remainder has the same sign as aNumber.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   546
     m < |aNumber| AND there is an integer k with (k * aNumber + m) = self
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   547
     The following is always true:
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   548
	(receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   549
     Compare with #rem:"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   550
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   551
    |abs rem negativeDivisor|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   552
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   553
    aNumber negative ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   554
	negativeDivisor := true.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   555
	abs := aNumber negated.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   556
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   557
	negativeDivisor := false.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   558
	abs := aNumber.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   559
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   560
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   561
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   562
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   563
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   564
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   565
    (aNumber class == SmallInteger) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   566
	(abs between:1 and:16r00ffffff) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   567
	    rem := (self absFastDivMod:abs) at:2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   568
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   569
	    rem := self absMod:abs asLargeInteger
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   570
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   571
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   572
	"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   573
	 if the argument is not a largeInteger, coerce
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   574
	"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   575
	(aNumber class == self class) ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   576
	    ^ self retry:#\\ coercing:aNumber
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   577
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   578
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   579
	rem := self absMod:abs.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   580
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   581
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   582
    rem = 0 ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   583
	negativeDivisor ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   584
	    rem := rem sign:-1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   585
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   586
	(self negative ~~ negativeDivisor) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   587
	    "different sign, so remainder would have been negative.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   588
	     rem has been rounded toward zero, this code will simulate
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   589
	     rounding to negative infinity."
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   590
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   591
	    rem := aNumber - rem.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   592
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   593
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   594
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   595
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   596
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   597
     (9000000000 \\ 4000000000)   = (900 \\ 400 * 10000000)  ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   598
     (-9000000000 \\ 4000000000)  = (-900 \\ 400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   599
     (9000000000 \\ -4000000000)  = (900 \\ -400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   600
     (-9000000000 \\ -4000000000) = (-900 \\ -400 * 10000000)ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   601
     (16000000000 \\ 4000000000)  = (1600 \\ 400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   602
     (-16000000000 \\ 4000000000)  = (-1600 \\ 400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   603
     (16000000000 \\ -4000000000)  = (1600 \\ -400 * 10000000) ifFalse:[self halt].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   604
     (-16000000000 \\ -4000000000)  = (-1600 \\ -400 * 10000000) ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   605
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   606
     9000000000 \\ 7      
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   607
     -9000000000 \\ 7     
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   608
     9000000000 \\ -7     
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   609
     -9000000000 \\ -7    
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
   610
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   611
     900 rem: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   612
     -900 rem: 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   613
     900 rem: -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   614
     -900 rem: -400               
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   615
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   616
     9000000000 rem: 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   617
     -9000000000 rem: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   618
     9000000000 rem: -4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   619
     -9000000000 rem: -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   620
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   621
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   622
    "Modified: / 5.11.1996 / 17:10:10 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   623
    "Modified: / 27.4.1999 / 20:03:40 / stefan"
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   624
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   625
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   626
abs
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   627
    "return my absolute value. redefined for speed."
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   628
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   629
    sign >= 0 ifTrue:[^ self].
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   630
    ^ self negated
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   631
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   632
    "Created: / 26.10.1999 / 21:28:06 / stefan"
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   633
!
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   634
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   635
divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   636
    "return an array filled with self // aNumber and
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   637
     self \\ aNumber.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   638
     The result is only defined for positive receiver and
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   639
     argument."
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   640
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   641
    |cls n|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   642
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   643
    cls := aNumber class.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   644
    (cls == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   645
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   646
	 this is the common case, dividing by a SmallInteger.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   647
	 Use a special method for this case ...
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   648
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   649
	(aNumber between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   650
	    ^ self absFastDivMod:aNumber abs.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   651
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   652
	n := aNumber asLargeInteger.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   653
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   654
	(cls == self class) ifFalse:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   655
	    ^ super divMod:aNumber            
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   656
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   657
	n := aNumber.
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   658
    ].
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   659
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   660
    ^ self absDivMod:n abs
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   661
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   662
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   663
     9000000000 // 4000000000   => 2
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   664
     9000000000 \\ 4000000000   => 1000000000 
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   665
     9000000000 divMod: 4000000000   => #(2 1000000000)
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   666
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   667
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   668
    "Created: / 29.10.1996 / 21:22:05 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   669
    "Modified: / 27.4.1999 / 19:48:58 / stefan"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   670
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   671
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   672
negated
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   673
    "return an integer with value negated from the receivers value."
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   674
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   675
    |newNumber sz|
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   676
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   677
    (sign == 0) ifTrue:[^ 0].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   678
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   679
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   680
     special case for SmallInteger minVal
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   681
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   682
    sign == 1 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   683
	sz := digitByteArray size.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   684
%{
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   685
	int idx;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   686
	unsigned char *bp;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   687
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   688
	bp = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   689
	idx = __intVal(sz);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   690
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   691
	while ((idx > 1) && (bp[idx-1] == 0)) idx--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   692
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   693
	if (idx == sizeof(INT)) {
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   694
#if defined(alpha64)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   695
	    if ( ((unsigned INT *)bp)[0] == 0x4000000000000000L)
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   696
#else
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
   697
# if defined(__LSBFIRST)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   698
	    if ( ((unsigned INT *)bp)[0] == 0x40000000)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   699
# else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   700
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   701
	     * generic code
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   702
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   703
	    if ((bp[idx-1] == 0x40)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   704
	     && (bp[idx-2] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   705
	     && (bp[idx-3] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   706
	     && (bp[idx-4] == 0)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   707
#  ifdef alpha64
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   708
	     && (bp[idx-5] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   709
	     && (bp[idx-6] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   710
	     && (bp[idx-7] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   711
	     && (bp[idx-8] == 0)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   712
#  endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   713
	    ) 
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   714
# endif
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   715
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   716
	    {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   717
		RETURN (__MKSMALLINT(_MIN_INT));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   718
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   719
	}
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   720
%}.
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   721
"/      sz == 4 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   722
"/        (digitByteArray at:1) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   723
"/          (digitByteArray at:2) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   724
"/            (digitByteArray at:3) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   725
"/              (digitByteArray at:4) == 16r40 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   726
"/                ^ SmallInteger minVal
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   727
"/              ].
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   728
"/            ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   729
"/          ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   730
"/        ]
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   731
"/      ]
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   732
    ].
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
   733
    "/ cg - can share the digits ...
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
   734
    newNumber := LargeInteger digitBytes:digitByteArray.
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   735
    newNumber sign:(sign negated).
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   736
    ^ newNumber
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   737
!
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   738
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   739
quo:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   740
    "return the quotient of the receiver and the argument, aNumber.
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   741
     The result is truncated toward zero (which is different from //, which
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   742
     truncates toward negative infinity).
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   743
     The results sign is negative if the receiver has a sign
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   744
     different from the args sign.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   745
     The following is always true:
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   746
	(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   747
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   748
2521
43b9d4fafb35 removed unused locals
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   749
    |otherSign quo abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   750
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   751
    otherSign := aNumber sign.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   752
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   753
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   754
     this is the common case, dividing by a SmallInteger.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   755
     Use a special method for this case ...
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   756
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   757
    (aNumber class == SmallInteger) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   758
	abs := aNumber.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   759
	abs := abs abs.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   760
	(abs between:1 and:16r00ffffff) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   761
	    quo := (self absFastDivMod:abs) at:1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   762
	    (sign == otherSign) ifTrue:[^ quo].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   763
	    ^ quo sign:-1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   764
	]
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   765
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   766
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   767
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   768
     if the argument is not a largeInteger, coerce
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   769
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   770
    (aNumber class == self class) ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   771
	^ self retry:#quo: coercing:aNumber
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   772
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   773
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   774
    sign < 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   775
	(sign == otherSign) ifTrue:[^ (self absDivMod:aNumber negated) at:1].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   776
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   777
	(sign == otherSign) ifTrue:[^ (self absDivMod:aNumber) at:1].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   778
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   779
    ^ ((self absDivMod:aNumber) at:1) sign:-1
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   780
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   781
    "
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   782
     900 // 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   783
     -900 // 400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   784
     900 // -400 
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   785
     -900 // -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   786
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   787
     9000000000 // 4000000000     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   788
     -9000000000 // 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   789
     9000000000 // -4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   790
     -9000000000 // -4000000000   
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   791
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   792
     900 quo: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   793
     -900 quo: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   794
     900 quo: -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   795
     -900 quo: -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   796
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   797
     9000000000 quo: 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   798
     -9000000000 quo: 4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   799
     9000000000 quo: -4000000000  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   800
     -9000000000 quo: -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   801
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   802
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   803
    "Modified: / 5.11.1996 / 14:14:17 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   804
    "Modified: / 27.4.1999 / 20:01:22 / stefan"
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   805
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   806
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   807
rem:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   808
    "return the remainder of division of the receiver by the argument, aNumber.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   809
     The returned remainder has the same sign as the receiver.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   810
     The following is always true:
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   811
	(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   812
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   813
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   814
    |rem abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   815
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   816
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   817
     this is the common case, dividing by a SmallInteger.
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   818
     Use special code for this case ...
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   819
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   820
    (aNumber class == SmallInteger) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   821
	abs := aNumber.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   822
	abs := abs abs.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   823
	(abs between:1 and:16r00ffffff) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   824
	    rem := (self absFastDivMod:abs) at:2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   825
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   826
	    rem := self absMod:abs asLargeInteger
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   827
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   828
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   829
	"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   830
	 if the argument is not a largeInteger, coerce
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   831
	"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   832
	(aNumber class == self class) ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   833
	    ^ self retry:#rem coercing:aNumber
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   834
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   835
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   836
	rem := self absMod:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   837
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   838
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   839
    sign < 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   840
	^ rem sign:-1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   841
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   842
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   843
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   844
    "
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   845
     900 \\ 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   846
     -900 \\ 400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   847
     900 \\ -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   848
     -900 \\ -400  
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   849
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   850
     9000000000 \\ 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   851
     -9000000000 \\ 4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   852
     9000000000 \\ -4000000000   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   853
     -9000000000 \\ -4000000000  
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   854
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   855
     900 rem: 400     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   856
     -900 rem: 400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   857
     900 rem: -400    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   858
     -900 rem: -400   
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   859
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   860
     9000000000 rem: 4000000000     
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   861
     -9000000000 rem: 4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   862
     9000000000 rem: -4000000000    
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   863
     -9000000000 rem: -4000000000   
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   864
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   865
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   866
    "Modified: / 5.11.1996 / 14:02:59 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   867
    "Modified: / 29.4.1999 / 11:26:51 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   868
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   869
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   870
!LargeInteger methodsFor:'bit operators'!
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   871
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   872
bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   873
    "return the bitwise-and of the receiver and the argument, anInteger"
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   874
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   875
%{  /* NOCONTEXT */
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   876
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   877
    if (__isSmallInteger(anInteger)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   878
	INT v2 = __intVal(anInteger);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   879
	INT v1;
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   880
#if defined(__LSBFIRST) || defined(i386)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   881
	v1 = *(INT *)(__stringVal(__INST(digitByteArray)));
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   882
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   883
	unsigned char *digits = (unsigned char *)(__stringVal(__INST(digitByteArray)));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   884
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   885
	v1 = digits[0] & 0xFF;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   886
	v1 = v1 | ((digits[1] & 0xFF)<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   887
	v1 = v1 | ((digits[2] & 0xFF)<<16);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   888
	v1 = v1 | ((digits[3] & 0xFF)<<24);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   889
	if (sizeof(unsigned INT) == 8) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   890
	    v1 = v1 | ((digits[4] & 0xFF)<<32);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   891
	    v1 = v1 | ((digits[5] & 0xFF)<<40);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   892
	    v1 = v1 | ((digits[6] & 0xFF)<<48);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   893
	    v1 = v1 | ((digits[7] & 0xFF)<<56);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   894
	}
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   895
#endif
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   896
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   897
	RETURN ( __MKSMALLINT(v1 & v2) );
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   898
    }
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   899
%}.
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   900
    ^ super bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   901
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   902
    "
6051
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   903
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFF) hexPrintString
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   904
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFF) hexPrintString  
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   905
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFF) hexPrintString   
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   906
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFF) hexPrintString  
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   907
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFF) hexPrintString       
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   908
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFF) hexPrintString     
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   909
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFFFF) hexPrintString   
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   910
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFFFFFF) hexPrintString   
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   911
    "
6051
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   912
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
   913
    "Modified: / 26.9.2001 / 17:34:03 / cg"
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   914
!
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   915
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   916
bitAt:anIntegerIndex
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   917
    "return the value of the index's bit (index starts at 1).
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   918
     Notice: the result of bitAt: on negative receivers is not 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   919
             defined in the language standard (since the implementation
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   920
             is free to choose any internal representation for integers)"
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   921
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   922
%{  /* NOCONTEXT */
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   923
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   924
    if (__isSmallInteger(anIntegerIndex)) {
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   925
        INT idx = __smallIntegerVal(anIntegerIndex) - 1;
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   926
        if (idx >= 0) {
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   927
            int v1;
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   928
            int byteOffset = idx / 8;
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   929
            int digitLen   = __stringSize(__INST(digitByteArray));
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   930
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   931
            if (digitLen < byteOffset) {
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   932
                RETURN(__mkSmallInteger(0));
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   933
            }
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   934
        
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   935
            v1 = ((unsigned char *)(__stringVal(__INST(digitByteArray))))[byteOffset];
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   936
            if (v1 & (1 << (idx % 8))) {
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   937
                RETURN(__mkSmallInteger(1));
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   938
            } else {
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   939
                RETURN(__mkSmallInteger(0));
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   940
            }
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   941
        }
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   942
    }
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   943
%}.
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   944
    ^ super bitAt:anIntegerIndex
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   945
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   946
    "
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   947
     16rFFFFFFFFFF01 bitAt:0 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   948
     16rFFFFFFFFFF01 bitAt:49 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   949
     16rFFFFFFFFFF01 bitAt:1 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   950
     16rFFFFFFFFFF01 bitAt:2 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   951
     16rFFFFFFFFFF02 bitAt:2 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   952
     16rFFFFFFFF01FF bitAt:8 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   953
     16rFFFFFFFF01FF bitAt:9 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   954
     16rFFFFFFFF01FF bitAt:10 
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   955
    "
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   956
!
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
   957
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   958
bitXor:anInteger
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   959
    "return the bitwise-or of the receiver and the argument, anInteger.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   960
     Here, a specially tuned version for largeInteger arguments 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   961
     (to speed up some cryptographic code)"
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   962
5958
ccf9a786af36 unused variables in bitXor:
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   963
    |len1 len2 
ccf9a786af36 unused variables in bitXor:
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   964
     "/ n "{ Class: SmallInteger }"
ccf9a786af36 unused variables in bitXor:
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   965
     "/ result byte 
ccf9a786af36 unused variables in bitXor:
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   966
     newBytes|
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   967
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   968
    anInteger class ~~ LargeInteger ifTrue:[^ super bitXor:anInteger].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   969
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   970
    (len1 := anInteger digitLength) > (len2 := self digitLength) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   971
	newBytes := anInteger digits copy.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   972
	newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1 
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   973
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   974
	newBytes := digitByteArray copy.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   975
	newBytes bitXorBytesFrom:1 to:len1 with:anInteger digits startingAt:1 
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   976
    ].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   977
    ^ (LargeInteger digitBytes:newBytes) compressed
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   978
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   979
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   980
     (16r112233445566778899 bitXor:16rFF                ) printStringRadix:16 '112233445566778866' 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   981
     (16r112233445566778899 bitXor:16rFFFFFFFFFFFFFFFF00) printStringRadix:16 'EEDDCCBBAA99887799'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   982
     (16r112233445566778899 bitXor:16rFF0000000000000000) printStringRadix:16 'EE2233445566778899'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   983
     (16r112233445566778899 bitXor:16r112233445566778800) printStringRadix:16 '99' 
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   984
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   985
     |bigNum1 bigNum2|
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   986
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   987
     bigNum1 := 2 raisedToInteger:512.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   988
     bigNum2 := 2 raisedToInteger:510.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   989
     Time millisecondsToRun:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   990
	1000000 timesRepeat:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   991
	   bigNum1 bitXor:bigNum2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   992
	]
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   993
     ]      
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   994
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   995
!
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
   996
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   997
lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   998
    "return the bitIndex of the lowest bit set. The returned bitIndex
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
   999
     starts at 1 for the least significant bit. 
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1000
     Returns 0 if no bit is set.
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1001
     For negative numbers, the low bit of my absolute value is returned.
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1002
     Redefined here for more performance of the gcd: algorithm, which
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1003
     is used when big fractions are reduced (should we write a primitive for this ?)."
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1004
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1005
    |sz   "{ Class: SmallInteger }"
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1006
     idx0 "{ Class: SmallInteger }"
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1007
     byte|
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1008
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1009
    sz := digitByteArray size.
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1010
    idx0 := 1.
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1011
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1012
%{
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1013
#if 1
7544
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1014
    /*
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1015
     * quickly advance over full 0-words
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1016
     */
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1017
    if (__isByteArray(__INST(digitByteArray))) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1018
        int __sz = __intVal(sz);
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1019
        unsigned char *__bP = (unsigned char *)(__byteArrayVal(__INST(digitByteArray)));
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1020
        unsigned char *__bP0 = __bP;
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1021
7481
dd6cc10d5d2d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7479
diff changeset
  1022
        while (__sz > (sizeof(INT) * 4)) {
dd6cc10d5d2d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7479
diff changeset
  1023
            if ( ( ((INT *)__bP)[0] 
dd6cc10d5d2d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7479
diff changeset
  1024
                 & ((INT *)__bP)[1] 
dd6cc10d5d2d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7479
diff changeset
  1025
                 & ((INT *)__bP)[2] 
dd6cc10d5d2d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7479
diff changeset
  1026
                 & ((INT *)__bP)[3]) != 0 ) break;
dd6cc10d5d2d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7479
diff changeset
  1027
            __sz -= sizeof(INT)*4;
dd6cc10d5d2d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7479
diff changeset
  1028
            __bP += sizeof(INT)*4;
dd6cc10d5d2d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7479
diff changeset
  1029
        }
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1030
        while (__sz > sizeof(INT)) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1031
            if ( ((INT *)__bP)[0] != 0 ) break;
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1032
            __sz -= sizeof(INT);
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1033
            __bP += sizeof(INT);
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1034
        }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1035
        while (__sz > 0) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1036
            int c;
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1037
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1038
            if ( (c = *__bP) != 0 ) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1039
                int bitIdx = (__bP - __bP0) * 8;
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1040
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1041
                if (c & 0x0F) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1042
                    if (c & 0x03) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1043
                        if (c & 0x01) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1044
                            RETURN ( __MKSMALLINT( bitIdx + 1) );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1045
                        } else {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1046
                            RETURN ( __MKSMALLINT( bitIdx + 2) );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1047
                        }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1048
                    } else {
7479
Claus Gittinger <cg@exept.de>
parents: 7478
diff changeset
  1049
                        if (c & 0x04) {
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1050
                            RETURN ( __MKSMALLINT( bitIdx + 3) );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1051
                        } else {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1052
                            RETURN ( __MKSMALLINT( bitIdx + 4) );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1053
                        }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1054
                    }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1055
                } else {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1056
                    if (c & 0x30) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1057
                        if (c & 0x10) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1058
                            RETURN ( __MKSMALLINT( bitIdx + 5) );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1059
                        } else {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1060
                            RETURN ( __MKSMALLINT( bitIdx + 6) );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1061
                        }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1062
                    } else {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1063
                        if (c & 0x40) {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1064
                            RETURN ( __MKSMALLINT( bitIdx + 7) );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1065
                        } else {
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1066
                            RETURN ( __MKSMALLINT( bitIdx + 8) );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1067
                        }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1068
                    }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1069
                }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1070
                break;
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1071
            }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1072
            __sz--;
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1073
            __bP++;
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1074
        }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1075
        idx0 = __MKSMALLINT( __bP - __bP0 + 1 );
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1076
    }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1077
#endif
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1078
%}.
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1079
    idx0 to:sz do:[:digitIndex |
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1080
        (byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1081
            ^ (digitIndex-1)*8 + (byte lowBit)
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1082
        ]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1083
    ].
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1084
    ^ 0 "/ should not happen
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1085
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1086
    "
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1087
     (1 bitShift:30) lowBit   
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1088
     (1 bitShift:30) highBit     
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1089
     (1 bitShift:31) lowBit      
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1090
     (1 bitShift:31) highBit    
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1091
     (1 bitShift:32) lowBit   
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1092
     (1 bitShift:32) highBit  
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1093
     (1 bitShift:33) lowBit    
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1094
     (1 bitShift:33) highBit   
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1095
     (1 bitShift:64) lowBit    
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1096
     (1 bitShift:64) highBit   
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1097
     (1 bitShift:1000) lowBit  
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1098
     (1 bitShift:1000) highBit 
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1099
     ((1 bitShift:64)-1) lowBit 
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1100
     ((1 bitShift:64)-1) highBit 
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1101
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1102
     1 to:1000 do:[:idx |
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1103
        self assert:(( 1 bitShift:idx) lowBit = (idx+1)).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1104
        self assert:(( 1 bitShift:idx) lowBit = ( 1 bitShift:idx) highBit).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1105
        self assert:(( 3 bitShift:idx) lowBit = (idx+1)).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1106
        self assert:(( 7 bitShift:idx) lowBit = (idx+1)).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1107
        self assert:(( 15 bitShift:idx) lowBit = (idx+1)).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1108
        self assert:(( 31 bitShift:idx) lowBit = (idx+1)).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1109
        self assert:(( 63 bitShift:idx) lowBit = (idx+1)).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1110
        self assert:(( 127 bitShift:idx) lowBit = (idx+1)).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1111
        self assert:(( 255 bitShift:idx) lowBit = (idx+1)).
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1112
     ]    
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1113
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1114
     |num|
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1115
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1116
     num := (1 bitShift:1000).
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1117
     Time millisecondsToRun:[
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1118
        100000 timesRepeat:[
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1119
            num lowBit
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1120
        ]
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1121
     ]     
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1122
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1123
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1124
    "Modified: 14.8.1997 / 11:55:34 / cg"
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1125
! !
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1126
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1127
!LargeInteger methodsFor:'byte access'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1128
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1129
digitAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1130
    "return 8 bits of value, starting at byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1131
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1132
    index > digitByteArray size ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1133
    ^ digitByteArray at:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1134
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1135
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1136
digitAt:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1137
    "set the 8 bits, index is a byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1138
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1139
    digitByteArray at:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1140
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1141
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1142
digitByteAt:index
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1143
    "return 8 bits of my signed value, starting at byte index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1144
     For positive receivers, this is the same as #digitAt:;
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1145
     for negative ones, the actual bit representation is returned."
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1146
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1147
    |t digits|
6359
fcb206734265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6106
diff changeset
  1148
    sign >= 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1149
	index > digitByteArray size ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1150
	    ^ 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1151
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1152
	^ digitByteArray at:index.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1153
    ].
6359
fcb206734265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6106
diff changeset
  1154
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1155
    "/ negative int - do 2's complement here
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1156
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1157
    t := self bitInvert + 1.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1158
    t sign:1.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1159
    digits := t digitBytes.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1160
    index > digits size ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1161
	^ 16rFF
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1162
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1163
    ^ digits at:index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1164
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1165
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1166
     16r11111111111111111111 negated digitByteAt:1
5382
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
  1167
     0 asLargeInteger digitByteAt:1 
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1168
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1169
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1170
    "Created: / 25.10.1998 / 14:12:21 / cg"
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1171
!
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1172
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1173
digitBytes
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1174
    "return a byteArray filled with the receivers bits
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1175
     (8 bits of the absolute value per element).
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1176
     Least significant byte is first!!"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1177
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1178
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1179
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1180
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1181
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1182
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1183
digitBytesMSB:msbFlag
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1184
    "return a byteArray filled with the receivers bits
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1185
     (8 bits of the absolute value per element),
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1186
     if msbflag = true, most significant byte is first,
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1187
     otherwise least significant byte is first"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1188
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1189
    msbFlag ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1190
	^ digitByteArray copyReverse.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1191
    ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1192
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1193
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1194
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1195
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1196
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1197
digitLength
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1198
    "return the number bytes used by this Integer.
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1199
     For negative receivers, the digitLength of its absolute value
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1200
     is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1201
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1202
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1203
     check if there is a 0-byte ...
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1204
     this allows to ask unnormalized LargeIntegers 
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1205
     for their digitLength
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1206
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1207
    |l "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1208
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1209
    l := digitByteArray size.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1210
    [l ~~ 0 and:[(digitByteArray at:l) == 0]] whileTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1211
	l := l - 1.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1212
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1213
    ^ l
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1214
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1215
    "Modified: 31.7.1997 / 13:18:28 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1216
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1217
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1218
digits
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1219
    "obsolete, use #digitBytes"
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1220
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1221
    <resource:#obsolete>
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1222
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1223
    ^ digitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1224
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1225
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1226
!LargeInteger methodsFor:'coercing & converting'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1227
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1228
asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1229
    "return a LargeInteger with same value as myself - thats me"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1230
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1231
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1232
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1233
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1234
asSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1235
    "return a SmallInteger with same value as myself - 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1236
     the result is invalid if the receivers value cannot 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1237
     be represented as a SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1238
     Q: should we raise an exception if this happens ?"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1239
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1240
    |value|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1241
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1242
    value := 0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1243
    (sign == 0) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1244
	digitByteArray reverseDo:[:aDigit |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1245
	    value := (value times:256) + aDigit 
345
claus
parents: 250
diff changeset
  1246
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1247
	(sign < 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1248
	    value := value negated
345
claus
parents: 250
diff changeset
  1249
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1250
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1251
    ^ value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1252
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1253
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1254
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1255
    "return the argument as a LargeInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1256
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1257
    ^ aNumber asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1258
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1259
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1260
compressed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1261
    "if the receiver can be represented as a SmallInteger, return
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1262
     a SmallInteger with my value; 
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1263
     otherwise remove leading zero bytes in the digitByte array
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1264
     and return the receiver"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1265
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1266
    |index "{ Class: SmallInteger }" 
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1267
     val   "{ Class: SmallInteger }" 
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1268
     index0
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1269
    |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1270
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1271
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1272
    OBJ t;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1273
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1274
    if (__INST(sign) == __MKSMALLINT(0)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1275
	RETURN (__MKSMALLINT(0));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1276
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1277
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1278
    t = __INST(digitByteArray);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1279
    if (__isByteArray(t)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1280
	unsigned char *__digitBytes = __ByteArrayInstPtr(t)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1281
	int _idx, _idx0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1282
	INT _val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1283
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1284
	_idx = _idx0 = __byteArraySize(t);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1285
	while ((_idx > 0) && (__digitBytes[_idx - 1] == 0)) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1286
	    _idx--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1287
	}
2788
e4436755d153 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2786
diff changeset
  1288
#ifdef alpha64
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1289
	switch (_idx) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1290
	    case 8:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1291
		_val = __digitBytes[7];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1292
		if (_val <= 0x40) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1293
		    _val = (_val<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1294
		    _val = (_val + __digitBytes[6]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1295
		    _val = (_val + __digitBytes[5]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1296
		    _val = (_val + __digitBytes[4]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1297
		    _val = (_val + __digitBytes[3]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1298
		    _val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1299
		    _val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1300
		    _val += __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1301
		    if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1302
			_val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1303
		    if (__ISVALIDINTEGER(_val)) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1304
			RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1305
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1306
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1307
		break;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1308
	    case 7:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1309
		_val = (__digitBytes[6]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1310
		_val = (_val + __digitBytes[5]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1311
		_val = (_val + __digitBytes[4]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1312
		_val = (_val + __digitBytes[3]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1313
		_val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1314
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1315
		_val += __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1316
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1317
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1318
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1319
	    case 6:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1320
		_val = (__digitBytes[5]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1321
		_val = (_val + __digitBytes[4]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1322
		_val = (_val + __digitBytes[3]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1323
		_val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1324
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1325
		_val += __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1326
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1327
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1328
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1329
	    case 5:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1330
		_val = (__digitBytes[4]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1331
		_val = (_val + __digitBytes[3]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1332
		_val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1333
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1334
		_val += __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1335
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1336
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1337
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1338
	    case 4:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1339
		_val = (__digitBytes[3]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1340
		_val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1341
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1342
		_val += __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1343
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1344
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1345
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1346
	    case 3:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1347
		_val = (__digitBytes[2]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1348
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1349
		_val += __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1350
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1351
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1352
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1353
	    case 2:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1354
		_val = (__digitBytes[1]<<8) + __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1355
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1356
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1357
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1358
	    case 1:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1359
		_val = __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1360
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1361
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1362
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1363
	    case 0:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1364
		RETURN (__MKSMALLINT(0));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1365
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1366
	}
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1367
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1368
	if (_idx <= 4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1369
	    if (_idx <= 2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1370
		if (_idx == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1371
		    RETURN (__MKSMALLINT(0));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1372
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1373
		if (_idx == 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1374
		    _val = __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1375
		    if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1376
			_val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1377
		    RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1378
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1379
		_val = (__digitBytes[1]<<8) + __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1380
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1381
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1382
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1383
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1384
	    if (_idx == 3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1385
		_val = (((__digitBytes[2]<<8) + __digitBytes[1])<<8) + __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1386
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1387
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1388
		RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1389
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1390
	    _val = __digitBytes[3];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1391
	    if (_val <= 0x40) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1392
		_val = (((((_val<<8) + __digitBytes[2])<<8) + __digitBytes[1])<<8) + __digitBytes[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1393
		if (__INST(sign) == __MKSMALLINT(-1))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1394
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1395
		if (__ISVALIDINTEGER(_val)) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1396
		    RETURN (__MKSMALLINT(_val));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1397
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1398
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1399
	}
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1400
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1401
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1402
	if (_idx == _idx0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1403
	    RETURN (self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1404
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1405
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1406
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1407
	 * must copy & cut off some bytes
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1408
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1409
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1410
	    OBJ newDigits;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1411
	    OBJ oldDigits;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1412
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1413
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1414
	     * careful - there is no context here to protect
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1415
	     * the receiver ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1416
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1417
	    __PROTECT__(self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1418
	    __PROTECT__(__INST(digitByteArray));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1419
	    newDigits = __BYTEARRAY_UNINITIALIZED_NEW_INT(_idx);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1420
	    __UNPROTECT__(oldDigits);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1421
	    __UNPROTECT__(self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1422
	    if (newDigits) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1423
		bcopy(__ByteArrayInstPtr(oldDigits)->ba_element,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1424
		      __ByteArrayInstPtr(newDigits)->ba_element,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1425
		      _idx);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1426
		__INST(digitByteArray) = newDigits; __STORE(self, newDigits);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1427
		RETURN (self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1428
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1429
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1430
	     * allocation failed ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1431
	     * ... fall through to trigger the error
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1432
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1433
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1434
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1435
%}.
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1436
    index0 := index := digitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1437
    [(index > 0) and:[(digitByteArray at:index) == 0]] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1438
	index := index - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1439
    ].
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1440
"/    ((index < SmallInteger maxBytes) 
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1441
"/    or:[(index == SmallInteger maxBytes) 
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1442
"/            and:[(digitByteArray at:index) < 16r20]])
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1443
"/    ifTrue:[
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1444
"/        val := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1445
"/        1 to:index do:[:i |
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1446
"/            val := val bitShift:8.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1447
"/            val := val bitOr:(digitByteArray at:i).
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1448
"/        ].
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1449
"/        ^ val * sign
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1450
"/    ].
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1451
    (index ~~ index0) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1452
	digitByteArray := digitByteArray copyFrom:1 to:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1453
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1454
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1455
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1456
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1457
generality
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1458
    "return the generality value - see ArithmeticValue>>retry:coercing:"
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1459
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1460
    ^ 40
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1461
!
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1462
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1463
value:aSmallInteger
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1464
    "setup my contents to represent the same value as aSmallInteger.
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
  1465
     This method will fail, if the argument is not a smallInteger.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1466
     This should only be used internally, 
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1467
     since it will create an unnormalized LargeInt (by purpose) if asked for."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1468
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1469
    |absValue 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1470
     b1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1471
     b2 "{ Class: SmallInteger }"
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1472
     b3 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1473
     b4 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1474
     b5 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1475
     b6 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1476
     b7 "{ Class: SmallInteger }"|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1477
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1478
    "
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1479
     could have simply created a 4-byte largeinteger and normalize it. 
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1480
     The code below does the normalize right away, avoiding the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1481
     overhead of producing any intermediate byte-arrays (and the scanning)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1482
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1483
    (aSmallInteger == 0) ifTrue: [
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1484
	digitByteArray := ByteArray with:0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1485
	sign := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1486
	^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1487
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1488
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1489
    (aSmallInteger < 0) ifTrue: [
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1490
	sign := -1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1491
	absValue := aSmallInteger negated
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1492
    ] ifFalse: [
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1493
	sign := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1494
	absValue := aSmallInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1495
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1496
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1497
    b1 := absValue bitAnd:16rFF.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1498
    absValue := absValue bitShift:-8.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1499
    absValue == 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1500
	digitByteArray := ByteArray with:b1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1501
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1502
	b2 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1503
	absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1504
	absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1505
	    digitByteArray := ByteArray with:b1 with:b2
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1506
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1507
	    b3 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1508
	    absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1509
	    absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1510
		digitByteArray := ByteArray with:b1 with:b2 with:b3
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1511
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1512
		b4 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1513
		absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1514
		absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1515
		    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1516
		] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1517
		    b5 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1518
		    absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1519
		    absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1520
			digitByteArray := ByteArray new:5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1521
			digitByteArray at:1 put:b1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1522
			digitByteArray at:2 put:b2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1523
			digitByteArray at:3 put:b3.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1524
			digitByteArray at:4 put:b4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1525
			digitByteArray at:5 put:b5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1526
		    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1527
			b6 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1528
			absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1529
			absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1530
			    digitByteArray := ByteArray new:6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1531
			    digitByteArray at:1 put:b1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1532
			    digitByteArray at:2 put:b2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1533
			    digitByteArray at:3 put:b3.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1534
			    digitByteArray at:4 put:b4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1535
			    digitByteArray at:5 put:b5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1536
			    digitByteArray at:6 put:b6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1537
			] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1538
			    b7 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1539
			    absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1540
			    absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1541
				digitByteArray := ByteArray new:7.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1542
				digitByteArray at:1 put:b1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1543
				digitByteArray at:2 put:b2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1544
				digitByteArray at:3 put:b3.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1545
				digitByteArray at:4 put:b4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1546
				digitByteArray at:5 put:b5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1547
				digitByteArray at:6 put:b6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1548
				digitByteArray at:7 put:b7.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1549
			    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1550
				digitByteArray := ByteArray new:8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1551
				digitByteArray at:1 put:b1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1552
				digitByteArray at:2 put:b2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1553
				digitByteArray at:3 put:b3.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1554
				digitByteArray at:4 put:b4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1555
				digitByteArray at:5 put:b5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1556
				digitByteArray at:6 put:b6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1557
				digitByteArray at:7 put:b7.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1558
				digitByteArray at:8 put:absValue.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1559
			    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1560
			]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1561
		    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1562
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1563
	    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1564
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1565
    ]
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1566
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1567
    "Modified: / 26.5.1999 / 22:18:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1568
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1569
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1570
!LargeInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1571
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1572
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1573
    "return true, if the argument, aNumber is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1574
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1575
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1576
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1577
    (aNumber class == self class) ifFalse:[
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1578
        ^ aNumber lessFromInteger:self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1579
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1580
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1581
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1582
    (sign > 0) ifTrue:[
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1583
        "I am positive"
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1584
        (otherSign > 0) ifTrue:[^ self absLess:aNumber].
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1585
        ^ false "aNumber is <= 0"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1586
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1587
    (sign == 0) ifTrue:[
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1588
        (otherSign > 0) ifTrue:[^ true].
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1589
        ^ false
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1590
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1591
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1592
    (otherSign > 0) ifTrue:[^ true].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1593
    (otherSign == 0) ifTrue:[^ true].
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1594
    ^ (aNumber absLess:self)
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1595
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1596
    "Modified: / 31.7.2002 / 10:08:19 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1597
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1598
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1599
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1600
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1601
     as the receiver, false otherwise"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1602
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1603
    "/ speed up compare to 0
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1604
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1605
    (aNumber == 0) ifTrue:[
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1606
        ^ sign == 0
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1607
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1608
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1609
    (aNumber class == self class) ifFalse:[
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1610
        "/
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1611
        "/ here, we depend on the fact, that largeinteger
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1612
        "/ results are always converted to smallInts, if possible.
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1613
        "/ therefore, a largeInt in the smallInt range is not allowed (possible)
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1614
        "/
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1615
        aNumber class == SmallInteger ifTrue:[^ false ].
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1616
        ^ aNumber equalFromInteger:self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1617
    ].
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1618
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1619
    (aNumber sign == sign) ifFalse:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1620
    ^ self absEq:aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1621
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1622
    "Modified: / 13.2.1998 / 11:43:15 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1623
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1624
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1625
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1626
    "return true, if the argument, aNumber is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1627
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1628
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1629
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1630
    (aNumber class == self class) ifFalse:[
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1631
        ^ (aNumber < self)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1632
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1633
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1634
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1635
    (sign > 0) ifTrue:[
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1636
        "I am positive"
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1637
        (otherSign > 0) ifTrue:[^ aNumber absLess:self].
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1638
        ^ true "aNumber is <= 0"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1639
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1640
    (sign == 0) ifTrue:[
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1641
        "I am zero"
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1642
        (otherSign > 0) ifTrue:[^ false].
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1643
        ^ true
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1644
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1645
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1646
    (otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1647
    (otherSign == 0) ifTrue:[^ false].
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1648
    ^ (self absLess:aNumber)
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1649
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1650
    "Modified: / 31.7.2002 / 10:08:59 / cg"
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1651
!
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1652
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1653
hash
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1654
    "return an integer useful for hashing on large numbers"
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1655
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1656
    ^ (self bitAnd:16r3FFFFFFF) + digitByteArray size
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1657
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1658
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1659
!LargeInteger methodsFor:'double dispatching'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1660
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1661
differenceFromInteger:anInteger
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1662
    "sent, when anInteger does not know how to subtract the receiver.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1663
     Return the result of 'anInteger - self'. The argument must be a SmallInteger."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1664
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1665
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1666
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1667
	    ^ self absFastMinus:anInteger sign:-1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1668
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1669
	^ self absFastPlus:anInteger sign:1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1670
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1671
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1672
	^ self negated
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1673
    ].
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1674
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  1675
	^ self absFastPlus:anInteger negated sign:-1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1676
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  1677
    ^ self absFastMinus:anInteger sign:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1678
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1679
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1680
     12345678901234567890          
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1681
     -12345678901234567890         
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1682
     12345678901234567890 differenceFromInteger:0       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1683
     12345678901234567890 differenceFromInteger:1       
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1684
     12345678901234567890 differenceFromInteger:-1      
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1685
     -12345678901234567890 differenceFromInteger:1   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1686
     -12345678901234567890 differenceFromInteger:-1   
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1687
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1688
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  1689
    "Modified: 20.10.1996 / 18:41:54 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1690
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1691
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1692
productFromInteger:anInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1693
    "sent, when anInteger does not know how to multiply the receiver.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1694
     Return the product of the receiver and the argument, aSmallInteger"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1695
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1696
    |num result 
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1697
     resultDigitByteArray
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1698
     val     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1699
     len     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1700
     carry   "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  1701
     prod    "{ Class: SmallInteger }" 
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1702
     ok lResult|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1703
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1704
    "multiplying by a small integer is done here"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1705
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1706
    "trivial cases"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1707
    anInteger == 0 ifTrue:[^ 0].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1708
    anInteger == 1 ifTrue:[^ self].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1709
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1710
    num := anInteger abs.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1711
    (num > 16r3FFFFF) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1712
	"if num is too big (so that multiplying by a byte could create a Large)"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1713
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1714
	^ anInteger retry:#* coercing:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1715
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1716
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1717
    len := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1718
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1719
    val := num.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1720
    val <= 16rFF ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1721
	lResult := len + 1.
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1722
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1723
	val <= 16rFFFF ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1724
	    lResult := len + 2
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1725
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1726
	    val <= 16rFFFFFF ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1727
		lResult := len + 4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1728
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1729
		lResult := len + 6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1730
	    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1731
	]
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1732
    ].
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  1733
    resultDigitByteArray := ByteArray uninitializedNew:lResult.
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2855
diff changeset
  1734
    result := self class basicNew setDigits:resultDigitByteArray.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1735
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1736
    anInteger < 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1737
	sign > 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1738
	    result sign:-1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1739
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1740
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1741
	sign < 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1742
	    result sign:sign
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1743
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1744
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1745
85
claus
parents: 77
diff changeset
  1746
    ok := false.
claus
parents: 77
diff changeset
  1747
%{
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1748
    OBJ __digitByteArray = __INST(digitByteArray);
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1749
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1750
    if (__isSmallInteger(len)
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  1751
     && __isByteArray(__digitByteArray)
85
claus
parents: 77
diff changeset
  1752
     && __isByteArray(resultDigitByteArray)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1753
	INT _l = __intVal(len);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1754
	INT _v = __intVal(val);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1755
	unsigned INT _carry = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1756
	unsigned INT _prod;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1757
	unsigned char *digitP = __ByteArrayInstPtr(__digitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1758
	unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1759
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1760
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1761
	 * skipping zeros does not help much (a few percent) on
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1762
	 * a P5 or other CPUS with a fast multiplier. 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1763
	 * It may make more of a difference on CPUs with slower 0-multiply.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1764
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1765
	while ((_l >= sizeof(INT)) && (((unsigned INT *)digitP)[0] == 0)) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1766
	     ((unsigned long *)resultP)[0] = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1767
	    digitP += sizeof(INT);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1768
	    resultP += sizeof(INT);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1769
	    _l -= sizeof(INT);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1770
	}
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1771
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1772
#if defined(i386) || defined(alpha) /* XXX actually: LSB_FIRST */
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  1773
# if defined (__GNUC__) && defined(i386)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1774
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1775
	 * can do it long-word-wise;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1776
	 * 32*32 -> 64 multiplication
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1777
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1778
	while (_l > 3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1779
	    unsigned __pHi, __pLow;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1780
	    unsigned __digit;
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  1781
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1782
	    /* 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1783
	     * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1784
	     * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1785
	     */
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  1786
	    __digit = ((unsigned long *)digitP)[0];
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1787
	    asm ("mull %3               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1788
		  addl %4,%%eax         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1789
		  adcl $0,%%edx"    
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1790
		    : "=a"  (__pLow),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1791
		      "=d"  (__pHi)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1792
		    : "0"   (__digit),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1793
		      "1"   ((unsigned long)(_v)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1794
		      "rm"  ((unsigned long)(_carry)) );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1795
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1796
	    ((unsigned long *)resultP)[0] = __pLow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1797
	    _carry = __pHi;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1798
	    digitP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1799
	    resultP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1800
	    _l -= 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1801
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1802
# else /* not GNU-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1803
#  if defined (WIN32) && defined(i386)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1804
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1805
	 * can do it long-word-wise;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1806
	 * 32*32 -> 64 multiplication
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1807
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1808
	while (_l > 3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1809
	    unsigned __pLow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1810
	    unsigned digit; 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1811
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1812
	    /* 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1813
	     * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1814
	     * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1815
	     */
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1816
/*
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1817
	    digit = ((unsigned long *)digitP)[0]; 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1818
	    edx::eax = (digit * _v);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1819
	    edx::eax += _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1820
	    ((unsigned long *)resultP)[0] = eax; -- pLow
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1821
	    _carry = edx; -- pHigh
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1822
	    digitP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1823
	    resultP += 4;
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  1824
*/
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1825
	    digit = ((unsigned long *)digitP)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1826
	    asm {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1827
		mov   eax, digit
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1828
		mov   edx, _v
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1829
		mul   edx
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1830
		add   eax, _carry
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1831
		adc   edx, 0 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1832
		mov   __pLow, eax
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1833
		mov   _carry, edx
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1834
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1835
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1836
	    ((unsigned long *)resultP)[0] = __pLow; 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1837
	    digitP += 4; 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1838
	    resultP += 4; 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1839
	    _l -= 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1840
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1841
#  else /* not WIN32-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1842
#   if defined(INT64)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1843
	if (_v <= 0xFFFFFFFFL) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1844
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1845
	     * have a 64bit int type ... good
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1846
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1847
	    UINT64 _prod64;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1848
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1849
	    /* have 64bit ints; can do it int-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1850
	     *
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1851
	     * max: 0xFFFFFFFF * 0xFFFFFFFF -> 0xFFFFFFFE.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1852
	     * + maxCarry (0xFFFFFFFF)  -> 0xFFFFFFFF.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1853
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1854
	    while (_l > 3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1855
		unsigned __t;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1856
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1857
		__t = ((unsigned *)digitP)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1858
		digitP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1859
		_prod64 = (INT64)_v;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1860
		_prod64 *= __t;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1861
		_prod64 += _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1862
		((unsigned *)resultP)[0] = _prod64 /* & 0xFFFFFFFFL */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1863
		_carry = _prod64 >> 32;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1864
		resultP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1865
		_l -= 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1866
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1867
	    if (_l > 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1868
		unsigned short __t;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1869
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1870
		__t = ((unsigned short *)digitP)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1871
		digitP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1872
		_prod64 = (INT64)_v;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1873
		_prod64 *= __t;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1874
		_prod64 += _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1875
		((unsigned short *)resultP)[0] = _prod64 /* & 0xFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1876
		_carry = _prod64 >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1877
		resultP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1878
		_l -= 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1879
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1880
	    if (_l > 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1881
		_prod64 = *digitP++ * _v + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1882
		*resultP++ = _prod64 /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1883
		_carry = _prod64 >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1884
		_l--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1885
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1886
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1887
#   else /* no INT64 type */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1888
	if (_v <= 0xFFFF) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1889
	    /* can do it short-wise 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1890
	     * 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1891
	     * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1892
	     * + maxCarry (0xFFFF)  -> 0xFFFF.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1893
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1894
	    while (_l > 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1895
		_prod = ((unsigned short *)digitP)[0] * _v + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1896
		((unsigned short *)resultP)[0] = _prod /* & 0xFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1897
		_carry = _prod >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1898
		digitP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1899
		resultP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1900
		_l -= 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1901
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1902
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1903
#   endif /* no INT64 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  1904
#  endif /* not WIN32-i386 */
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  1905
# endif /* not GNU-i386 */
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  1906
#else /* not LSB_FIRST */
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1907
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1908
# ifdef mips
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1909
#  define LOAD_WORD_WISE
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1910
   /* no, STORE_WORD_WISE makes it slower */
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1911
# endif
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1912
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1913
	if (_v <= 0xFFFF) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1914
	    /* can do it short-wise 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1915
	     * 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1916
	     * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1917
	     * + maxCarry (0xFFFF)  -> 0xFFFF.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1918
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1919
	    while (_l > 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1920
		unsigned int t;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1921
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1922
#if defined(LOAD_WORD_WISE)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1923
		/* better fetch short-wise */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1924
		t = ((unsigned short *)digitP)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1925
		digitP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1926
		t = ((t >> 8) | (t << 8)) & 0xFFFF;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1927
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1928
		t = (digitP[1]<<8) + digitP[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1929
		digitP += 2;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1930
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1931
		_prod = t * _v + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1932
		_carry = _prod >> 16;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1933
#if defined(STORE_WORD_WISE)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1934
		/* better store short-wise */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1935
		_prod = ((_prod >> 8) | (_prod << 8)) & 0xFFFF;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1936
		((unsigned short *)resultP)[0] = _prod;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1937
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1938
		resultP[0] = _prod /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1939
		resultP[1] = (_prod>>8) /* & 0xFF */;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  1940
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1941
		resultP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1942
		_l -= 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1943
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1944
	}
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  1945
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  1946
#endif /* LSB_FIRST */
1797
8dafe47b33fd faster multiplication by an integer.
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
  1947
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1948
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1949
	 * rest is done byte-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1950
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1951
	while (_l > 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1952
	    _prod = *digitP++ * _v + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1953
	    *resultP++ = _prod /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1954
	    _carry = _prod >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1955
	    _l--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1956
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1957
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1958
	_l = __intVal(lResult) - __intVal(len);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1959
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1960
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1961
	 * remaining carry
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1962
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1963
	while (_carry) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1964
	    *resultP++ = _carry /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1965
	    _carry >>= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1966
	    _l--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1967
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1968
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1969
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1970
	 * remaining zeros
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1971
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1972
	while (_l--) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1973
	    *resultP++ = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1974
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1975
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1976
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1977
	 * need compress ?
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1978
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1979
	if (resultP[-1]) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1980
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1981
	     * no
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1982
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1983
	    RETURN(result);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1984
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1985
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1986
	ok = true;
85
claus
parents: 77
diff changeset
  1987
    }
claus
parents: 77
diff changeset
  1988
%}.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1989
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1990
     fall back - normally not reached
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1991
     (could make it a primitive-failure as well)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1992
    "
85
claus
parents: 77
diff changeset
  1993
    ok ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1994
	carry := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1995
	1 to:len do:[:i |
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1996
	    prod := (digitByteArray basicAt:i) * val + carry.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1997
	    resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1998
	    carry := prod bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1999
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2000
	[carry ~~ 0] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2001
	    len := len + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2002
	    resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2003
	    carry := carry bitShift:-8
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2004
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2005
	[len < lResult] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2006
	    len := len + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2007
	    resultDigitByteArray basicAt:len put:0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2008
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2009
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2010
    ^ result compressed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2011
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2012
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2013
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2014
    "sent, when anInteger does not know how to add the receiver.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2015
     Return the sum of the receiver and the argument, (which must be a SmallInteger)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2016
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2017
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2018
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2019
	    ^ self absFastPlus:anInteger sign:1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2020
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2021
	^ self absFastMinus:anInteger sign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2022
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2023
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2024
	^ self
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2025
    ].
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2026
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2027
	^ self absFastMinus:anInteger sign:1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2028
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2029
    ^ self absFastPlus:anInteger sign:-1
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2030
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2031
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2032
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2033
     12345678901234567890          
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2034
     -12345678901234567890         
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2035
     12345678901234567890 sumFromInteger:0       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2036
     -12345678901234567890 sumFromInteger:0       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2037
     12345678901234567890 sumFromInteger:1       
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2038
     12345678901234567890 sumFromInteger:-1      
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2039
     -12345678901234567890 sumFromInteger:1     
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2040
     -12345678901234567890 sumFromInteger:-1   
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2041
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2042
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2043
    "Modified: / 9.1.1998 / 13:27:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2044
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2045
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2046
!LargeInteger methodsFor:'printing & storing'!
345
claus
parents: 250
diff changeset
  2047
5682
a1a516779f72 remove storeOn: use insteat the default printString
ca
parents: 5437
diff changeset
  2048
xxxstoreOn:aStream
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2049
    "append a representation of the receiver to aStream, which can
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2050
     be used to reconstruct the receiver."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2051
5682
a1a516779f72 remove storeOn: use insteat the default printString
ca
parents: 5437
diff changeset
  2052
    aStream nextPutAll:'('.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2053
    self printOn:aStream.
5954
d706efecb134 ZeroDivide has a parameter
Claus Gittinger <cg@exept.de>
parents: 5682
diff changeset
  2054
    aStream nextPutAll:' asLargeInteger)'
d706efecb134 ZeroDivide has a parameter
Claus Gittinger <cg@exept.de>
parents: 5682
diff changeset
  2055
! !
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2056
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2057
!LargeInteger methodsFor:'private'!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2058
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2059
absDivMod:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2060
    "return an array with two LargeIntegers representing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2061
     abs(self) // abs(theArgument) and abs(self) \\ abs(theArgument).
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  2062
     Used as a helper for \\, //, rem: and quo:.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  2063
     This method needs a rewrite."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2064
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2065
    |dividend divisor 
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2066
     quo digits
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2067
     shift "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2068
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2069
    anInteger == 0 ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2070
        ^ ZeroDivide raiseRequestWith:thisContext
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2071
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2072
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2073
    self = anInteger ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2074
        ^ Array with:1 with:0
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2075
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2076
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2077
    shift := self highBit - anInteger highBit.
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  2078
    dividend := LargeInteger digitBytes:digitByteArray copy. "/ self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2079
    shift < 0 ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2080
        ^ Array with:0 with:dividend compressed.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2081
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  2082
    shift == 0 ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2083
        divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  2084
    ] ifFalse:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2085
        divisor := anInteger bitShift:shift.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2086
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2087
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2088
    quo := self class basicNew numberOfDigits:((shift // 8) + 1). 
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2089
    digits := quo digitBytes.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2090
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2091
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2092
    [shift > 0] whileTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2093
        (dividend absLess:divisor) ifFalse:[
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2094
            digits bitSetAt:shift.
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2095
            (dividend absSubtract: divisor) ifFalse:[ "result == 0"
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2096
                ^ Array with:quo compressed with:dividend compressed            
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2097
            ].
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2098
        ].
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2099
        shift := shift - 1.
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2100
        divisor div2.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2101
    ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2102
    ^ Array with:quo compressed with:dividend compressed
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2103
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2104
    "
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2105
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:4000000000] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2106
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:3000000000] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2107
     16000000000 absDivMod:4000000000 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2108
     16000000000 absDivMod:3000000000
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2109
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2110
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2111
    "Modified: / 5.11.1996 / 18:40:24 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2112
    "Created: / 27.4.1999 / 19:45:44 / stefan"
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  2113
    "Modified: / 26.7.1999 / 10:46:36 / stefan"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2114
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2115
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2116
absEq:aLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2117
    "return true, if abs(self) = abs(theArgument)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2118
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2119
    |len1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2120
     len2 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2121
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2122
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2123
     otherDigitByteArray |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2124
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2125
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2126
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2127
    len2 := otherDigitByteArray size.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2128
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2129
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2130
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2131
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2132
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2133
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2134
    [(digitByteArray basicAt:len1) == 0] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2135
	len1 := len1 - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2136
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2137
    [(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2138
	len2 := len2 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2139
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2140
    (len1 ~~ len2) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2141
    [len1 > 0] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2142
	d1 := digitByteArray basicAt:len1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2143
	d2 := otherDigitByteArray basicAt:len1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2144
	(d1 ~~ d2) ifTrue:[^ false].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2145
	len1 := len1 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2146
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2147
    ^ true
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2148
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2149
    "Modified: / 8.5.1999 / 18:37:02 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2150
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2151
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2152
absFastDivMod:aPositiveSmallInteger
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2153
    "return an array with two LargeIntegers representing
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2154
     abs(self) // aPositiveSmallInteger and 
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2155
     abs(self) \\ aPositiveSmallInteger."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2156
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2157
    |tmp1     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2158
     prevRest "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2159
     count    "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  2160
     newDigitByteArray result
claus
parents: 77
diff changeset
  2161
     ok|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2162
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2163
    aPositiveSmallInteger == 0 ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2164
        ^ ZeroDivide raiseRequestWith:thisContext
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2165
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2166
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2167
"This cannot happen (if always normalized)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2168
    self < aPositiveSmallInteger ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2169
        ^ Array with:0 with:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2170
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2171
"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2172
    count := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2173
    result := self class basicNew numberOfDigits:count.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2174
    newDigitByteArray := result digitBytes.
85
claus
parents: 77
diff changeset
  2175
    ok := false.
claus
parents: 77
diff changeset
  2176
%{
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2177
    OBJ __digits;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2178
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2179
    __digits = __INST(digitByteArray);
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2180
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2181
    if (__isByteArray(__digits)
85
claus
parents: 77
diff changeset
  2182
     && __isByteArray(newDigitByteArray)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2183
     && __bothSmallInteger(count, aPositiveSmallInteger)) {
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2184
        unsigned INT rest = 0;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2185
        int index = __intVal(count);
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2186
        int index0;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2187
        unsigned INT divisor = __intVal(aPositiveSmallInteger);
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2188
        unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2189
        unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2190
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2191
        index0 = index - 1;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2192
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2193
        /* 
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2194
         * divide short-wise 
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2195
         */
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2196
        if (divisor <= 0xFFFF) {
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2197
            if ((index & 1) == 0) { /* even number of bytes */
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2198
                while (index > 1) {
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2199
                    unsigned INT t;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2200
                    unsigned INT div;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2201
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2202
                    index -= 2;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2203
#if defined(__LSBFIRST) || defined(i386)
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2204
                    t = *((unsigned short *)(&digitBytes[index]));
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2205
#else
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2206
                    t = digitBytes[index+1];
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2207
                    t = (t << 8) | digitBytes[index];
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2208
#endif
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2209
                    t = t | (rest << 16);
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2210
                    div = t / divisor;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2211
                    rest = t % divisor;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2212
#if defined(__LSBFIRST) || defined(i386)
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2213
                    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2214
#else
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2215
                    resultBytes[index+1] = div >> 8;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2216
                    resultBytes[index] = div /* & 0xFF */;
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2217
#endif
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2218
                }
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2219
            }
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2220
        }
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2221
        while (index > 0) {
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2222
            unsigned INT t;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2223
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2224
            index--;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2225
            t = digitBytes[index];
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2226
            t = t | (rest << 8);
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2227
            resultBytes[index] = t / divisor;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2228
            rest = t % divisor;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2229
        }
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2230
        prevRest = __MKSMALLINT(rest);
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2231
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2232
        /*
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2233
         * no need to normalize ?
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2234
         */
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2235
        while ((index0 >= sizeof(INT)) && (resultBytes[index0]==0)) {
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2236
            index0--;
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2237
        }
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2238
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2239
        if (index0 > sizeof(INT)) {
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2240
            RETURN ( __ARRAY_WITH2(result, prevRest));
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2241
        }
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2242
        if ((index0 == sizeof(INT))
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2243
         && resultBytes[index0] >= 0x40) {
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2244
            RETURN ( __ARRAY_WITH2(result, prevRest));
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2245
        }
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2246
        /*
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2247
         * must compress
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2248
         */
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2249
        ok = true;
85
claus
parents: 77
diff changeset
  2250
    }
claus
parents: 77
diff changeset
  2251
%}.
claus
parents: 77
diff changeset
  2252
    "
claus
parents: 77
diff changeset
  2253
     slow code - not normally reached
claus
parents: 77
diff changeset
  2254
     (could also do a primitiveFailure here)
claus
parents: 77
diff changeset
  2255
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2256
    ok ifFalse:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  2257
        ^ self absDivMod:(LargeInteger value:aPositiveSmallInteger).
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2258
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2259
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  2260
    ^ Array with:(result compressed) with:prevRest
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2261
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2262
    "
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  2263
     16r123412341234 asLargeInteger absDivMod:(LargeInteger value:10) 
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  2264
     ((16r1234 asLargeInteger absFastDivMod:16rffff) at:2) printStringRadix:16
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  2265
     ((16r00123456 asLargeInteger absFastDivMod:16rffffff) at:2) printStringRadix:16  
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  2266
     ((666666666666666666 asLargeInteger absFastDivMod:16r3))  
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  2267
     ((1666666666 asLargeInteger absFastDivMod:16r3))  
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2268
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2269
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2270
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2271
absFastMinus:aSmallInteger sign:newSign
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2272
    "return a LargeInteger representing abs(self) - abs(theArgument)
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2273
     with sign: newSign.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2274
     The result is normalized.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2275
     This is a helper for addition and subtraction - not for public use."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2276
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2277
    |result resultDigitByteArray lastDigit ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2278
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2279
     rsltLen "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2280
     index   "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2281
     borrow  "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2282
     diff    "{ Class: SmallInteger }" |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2283
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2284
    "/ the following code only works with
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2285
    "/ smallIntegers in the range _MIN_INT+255 .. _MAX_INT-255
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2286
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2287
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2288
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2289
	^ self absMinus:(LargeInteger value:aSmallInteger) sign:newSign.
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2290
    ]. 
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2291
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2292
    len := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2293
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2294
    rsltLen := len "+ 1".
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2295
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2296
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2297
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2298
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2299
    borrow := aSmallInteger abs.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2300
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2301
%{
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2302
    if (__isByteArray(__INST(digitByteArray))
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2303
     && __isByteArray(resultDigitByteArray)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2304
	unsigned INT __borrow = __intVal(borrow);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2305
	INT __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2306
	int __index = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2307
	int __len = __intVal(len);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2308
	unsigned char *__digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2309
	unsigned char *__resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2310
	int __len3;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2311
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2312
#if defined(alpha64)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2313
	/* 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2314
	 * subtract int-wise 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2315
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2316
	__len3 = __len - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2317
	while (__index < __len3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2318
	    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2319
	    __diff = ((unsigned int *)(__digitP + __index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2320
	    __diff -= (__borrow & 0xFFFFFFFFL);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2321
	    __borrow >>= 32;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2322
	    if (__diff < 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2323
		/* __diff += 0x100000000; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2324
		__borrow++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2325
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2326
	    ((unsigned int *)(__resultP+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2327
	    __index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2328
	}
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2329
#endif
4182
a867ecbf5e56 tuned abdFastMinus:
Claus Gittinger <cg@exept.de>
parents: 4181
diff changeset
  2330
#if defined(__LSBFIRST) || defined(i386)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2331
	/* 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2332
	 * subtract short-wise 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2333
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2334
	while (__index < __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2335
	    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2336
	    __diff = ((unsigned short *)(__digitP+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2337
	    __diff -= (__borrow & 0xFFFF);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2338
	    __borrow >>= 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2339
	    if (__diff < 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2340
		/* __diff += 0x10000; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2341
		__borrow++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2342
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2343
		if (__borrow == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2344
		    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2345
		    __index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2346
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2347
		    /* nothing more to subtract .. */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2348
		    while (__index < __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2349
			((unsigned short *)(__resultP+__index-1))[0] = ((unsigned short *)(__digitP+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2350
			__index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2351
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2352
		    if (__index <= __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2353
			__resultP[__index-1] = __digitP[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2354
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2355
		    break;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2356
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2357
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2358
	    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2359
	    __index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2360
	}
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2361
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2362
	/* 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2363
	 * subtract byte-wise 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2364
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2365
	while (__index <= __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2366
	    __diff = __digitP[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2367
	    __diff -= (__borrow & 0xFF);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2368
	    __borrow >>= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2369
	    if (__diff < 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2370
		/* __diff += 0x100; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2371
		__borrow++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2372
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2373
		if (__borrow == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2374
		    __resultP[__index-1] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2375
		    __index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2376
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2377
		    /* nothing more to subtract .. */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2378
		    while (__index <= __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2379
			__resultP[__index-1] = __digitP[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2380
			__index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2381
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2382
		    break;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2383
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2384
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2385
	    __resultP[__index-1] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2386
	    __index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2387
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2388
	lastDigit = __MKSMALLINT( __resultP[__index-1-1] );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2389
	ok = true;
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2390
    }
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2391
%}.
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2392
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2393
    ok == true ifFalse:[        "/ cannot happen
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2394
	index := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2395
	[borrow ~~ 0] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2396
	    (index <= len) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2397
		diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2398
		borrow := borrow bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2399
		diff < 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2400
		    diff := diff + 256.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2401
		    borrow := borrow + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2402
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2403
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2404
		diff := borrow bitAnd:255.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2405
		borrow := borrow bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2406
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2407
	    resultDigitByteArray basicAt:index put:(lastDigit := diff).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2408
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2409
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2410
	[index <= len] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2411
	    resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2412
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2413
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2414
	(index <= rsltLen) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2415
	    lastDigit := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2416
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2417
    ].
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2418
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  2419
    (lastDigit == 0 or:[rsltLen <= SmallInteger maxBytes]) ifTrue:[ 
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2420
	^ result compressed.
4182
a867ecbf5e56 tuned abdFastMinus:
Claus Gittinger <cg@exept.de>
parents: 4181
diff changeset
  2421
    ]. 
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2422
    ^ result
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2423
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2424
    "                                                          
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2425
     12345678900000000000 absFastMinus:1 sign:1       
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2426
     12345678900000000000 absFastMinus:1 sign:-1      
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2427
     12345678900000000000 absFastMinus:1000000 sign:1 
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2428
     12345678900000000000 absFastMinus:255 sign:1     
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2429
     (SmallInteger maxVal + 1) absFastMinus:1 sign:1
4947
a371032036d9 fixes for alpha
Claus Gittinger <cg@exept.de>
parents: 4946
diff changeset
  2430
     (SmallInteger minVal - 1) absFastMinus:1 sign:1  
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2431
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2432
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2433
    "Modified: 24.3.1997 / 21:33:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2434
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2435
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2436
absFastPlus:aSmallInteger sign:newSign
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2437
    "return a LargeInteger representing abs(self) + abs(theArgument).
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2438
     with sign: newSign.
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2439
     The result is normalized. The argument must be a smallInteger
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2440
     with byteSize one less than the integer byteSize.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2441
     This is a helper for addition and subtraction - not for public use."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2442
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2443
    |result resultDigitByteArray lastDigit
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2444
     ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2445
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2446
     rsltLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2447
     index "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2448
     carry "{ Class: SmallInteger }" |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2449
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2450
    "/ the following code only works with
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2451
    "/ smallIntegers in the range _MIN_INT+255 .. _MAX_INT-255
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2452
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2453
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2454
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2455
	^ self absPlus:(LargeInteger value:aSmallInteger) sign:newSign.
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2456
    ]. 
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2457
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2458
    len := rsltLen := digitByteArray size.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2459
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2460
    "/ there can only be an overflow from the high byte,
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2461
    "/ if it is 255 (since the other number is definitely smaller)
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2462
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2463
    (digitByteArray at:len) == 16rFF ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2464
	rsltLen := len + 1.
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2465
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2466
	"/ or the argument has something in the high byte ..
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2467
%{
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2468
#ifdef alpha64
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2469
	if (__intVal(aSmallInteger) & 0xFF00000000000000L) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2470
	    rsltLen = __MKSMALLINT(__intVal(len) + 1);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2471
	}
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2472
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2473
	if (__intVal(aSmallInteger) & 0xFF000000) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2474
	    rsltLen = __MKSMALLINT(__intVal(len) + 1);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2475
	}
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2476
#endif
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2477
%}
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2478
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2479
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2480
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2481
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2482
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2483
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2484
%{
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2485
    if (__isByteArray(__INST(digitByteArray))
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2486
     && __isByteArray(resultDigitByteArray)
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2487
     && __isSmallInteger(aSmallInteger)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2488
	/* carry is NOT unsigned (see negation below) */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2489
	INT __carry = __intVal(aSmallInteger);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2490
	int __index = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2491
	int __len = __intVal(len);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2492
	unsigned char *__src = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2493
	unsigned char *__dst = (unsigned char *)(__ByteArrayInstPtr(resultDigitByteArray)->ba_element);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2494
	INT __ptrDelta = __dst - __src;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2495
	unsigned char *__srcLast = __src + __len - 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2496
	int __rsltLen = __intVal(rsltLen);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2497
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2498
	if (__carry < 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2499
	    __carry = -__carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2500
	}
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2501
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2502
#if defined(__LSBFIRST) || defined(i386) || defined(alpha)
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2503
# if defined(i386) && defined(__GNUC__)
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2504
#  if 0 /* NOTICE - the code below is 20% slower ... - why */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2505
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2506
	 * add long-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2507
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2508
	asm("  jecxz nothingToDo                                      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2509
	       movl  %%eax, %%esi      /* __src input */              \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2510
	       movl  %%ebx, %%edi      /* __dst input */              \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2511
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2512
	       /* the first 4-byte int */                             \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2513
	       lodsl                   /* fetch */                    \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2514
	       addl  %%edx, %%eax      /* add */                      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2515
	       stosl                   /* store */                    \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2516
	       leal  -1(%%ecx),%%ecx   /* do not clobber carry */     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2517
	       jecxz doneLoop          /* any more ? */               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2518
	       /* remaining 4-byte ints */                            \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2519
	       jmp   addLoop                                          \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2520
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2521
	       .align 8                                               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2522
	     addLoop:                                                 \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2523
	       movl  0(%%esi), %%ebx   /* fetch  */                   \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2524
	       jnc   copyLoop2                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2525
	       movl  $0, %%eax                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2526
	       leal  4(%%esi), %%esi                                  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2527
	       adcl  %%ebx, %%eax      /* & add carry from prev int */\n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2528
	       leal  8(%%edi), %%edi                                  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2529
	       movl  %%eax, -8(%%edi)  /* store */                    \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2530
	       leal  -1(%%ecx),%%ecx   /* do not clobber carry */     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2531
	       jecxz doneLoop          /* any more ? */               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2532
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2533
	       movl  0(%%esi), %%ebx   /* fetch  */                   \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2534
	       movl  $0, %%eax                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2535
	       leal  4(%%esi), %%esi                                  \
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2536
	       adcl  %%ebx, %%eax      /* & add carry from prev int */\n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2537
	       movl  %%eax, -4(%%edi)  /* store */                    \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2538
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2539
	       loop  addLoop                                          \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2540
	       jmp   doneLoop                                         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2541
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2542
	       .align 8                                               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2543
	     copyLoop:                                                \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2544
	       movl  0(%%esi), %%ebx                                  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2545
	     copyLoop2:                                               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2546
	       add   $4, %%esi                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2547
	       add   $4, %%edi                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2548
	       movl  %%ebx, -4(%%edi)                                 \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2549
	       loop  copyLoop                                         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2550
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2551
	     doneLoop:                                                \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2552
	       movl  $0, %%edx         /* do not clobber carry (xorl clears it) */   \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2553
	       adcl  $0, %%edx                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2554
	       movl  %%esi, %%eax      /* __src output */             \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2555
	     nothingToDo:                                             \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2556
	    " : "=d"  ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2557
		"=a"  (__src)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2558
	      : "1"   (__src),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2559
		"b"   (__dst),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2560
		"c"   (__len / 4),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2561
		"0"   (__carry)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2562
	      : "esi", "edi");
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2563
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2564
#  else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2565
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2566
	    unsigned char *__srcLastX;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2567
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2568
	    __srcLastX = __srcLast - 3 - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2569
	    while (__src <= __srcLastX) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2570
		unsigned int __sum, __sum2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2571
		unsigned __digit1, __digit2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2572
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2573
		__digit1 = ((unsigned *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2574
		__digit2 = ((unsigned *)__src)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2575
		asm ("addl %%edx,%%ecx          \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2576
		      adcl $0, %%eax            \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2577
		      movl $0, %%edx            \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2578
		      adcl $0, %%edx"    
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2579
			: "=d"  ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2580
			  "=c"  ((unsigned long)(__sum)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2581
			  "=a"  ((unsigned long)(__sum2))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2582
			: "0"   ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2583
			  "1"   (__digit1),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2584
			  "2"   (__digit2));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2585
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2586
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2587
		((unsigned int *)(__src + __ptrDelta))[1] = __sum2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2588
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2589
		__src += 8;  
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2590
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2591
		if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2592
		    while (__src <= __srcLastX) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2593
			/* copy over words */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2594
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2595
			((unsigned int *)(__src + __ptrDelta))[1] = ((unsigned int *)__src)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2596
			__src += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2597
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2598
		    while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2599
			/* copy over bytes */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2600
			__src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2601
			__src ++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2602
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2603
		    goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2604
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2605
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2606
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2607
	    __srcLastX = __srcLastX + 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2608
	    if (__src <= __srcLastX) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2609
		unsigned int __sum, __digit;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2610
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2611
		__digit = ((unsigned *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2612
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2613
		asm ("addl %%eax,%%edx  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2614
		      movl $0,%%eax     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2615
		      adcl $0,%%eax"    
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2616
			: "=a"  ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2617
			  "=d"  ((unsigned long)(__sum))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2618
			: "0"   ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2619
			  "1"   (__digit) );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2620
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2621
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2622
		__src += 4;  
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2623
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2624
		if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2625
		    while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2626
			/* copy over bytes */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2627
			__src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2628
			__src ++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2629
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2630
		    goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2631
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2632
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2633
	}
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  2634
#  endif
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2635
# else 
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2636
#  if defined(i386) && defined(WIN32)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2637
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2638
	    unsigned char *__srcLast4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2639
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2640
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2641
	     * add long-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2642
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2643
	    __srcLast4 = __srcLast - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2644
	    while (__src <= __srcLast4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2645
		unsigned int __sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2646
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2647
		__sum = ((unsigned int *)__src)[0];    
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2648
		asm {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2649
		      mov eax, __sum
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2650
		      add eax, __carry
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2651
		      mov edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2652
		      adc edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2653
		      mov __sum, eax
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2654
		      mov __carry, edx
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2655
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2656
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2657
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2658
		__src += 4;  
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2659
		if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2660
		    while (__src <= __srcLast4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2661
			/* copy over words */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2662
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2663
			__src += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2664
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2665
		    while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2666
			/* copy over bytes */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2667
			__src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2668
			__src ++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2669
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2670
		    goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2671
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2672
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2673
	}
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2674
#  else 
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2675
#   ifdef alpha64
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2676
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2677
	    unsigned char *__srcLast4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2678
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2679
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2680
	     * add long-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2681
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2682
	    __srcLast4 = __srcLast - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2683
	    while (__src <= __srcLast4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2684
		unsigned INT __sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2685
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2686
		__sum = ((unsigned int *)__src)[0] + __carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2687
		((unsigned int *)(__src + __ptrDelta))[0] = __sum /* & 0xFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2688
		__src += 4;  
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2689
		__carry = __sum >> 32;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2690
		if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2691
		    while (__src <= __srcLast4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2692
			/* copy over words */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2693
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2694
			__src += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2695
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2696
		    while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2697
			/* copy over bytes */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2698
			__src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2699
			__src ++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2700
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2701
		    goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2702
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2703
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2704
	}
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2705
#   endif /* alpha64 */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2706
#  endif /* i386 & WIN32 */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2707
# endif /* i386 & GNUC */
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2708
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2709
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2710
	 * add short-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2711
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2712
	while (__src < __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2713
	    __carry += ((unsigned short *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2714
	    ((unsigned short *)(__src + __ptrDelta))[0] = __carry /* & 0xFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2715
	    __carry >>= 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2716
	    __src += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2717
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2718
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2719
	 * last (odd) byte
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2720
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2721
	if (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2722
	    __carry += __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2723
	    __src[__ptrDelta] = __carry /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2724
	    __carry >>= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2725
	    __src++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2726
	}
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2727
#else /* not __LSBFIRST */
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  2728
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2729
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2730
	 * add byte-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2731
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2732
	while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2733
	    __carry += __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2734
	    __src[__ptrDelta] = __carry /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2735
	    __src++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2736
	    __carry >>= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2737
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2738
	    if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2739
		while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2740
		    /* copy over rest */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2741
		    __src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2742
		    __src++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2743
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2744
		goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2745
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2746
	}
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2747
#endif /* __LSBFIRST */
4185
375439993eb7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4182
diff changeset
  2748
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  2749
    doneSource: ;
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2750
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2751
	 * now, at most one other byte is to be stored ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2752
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2753
	if (__len < __rsltLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2754
	    __src[__ptrDelta] = __carry /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2755
	    __src++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2756
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2757
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2758
	if (__src[__ptrDelta-1]) {      /* lastDigit */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2759
	    RETURN (result);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2760
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2761
	ok = true;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2762
    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2763
%}.
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2764
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2765
    ok ~~ true ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2766
	index := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2767
	carry := aSmallInteger abs.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2768
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2769
	[carry ~~ 0] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2770
	    (index <= len) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2771
		carry := (digitByteArray basicAt:index) + carry.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2772
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2773
	    resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2774
	    carry := carry bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2775
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2776
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2777
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2778
	(index <= rsltLen) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2779
	    [index <= len] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2780
		resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2781
		index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2782
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2783
	    lastDigit := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2784
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2785
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2786
	(lastDigit ~~ 0 and:[rsltLen > SmallInteger maxBytes]) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2787
	    ^ result
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2788
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2789
    ].
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2790
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2791
    ^ result compressed
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2792
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2793
    "Modified: 24.3.1997 / 21:32:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2794
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2795
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2796
absLess:aLargeInteger
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2797
    "return true, if abs(self) < abs(theArgument).
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2798
     This handles unnormalized largeIntegers."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2799
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2800
    |myLen "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2801
     otherLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2802
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2803
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2804
     otherDigitByteArray |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2805
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2806
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2807
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2808
    otherLen := otherDigitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2809
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2810
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2811
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2812
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2813
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2814
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2815
    [myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2816
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2817
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2818
    [otherLen > 0 and:[(otherDigitByteArray basicAt:otherLen) == 0]] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2819
	otherLen := otherLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2820
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2821
    (myLen < otherLen) ifTrue:[^ true].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2822
    (myLen > otherLen) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2823
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2824
    [myLen > 0] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2825
	d1 := digitByteArray basicAt:myLen.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2826
	d2 := otherDigitByteArray basicAt:myLen.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2827
	d1 == d2 ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2828
	    (d1 < d2) ifTrue:[^ true].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2829
	    ^ false
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2830
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2831
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2832
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2833
    ^ false
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2834
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2835
    "Modified: / 3.5.1999 / 08:06:28 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2836
    "Modified: / 8.5.1999 / 18:37:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2837
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2838
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2839
absLessEq:aLargeInteger
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2840
    "return true, if abs(self) <= abs(theArgument).
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2841
     This handles unnormalized largeIntegers."
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2842
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2843
    |myLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2844
     otherLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2845
     d1   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2846
     d2   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2847
     otherDigitByteArray |
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2848
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2849
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2850
    otherDigitByteArray := aLargeInteger digitBytes.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2851
    otherLen := otherDigitByteArray size.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2852
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2853
    "/ the highest digit(s) should not be zero
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2854
    "/ when properly normalized; 
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2855
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2856
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2857
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2858
    [(digitByteArray basicAt:myLen) == 0] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2859
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2860
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2861
    [(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2862
	otherLen := otherLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2863
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2864
    (myLen < otherLen) ifTrue:[^ true].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2865
    (myLen > otherLen) ifTrue:[^ false].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2866
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2867
    [myLen > 0] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2868
	d1 := digitByteArray basicAt:myLen.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2869
	d2 := otherDigitByteArray basicAt:myLen.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2870
	d1 == d2 ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2871
	    (d1 < d2) ifTrue:[^ true].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2872
	    ^ false.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2873
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2874
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2875
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2876
    ^ true
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2877
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2878
    "Created: / 13.2.1998 / 12:19:45 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2879
    "Modified: / 30.4.1999 / 12:46:31 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2880
    "Modified: / 8.5.1999 / 18:37:15 / cg"
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2881
!
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2882
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2883
absMinus:aLargeInteger sign:newSign
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2884
    "return a LargeInteger representing abs(self) - abs(theArgument)
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2885
     with sign: newSign.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2886
     The result is normalized. The argument must be a largeInteger
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2887
     with a byteSize smaller than the receivers byteSize.
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2888
     This is a helper for addition and subtraction - not for public use."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2889
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2890
    |result done
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2891
     otherDigitByteArray resultDigitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2892
     len1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2893
     len2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2894
     index  "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2895
     borrow "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2896
     diff   "{ Class: SmallInteger }"
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2897
     carry  "{ Class: SmallInteger }" 
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2898
     lastDigit   
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2899
     lResult ok|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2900
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2901
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2902
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2903
    len2 := otherDigitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2904
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2905
    len1 > len2 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2906
	lResult := len1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2907
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2908
	lResult := (len1 max: len2) + 1.
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  2909
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  2910
    result := self class basicNew numberOfDigits:lResult.
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  2911
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2912
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2913
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2914
    lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2915
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2916
%{
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2917
    OBJ _digitByteArray = __INST(digitByteArray);
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2918
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2919
    if (__isByteArray(_digitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2920
     && __isByteArray(otherDigitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2921
     && __isByteArray(resultDigitByteArray)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2922
	int __len1 = __intVal(len1);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2923
	int __len2 = __intVal(len2);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2924
	int __minLen = __len1 < __len2 ? __len1 : __len2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2925
	int __index, __borrow = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2926
	INT __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2927
	unsigned char *__myDigits, *__otherDigits, *__resultDigits;
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  2928
        
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2929
	ok = true;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2930
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2931
	__resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2932
	__otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2933
	__myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2934
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2935
	__index = 1;
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2936
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2937
#if defined(alpha64)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2938
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2939
	 * subtract int-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2940
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2941
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2942
	while ((__index+3) <= __minLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2943
	    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2944
	    __diff = ((unsigned int *)(__myDigits+__index-1))[0]; 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2945
	    __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2946
	    __diff -= __borrow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2947
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2948
	    if (__diff >= 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2949
		__borrow = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2950
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2951
		__borrow = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2952
		/* __diff += 0x10000; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2953
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2954
	    ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2955
	    __index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2956
	}
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2957
#endif /* alpha64 */
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  2958
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  2959
#if defined(i386) || defined(__LSBFIRST)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2960
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2961
	 * subtract short-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2962
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2963
	while (__index < __minLen) {   /* i.e. index+1 <= minLen */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2964
	    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2965
	    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2966
	    __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2967
	    __diff -= __borrow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2968
	    if (__diff >= 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2969
		__borrow = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2970
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2971
		__borrow = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2972
		/* __diff += 0x10000; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2973
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2974
	    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2975
	    __index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2976
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2977
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2978
	if (__index == __minLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2979
	    /* one of the operands has odd length - cannot continue short-wise */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2980
	} else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2981
	    if (__len1 > __len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2982
		while (__index < __len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2983
		    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2984
		    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2985
		    __diff -= __borrow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2986
		    if (__diff >= 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2987
			__borrow = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2988
			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2989
			__index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2990
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2991
			/* copy over rest */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2992
			while (__index < __len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2993
			    ((unsigned short *)(__resultDigits+__index-1))[0] = ((unsigned short *)(__myDigits+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2994
			    __index+=2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2995
			}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2996
			if (__index <= __len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2997
			    __resultDigits[__index-1] = __myDigits[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2998
			    __index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2999
			}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3000
			break;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3001
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3002
		    __borrow = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3003
		    /* __diff += 0x10000; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3004
		    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3005
		    __index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3006
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3007
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3008
		if (__len2 > __len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3009
		    while (__index < __len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3010
			/* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3011
			__diff = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3012
			__diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3013
			__diff -= __borrow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3014
			if (__diff >= 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3015
			    __borrow = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3016
			} else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3017
			    __borrow = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3018
			    /* __diff += 0x10000; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3019
			}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3020
			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3021
			__index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3022
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3023
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3024
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3025
	}
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  3026
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3027
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3028
	 * subtract byte-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3029
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3030
	while (__index <= __minLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3031
	    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3032
	    __diff = __myDigits[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3033
	    __diff -= __otherDigits[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3034
	    __diff -= __borrow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3035
	    if (__diff >= 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3036
		__borrow = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3037
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3038
		__borrow = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3039
		/* __diff += 0x100; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3040
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3041
	    __resultDigits[__index-1] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3042
	    __index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3043
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3044
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3045
	if (__len1 > __len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3046
	    while (__index <= __len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3047
		/* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3048
		__diff = __myDigits[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3049
		__diff -= __borrow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3050
		if (__diff >= 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3051
		    __borrow = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3052
		    /* copy over rest */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3053
		    __resultDigits[__index-1] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3054
		    __index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3055
		    while (__index <= __len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3056
			__resultDigits[__index-1] = __myDigits[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3057
			__index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3058
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3059
		    break;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3060
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3061
		__borrow = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3062
		/* __diff += 0x100; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3063
		__resultDigits[__index-1] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3064
		__index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3065
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3066
	} else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3067
	    if (__len2 > __len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3068
		while (__index <= __len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3069
		    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3070
		    __diff = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3071
		    __diff -= __otherDigits[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3072
		    __diff -= __borrow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3073
		    if (__diff >= 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3074
			__borrow = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3075
		    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3076
			__borrow = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3077
			/* __diff += 0x100; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3078
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3079
		    __resultDigits[__index-1] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3080
		    __index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3081
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3082
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3083
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3084
	borrow = __MKSMALLINT(__borrow);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3085
	index = __MKSMALLINT(__index);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3086
	lastDigit = __MKSMALLINT(__resultDigits[__intVal(lResult)-1]);
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3087
    }
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3088
%}.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3089
    ok == true ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3090
	index := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3091
	borrow := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3092
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3093
	done := false.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3094
	[done] whileFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3095
	    diff := borrow.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3096
	    (index <= len1) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3097
		diff := diff + (digitByteArray basicAt:index).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3098
		(index <= len2) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3099
		    diff := diff - (otherDigitByteArray basicAt:index)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3100
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3101
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3102
		(index <= len2) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3103
		    diff := diff - (otherDigitByteArray basicAt:index)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3104
		] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3105
		    "end reached"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3106
		    done := true
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3107
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3108
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3109
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3110
	    "/ workaround for
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3111
	    "/ gcc code generator bug
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3112
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3113
	    (diff >= 0) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3114
		borrow := 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3115
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3116
		borrow := -1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3117
		diff := diff + 16r100
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3118
	    ].
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3119
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3120
    "/        (diff < 0) ifTrue:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3121
    "/            borrow := -1.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3122
    "/            diff := diff + 16r100
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3123
    "/        ] ifFalse:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3124
    "/            borrow := 0
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3125
    "/        ].
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3126
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3127
	    resultDigitByteArray basicAt:index put:diff.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3128
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3129
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3130
	lastDigit := resultDigitByteArray basicAt:lResult.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3131
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3132
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3133
    (borrow ~~ 0) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3134
	"/ must generate 255's complement
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3135
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3136
	result sign:-1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3137
	[index <= lResult] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3138
	    resultDigitByteArray basicAt:index put:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3139
	    index := index + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3140
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3141
	index := lResult.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3142
	[index > 0] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3143
	    resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3144
	    index := index - 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3145
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3146
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3147
	index := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3148
	carry := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3149
	[carry ~~ 0] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3150
	    (index <= lResult) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3151
		carry := (resultDigitByteArray basicAt:index) + carry.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3152
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3153
	    resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3154
	    carry := carry bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3155
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3156
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3157
	lastDigit := resultDigitByteArray basicAt:lResult.
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3158
    ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3159
    (lastDigit ~~ 0 and:[lResult > SmallInteger maxBytes]) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3160
	^ result
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3161
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3162
    ^ result compressed
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3163
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3164
    "Modified: 5.11.1996 / 14:09:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3165
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3166
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3167
absMod:anInteger
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3168
    "return a LargeIntegers representing
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3169
     abs(self) \\ abs(theArgument).
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3170
     Used as a helper for \\ and rem:"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3171
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3172
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3173
    |dividend divisor 
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3174
     shift "{ Class: SmallInteger }" |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3175
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3176
    anInteger == 0 ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3177
        ^ ZeroDivide raiseRequestWith:thisContext
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3178
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3179
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3180
    self = anInteger ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3181
        ^ 0
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3182
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3183
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3184
    shift := self highBit - anInteger highBit.
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  3185
    dividend := LargeInteger digitBytes:digitByteArray copy. "/ self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3186
    shift < 0 ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3187
        ^ dividend compressed.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3188
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3189
    shift == 0 ifTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3190
        divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3191
    ] ifFalse:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3192
        divisor := anInteger bitShift:shift.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3193
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3194
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3195
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3196
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3197
    [shift > 0] whileTrue:[
7141
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3198
        (dividend absLess:divisor) ifFalse:[
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3199
            (dividend absSubtract: divisor) ifFalse:[ "result == 0"
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3200
                ^ dividend compressed            
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3201
            ].
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3202
        ].
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3203
        shift := shift - 1.
033f2c26d8e6 replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents: 6677
diff changeset
  3204
        divisor div2.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3205
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3206
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3207
    ^ dividend compressed
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3208
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3209
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3210
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absMod:4000000001] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3211
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absDivMod:4000000001] ]  
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3212
     16000000000 absMod:4000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3213
     16000000000 absMod:3000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3214
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3215
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3216
    "Modified: / 5.11.1996 / 18:40:24 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3217
    "Created: / 27.4.1999 / 19:45:44 / stefan"
4454
16acdd393dd0 Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
  3218
    "Modified: / 26.7.1999 / 10:46:18 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3219
!
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3220
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3221
absMul:aLargeInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3222
    "return a LargeInteger representing abs(self) * abs(theArgument)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3223
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3224
    |result otherDigitByteArray resultDigitByteArray ok
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3225
     idx      "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3226
     carry    "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3227
     len1     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3228
     len2     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3229
     dstIndex "{ Class: SmallInteger }"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3230
     prod     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3231
     v        "{ Class: SmallInteger }"|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3232
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3233
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3234
    otherDigitByteArray := aLargeInteger digitBytes.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3235
    len2 := otherDigitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3236
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  3237
    result := LargeInteger basicNew numberOfDigits:(len1 + len2).
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3238
    resultDigitByteArray := result digitBytes.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3239
    ok := false.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3240
%{
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  3241
    if (__isByteArray(__INST(digitByteArray))
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3242
     && __isByteArray(otherDigitByteArray)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3243
     && __isByteArray(resultDigitByteArray)
250
a5deb61ffdac *** empty log message ***
claus
parents: 175
diff changeset
  3244
     && __bothSmallInteger(len1, len2)) {
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3245
        unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3246
        unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3247
        unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3248
        unsigned char *_p1, *_p2, *_pResult, *_pResult0, *_pResult1, *_p1Last, *_p2Last;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3249
        unsigned char *_pResultLast1;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3250
        unsigned INT _v;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3251
        int _len1 = __intVal(len1);
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3252
        int _len2 = __intVal(len2);
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3253
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3254
        _p1Last = myBytes    + _len1 - 1;  /* the last byte */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3255
        _p2Last = otherBytes + _len2 - 1;  /* the last byte */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3256
        _pResult0 = resultBytes;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3257
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3258
        /*
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3259
         *        aaa...aaa      f1[0] * f2
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3260
         *       bbb...bbb       f1[1] * f2
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3261
         *      ccc...ccc        f1[2] * f2
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3262
         *     ...
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3263
         *    xxx...xxx          f1[high] * f2
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3264
         *
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3265
         * start short-wise
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3266
         * bounds: (16rFFFF * 16rFFFF) + 16rFFFF -> FFFF0000
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3267
         */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3268
        _p1 = myBytes;
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3269
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3270
#if defined(alpha64)
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3271
        /* loop over ints of f1 */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3272
        for (; _p1 < _p1Last-2; _p1 += 4, _pResult0 += 4) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3273
            unsigned INT word1 = ((unsigned int *)_p1)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3274
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3275
            _pResult = _pResult0;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3276
            _p2 = otherBytes;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3277
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3278
            /* loop over ints of f2 */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3279
            while (_p2 < (_p2Last-2)) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3280
                _v = (word1 * ((unsigned int *)_p2)[0]) + ((unsigned int *)_pResult)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3281
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3282
                _v >>= 32; /* now _v contains the carry*/
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3283
                _pResult += 4;                
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3284
                if (_v) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3285
                    unsigned char *_pResultLast3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3286
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3287
                    /* distribute carry - int-wise, then byte-wise */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3288
                    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3289
                    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3290
                        if (_pResult1 > _pResultLast3) break;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3291
                        _v += ((unsigned int *)_pResult1)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3292
                        ((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3293
                        _v >>= 32;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3294
                    }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3295
                    for (; _v; _pResult1++) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3296
                        _v += _pResult1[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3297
                        _pResult1[0] = _v /* & 0xFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3298
                        _v >>= 8;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3299
                    }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3300
                }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3301
                _p2 += 4;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3302
            }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3303
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3304
            /* possible odd highByte of f2 */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3305
            while (_p2 <= _p2Last) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3306
                _v = (word1 * _p2[0]) + ((unsigned int *)_pResult)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3307
                ((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3308
                _v >>= 32; /* now _v contains the carry*/
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3309
                _pResult += 4;                
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3310
                if (_v) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3311
                    unsigned char *_pResultLast3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3312
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3313
                    /* distribute carry - int-wise, then byte-wise */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3314
                    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3315
                    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3316
                        if (_pResult1 > _pResultLast3) break;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3317
                        _v += ((unsigned int *)_pResult1)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3318
                        ((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3319
                        _v >>= 32;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3320
                    }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3321
                    for (; _v; _pResult1++) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3322
                        _v += _pResult1[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3323
                        _pResult1[0] = _v /* & 0xFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3324
                        _v >>= 8;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3325
                    }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3326
                }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3327
                _p2++;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3328
            }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3329
        }
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3330
#endif /* alpha64 */
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3331
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3332
        /* loop over shorts of f1 */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3333
        for (; _p1 < _p1Last; _p1 += 2, _pResult0 += 2) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3334
            unsigned int short1 = ((unsigned short *)_p1)[0];
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3335
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3336
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3337
            short1 = ((short1 >> 8) & 0xFF) | ((short1 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3338
#endif
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3339
            _pResult = _pResult0;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3340
            _p2 = otherBytes;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3341
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3342
            /* loop over shorts of f2 */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3343
            while (_p2 < _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3344
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3345
                unsigned int _short2;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3346
                unsigned int _short3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3347
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3348
                _short2 = ((unsigned short *)_p2)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3349
                _short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3350
                _short3 = ((unsigned short *)_pResult)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3351
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3352
                _v = (short1 * _short2) + _short3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3353
                _pResult[0] = _v;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3354
                _pResult[1] = _v >> 8;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3355
#else /* LSBFIRST */
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3356
                _v = (short1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3357
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3358
#endif
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3359
                _v >>= 16; /* now _v contains the carry*/
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3360
                _pResult += 2;                
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3361
                if (_v) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3362
                    /* distribute carry - short-wise, then byte-wise */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3363
                    _pResult1 = _pResult;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3364
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)  
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3365
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3366
                    for (; _v; _pResult1 += 2) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3367
                        if (_pResult1 > _pResultLast1) break;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3368
                        _v += ((unsigned short *)_pResult1)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3369
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3370
                        _v >>= 16;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3371
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3372
#endif
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3373
                    for (; _v; _pResult1++) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3374
                        _v += _pResult1[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3375
                        _pResult1[0] = _v /* & 0xFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3376
                        _v >>= 8;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3377
                    }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3378
                }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3379
                _p2 += 2;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3380
            }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3381
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3382
            /* possible odd highByte of f2 */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3383
            if (_p2 <= _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3384
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3385
                unsigned int _short3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3386
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3387
                _short3 = ((unsigned short *)_pResult)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3388
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3389
                _v = (short1 * _p2[0]) + _short3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3390
                _pResult[0] = _v;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3391
                _pResult[1] = _v >> 8;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3392
#else /* LSBFIRST */
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3393
                _v = (short1 * _p2[0]) + ((unsigned short *)_pResult)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3394
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3395
#endif
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3396
                _v >>= 16; /* now _v contains the carry*/
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3397
                _pResult += 2;                
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3398
                if (_v) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3399
                    /* distribute carry - short-wise, then byte-wise */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3400
                    _pResult1 = _pResult;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3401
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)  
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3402
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3403
                    for (; _v; _pResult1 += 2) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3404
                        if (_pResult1 > _pResultLast1) break;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3405
                        _v += ((unsigned short *)_pResult1)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3406
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3407
                        _v >>= 16;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3408
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3409
#endif
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3410
                    for (; _v; _pResult1++) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3411
                        _v += _pResult1[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3412
                        _pResult1[0] = _v /* & 0xFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3413
                        _v >>= 8;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3414
                    }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3415
                }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3416
                _p2++;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3417
            }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3418
        }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3419
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3420
        /* possible odd highByte of f1 (or byteLoop, if not LSBFIRST) */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3421
        for (; _p1 <= _p1Last; _p1++, _pResult0++) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3422
            unsigned int byte1 = _p1[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3423
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3424
            _pResult = _pResult0;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3425
            _p2 = otherBytes;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3426
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3427
            /* loop over shorts of f2 */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3428
            while (_p2 < _p2Last) {
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3429
#if !defined(__LSBFIRST) && !defined(alpha) && !defined(i386)  
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3430
                unsigned int _short2;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3431
                unsigned int _short3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3432
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3433
                _short2 = ((unsigned short *)_p2)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3434
                _short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3435
                _short3 = ((unsigned short *)_pResult)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3436
                _short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3437
                _v = (byte1 * _short2) + _short3;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3438
                _pResult[0] = _v;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3439
                _pResult[1] = _v >> 8;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3440
#else /* LSBFIRST */
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3441
                _v = (byte1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3442
                ((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3443
#endif
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3444
                _v >>= 16; /* now _v contains the carry*/
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3445
                _pResult += 2;                
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3446
                if (_v) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3447
                    /* distribute carry - short-wise, then byte-wise */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3448
                    _pResult1 = _pResult;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3449
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3450
                    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3451
                    for (_pResult1 = _pResult; _v; _pResult1 += 2) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3452
                        if (_pResult1 > _pResultLast1) break;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3453
                        _v += ((unsigned short *)_pResult1)[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3454
                        ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3455
                        _v >>= 16;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3456
                    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3457
#endif /* __LSBFIRST */
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3458
                    for (; _v; _pResult1++) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3459
                        _v += _pResult1[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3460
                        _pResult1[0] = _v /* & 0xFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3461
                        _v >>= 8;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3462
                    }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3463
                }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3464
                _p2 += 2;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3465
            }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3466
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3467
            /* possible odd highByte of f2 (or byteLoop, if not LSBFIRST) */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3468
            while (_p2 <= _p2Last) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3469
                _v = (byte1 * _p2[0]) + _pResult[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3470
                _pResult[0] = _v /* & 0xFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3471
                _v >>= 8; /* now _v contains the carry*/
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3472
                _pResult++;                
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3473
                if (_v) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3474
                    /* distribute carry */
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3475
                    for (_pResult1 = _pResult; _v; _pResult1++) {
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3476
                        _v += _pResult1[0];
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3477
                        _pResult1[0] = _v /* & 0xFF */;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3478
                        _v >>= 8;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3479
                    }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3480
                }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3481
                _p2++;
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3482
            }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3483
        }
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3484
        ok = true;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3485
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3486
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3487
    ok ifFalse:[
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3488
        1 to:len1 do:[:index1 |
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3489
            1 to:len2 do:[:index2 |
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3490
                dstIndex := index1 + index2 - 1.
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3491
                prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3492
                prod := prod + (resultDigitByteArray basicAt:dstIndex).
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3493
                resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3494
                carry := prod bitShift:-8.
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3495
                carry ~~ 0 ifTrue:[
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3496
                    idx := dstIndex + 1.
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3497
                    [carry ~~ 0] whileTrue:[
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3498
                        v := (resultDigitByteArray basicAt:idx) + carry.
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3499
                        resultDigitByteArray basicAt:idx put:(v bitAnd:255).
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3500
                        carry := v bitShift:-8.
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3501
                        idx := idx + 1
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3502
                    ]
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3503
                ]
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3504
            ]
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  3505
        ].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3506
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3507
    ^ result compressed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3508
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3509
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3510
absPlus:aLargeInteger sign:newSign
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3511
    "return a LargeInteger representing abs(self) + abs(theArgument)
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3512
     with sign: newSign.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3513
     The result is normalized. The argument must be a smallInteger
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3514
     with byteSize one less than the integer byteSize.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3515
     This is a helper for addition and subtraction - not for public use."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3516
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3517
    |result done otherDigitByteArray resultDigitByteArray
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3518
     len1   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3519
     len2   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3520
     newLen "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3521
     index  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3522
     carry  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3523
     sum    "{ Class: SmallInteger }" |
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3524
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3525
    otherDigitByteArray := aLargeInteger digitBytes.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3526
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3527
%{
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3528
    OBJ _digitByteArray = __INST(digitByteArray);
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3529
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3530
    if (__isByteArray(_digitByteArray)
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3531
     && __isByteArray(otherDigitByteArray)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3532
	int _len1, _len2, _newLen;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3533
	unsigned char *_myDigits, *_otherDigits, *_newDigits;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3534
	int _index, _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3535
	int _comLen;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3536
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3537
	_len1 = __byteArraySize(_digitByteArray);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3538
	_len2 = __byteArraySize(otherDigitByteArray);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3539
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3540
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3541
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3542
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3543
	if (_len1 < _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3544
	    _comLen = _len1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3545
	    _newLen = _len2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3546
	    if (_otherDigits[_len2 - 1] == 0xFF) _newLen++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3547
	} else if (_len2 < _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3548
	    _comLen = _len2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3549
	    _newLen = _len1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3550
	    if (_myDigits[_len1 - 1] == 0xFF) _newLen++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3551
	} else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3552
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3553
	     * there can only be an overflow from the high bytes,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3554
	     * if their sum is >= 255
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3555
	     * (with sum==255, a carry could still occur from the next lower bytes)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3556
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3557
	    _newLen = _len1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3558
	    if ((_otherDigits[_len2 - 1] + _myDigits[_len1 - 1]) >= 0xFF) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3559
		_newLen++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3560
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3561
		if (_newLen == sizeof(INT)) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3562
		    OBJ _uint;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3563
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3564
		    /* 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3565
		     * two word-sized numbers, no carry - a very common case ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3566
		     */
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3567
#if defined(__LSB_FIRST) || defined(i386) || defined(alpha)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3568
		    unsigned INT _sum = *(unsigned INT *)_otherDigits + *(unsigned INT *)_myDigits;
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3569
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3570
		    unsigned INT _sum = __unsignedLongIntVal(self) + __unsignedLongIntVal(aLargeInteger);
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  3571
#endif /* not LSB_FIRST */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3572
		    if (_sum <= _MAX_INT) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3573
			_uint = __MKSMALLINT(_sum * __intVal(newSign));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3574
		    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3575
			_uint = __MKULARGEINT(_sum);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3576
			__LargeIntegerInstPtr(_uint)->l_sign = newSign;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3577
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3578
		    RETURN (_uint);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3579
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3580
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3581
	    _comLen = _len1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3582
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3583
	resultDigitByteArray = __BYTEARRAY_UNINITIALIZED_NEW_INT(_newLen);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3584
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3585
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3586
	 * must refetch - GC could have been invoked
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3587
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3588
	_digitByteArray = __INST(digitByteArray);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3589
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3590
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3591
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3592
	_newDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3593
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3594
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3595
	 * add them ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3596
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3597
	_index = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3598
	_carry = 0;
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3599
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3600
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3601
# if 0 && defined(alpha64) && defined(__GNUC__)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3602
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3603
	    int _comLen7;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3604
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3605
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3606
	     * have a 64bit integers;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3607
	     * add quad-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3608
	     * accessing bytes at: [index-1][index][index+1]..[index+6]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3609
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3610
	    _comLen7 = _comLen - 3 - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3611
	    while (_index <= _comLen7) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3612
		UINT64 _sum, _t1, _t2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3613
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3614
		asm ("addq   %5,%6,%1         /* sum */                  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3615
		      addq   %0,%1,%1         /* plus carryIn */         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3616
		      cmpult %1,%5,%2         /* was there a carry ? */  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3617
		      cmpult %1,%6,%3         /* was there a carry ? */  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3618
		      bis    %2,%3,%0         /* carryOut */             \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3619
		     "    
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3620
			: "=r"  (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3621
			  "=r"  (_sum),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3622
			  "r"   (_t1),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3623
			  "r"   (_t2)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3624
			: "r"   (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3625
			  "r"   (((unsigned long *)(&(_myDigits[_index - 1])))[0]), 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3626
			  "r"   (((unsigned long *)(&(_otherDigits[_index - 1])))[0])
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3627
		    );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3628
		/* _sum = _sum & 0xFFFFFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3629
		((unsigned long *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3630
		_index += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3631
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3632
	}
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3633
# endif /* alpha64 */
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3634
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
  3635
# if 0 && defined(alpha64)      /* not faster */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3636
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3637
	    int _comLen7;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3638
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3639
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3640
	     * have a 64bit integers;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3641
	     * add quad-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3642
	     * accessing bytes at: [index-1][index][index+1]..[index+6]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3643
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3644
	    _comLen7 = _comLen - 3 - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3645
	    while (_index <= _comLen7) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3646
		UINT64 _sum, _t1, _t2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3647
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3648
		_t1 = ((UINT64 *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3649
		_t2 = ((UINT64 *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3650
		_sum = _t1 + _t2 + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3651
		((UINT64 *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3652
		_carry = (_sum < _t1) | (_sum < _t2);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3653
		_index += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3654
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3655
	}
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3656
# endif /* alpha64 */
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3657
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3658
# ifdef UINT64
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3659
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3660
	    int _comLen3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3661
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3662
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3663
	     * have a 64bit integer type;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3664
	     * add int-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3665
	     * accessing bytes at: [index-1][index][index+1][index+2]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3666
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3667
	    _comLen3 = _comLen - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3668
	    while (_index <= _comLen3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3669
		UINT64 _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3670
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3671
		/* do not merge the 3 lines below into one -
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3672
		 * (will do sign extension then, which is wrong here)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3673
		 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3674
		_sum = (unsigned)_carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3675
		_sum += ((unsigned int *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3676
		_sum += ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3677
		_carry = _sum >> 32;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3678
		/* _sum = _sum & 0xFFFFFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3679
		((unsigned int *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3680
		_index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3681
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3682
	}
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3683
# else
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  3684
#  if defined(i386) && defined(__GNUC__)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3685
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3686
	    int _comLen3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3687
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3688
	    _comLen3 = _comLen - 3 - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3689
	    while (_index <= _comLen3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3690
		unsigned int _sum, _sum2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3691
		unsigned int __in1A, __in1B, __in2A, __in2B;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3692
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3693
		__in1A = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3694
		__in2A = ((unsigned int *)(&(_myDigits[_index - 1])))[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3695
		__in1B = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3696
		__in2B = ((unsigned int *)(&(_otherDigits[_index - 1])))[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3697
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3698
		asm ("addl %%edx,%%eax  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3699
		      movl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3700
		      adcl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3701
		      addl %5,%%eax     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3702
		      adcl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3703
					\n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3704
		      addl %%edx,%%ecx  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3705
		      movl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3706
		      adcl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3707
		      addl %7,%%ecx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3708
		      adcl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3709
		     "    
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3710
			: "=d"  (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3711
			  "=a"  (_sum),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3712
			  "=c"  (_sum2)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3713
			: "0"   (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3714
			  "1"   (__in1A), 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3715
			  "rm"  (__in1B), 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3716
			  "2"   (__in2A), 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3717
			  "rm"  (__in2B) 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3718
		    );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3719
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3720
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3721
		((unsigned *)(&(_newDigits[_index - 1])))[1] = _sum2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3722
		_index += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3723
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3724
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3725
	     * add int-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3726
	     * accessing bytes at: [index-1][index][index+1][index+2]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3727
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3728
	    _comLen3 = _comLen3 + 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3729
	    if (_index <= _comLen3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3730
		unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3731
		unsigned int __inA, __inB;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3732
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3733
		__inA = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3734
		__inB = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3735
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3736
		asm ("addl %%edx,%%eax      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3737
		      movl $0,%%edx         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3738
		      adcl $0,%%edx         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3739
		      addl %4,%%eax         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3740
		      adcl $0,%%edx"    
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3741
			: "=d"  (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3742
			  "=a"  (_sum)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3743
			: "0"   (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3744
			  "1"   (__inA), 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3745
			  "rm"  (__inB) 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3746
		    );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3747
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3748
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3749
		_index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3750
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3751
	}
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  3752
#  endif /* i386 && GNUC */
4276
e521248cbb88 tuned large + large on win32
Claus Gittinger <cg@exept.de>
parents: 4270
diff changeset
  3753
#  if defined(i386) && defined(WIN32)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3754
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3755
	    int _comLen3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3756
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3757
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3758
	     * add long-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3759
	     * accessing bytes at: [index-1][index][index+1][index+2]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3760
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3761
	    _comLen3 = _comLen - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3762
	    while (_index <= _comLen3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3763
		unsigned int _sum, _v1, _v2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3764
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3765
		_v1 = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3766
		_v2 = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3767
		asm { 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3768
		      mov eax, _v1   
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3769
		      add eax, _v2   
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3770
		      mov edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3771
		      adc edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3772
		      add eax, _carry   
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3773
		      adc edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3774
		      mov _carry, edx
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3775
		      mov _sum, eax
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3776
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3777
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3778
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3779
		_index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3780
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3781
	}
4276
e521248cbb88 tuned large + large on win32
Claus Gittinger <cg@exept.de>
parents: 4270
diff changeset
  3782
#  endif /* i386 && WIN32 */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3783
# endif /* INT64 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3784
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3785
	 * add short-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3786
	 * accessing bytes at: [index-1][index]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3787
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3788
	while (_index < _comLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3789
	    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3790
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3791
	    _sum = _carry 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3792
		   + ((unsigned short *)(&(_myDigits[_index - 1])))[0]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3793
		   + ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3794
	    _carry = _sum >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3795
	    /* _sum = _sum & 0xFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3796
	    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3797
	    _index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3798
	}
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3799
#else
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3800
# ifdef sparc
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3801
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3802
	 * add short-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3803
	 * accessing bytes at: [index-1][index]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3804
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3805
	while (_index < _comLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3806
	    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3807
	    unsigned short _v1, _v2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3808
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3809
	    _v1 = ((unsigned short *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3810
	    _v2 = ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3811
	    _sum = _carry + (_v1>>8) + (_v2>>8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3812
	    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3813
	    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3814
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3815
	    _sum = _carry + (_v1 & 0xFF) + (_v2 & 0xFF);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3816
	    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3817
	    _newDigits[_index] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3818
	    _index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3819
	}
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  3820
# endif
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
  3821
#endif /* __LSBFIRST */
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  3822
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3823
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3824
	 * add byte-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3825
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3826
	while (_index <= _comLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3827
	    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3828
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3829
	    _sum = _carry 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3830
		   + _myDigits[_index - 1] 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3831
		   + _otherDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3832
	    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3833
	    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3834
	    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3835
	    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3836
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3837
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3838
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3839
	 * rest
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3840
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3841
	if (_len1 > _len2) {
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3842
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3843
	    if (_index <= _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3844
		if ((_index - 1) & 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3845
		    /* odd byte */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3846
		    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3847
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3848
		    _sum = _carry + _myDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3849
		    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3850
		    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3851
		    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3852
		    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3853
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3854
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3855
		while (_index < _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3856
		    /* shorts */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3857
		    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3858
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3859
		    _sum = _carry + *(unsigned short *)(&(_myDigits[_index - 1]));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3860
		    _carry = _sum >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3861
		    /* _sum = _sum & 0xFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3862
		    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3863
		    _index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3864
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3865
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3866
		if (_index <= _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3867
		    /* last byte */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3868
		    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3869
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3870
		    _sum = _carry + _myDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3871
		    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3872
		    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3873
		    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3874
		    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3875
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3876
	    }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3877
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3878
	    while (_index <= _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3879
		unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3880
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3881
		_sum = _carry + _myDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3882
		_carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3883
		/* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3884
		_newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3885
		_index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3886
	    }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3887
#endif /* not LSB */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3888
	} else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3889
	    if (_len2 > _len1) {
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3890
#if defined(__LSBFIRST) || defined(alpha) || defined(i386)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3891
		if (_index <= _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3892
		    if ((_index - 1) & 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3893
			/* odd byte */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3894
			unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3895
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3896
			_sum = _carry + _otherDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3897
			_carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3898
			/* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3899
			_newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3900
			_index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3901
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3902
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3903
		    while (_index < _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3904
			/* shorts */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3905
			unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3906
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3907
			_sum = _carry + *(unsigned short *)(&(_otherDigits[_index - 1]));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3908
			_carry = _sum >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3909
			/* _sum = _sum & 0xFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3910
			*(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3911
			_index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3912
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3913
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3914
		    if (_index <= _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3915
			/* last byte */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3916
			unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3917
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3918
			_sum = _carry + _otherDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3919
			_carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3920
			/* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3921
			_newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3922
			_index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3923
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3924
		}
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3925
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3926
		while (_index <= _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3927
		    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3928
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3929
		    _sum = _carry + _otherDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3930
		    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3931
		    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3932
		    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3933
		    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3934
		}
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  3935
#endif /* not LSB */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3936
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3937
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3938
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3939
	while (_index <= _newLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3940
	    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3941
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3942
	    _sum = _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3943
	    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3944
	    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3945
	    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3946
	    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3947
	}
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3948
    }
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3949
%}.
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3950
    resultDigitByteArray notNil ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3951
	result := self class basicNew.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3952
	result setDigits:resultDigitByteArray.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3953
	result sign:newSign.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  3954
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3955
	len1 := digitByteArray size.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3956
	len2 := otherDigitByteArray size.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3957
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3958
	"/ earlier versions estimated the newLength as:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3959
	"/ (len1 max:len2) + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3960
	"/ and reduced the result.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3961
	"/ however, if one of the addends is smaller,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3962
	"/ the result will never require another digit,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3963
	"/ if the highest digit of the larger addent is
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3964
	"/ not equal to 255. Therefore, in most cases,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3965
	"/ we can avoid the computation and resizing 
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3966
	"/ in #reduced.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3967
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3968
	len1 < len2 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3969
	    newLen := len2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3970
	    (otherDigitByteArray at:len2) == 16rFF ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3971
		newLen := newLen + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3972
	    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3973
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3974
	    len2 < len1 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3975
		newLen := len1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3976
		(digitByteArray at:len1) == 16rFF ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3977
		    newLen := newLen + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3978
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3979
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3980
		newLen := len1 + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3981
	    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3982
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3983
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3984
	result := self class basicNew numberOfDigits:newLen.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3985
	result sign:newSign.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3986
	resultDigitByteArray := result digitBytes.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3987
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3988
	index := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3989
	carry := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3990
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3991
	done := false.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3992
	[done] whileFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3993
	    sum := carry.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3994
	    (index <= len1) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3995
		sum := sum + (digitByteArray basicAt:index).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3996
		(index <= len2) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3997
		    sum := sum + (otherDigitByteArray basicAt:index)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3998
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3999
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4000
		(index <= len2) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4001
		    sum := sum + (otherDigitByteArray basicAt:index)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4002
		] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4003
		    "end reached"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4004
		    done := true
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4005
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4006
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4007
	    (sum >= 16r100) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4008
		carry := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4009
		sum := sum - 16r100
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4010
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4011
		carry := 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4012
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4013
	    resultDigitByteArray basicAt:index put:sum.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4014
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4015
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4016
    ].
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4017
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4018
    ^ result compressed
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4019
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4020
    "Modified: 11.8.1997 / 03:23:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4021
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4022
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4023
absSubtract:aLargeInteger
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4024
    "private helper for division:
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4025
        destructively subtract aLargeInteger from myself
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4026
        AND return true, if the result is non-zero, false otherwise.
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4027
        (i.e. this method has both a return value and a side-effect
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4028
         on the receiver)
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4029
        Only allowed for positive receiver and argument
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4030
        The receiver must be >= the argument.
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4031
        The receiver must be a temporary scratch-number"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4032
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4033
    |otherDigitByteArray
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4034
     len1   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4035
     len2   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4036
     index  "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4037
     borrow "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4038
     diff   "{ Class: SmallInteger }"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4039
     notZero
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4040
    |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4041
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4042
    notZero := false.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4043
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4044
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4045
    len2 := otherDigitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4046
    len2 > len1 ifTrue:[
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4047
        [(otherDigitByteArray at:len2) == 0] whileTrue:[
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4048
            len2 := len2 - 1
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4049
        ].
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4050
        len2 > len1 ifTrue:[
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4051
            self error:'operation failed' "/ may not be called that way
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4052
        ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4053
    ].
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4054
    "/ knowing that len2 is <= len1
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4055
%{
4189
Claus Gittinger <cg@exept.de>
parents: 4188
diff changeset
  4056
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4057
    OBJ _digitByteArray = __INST(digitByteArray);
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4058
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4059
    if (__isByteArray(_digitByteArray)
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4060
     && __isByteArray(otherDigitByteArray)) {
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4061
        int _len1 = __intVal(len1), 
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4062
            _len2 = __intVal(len2);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4063
        unsigned char *_myDigits, *_otherDigits;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4064
        int _index = 1, _borrow = 0;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4065
        INT _diff;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4066
        INT anyBitNonZero = 0;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4067
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4068
        _otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4069
        _myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4070
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4071
#if defined(alpha64)
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4072
        {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4073
            int _len2Q;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4074
            /*
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4075
             * subtract int-wise
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4076
             */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4077
            _len2Q = _len2-2;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4078
            while (_index < _len2Q) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4079
                /* do not combine the expression below (may lead to unsigned result on some machines */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4080
                _diff = ((unsigned int *)(_myDigits+_index-1))[0];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4081
                _diff -= ((unsigned int *)(_otherDigits+_index-1))[0];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4082
                _diff -= _borrow;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4083
                if (_diff >= 0) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4084
                    _borrow = 0;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4085
                } else {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4086
                    _borrow = 1;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4087
                    /* _diff += 0x10000; */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4088
                }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4089
                ((unsigned int *)(_myDigits+_index-1))[0] = _diff;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4090
                anyBitNonZero |= (_diff & 0xFFFFFFFFL);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4091
                _index += 4;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4092
            }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4093
        }
4270
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4094
#endif
01f4b79450ff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4268
diff changeset
  4095
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4096
#if defined(i386) || defined(__LSBFIRST)
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4097
        /*
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4098
         * subtract short-wise
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4099
         */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4100
        while (_index < _len2) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4101
            /* do not combine the expression below (may lead to unsigned result on some machines */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4102
            _diff = ((unsigned short *)(_myDigits+_index-1))[0];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4103
            _diff -= ((unsigned short *)(_otherDigits+_index-1))[0];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4104
            _diff -= _borrow;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4105
            if (_diff >= 0) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4106
                _borrow = 0;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4107
            } else {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4108
                _borrow = 1;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4109
                /* _diff += 0x10000; */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4110
            }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4111
            ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4112
            anyBitNonZero |= (_diff & 0xFFFF);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4113
            _index += 2;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4114
        }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4115
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4116
        if (_index <= _len2) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4117
            /*
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4118
             * cannot continue with shorts - there is an odd number of
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4119
             * bytes in the minuent
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4120
             */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4121
        } else {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4122
            while (_index < _len1) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4123
                /* do not combine the expression below (may lead to unsigned result on some machines */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4124
                _diff = ((unsigned short *)(_myDigits+_index-1))[0];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4125
                _diff -= _borrow;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4126
                if (_diff >= 0) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4127
                    /* _borrow = 0; */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4128
                    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4129
                    anyBitNonZero |= (_diff & 0xFFFF);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4130
                    _index += 2;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4131
                    while (_index < _len1) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4132
                        anyBitNonZero |= ((unsigned short *)(_myDigits+_index-1))[0];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4133
                        if (anyBitNonZero) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4134
                            RETURN (true);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4135
                        }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4136
                        _index += 2;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4137
                    }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4138
                    /* last odd index */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4139
                    if (_index <= _len1) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4140
                        anyBitNonZero |= _myDigits[_index - 1];;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4141
                        if (anyBitNonZero) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4142
                            RETURN (true);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4143
                        }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4144
                        _index++;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4145
                    }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4146
                    RETURN (anyBitNonZero ? true : false);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4147
                }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4148
                _borrow = 1;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4149
                /* _diff += 0x10000; */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4150
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4151
                ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4152
                anyBitNonZero |= (_diff & 0xFFFF);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4153
                _index += 2;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4154
            }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4155
        }
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4156
#endif
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4157
        /*
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4158
         * subtract byte-wise
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4159
         */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4160
        while (_index <= _len2) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4161
            /* do not combine the expression below (may lead to unsigned result on some machines */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4162
            _diff = _myDigits[_index - 1];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4163
            _diff -= _otherDigits[_index - 1];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4164
            _diff -= _borrow;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4165
            if (_diff >= 0) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4166
                _borrow = 0;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4167
            } else {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4168
                _borrow = 1;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4169
                /* _diff += 0x100; */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4170
            }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4171
            _myDigits[_index - 1] = _diff;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4172
            anyBitNonZero |= (_diff & 0xFF);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4173
            _index++;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4174
        }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4175
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4176
        while (_index <= _len1) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4177
            /* do not combine the expression below (may lead to unsigned result on some machines */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4178
            _diff = _myDigits[_index - 1];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4179
            _diff -= _borrow;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4180
            if (_diff >= 0) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4181
                /* _borrow = 0; */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4182
                _myDigits[_index - 1] = _diff;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4183
                anyBitNonZero |= (_diff & 0xFF);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4184
                _index++;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4185
                while (_index <= _len1) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4186
                    anyBitNonZero |= _myDigits[_index - 1];
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4187
                    if (anyBitNonZero) {
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4188
                        RETURN (true);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4189
                    }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4190
                    _index++;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4191
                }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4192
                break;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4193
            }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4194
            _borrow = 1;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4195
            /* _diff += 0x100; */
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4196
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4197
            _myDigits[_index - 1] = _diff;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4198
            anyBitNonZero |= (_diff & 0xFF);
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4199
            _index++;
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4200
        }
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4201
        RETURN (anyBitNonZero ? true : false);
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4202
    }
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4203
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4204
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4205
    index := 1.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4206
    borrow := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4207
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4208
    [index <= len1] whileTrue:[
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4209
        diff := borrow.
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4210
        diff := diff + (digitByteArray basicAt:index).
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4211
        index <= len2 ifTrue:[
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4212
            diff := diff - (otherDigitByteArray basicAt:index).
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4213
        ].
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4214
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4215
        "/ workaround for
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4216
        "/ gcc code generator bug
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4217
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4218
        (diff >= 0) ifTrue:[
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4219
            borrow := 0
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4220
        ] ifFalse:[
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4221
            borrow := -1.
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4222
            diff := diff + 16r100
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4223
        ].
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4224
        diff ~~ 0 ifTrue:[
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4225
            notZero := true
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4226
        ].
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4227
        digitByteArray basicAt:index put:diff.
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  4228
        index := index + 1
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4229
    ].
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4230
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4231
    ^ notZero
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4232
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4233
    "Created: / 5.11.1996 / 16:23:47 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4234
    "Modified: / 5.11.1996 / 18:56:50 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4235
    "Modified: / 27.4.1999 / 18:08:23 / stefan"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4236
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4237
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4238
div2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4239
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4240
       destructively divide the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4241
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4242
    |prevBit|
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4243
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4244
%{  /* NOCONTEXT */
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4245
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4246
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4247
    if (__isByteArray(__digits)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4248
	int __nBytes = __byteArraySize(__digits);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4249
	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4250
	unsigned INT __this, __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4251
	int __idx;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4252
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4253
	if (__nBytes == 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4254
	    __bp[0] >>= 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4255
	    RETURN (self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4256
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4257
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4258
	__idx = 1;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4259
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4260
#if defined(alpha64)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4261
	if (sizeof(unsigned INT) == 8) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4262
	    int __endIndex = __nBytes - 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4263
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4264
	    if (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4265
		__this = ((unsigned INT *)__bp)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4266
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4267
		while (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4268
		    __next = ((unsigned INT *)__bp)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4269
		    __this = (__this >> 1) /* & 0x7FFFFFFFFFFFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4270
		    __this |= __next << 63;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4271
		    ((unsigned INT *)__bp)[0] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4272
		    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4273
		    __bp += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4274
		    __idx += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4275
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4276
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4277
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4278
#else
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  4279
# if defined(__LSBFIRST)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4280
	if (sizeof(unsigned int) == 4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4281
	    int __endIndex = __nBytes - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4282
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4283
	    if (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4284
		__this = ((unsigned INT *)__bp)[0];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4285
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  4286
# if 0
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4287
		__idx += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4288
		while (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4289
		    __next = ((unsigned int *)__bp)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4290
		    __this = (__this >> 1) /* & 0x7FFFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4291
		    __this |= __next << 31;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4292
		    ((unsigned int *)__bp)[0] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4293
		    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4294
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4295
		    __next = ((unsigned int *)__bp)[2];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4296
		    __this = (__this >> 1) /* & 0x7FFFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4297
		    __this |= __next << 31;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4298
		    ((unsigned int *)__bp)[1] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4299
		    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4300
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4301
		    __bp += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4302
		    __idx += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4303
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4304
		__idx -= 4;
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  4305
# endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4306
		while (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4307
		    __next = ((unsigned int *)__bp)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4308
		    __this = (__this >> 1) /* & 0x7FFFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4309
		    __this |= __next << 31;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4310
		    ((unsigned int *)__bp)[0] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4311
		    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4312
		    __bp += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4313
		    __idx += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4314
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4315
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4316
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4317
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4318
#endif
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4319
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4320
	__this = __bp[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4321
	while (__idx < __nBytes) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4322
	    __next = __bp[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4323
	    __this >>= 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4324
	    __this |= __next << 7;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4325
	    __bp[0] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4326
	    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4327
	    __bp++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4328
	    __idx++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4329
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4330
	__bp[0] = __this >> 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4331
	RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4332
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4333
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4334
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4335
    prevBit := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4336
    digitByteArray size to:1 by:-1 do:[:idx |
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4337
	|thisByte|
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4338
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4339
	thisByte := digitByteArray at:idx.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4340
	digitByteArray at:idx put:((thisByte bitShift:-1) bitOr:prevBit).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4341
	prevBit := (thisByte bitAnd:1) bitShift:7.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4342
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4343
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4344
    "
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  4345
     100000 asLargeInteger div2           
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4346
     1000000000000000000000000000 div2  
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4347
     10000000000000000000000000000000000000000000 div2
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  4348
    "                                                     
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4349
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4350
    "Modified: 5.11.1996 / 16:12:56 / cg"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4351
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4352
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4353
mul2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4354
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4355
       destructively multiply the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4356
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4357
    |nBytes "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4358
     b      "{ Class: SmallInteger }"
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4359
     t prevBit|
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4360
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4361
    nBytes := digitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4362
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4363
    b := digitByteArray at:nBytes.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4364
    (b bitAnd:16r80) ~~ 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4365
	"/ need another byte
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4366
	nBytes := nBytes + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4367
	t := ByteArray uninitializedNew:nBytes.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4368
	t replaceFrom:1 to:nBytes-1 with:digitByteArray startingAt:1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4369
	t at:nBytes put:0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4370
	digitByteArray := t.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4371
    ].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4372
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4373
%{
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4374
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4375
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4376
    if (__isByteArray(__digits)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4377
	int __nBytes = __intVal(nBytes);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4378
	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4379
	unsigned INT __carry = 0, __newCarry,  __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4380
	int __idx;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4381
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4382
#if defined(alpha64)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4383
	if (sizeof(unsigned INT) == 8) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4384
	    while (__nBytes >= 8) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4385
		__this = ((unsigned INT *)__bp)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4386
		__newCarry = (__this >> 63) /* & 1 */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4387
		((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4388
		__carry = __newCarry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4389
		__bp += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4390
		__nBytes -= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4391
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4392
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4393
#else
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4394
# if defined(__LSBFIRST) || defined(i386) /* XXX actually: LSB_FIRST */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4395
	if (sizeof(unsigned int) == 4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4396
	    while (__nBytes >= 4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4397
		__this = ((unsigned int *)__bp)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4398
		__newCarry = (__this >> 31) /* & 1 */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4399
		((unsigned int *)__bp)[0] = (__this << 1) | __carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4400
		__carry = __newCarry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4401
		__bp += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4402
		__nBytes -= 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4403
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4404
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4405
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4406
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4407
	while (__nBytes) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4408
	    __this = __bp[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4409
	    __newCarry = (__this >> 7) /* & 1 */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4410
	    __bp[0] = (__this << 1) | __carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4411
	    __carry = __newCarry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4412
	    __bp++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4413
	    __nBytes--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4414
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4415
	RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4416
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4417
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4418
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4419
    prevBit := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4420
    1 to:digitByteArray size do:[:idx |
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4421
	|thisByte|
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4422
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4423
	thisByte := digitByteArray at:idx.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4424
	digitByteArray at:idx put:(((thisByte bitShift:1) bitAnd:16rFF) bitOr:prevBit).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4425
	prevBit := (thisByte bitShift:-7) bitAnd:1.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4426
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4427
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4428
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4429
     100000 asLargeInteger mul2 
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4430
     16r7FFFFFFFFFFF copy mul2 hexPrintString
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4431
     16rFFFFFFFFFFFF copy mul2 hexPrintString 
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4432
     16r7FFFFFFFFFFFFF copy mul2 hexPrintString 
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4433
     16rFFFFFFFFFFFFFF copy mul2 hexPrintString 
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4434
     10000000000000000000000000000 mul2 
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4435
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4436
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4437
    "Modified: 5.11.1996 / 16:37:32 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4438
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4439
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4440
mul256
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4441
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4442
       destructively multiply the receiver by 256."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4443
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4444
    |newDigits newSize|
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4445
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4446
    newSize := digitByteArray size + 1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4447
    newDigits := ByteArray uninitializedNew:newSize.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4448
"/    newDigits replaceFrom:2 with:digitByteArray startingAt:1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4449
    newDigits replaceBytesFrom:2 to:newSize with:digitByteArray startingAt:1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4450
    newDigits at:1 put:0.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4451
    digitByteArray := newDigits
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4452
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4453
    "Modified: / 20.5.1999 / 09:16:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4454
!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4455
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4456
numberOfDigits:nDigits
2001
8c2b957f0cb3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
  4457
"/    digitByteArray := ByteArray uninitializedNew:nDigits.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4458
    digitByteArray := ByteArray new:nDigits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4459
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4460
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4461
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4462
setDigits:digits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4463
    digitByteArray := digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4464
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4465
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4466
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4467
sign:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4468
    sign := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4469
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4470
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4471
!LargeInteger methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4472
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4473
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4474
    "return true if the receiver is even"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4475
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4476
    ^ (digitByteArray at:1) even
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4477
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4478
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4479
negative
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4480
    "return true, if the receiver is < 0"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4481
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4482
    ^ (sign < 0)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4483
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4484
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4485
odd
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4486
    "return true if the receiver is odd"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4487
1983
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4488
    ^ (digitByteArray at:1) odd
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4489
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  4490
    "Modified: 18.11.1996 / 22:19:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4491
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4492
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4493
positive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4494
    "return true, if the receiver is >= 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4495
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4496
    ^ (sign >= 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4497
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4498
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4499
sign
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7446
diff changeset
  4500
    "return the sign of the receiver (-1, 0 or 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4501
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4502
    ^ sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4503
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4504
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4505
strictlyPositive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4506
    "return true, if the receiver is > 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4507
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4508
    ^ (sign > 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4509
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4510
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  4511
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4512
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4513
version
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  4514
    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.177 2004-04-27 12:29:44 stefan Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4515
! !