LargeInteger.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 31 Oct 2011 22:19:21 +0000
branchjv
changeset 17892 d86c8bd5ece3
parent 17869 9610c6c94e71
child 17910 8d796ca8bd1d
permissions -rw-r--r--
Merged with CVS
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
"
5382
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
    12
"{ Package: 'stx:libbasic' }"
b4a9021ea256 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5023
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
Integer subclass:#LargeInteger
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    15
	instanceVariableNames:'sign digitByteArray'
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    16
	classVariableNames:''
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    17
	poolDictionaries:''
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
    18
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
    21
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
 COPYRIGHT (c) 1994 by Claus Gittinger
345
claus
parents: 250
diff changeset
    26
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    37
documentation
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    38
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    39
    This class provides arbitrary precision integers. These are represented as:
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    40
      sign (-1/0/+1) and, if sign ~~ 0
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    41
      a ByteArray of digits with 8 bits per element;
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    42
      least significant 8 bits at index 1 ...
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    43
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
    44
    The implementation is not completely tuned for high performance
4264
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    45
    (more key-methods should be rewritten as primitives), although the
9fd0385c26d0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4263
diff changeset
    46
    common operations have been pretty tuned for some architectures.
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    47
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    48
    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
    49
    SmallInteger arithmetic (overflowing the SmallInteger range).
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    50
    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
    51
    SmallIntegers, when possible (see #compressed).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    52
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    53
    In contrast to ST-80, there is only one class for LargeIntegers, keeping
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    54
    the sign as an instance variable (ST-80 has LargePositiveInteger and
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    55
    LargeNegativeInteger). This may change.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    56
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    57
    [author:]
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
    58
	Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    59
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1504
diff changeset
    60
    [see also:]
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
    61
	Number
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    62
	Float Fraction FixedPoint
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
    63
	SmallInteger
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    64
"
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    65
!
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
testing
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    68
"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
    69
   test largeInt multiplication & division
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    70
   (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
    71
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    72
   |last v|
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    73
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    74
   v := last := 1.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    75
   2 to:3000 do:[:i |
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    76
       i printCR.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
    77
       v := v * i.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    78
       (v / i) ~= last ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
    79
	   self halt
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    80
       ].
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    81
       last := v.
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
    82
   ]
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    83
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
   test addition, subtraction:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    86
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    87
   SmallInteger maxVal                -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    88
   SmallInteger maxVal + 1            -> 1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    89
   SmallInteger maxVal + 2            -> 1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    90
   (SmallInteger maxVal + 2) - 2      -> 1073741823
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    91
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    92
   SmallInteger minVal                -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    93
   SmallInteger minVal - 1            -> -1073741825
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    94
   SmallInteger minVal - 2            -> -1073741826
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    95
   (SmallInteger minVal - 2) + 2      -> -1073741824
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    96
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    97
   1234567890 + 10                    -> 1234567900
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    98
   1111111111 + 1111111111            -> 2222222222
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
    99
   1111111111 - 1111111111            -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   100
   1111111111 - 2222222222            -> -1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   101
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   102
   1111111111 * 2                     -> 2222222222
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
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   105
   1111111111 * 1111111111            -> 1234567900987654321
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   106
   1234567900987654321 // 1111111111  -> 1111111111
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   107
   1234567900987654321 \\ 1111111111  -> 0
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   108
   1234567900987654322 \\ 1111111111  -> 1
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   109
   1234567900987654421 \\ 1111111111  -> 100
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   110
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   111
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   112
   addition:
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   113
   (16rFFFFFFF0 + 1          ) hexPrintString -> 'FFFFFFF1'
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   114
   (16rFFFFFFFF + 1          ) hexPrintString -> '100000000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   115
   (16rFFFFFFFF + 2          ) hexPrintString -> '100000001'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   116
   (16rFFFFFFFF + 16rFFFFFF  ) hexPrintString -> '100FFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   117
   (16rFFFFFFFF + 16rFFFFFFFF) hexPrintString -> '1FFFFFFFE'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   118
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   119
   20 factorial         -> 2432902008176640000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   120
   20 factorial + 10000 -> 2432902008176650000
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   121
   20 factorial               hexPrintString -> '21C3677C82B40000'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   122
   (20 factorial + 16rFFFF)   hexPrintString -> '21C3677C82B4FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   123
   (20 factorial + 16rFFFFFF) hexPrintString -> '21C3677C83B3FFFF'
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
   124
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   125
   test comparison:
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   126
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   127
   -1234567890 >  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   128
   -1234567890 >= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   129
   -1234567890 <  -1234567890         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   130
   -1234567890 <= -1234567890         true
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         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   133
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   134
   -1234567890 >  -1234567891         true
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         false
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         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   140
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   141
   -1234567891 >  -1234567890         false
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         true
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         false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   146
   -1234567891 ~= -1234567890         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   147
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   148
    1234567890 >  -1234567890         true
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         false
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         true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   154
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   155
   -1234567890 >  1234567890          false
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          true
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          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   160
   -1234567890 ~= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   161
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   162
    1234567890 >  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   163
    1234567890 >= 1234567890          true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   164
    1234567890 <  1234567890          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   165
    1234567890 <= 1234567890          true
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          false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   168
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   169
   -1234567890 >  -10                 false
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                 true
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                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   174
   -1234567890 ~= -10                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   175
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   176
   -1234567890 >  10                  false
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                  true
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                  false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   181
   -1234567890 ~= 10                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   182
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   183
   -10 >  -1234567890                 true
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                 false
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                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   189
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   190
    10 >  -1234567890                 true
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                 false
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                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   196
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   197
    1234567890 >  -10                 true
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   198
    1234567890 >= -10                 true
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   199
    1234567890 <  -10                 false
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   200
    1234567890 <= -10                 false
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   201
    1234567890 =  -10                 false
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   202
    1234567890 ~= -10                 true
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   203
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   204
    1234567890 >  10                  true
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                  false
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                  true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   210
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   211
   -10 >   1234567890                 false
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                 true
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                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   216
   -10 ~=  1234567890                 true
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   217
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   218
    10 >   1234567890                 false
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                 true
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                 false
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
   223
    10 ~=  1234567890                 true
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
   224
"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   225
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   226
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   227
!LargeInteger class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   228
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   229
digitBytes:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   230
    "create and return a new LargeInteger with digits (lsb-first)
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   231
     from the argument, aByteArray.
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   232
     Experimental interface - May change/be removed without notice."
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   233
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   234
    ^ self basicNew setDigits:aByteArrayOfDigits
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   235
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
     LargeInteger digitBytes:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]
4806
1b48e7420cfe comment
Claus Gittinger <cg@exept.de>
parents: 4794
diff changeset
   238
     (LargeInteger digitBytes:#[16r12 16r34 16r56 16r78 16r90]) hexPrintString
4794
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   239
    "
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
    "Modified: / 8.5.1998 / 21:40:41 / cg"
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   242
!
19e05d7c2d3b new instance creation: #digitBytes:
Claus Gittinger <cg@exept.de>
parents: 4663
diff changeset
   243
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   244
digitBytes:aByteArrayOfDigits MSB:msb
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   245
    "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
   246
     from the argument, aByteArray."
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   247
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   248
    |digits|
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   249
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   250
    msb == false ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   251
	digits := aByteArrayOfDigits
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   252
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   253
	digits := aByteArrayOfDigits copy reverse
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   254
    ].
6106
daf0e9692237 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   255
    ^ self basicNew setDigits:digits
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   256
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   257
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   258
     (LargeInteger digitBytes:#[16r10 16r20 16r30 16r00] MSB:false) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   259
     (LargeInteger digitBytes:#[16r10 16r20 16r30 16r00] MSB:true) hexPrintString
5020
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   260
    "
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   261
!
eff43341e72c added #digitBytes:MSB:
ca
parents: 5014
diff changeset
   262
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   263
new
4299
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   264
    "catch creation message.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   265
     LargeIntegers are only created by system code, which
4299
2028db93d182 comment
Claus Gittinger <cg@exept.de>
parents: 4293
diff changeset
   266
     uses basicNew and cares for correct initialization."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   267
a27a279701f8 Initial revision
claus
parents:
diff changeset
   268
    self error:'LargeIntegers cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
   269
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   271
new:numberOfDigits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   272
    "catch creation message"
2
claus
parents: 1
diff changeset
   273
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   274
    self error:'LargeIntegers cannot be created with new'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   275
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   276
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   277
value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   278
    "create and return a new LargeInteger with value taken from
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   279
     the argument, aSmallInteger.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   280
     Notice:
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   281
	this should be only used internally, since such small
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   282
	largeIntegers do not normally occur in the system.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   283
	(They are used by myself)
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   284
     May change/be removed without notice."
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
   285
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   286
    ^ self basicNew value:aSmallInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
    "LargeInteger value:3689"
3438
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   289
2e64ef848871 oops - last change was not good
Claus Gittinger <cg@exept.de>
parents: 3431
diff changeset
   290
    "Modified: / 8.5.1998 / 21:40:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   292
17865
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   293
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   294
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   295
!LargeInteger class methodsFor:'queries'!
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   297
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   298
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   299
     Here, true is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   302
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
   303
    "Modified: 23.4.1996 / 15:59:21 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   304
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   305
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   306
!LargeInteger methodsFor:'arithmetic'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   307
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
* aNumber
11731
f3adbab61060 comment
Claus Gittinger <cg@exept.de>
parents: 11723
diff changeset
   309
    "return the product of the receiver and the argument."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   311
    |otherSign numberClass|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
    (sign == 0) ifTrue:[^ 0].  "cannot happen if correctly normalized"
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
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   316
     this is the common case, multiplying with SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
     Use a special method for this case ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   318
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   319
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   320
	^ self productFromInteger:aNumber
701
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
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
     if the argument is not a largeInteger, coerce
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   325
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   326
    (numberClass == self class) ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   327
	^ self retry:#* coercing:aNumber
701
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   330
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   331
    (sign == otherSign) ifTrue:[^ self absMul:aNumber].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   332
    (otherSign == 0) ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   333
    ^ (self absMul:aNumber) sign:-1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   334
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   335
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   336
+ aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   337
    "return the sum of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   338
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   339
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   340
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   341
    (sign == 0) ifTrue:[^ aNumber].  "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   342
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   343
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   344
     this is the common case, adding a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   345
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   346
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   347
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   348
	^ self sumFromInteger:aNumber
92
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
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   352
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   353
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   354
    (numberClass == self class) ifFalse:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   355
	^ self retry:#+ coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   356
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   357
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   358
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   359
    (sign > 0) ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   360
	"I am positive"
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   361
	(otherSign > 0) ifTrue:[^ self absPlus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   362
	(otherSign < 0) ifTrue:[^ self absMinus:aNumber sign:1].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
   363
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   364
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   365
    "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
   366
    (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
   367
    (otherSign < 0) ifTrue:[^ self absPlus:aNumber sign:-1].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   368
    ^ self
357
claus
parents: 345
diff changeset
   369
claus
parents: 345
diff changeset
   370
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   371
     SmallInteger maxVal
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   372
     SmallInteger maxVal + 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   373
     SmallInteger maxVal + 2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   374
     SmallInteger minVal
357
claus
parents: 345
diff changeset
   375
     SmallInteger minVal - 1
claus
parents: 345
diff changeset
   376
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   377
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   378
    "Modified: / 9.1.1998 / 13:26:28 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   379
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   380
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   381
- aNumber
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   382
    "return the difference of the receiver and the argument, aNumber"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   383
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   384
    |otherSign numberClass|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   385
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   386
    (sign == 0) ifTrue:[^ aNumber negated].     "cannot happen if correctly normalized"
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   387
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   388
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   389
     this is the common case, subtracting a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   390
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   391
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   392
    ((numberClass := aNumber class) == SmallInteger) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   393
	sign > 0 ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   394
	    aNumber > 0 ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   395
		^ self absFastMinus:aNumber sign:1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   396
	    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   397
	    ^ self absFastPlus:aNumber sign:1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   398
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   399
	aNumber > 0 ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   400
	    ^ self absFastPlus:aNumber sign:-1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   401
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   402
	^ self absFastMinus:aNumber sign:-1
92
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
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   406
     if the argument is not a largeInteger, coerce
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   407
    "
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   408
    (numberClass == self class) ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   409
	^ self retry:#- coercing:aNumber
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   410
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   411
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   412
    otherSign := aNumber sign.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   413
    (sign > 0) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   414
	"I am positive"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   415
	(otherSign > 0) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   416
	    "+large - +large"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   417
	    ^ self absMinus:aNumber sign:1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   418
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   419
	(otherSign < 0) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   420
	    "+large - -large"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   421
	    ^ self absPlus:aNumber sign:1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   422
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   423
	"should not happen"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   424
	^ self
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   425
    ].
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   426
    "I am negative"
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   427
    (otherSign > 0) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   428
	"-large - +large"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   429
	^ self absPlus:aNumber sign:-1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   430
    ].
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   431
    (otherSign < 0) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   432
	"-large - -large"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   433
	^ self absMinus:aNumber sign:-1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
   434
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   435
    ^ self
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   436
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   437
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   438
     12345678901234567890 - 0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   439
     12345678901234567890 - 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   440
     12345678901234567890 - -1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   441
     -12345678901234567890 - 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   442
     -12345678901234567890 - -1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   443
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   444
     12345678901234567890 - 12345678901234567880
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   445
     12345678901234567890 - 12345000000000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   446
     12345678901234567890 - -87654321098765432110
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   447
     -12345678901234567890 - 87654321098765432110
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   448
     -12345678901234567890 - -12345678901234567880
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   449
     -12345678901234567890 - -12345678901234567980
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   450
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   451
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
   452
    "Modified: 20.10.1996 / 18:42:16 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   453
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   454
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   455
/ aNumber
1065
77b25fb9f9d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   456
    "return the quotient of the receiver and the argument, aNumber"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   457
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   458
    aNumber isInteger ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   459
	^ Fraction numerator:self 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:
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
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:[
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   486
        abs := aNumber.
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   487
        abs := abs abs.
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   488
        (abs between:1 and:16r00ffffff) ifTrue:[
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   489
            divMod := self absFastDivMod:abs.
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   490
        ] ifFalse:[
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   491
            n := abs asLargeInteger.
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   492
        ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   493
    ] ifFalse:[
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   494
        "
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   495
         if the argument is not a largeInteger, coerce
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   496
        "
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   497
        (cls == self class) ifFalse:[
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   498
            ^ self retry:#// coercing:aNumber
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   499
        ].
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
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:[
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
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:[
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   508
        "/ adjust for truncation if negative and there is a remainder ...
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   509
        "/ be careful: there is one special case to care for here:
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   510
        "/ if quo is maxInt+1, the negation can be represented as a smallInt.
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   511
        quo := quo sign:-1.
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   512
        (divMod at:2) == 0 ifFalse:[
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   513
            ^ quo - 1
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   514
        ].
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   515
        quo digitLength == SmallInteger maxBytes ifTrue:[
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   516
            ^ quo compressed
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
   517
        ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   518
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   519
    ^ quo
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   520
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   521
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   522
     (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
   523
     (-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
   524
     (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
   525
     (-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
   526
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   527
     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
   528
     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
   529
     16rfffffffff // 16r001fffff  =  32768 ifFalse:[self halt].
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   530
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   531
     900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   532
     -900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   533
     900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   534
     -900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   535
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   536
     9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   537
     -9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   538
     9000000000 quo: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   539
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   540
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   541
     0 // 40000000000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   542
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   543
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   544
    "Modified: / 5.11.1996 / 16:39:36 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   545
    "Modified: / 27.4.1999 / 19:50:26 / stefan"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   546
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   547
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   548
\\ aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   549
    "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
   550
     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
   551
     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
   552
     The following is always true:
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   553
	(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
   554
     Compare with #rem:"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   555
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   556
    |abs rem negativeDivisor|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   557
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   558
    aNumber negative ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   559
	negativeDivisor := true.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   560
	abs := aNumber negated.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   561
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   562
	negativeDivisor := false.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   563
	abs := aNumber.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   564
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   565
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   566
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   567
     this is the common case, dividing by a SmallInteger.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   568
     Use a special method for this case ...
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   569
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
   570
    (aNumber class == SmallInteger) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   571
	(abs between:1 and:16r00ffffff) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   572
	    rem := (self absFastDivMod:abs) at:2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   573
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   574
	    rem := self absMod:abs asLargeInteger
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   575
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   576
    ] ifFalse:[
6665
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
	 if the argument is not a largeInteger, coerce
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   579
	"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   580
	(aNumber class == self class) ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   581
	    ^ self retry:#\\ coercing:aNumber
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   582
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   583
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   584
	rem := self absMod:abs.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   585
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   586
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   587
    rem = 0 ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   588
	negativeDivisor ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   589
	    rem := rem sign:-1
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
	(self negative ~~ negativeDivisor) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   592
	    "different sign, so remainder would have been negative.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   593
	     rem has been rounded toward zero, this code will simulate
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   594
	     rounding to negative infinity."
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   595
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   596
	    rem := aNumber - rem.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   597
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   598
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   599
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   600
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   601
    "
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   602
     (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
   603
     (-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
   604
     (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
   605
     (-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
   606
     (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
   607
     (-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
   608
     (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
   609
     (-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
   610
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   611
     9000000000 \\ 7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   612
     -9000000000 \\ 7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   613
     9000000000 \\ -7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   614
     -9000000000 \\ -7
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   615
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   616
     900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   617
     -900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   618
     900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   619
     -900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   620
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   621
     9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   622
     -9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   623
     9000000000 rem: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   624
     -9000000000 rem: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   625
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   626
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   627
    "Modified: / 5.11.1996 / 17:10:10 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   628
    "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
   629
!
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   630
4946
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   631
abs
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   632
    "return my absolute value. redefined for speed."
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
    sign >= 0 ifTrue:[^ self].
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   635
    ^ self negated
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   636
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   637
    "Created: / 26.10.1999 / 21:28:06 / stefan"
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   638
!
d18052030990 fixed add/subtract for alpha;
Claus Gittinger <cg@exept.de>
parents: 4942
diff changeset
   639
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   640
divMod:aNumber
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   641
    "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
   642
     self \\ aNumber.
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   643
     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
   644
     argument."
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   645
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   646
    |cls n|
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   647
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   648
    cls := aNumber class.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   649
    (cls == SmallInteger) ifTrue:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   650
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   651
	 this is the common case, dividing by a SmallInteger.
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   652
	 Use a special method for this case ...
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   653
	"
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   654
	(aNumber between:1 and:16r00ffffff) ifTrue:[
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   655
	    ^ self absFastDivMod:aNumber abs.
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 asLargeInteger.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   658
    ] ifFalse:[
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   659
	(cls == self class) ifFalse:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   660
	    ^ super divMod:aNumber
4162
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   661
	].
0e19153c1481 slightly tuned absMul:
Claus Gittinger <cg@exept.de>
parents: 4160
diff changeset
   662
	n := aNumber.
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   663
    ].
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   664
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   665
    ^ self absDivMod:n abs
1842
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
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   668
     9000000000 // 4000000000   => 2
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   669
     9000000000 \\ 4000000000   => 1000000000
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   670
     9000000000 divMod: 4000000000   => #(2 1000000000)
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   671
    "
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   672
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   673
    "Created: / 29.10.1996 / 21:22:05 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   674
    "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
   675
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   676
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   677
negated
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   678
    "return an integer with value negated from the receivers value."
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   679
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   680
    |newNumber sz|
1210
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 == 0) ifTrue:[^ 0].
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   683
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   684
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   685
     special case for SmallInteger minVal
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   686
    "
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   687
    sign == 1 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   688
	sz := digitByteArray size.
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   689
%{
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   690
	int idx;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   691
	unsigned char *bp;
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
	bp = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   694
	idx = __intVal(sz);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   695
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   696
	while ((idx > 1) && (bp[idx-1] == 0)) idx--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   697
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   698
	if (idx == sizeof(INT)) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   699
#if defined(__LSBFIRST__)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   700
# if __POINTER_SIZE__ == 8
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   701
	    if ( ((unsigned INT *)bp)[0] == 0x4000000000000000L)
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   702
# else
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   703
	    if ( ((unsigned INT *)bp)[0] == 0x40000000)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   704
# endif
3428
fb8dbb5dce40 fixed negated for the minVal case;
Claus Gittinger <cg@exept.de>
parents: 3424
diff changeset
   705
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   706
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   707
	     * generic code
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   708
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   709
	    if ((bp[idx-1] == 0x40)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   710
	     && (bp[idx-2] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   711
	     && (bp[idx-3] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   712
	     && (bp[idx-4] == 0)
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   713
# if __POINTER_SIZE__ == 8
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   714
	     && (bp[idx-5] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   715
	     && (bp[idx-6] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   716
	     && (bp[idx-7] == 0)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   717
	     && (bp[idx-8] == 0)
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   718
# endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   719
	    )
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   720
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   721
	    {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
   722
		RETURN (__mkSmallInteger(_MIN_INT));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   723
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   724
	}
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   725
%}.
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   726
"/      sz == 4 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   727
"/        (digitByteArray at:1) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   728
"/          (digitByteArray at:2) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   729
"/            (digitByteArray at:3) == 0 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   730
"/              (digitByteArray at:4) == 16r40 ifTrue:[
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   731
"/                ^ SmallInteger minVal
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   732
"/              ].
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   733
"/            ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   734
"/          ]
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   735
"/        ]
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
   736
"/      ]
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   737
    ].
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
   738
    "/ cg - can share the digits ...
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
   739
    newNumber := LargeInteger digitBytes:digitByteArray.
1210
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   740
    newNumber sign:(sign negated).
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   741
    ^ newNumber
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   742
!
b2fbf119dbbd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   743
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   744
quo:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   745
    "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
   746
     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
   747
     truncates toward negative infinity).
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   748
     The results sign is negative if the receiver has a sign
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   749
     different from the args sign.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   750
     The following is always true:
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   751
	(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   752
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   753
2521
43b9d4fafb35 removed unused locals
Claus Gittinger <cg@exept.de>
parents: 2495
diff changeset
   754
    |otherSign quo abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   755
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   756
    otherSign := aNumber sign.
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   757
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   758
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   759
     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
   760
     Use a special method for this case ...
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   761
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   762
    (aNumber class == SmallInteger) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   763
	abs := aNumber.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   764
	abs := abs abs.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   765
	(abs between:1 and:16r00ffffff) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   766
	    quo := (self absFastDivMod:abs) at:1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   767
	    (sign == otherSign) ifTrue:[^ quo].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   768
	    ^ quo sign:-1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   769
	]
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   770
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   771
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
     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
   774
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   775
    (aNumber class == self class) ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   776
	^ self retry:#quo: coercing:aNumber
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   777
    ].
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   778
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   779
    sign < 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   780
	(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
   781
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   782
	(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
   783
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   784
    ^ ((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
   785
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   786
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   787
     900 // 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   788
     -900 // 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   789
     900 // -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   790
     -900 // -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   791
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   792
     9000000000 // 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   793
     -9000000000 // 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   794
     9000000000 // -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   795
     -9000000000 // -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   796
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   797
     900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   798
     -900 quo: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   799
     900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   800
     -900 quo: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   801
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   802
     9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   803
     -9000000000 quo: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   804
     9000000000 quo: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   805
     -9000000000 quo: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   806
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   807
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   808
    "Modified: / 5.11.1996 / 14:14:17 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   809
    "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
   810
!
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   811
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   812
rem:aNumber
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   813
    "return the remainder of division of the receiver by the argument, aNumber.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   814
     The returned remainder has the same sign as the receiver.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   815
     The following is always true:
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   816
	(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 6051
diff changeset
   817
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   818
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   819
    |rem abs "{ Class: SmallInteger }" |
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   820
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   821
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   822
     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
   823
     Use special code for this case ...
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   824
    "
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   825
    (aNumber class == SmallInteger) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   826
	abs := aNumber.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   827
	abs := abs abs.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   828
	(abs between:1 and:16r00ffffff) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   829
	    rem := (self absFastDivMod:abs) at:2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   830
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   831
	    rem := self absMod:abs asLargeInteger
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   832
	].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   833
    ] ifFalse:[
6665
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
	 if the argument is not a largeInteger, coerce
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   836
	"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   837
	(aNumber class == self class) ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   838
	    ^ self retry:#rem coercing:aNumber
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   839
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   840
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   841
	rem := self absMod:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   842
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   843
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
   844
    sign < 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
   845
	^ rem sign:-1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   846
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
   847
    ^ rem
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   848
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   849
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   850
     900 \\ 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   851
     -900 \\ 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   852
     900 \\ -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   853
     -900 \\ -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   854
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   855
     9000000000 \\ 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   856
     -9000000000 \\ 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   857
     9000000000 \\ -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   858
     -9000000000 \\ -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   859
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   860
     900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   861
     -900 rem: 400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   862
     900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   863
     -900 rem: -400
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   864
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   865
     9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   866
     -9000000000 rem: 4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   867
     9000000000 rem: -4000000000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
   868
     -9000000000 rem: -4000000000
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   869
    "
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
   870
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
   871
    "Modified: / 5.11.1996 / 14:02:59 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
   872
    "Modified: / 29.4.1999 / 11:26:51 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   873
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   874
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   875
!LargeInteger methodsFor:'bit operators'!
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
   876
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   877
bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   878
    "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
   879
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   880
%{  /* NOCONTEXT */
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   881
    if (__isSmallInteger(anInteger)) {
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   882
        INT v2 = __intVal(anInteger);
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   883
        INT v1;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
   884
#if defined(__LSBFIRST__)
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   885
        v1 = *(INT *)(__byteArrayVal(__INST(digitByteArray)));
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   886
#else
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   887
        unsigned char *digits = (unsigned char *)(__byteArrayVal(__INST(digitByteArray)));
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   888
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   889
        v1 = digits[0] & 0xFF;
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   890
        v1 = v1 | ((digits[1] & 0xFF)<<8);
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   891
        v1 = v1 | ((digits[2] & 0xFF)<<16);
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   892
        v1 = v1 | ((digits[3] & 0xFF)<<24);
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   893
# if (__POINTER_SIZE__ == 8)
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   894
        v1 = v1 | ((digits[4] & 0xFF)<<32);
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   895
        v1 = v1 | ((digits[5] & 0xFF)<<40);
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   896
        v1 = v1 | ((digits[6] & 0xFF)<<48);
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   897
        v1 = v1 | ((digits[7] & 0xFF)<<56);
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   898
 #endif
4663
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
   899
#endif
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
   900
        RETURN ( __mkSmallInteger(v1 & v2) );
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
   901
    }
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   902
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   903
    if (__isLargeInteger(anInteger)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   904
        OBJ _myDigitByteArray = __INST(digitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   905
        OBJ _otherDigitByteArray = __LargeIntegerInstPtr(anInteger)->l_digits;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   906
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   907
        if (__isByteArray(_myDigitByteArray)
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   908
         && __isByteArray(_otherDigitByteArray)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   909
            unsigned char *pDigits1, *pDigits2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   910
            int size1, size2, minSize;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   911
            union {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   912
                double d;                    // force align
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   913
                unsigned char chars[2048+8];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   914
            } buffer;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   915
            unsigned char *pRslt;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   916
            OBJ newDigits, newLarge;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   917
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   918
            pDigits1 = (unsigned char *)(__byteArrayVal(_myDigitByteArray));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   919
            pDigits2 = (unsigned char *)(__byteArrayVal(_otherDigitByteArray));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   920
            pRslt = (void *)(buffer.chars);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   921
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   922
            size1 = __byteArraySize(_myDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   923
            size2 = __byteArraySize(_otherDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   924
            minSize = (size1 < size2) ? size1 : size2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   925
            if (minSize <= sizeof(buffer.chars)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   926
                int n = minSize;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   927
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   928
            /* not worth it - but a nice try and first testbed for mmx... */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   929
#define x__USE_MMX__
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   930
#ifdef __USE_MMX__
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   931
#ifdef __VISUALC__
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   932
                if (((INT)pRslt & 7) == 0) {    // 8-byte aligned
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   933
                    if (((INT)pDigits1 & 7) == ((INT)pDigits2 & 7)) {   // same align
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   934
                        while (((INT)pDigits1 & 7) && (n >= sizeof(int))) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   935
                            ((int *)pRslt)[0] = ((int *)pDigits1)[0] & ((int *)pDigits2)[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   936
                            pRslt += sizeof(int);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   937
                            pDigits1 += sizeof(int);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   938
                            pDigits2 += sizeof(int);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   939
                            pDigits2 += sizeof(int);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   940
                            n -= sizeof(int);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   941
                        }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   942
                        for (; n >= 8; n -= 8) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   943
                            __asm {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   944
                                mov eax, pDigits1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   945
                                movq mm0, [eax]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   946
                                mov eax, pDigits2
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   947
                                movq mm1, [eax]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   948
                                pand mm0, mm1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   949
                                mov eax, pRslt
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   950
                                movq [eax], mm0
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   951
                            }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   952
                            pDigits1 += 8;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   953
                            pDigits2 += 8;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   954
                            pRslt += 8;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   955
                        }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   956
                        __asm {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   957
                            emms ; switch back to FPU state.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   958
                        }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   959
                    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   960
                }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   961
#endif /* __VISUALC__ */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   962
#endif /* __USE_MMX__ */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   963
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   964
                for (; n >= sizeof(INT)*4; n -= sizeof(INT)*4) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   965
                    ((INT *)pRslt)[0] = ((INT *)pDigits1)[0] & ((INT *)pDigits2)[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   966
                    ((INT *)pRslt)[1] = ((INT *)pDigits1)[1] & ((INT *)pDigits2)[1];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   967
                    ((INT *)pRslt)[2] = ((INT *)pDigits1)[2] & ((INT *)pDigits2)[2];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   968
                    ((INT *)pRslt)[3] = ((INT *)pDigits1)[3] & ((INT *)pDigits2)[3];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   969
                    pRslt += sizeof(INT)*4;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   970
                    pDigits1 += sizeof(INT)*4;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   971
                    pDigits2 += sizeof(INT)*4;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   972
                }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   973
                for (; n >= sizeof(INT); n -= sizeof(INT)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   974
                    ((INT *)pRslt)[0] = ((INT *)pDigits1)[0] & ((INT *)pDigits2)[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   975
                    pRslt += sizeof(INT);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   976
                    pDigits1 += sizeof(INT);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   977
                    pDigits2 += sizeof(INT);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   978
                }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   979
                for (; n > 0; n--) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   980
                    *pRslt = *pDigits1 & *pDigits2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   981
                    pRslt++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   982
                    pDigits1++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   983
                    pDigits2++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   984
                }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   985
                // normalize
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   986
                while ((pRslt[-1]==0) && (pRslt > buffer.chars)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   987
                    pRslt--;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   988
                }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   989
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   990
                // allocate result
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   991
                n = pRslt-buffer.chars;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   992
                if (n <= sizeof(INT)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   993
                    INT val = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   994
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   995
                    // make it a smallInteger / 32bitInteger
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   996
                    while (n > 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   997
                        val = (val << 8) + buffer.chars[--n];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   998
                    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   999
                    RETURN (__MKUINT(val));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1000
                }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1001
                newDigits = __MKBYTEARRAY(buffer.chars, n);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1002
                if (newDigits) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1003
                    __PROTECT__(newDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1004
                    newLarge = __STX___new(sizeof(struct __LargeInteger));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1005
                    __UNPROTECT__(newDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1006
                    if (newLarge) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1007
                        __InstPtr(newLarge)->o_class = LargeInteger; __STORE(newLarge, LargeInteger);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1008
                        __LargeIntegerInstPtr(newLarge)->l_digits = newDigits; __STORE(newLarge, newDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1009
                        __LargeIntegerInstPtr(newLarge)->l_sign = __MKSMALLINT(1);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1010
                        RETURN (newLarge);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1011
                    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1012
                }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1013
            }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1014
        }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1015
    }
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1016
%}.
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1017
    ^ super bitAnd:anInteger
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1018
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1019
    "
6051
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1020
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFF) hexPrintString
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1021
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1022
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1023
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1024
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1025
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1026
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFFFF) hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1027
     (16rFFEEDDCCBBAA998877665544332211 bitAnd:16rFFFFFFFFFFFFFFFFFF) hexPrintString
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1028
    "
6051
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1029
e86757447e81 comment
Claus Gittinger <cg@exept.de>
parents: 6049
diff changeset
  1030
    "Modified: / 26.9.2001 / 17:34:03 / cg"
4612
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1031
!
724572ee0390 fast and: with a smallInteger
Claus Gittinger <cg@exept.de>
parents: 4454
diff changeset
  1032
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1033
bitAt:anIntegerIndex
11501
4c31d5628937 changed #bitAt:
Claus Gittinger <cg@exept.de>
parents: 10728
diff changeset
  1034
    "return the value of the index's bit (index starts at 1) as 0 or 1.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1035
     Notice: the result of bitAt: on negative receivers is not
17797
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1036
             defined in the language standard (since the implementation
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1037
             is free to choose any internal representation for integers)"
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1038
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1039
%{  /* NOCONTEXT */
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1040
    if (__isSmallInteger(anIntegerIndex)) {
17797
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1041
        INT idx = __smallIntegerVal(anIntegerIndex) - 1;
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1042
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1043
        if (idx >= 0) {
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1044
            int v1;
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1045
            int byteOffset = idx / 8;
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1046
            int digitLen   = __byteArraySize(__INST(digitByteArray));
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1047
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1048
            if (digitLen < byteOffset) {
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1049
                RETURN(__mkSmallInteger(0));
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1050
            }
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1051
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1052
            v1 = (__byteArrayVal(__INST(digitByteArray)))[byteOffset];
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1053
            if (v1 & (1 << (idx % 8))) {
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1054
                RETURN(__mkSmallInteger(1));
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1055
            } else {
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1056
                RETURN(__mkSmallInteger(0));
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1057
            }
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1058
        }
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1059
    }
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1060
%}.
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1061
    ^ super bitAt:anIntegerIndex
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1062
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1063
    "
11605
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
  1064
     TestCase should:[ 16rFFFFFFFFFF01 bitAt:0 ] raise:Error
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
  1065
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:49 ) == 0
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
  1066
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:1  ) == 1
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
  1067
     TestCase assert:( 16rFFFFFFFFFF01 bitAt:2  ) == 0
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
  1068
     TestCase assert:( 16rFFFFFFFFFF02 bitAt:2  ) == 1
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
  1069
     TestCase assert:( 16rFFFFFFFF01FF bitAt:8  ) == 1
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
  1070
     TestCase assert:( 16rFFFFFFFF01FF bitAt:9  ) == 1
adff1007beb2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11604
diff changeset
  1071
     TestCase assert:( 16rFFFFFFFF01FF bitAt:10 ) == 0
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1072
    "
17797
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1073
71451ae83564 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17780
diff changeset
  1074
    "Modified: / 10-08-2010 / 12:33:04 / cg"
8334
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1075
!
4466f66d1f9a Define #bitAt:
Stefan Vogel <sv@exept.de>
parents: 7544
diff changeset
  1076
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1077
bitXor:anInteger
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1078
    "return the bitwise-or of the receiver and the argument, anInteger.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1079
     Here, a specially tuned version for largeInteger arguments
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1080
     (to speed up some cryptographic code)"
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1081
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1082
    |len1 len2
5958
ccf9a786af36 unused variables in bitXor:
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1083
     "/ n "{ Class: SmallInteger }"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1084
     "/ result byte
5958
ccf9a786af36 unused variables in bitXor:
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
  1085
     newBytes|
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1086
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1087
    anInteger class ~~ LargeInteger ifTrue:[^ super bitXor:anInteger].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1088
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1089
    (len1 := anInteger digitLength) > (len2 := self digitLength) ifTrue:[
17841
7abcc4aef871 Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17834
diff changeset
  1090
        newBytes := anInteger digitBytes copy.
7abcc4aef871 Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17834
diff changeset
  1091
        newBytes bitXorBytesFrom:1 to:len2 with:digitByteArray startingAt:1
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1092
    ] ifFalse:[
17841
7abcc4aef871 Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17834
diff changeset
  1093
        newBytes := digitByteArray copy.
7abcc4aef871 Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17834
diff changeset
  1094
        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
  1095
    ].
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1096
    ^ (LargeInteger digitBytes:newBytes) compressed
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1097
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1098
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1099
     (16r112233445566778899 bitXor:16rFF                ) printStringRadix:16 '112233445566778866'
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1100
     (16r112233445566778899 bitXor:16rFFFFFFFFFFFFFFFF00) printStringRadix:16 'EEDDCCBBAA99887799'
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1101
     (16r112233445566778899 bitXor:16rFF0000000000000000) printStringRadix:16 'EE2233445566778899'
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1102
     (16r112233445566778899 bitXor:16r112233445566778800) printStringRadix:16 '99'
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1103
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1104
     |bigNum1 bigNum2|
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1105
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1106
     bigNum1 := 2 raisedToInteger:512.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1107
     bigNum2 := 2 raisedToInteger:510.
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1108
     Time millisecondsToRun:[
17841
7abcc4aef871 Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17834
diff changeset
  1109
        1000000 timesRepeat:[
7abcc4aef871 Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17834
diff changeset
  1110
           bigNum1 bitXor:bigNum2.
7abcc4aef871 Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17834
diff changeset
  1111
        ]
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1112
     ]
4920
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1113
    "
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1114
!
802099ba0ac0 big speedup for bitXor:
Claus Gittinger <cg@exept.de>
parents: 4831
diff changeset
  1115
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1116
lowBit
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1117
    "return the bitIndex of the lowest bit set. The returned bitIndex
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1118
     starts at 1 for the least significant bit.
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1119
     Returns 0 if no bit is set.
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1120
     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
  1121
     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
  1122
     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
  1123
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1124
    |sz   "{ Class: SmallInteger }"
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1125
     idx0 "{ Class: SmallInteger }"
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1126
     byte|
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1127
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1128
    idx0 := 1.
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1129
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1130
%{  
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1131
    OBJ __digitByteArray = __INST(digitByteArray);
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1132
7544
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1133
    /*
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1134
     * quickly advance over full 0-words
dcde4788d7f0 comment
Claus Gittinger <cg@exept.de>
parents: 7481
diff changeset
  1135
     */
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1136
    if (__isByteArray(__digitByteArray)) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1137
        int __sz = __byteArraySize(__digitByteArray);
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1138
        unsigned char *__bP = __byteArrayVal(__digitByteArray);
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1139
        unsigned char *__bP0 = __bP;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1140
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1141
        sz = _MKSMALLINT(__sz);
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1142
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1143
#ifdef __UNROLL_LOOPS__
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1144
        while (__sz > (sizeof(INT) * 4)) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1145
            if (( ((INT *)__bP)[0] 
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1146
                 | ((INT *)__bP)[1] 
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1147
                 | ((INT *)__bP)[2] 
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1148
                 | ((INT *)__bP)[3] ) != 0) break;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1149
            __sz -= sizeof(INT) * 4;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1150
            __bP += sizeof(INT) * 4;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1151
        }
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1152
#endif
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1153
        while (__sz > sizeof(INT)) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1154
            if ( ((INT *)__bP)[0] != 0 ) break;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1155
            __sz -= sizeof(INT);
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1156
            __bP += sizeof(INT);
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1157
        }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1158
        while (__sz > 0) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1159
            unsigned int c;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1160
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1161
            if ( (c = *__bP) != 0 ) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1162
                int bitIdx = (__bP - __bP0) * 8;
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1163
#ifdef __BSF
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1164
                {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1165
                    int index;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1166
                    int t = c;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1167
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1168
                    index = __BSF(t);
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1169
                    RETURN ( __mkSmallInteger(index + 1 + bitIdx) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1170
                }
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1171
#else
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1172
                if (c & 0x0F) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1173
                    if (c & 0x03) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1174
                        if (c & 0x01) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1175
                            RETURN ( __mkSmallInteger( bitIdx + 1) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1176
                        } else {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1177
                            RETURN ( __mkSmallInteger( bitIdx + 2) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1178
                        }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1179
                    } else {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1180
                        if (c & 0x04) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1181
                            RETURN ( __mkSmallInteger( bitIdx + 3) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1182
                        } else {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1183
                            RETURN ( __mkSmallInteger( bitIdx + 4) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1184
                        }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1185
                    }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1186
                } else {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1187
                    if (c & 0x30) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1188
                        if (c & 0x10) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1189
                            RETURN ( __mkSmallInteger( bitIdx + 5) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1190
                        } else {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1191
                            RETURN ( __mkSmallInteger( bitIdx + 6) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1192
                        }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1193
                    } else {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1194
                        if (c & 0x40) {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1195
                            RETURN ( __mkSmallInteger( bitIdx + 7) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1196
                        } else {
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1197
                            RETURN ( __mkSmallInteger( bitIdx + 8) );
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1198
                        }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1199
                    }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1200
                }
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1201
#endif
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1202
                break;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1203
            }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1204
            __sz--;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1205
            __bP++;
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1206
        }
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1207
        idx0 = __mkSmallInteger( __bP - __bP0 + 1 );
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1208
    }
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1209
%}.
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1210
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1211
    "/ never actually reached
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1212
    idx0 to:sz do:[:digitIndex |
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1213
        (byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1214
            ^ (digitIndex-1)*8 + (byte lowBit)
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1215
        ]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1216
    ].
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1217
    ^ 0 "/ should not happen
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1218
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1219
    "
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1220
     (1 bitShift:0) lowBit
8929
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1221
     (1 bitShift:10) lowBit
cdddcc1c470e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  1222
     (1 bitShift:20) lowBit
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1223
     (1 bitShift:30) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1224
     (1 bitShift:30) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1225
     (1 bitShift:31) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1226
     (1 bitShift:31) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1227
     (1 bitShift:32) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1228
     (1 bitShift:32) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1229
     (1 bitShift:33) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1230
     (1 bitShift:33) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1231
     (1 bitShift:64) lowBit
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1232
     (1 bitShift:64) highBit
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1233
     (1 bitShift:1000) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1234
     (1 bitShift:1000) highBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1235
     ((1 bitShift:64)-1) lowBit
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1236
     ((1 bitShift:64)-1) highBit
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1237
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1238
     1 to:1000 do:[:idx |
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1239
        self assert:(( 1 bitShift:idx) lowBit = (idx+1)).
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1240
        self assert:(( 1 bitShift:idx) lowBit = ( 1 bitShift:idx) highBit).
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1241
        self assert:(( 3 bitShift:idx) lowBit = (idx+1)).
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1242
        self assert:(( 7 bitShift:idx) lowBit = (idx+1)).
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1243
        self assert:(( 15 bitShift:idx) lowBit = (idx+1)).
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1244
        self assert:(( 31 bitShift:idx) lowBit = (idx+1)).
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1245
        self assert:(( 63 bitShift:idx) lowBit = (idx+1)).
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1246
        self assert:(( 127 bitShift:idx) lowBit = (idx+1)).
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1247
        self assert:(( 255 bitShift:idx) lowBit = (idx+1)).
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1248
     ]
7478
2f7430bfd7ac tuned lowBit (req'd for gcd)
Claus Gittinger <cg@exept.de>
parents: 7471
diff changeset
  1249
6480
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1250
     |num|
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1251
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1252
     num := (1 bitShift:1000).
4ff7f2af25fc lowBit now returns 0 if no bit is set.
Claus Gittinger <cg@exept.de>
parents: 6359
diff changeset
  1253
     Time millisecondsToRun:[
17754
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1254
        1000000 timesRepeat:[
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1255
            num lowBit
5322906cdb6a Merged with trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17735
diff changeset
  1256
        ]
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1257
     ]
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1258
    "
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1259
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1260
    "Modified: 14.8.1997 / 11:55:34 / cg"
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1261
!
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1262
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1263
setBit:index
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1264
    "return a new integer, where the specified bit is on.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1265
     Bits are counted from 1 starting with the least significant.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1266
     The methods name may be missleading: the receiver is not changed,
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1267
     but a new number is returned. Should be named #withBitSet:"
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1268
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1269
    |myDigitLength newDigitLength newDigitBytes byteIndexOfBitToSet|
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1270
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1271
    index <= 0 ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1272
	^ SubscriptOutOfBoundsSignal
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1273
		raiseRequestWith:index
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1274
		errorString:'index out of bounds'
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1275
    ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1276
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1277
    myDigitLength := digitByteArray size.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1278
    byteIndexOfBitToSet := ((index-1)//8)+1.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1279
    byteIndexOfBitToSet > myDigitLength ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1280
	newDigitLength := myDigitLength max:byteIndexOfBitToSet.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1281
	newDigitBytes := ByteArray new:newDigitLength.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1282
	newDigitBytes replaceFrom:1 to:myDigitLength with:digitByteArray startingAt:1.
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1283
    ] ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1284
	newDigitBytes := digitByteArray copy
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1285
    ].
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1286
    newDigitBytes
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1287
	at:byteIndexOfBitToSet
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1288
	put:((newDigitBytes at:byteIndexOfBitToSet) setBit:(((index-1)\\8)+1)).
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1289
    ^ (self class digitBytes:newDigitBytes) sign:sign
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1290
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1291
    "
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1292
     TestCase assert:( 16r80000000 setBit:3  ) = 16r80000004
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1293
     TestCase assert:( 16r80000000 setBit:33 ) = 16r180000000
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1294
    "
2855
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1295
! !
9c26fec68549 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2850
diff changeset
  1296
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1297
!LargeInteger methodsFor:'bit operators-32bit'!
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1298
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1299
bitInvert32
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1300
    "return the value of the receiver with all bits inverted in 32bit signed int space
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1301
     (changes the sign)"
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1302
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1303
%{  /* NOCONTEXT */
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1304
    unsigned INT v;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1305
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1306
    v = __unsignedLongIntVal(self);
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1307
    v = ~v;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1308
#if __POINTER_SIZE__ == 8
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1309
    v &= 0xFFFFFFFFL;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1310
#endif
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1311
    RETURN ( __MKUINT(v) );
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1312
%}.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1313
    ^ self primitiveFailed
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1314
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1315
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1316
     16r80000000 bitInvert32 hexPrintString
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1317
     16r7FFFFFFF bitInvert32 hexPrintString
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1318
     16rFFFFFFFF bitInvert32 hexPrintString
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1319
     0 bitInvert32 hexPrintString
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1320
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1321
!
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1322
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1323
bitRotate32:shiftCount
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1324
    "return the value of the receiver rotated by shiftCount bits,
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1325
     but only within 32 bits, rotating left for positive, right for negative counts.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1326
     Rotates through the sign bit.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1327
     Useful for crypt algorithms, or to emulate C/Java semantics."
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1328
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1329
%{  /* NOCONTEXT */
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1330
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1331
    unsigned INT bits;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1332
    int count;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1333
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1334
    if (__isSmallInteger(shiftCount)) {
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1335
        count = __intVal(shiftCount);
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1336
        count = count % 32;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1337
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1338
        bits = __unsignedLongIntVal(self);
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1339
        if (count > 0) {
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1340
            bits = (bits << count) | (bits >> (32-count));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1341
        } else {
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1342
            bits = (bits >> (-count)) | (bits << (32-(-count)));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1343
        }
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1344
#if __POINTER_SIZE__ == 8
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1345
        bits &= 0xFFFFFFFFL;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1346
#endif
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1347
        RETURN (__MKUINT(bits));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1348
    }
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1349
%}.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1350
    ^ self primitiveFailed
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1351
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1352
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1353
     (1 bitShift32:31) rotate32:0   
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1354
     (1 bitShift32:31) rotate32:1   
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1355
     (1 bitShift32:31) rotate32:-1   
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1356
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1357
!
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1358
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1359
bitShift32:shiftCount
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1360
    "return the value of the receiver shifted by shiftCount bits,
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1361
     but only within 32 bits, shifting into/out-of the sign bit.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1362
     May be useful for communication interfaces, to create ST-numbers
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1363
     from a signed 32bit int value given as individual bytes,
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1364
     or to emulate C/Java semantics.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1365
     The shift is unsigned"
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1366
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1367
%{  /* NOCONTEXT */
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1368
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1369
    unsigned INT bits;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1370
    int count;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1371
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1372
    if (__isSmallInteger(shiftCount)) {
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1373
        count = __intVal(shiftCount);
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1374
        if (count >= 32) {
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1375
            RETURN (__mkSmallInteger(0));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1376
        }
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1377
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1378
        bits = __unsignedLongIntVal(self);
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1379
        if (count > 0) {
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1380
            bits = bits << count;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1381
        } else {
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1382
            bits = bits >> (-count);
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1383
        }
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1384
#if __POINTER_SIZE__ == 8
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1385
        bits &= 0xFFFFFFFFL;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1386
#endif
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1387
        RETURN (__MKUINT(bits));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1388
    }
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1389
%}.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1390
    ^ self primitiveFailed
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1391
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1392
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1393
     128 bitShift:24
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1394
     128 bitShift32:24
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1395
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1396
     1 bitShift:31
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1397
     1 bitShift32:31
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1398
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1399
!
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1400
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1401
bitXor32:aNumber
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1402
    "return the xor of the receiver and the argument.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1403
     The argument must be a SmallInteger or a 4-byte LargeInteger.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1404
     If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1405
     This is of course not always correct, but allows for C/Java behavior to be emulated."
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1406
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1407
%{  /* NOCONTEXT */
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1408
    INT rslt;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1409
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1410
    rslt =  __unsignedLongIntVal(self) ^ __unsignedLongIntVal(aNumber);
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1411
#if __POINTER_SIZE__ == 8
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1412
    rslt &= 0xFFFFFFFFL;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1413
#endif
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1414
    RETURN ( __MKUINT(rslt));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1415
%}.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1416
    self primitiveFailed
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1417
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1418
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1419
     16r7FFFFFFF bitXor: 16r80000000          4294967295
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1420
     16r7FFFFFFF bitXor32: 16r80000000
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1421
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1422
! !
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1423
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1424
!LargeInteger methodsFor:'byte access'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1425
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1426
digitAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1427
    "return 8 bits of value, starting at byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1428
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1429
    index > digitByteArray size ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1430
    ^ digitByteArray at:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1431
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1432
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1433
digitAt:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1434
    "set the 8 bits, index is a byte index"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1435
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1436
    digitByteArray at:index put:aByte
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1437
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1438
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1439
digitByteAt:index
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1440
    "return 8 bits of my signed value, starting at byte index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1441
     For positive receivers, this is the same as #digitAt:;
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1442
     for negative ones, the actual bit representation is returned."
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1443
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1444
    |t digits|
6359
fcb206734265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6106
diff changeset
  1445
    sign >= 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1446
	index > digitByteArray size ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1447
	    ^ 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1448
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1449
	^ digitByteArray at:index.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1450
    ].
6359
fcb206734265 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6106
diff changeset
  1451
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1452
    "/ negative int - do 2's complement here
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1453
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1454
    t := self bitInvert + 1.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1455
    t sign:1.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1456
    digits := t digitBytes.
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1457
    index > digits size ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1458
	^ 16rFF
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1459
    ].
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1460
    ^ digits at:index.
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1461
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1462
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1463
     16r11111111111111111111 negated digitByteAt:1
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1464
     0 asLargeInteger digitByteAt:1
3891
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1465
    "
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1466
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1467
    "Created: / 25.10.1998 / 14:12:21 / cg"
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1468
!
1bbab65996ef added #digitByteAt:
Claus Gittinger <cg@exept.de>
parents: 3440
diff changeset
  1469
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1470
digitBytes
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1471
    "return a byteArray filled with the receivers bits
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1472
     (8 bits of the absolute value per element).
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1473
     Least significant byte is first!!"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1474
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1475
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1476
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1477
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1478
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1479
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1480
digitBytesMSB:msbFlag
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1481
    "return a byteArray filled with the receivers bits
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1482
     (8 bits of the absolute value per element),
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1483
     if msbflag = true, most significant byte is first,
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1484
     otherwise least significant byte is first"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1485
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1486
    msbFlag ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1487
	^ digitByteArray copyReverse.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1488
    ].
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1489
    ^ digitByteArray
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1490
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1491
    "Modified: / 5.5.1999 / 14:57:03 / stefan"
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1492
!
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  1493
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1494
digitLength
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1495
    "return the number bytes used by this Integer.
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1496
     For negative receivers, the digitLength of its absolute value
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1497
     is returned."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1498
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1499
    "
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1500
     check if there is a 0-byte ...
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1501
     this allows to ask unnormalized LargeIntegers
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1502
     for their digitLength
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1503
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1504
    |l "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1505
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1506
    l := digitByteArray size.
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1507
    [l ~~ 0 and:[(digitByteArray at:l) == 0]] whileTrue:[
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  1508
	l := l - 1.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1509
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1510
    ^ l
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
  1511
2816
62edd11b5e66 commentary
Claus Gittinger <cg@exept.de>
parents: 2793
diff changeset
  1512
    "Modified: 31.7.1997 / 13:18:28 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1513
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1514
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1515
digits
7288
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1516
    "obsolete, use #digitBytes"
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1517
36b9824c75df Mark obsolete methods
Stefan Vogel <sv@exept.de>
parents: 7141
diff changeset
  1518
    <resource:#obsolete>
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1519
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1520
    ^ digitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1521
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1522
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1523
!LargeInteger methodsFor:'coercing & converting'!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1524
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1525
asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1526
    "return a LargeInteger with same value as myself - thats me"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1527
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1528
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1529
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1530
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1531
asSigned32
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1532
    "return a 32-bit integer with my bit-pattern. Receiver must be unsigned (i.e. positive).
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1533
     May be required for bit operations on the sign-bit and/or to
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1534
     convert C/Java numbers."
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1535
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1536
%{  /* NOCONTEXT */
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1537
    int rslt;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1538
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1539
    rslt =  (int)(__unsignedLongIntVal(self));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1540
    RETURN ( __MKINT(rslt));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1541
%}.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1542
    self primitiveFailed
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1543
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1544
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1545
     16r80000000 asSigned32
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1546
     16r40000000 asSigned32
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1547
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1548
!
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1549
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1550
asSmallInteger
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1551
    "return a SmallInteger with same value as myself -
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1552
     the result is invalid if the receivers value cannot
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1553
     be represented as a SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1554
     Q: should we raise an exception if this happens ?"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1555
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1556
    |value|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1557
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1558
    value := 0.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1559
    (sign == 0) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1560
	digitByteArray reverseDo:[:aDigit |
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1561
	    value := (value times:256) + aDigit
345
claus
parents: 250
diff changeset
  1562
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1563
	(sign < 0) ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1564
	    value := value negated
345
claus
parents: 250
diff changeset
  1565
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  1566
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1567
    ^ value
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
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1570
asUnsigned32
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1571
    "return a 32-bit integer with my bit-pattern. Receiver must be unsigned (i.e. positive).
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1572
     May be required for bit operations on the sign-bit and/or to
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1573
     convert C/Java numbers."
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1574
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1575
%{  /* NOCONTEXT */
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1576
    unsigned int rslt;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1577
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1578
    rslt =  (int)(__unsignedLongIntVal(self));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1579
    RETURN ( __MKUINT(rslt));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1580
%}.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1581
    self primitiveFailed
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1582
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1583
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1584
     16r80000000 asUnsigned32
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1585
     16r40000000 asUnsigned32
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1586
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1587
!
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  1588
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1589
coerce:aNumber
11723
40267c26c7eb comment
Claus Gittinger <cg@exept.de>
parents: 11605
diff changeset
  1590
    "convert the argument aNumber into an instance of the receivers class and return it."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1591
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1592
    ^ aNumber asLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1593
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1594
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  1595
compressed
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1596
    "if the receiver can be represented as a SmallInteger, return
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1597
     a SmallInteger with my value;
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1598
     otherwise remove leading zero bytes in the digitByte array
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1599
     and return the receiver"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1600
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1601
    |index "{ Class: SmallInteger }"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1602
     val   "{ Class: SmallInteger }"
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1603
     index0
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1604
    |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1605
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1606
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1607
    OBJ t;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1608
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1609
    if (__INST(sign) == __mkSmallInteger(0)) {
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1610
	RETURN (__mkSmallInteger(0));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1611
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1612
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  1613
    t = __INST(digitByteArray);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1614
    if (__isByteArray(t)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1615
	unsigned char *__digitBytes = __ByteArrayInstPtr(t)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1616
	int _idx, _idx0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1617
	INT _val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1618
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1619
	_idx = _idx0 = __byteArraySize(t);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1620
	while ((_idx > 0) && (__digitBytes[_idx - 1] == 0)) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1621
	    _idx--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1622
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  1623
#if __POINTER_SIZE__ == 8
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1624
	switch (_idx) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1625
	    case 8:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1626
		_val = __digitBytes[7];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1627
		if (_val <= 0x40) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1628
		    _val = (_val<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1629
		    _val = (_val + __digitBytes[6]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1630
		    _val = (_val + __digitBytes[5]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1631
		    _val = (_val + __digitBytes[4]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1632
		    _val = (_val + __digitBytes[3]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1633
		    _val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1634
		    _val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1635
		    _val += __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1636
		    if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1637
			_val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1638
		    if (__ISVALIDINTEGER(_val)) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1639
			RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1640
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1641
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1642
		break;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1643
	    case 7:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1644
		_val = (__digitBytes[6]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1645
		_val = (_val + __digitBytes[5]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1646
		_val = (_val + __digitBytes[4]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1647
		_val = (_val + __digitBytes[3]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1648
		_val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1649
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1650
		_val += __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1651
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1652
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1653
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1654
	    case 6:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1655
		_val = (__digitBytes[5]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1656
		_val = (_val + __digitBytes[4]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1657
		_val = (_val + __digitBytes[3]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1658
		_val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1659
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1660
		_val += __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1661
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1662
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1663
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1664
	    case 5:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1665
		_val = (__digitBytes[4]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1666
		_val = (_val + __digitBytes[3]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1667
		_val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1668
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1669
		_val += __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1670
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1671
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1672
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1673
	    case 4:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1674
		_val = (__digitBytes[3]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1675
		_val = (_val + __digitBytes[2]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1676
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1677
		_val += __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1678
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1679
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1680
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1681
	    case 3:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1682
		_val = (__digitBytes[2]<<8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1683
		_val = (_val + __digitBytes[1]) << 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1684
		_val += __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1685
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1686
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1687
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1688
	    case 2:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1689
		_val = (__digitBytes[1]<<8) + __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1690
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1691
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1692
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1693
	    case 1:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1694
		_val = __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1695
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1696
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1697
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1698
	    case 0:
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1699
		RETURN (__mkSmallInteger(0));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1700
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1701
	}
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1702
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1703
	if (_idx <= 4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1704
	    if (_idx <= 2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1705
		if (_idx == 0) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1706
		    RETURN (__mkSmallInteger(0));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1707
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1708
		if (_idx == 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1709
		    _val = __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1710
		    if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1711
			_val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1712
		    RETURN (__mkSmallInteger(_val));
6665
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
		_val = (__digitBytes[1]<<8) + __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1715
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1716
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1717
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1718
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1719
	    if (_idx == 3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1720
		_val = (((__digitBytes[2]<<8) + __digitBytes[1])<<8) + __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1721
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1722
		    _val = -_val;
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1723
		RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1724
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1725
	    _val = __digitBytes[3];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1726
	    if (_val <= 0x40) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1727
		_val = (((((_val<<8) + __digitBytes[2])<<8) + __digitBytes[1])<<8) + __digitBytes[0];
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1728
		if (__INST(sign) == __mkSmallInteger(-1))
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1729
		    _val = -_val;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1730
		if (__ISVALIDINTEGER(_val)) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  1731
		    RETURN (__mkSmallInteger(_val));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1732
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1733
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1734
	}
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1735
#endif
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1736
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1737
	if (_idx == _idx0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1738
	    RETURN (self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1739
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1740
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1741
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1742
	 * must copy & cut off some bytes
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1743
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1744
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1745
	    OBJ newDigits;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1746
	    OBJ oldDigits;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1747
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1748
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1749
	     * careful - there is no context here to protect
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1750
	     * the receiver ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1751
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1752
	    __PROTECT__(self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1753
	    __PROTECT__(__INST(digitByteArray));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1754
	    newDigits = __BYTEARRAY_UNINITIALIZED_NEW_INT(_idx);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1755
	    __UNPROTECT__(oldDigits);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1756
	    __UNPROTECT__(self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1757
	    if (newDigits) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1758
		bcopy(__ByteArrayInstPtr(oldDigits)->ba_element,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1759
		      __ByteArrayInstPtr(newDigits)->ba_element,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1760
		      _idx);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1761
		__INST(digitByteArray) = newDigits; __STORE(self, newDigits);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1762
		RETURN (self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1763
	    }
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
	     * allocation failed ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1766
	     * ... fall through to trigger the error
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1767
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1768
	}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1769
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1770
%}.
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1771
    index0 := index := digitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1772
    [(index > 0) and:[(digitByteArray at:index) == 0]] whileTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1773
	index := index - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1774
    ].
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1775
"/    ((index < SmallInteger maxBytes)
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1776
"/    or:[(index == SmallInteger maxBytes)
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1777
"/            and:[(digitByteArray at:index) < 16r20]])
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1778
"/    ifTrue:[
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1779
"/        val := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1780
"/        1 to:index do:[:i |
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1781
"/            val := val bitShift:8.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1782
"/            val := val bitOr:(digitByteArray at:i).
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1783
"/        ].
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1784
"/        ^ val * sign
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  1785
"/    ].
2267
123ec897aca5 tuned #compressed
Claus Gittinger <cg@exept.de>
parents: 2001
diff changeset
  1786
    (index ~~ index0) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1787
	digitByteArray := digitByteArray copyFrom:1 to:index
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1788
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1789
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1790
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1791
7446
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1792
generality
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1793
    "return the generality value - see ArithmeticValue>>retry:coercing:"
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1794
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1795
    ^ 40
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1796
!
81d4bbeb830e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7405
diff changeset
  1797
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1798
value:aSmallInteger
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1799
    "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
  1800
     This method will fail, if the argument is not a smallInteger.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1801
     This should only be used internally,
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1802
     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
  1803
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1804
    |absValue
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1805
     b1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1806
     b2 "{ Class: SmallInteger }"
2786
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1807
     b3 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1808
     b4 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1809
     b5 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1810
     b6 "{ Class: SmallInteger }"
8f05ce0a14e1 alpha64 changes
Claus Gittinger <cg@exept.de>
parents: 2521
diff changeset
  1811
     b7 "{ Class: SmallInteger }"|
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1812
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1813
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1814
     could have simply created a 4-byte largeinteger and normalize it.
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1815
     The code below does the normalize right away, avoiding the
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1816
     overhead of producing any intermediate byte-arrays (and the scanning)
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1817
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1818
    (aSmallInteger == 0) ifTrue: [
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1819
	digitByteArray := ByteArray with:0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1820
	sign := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1821
	^ self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1822
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1823
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1824
    (aSmallInteger < 0) ifTrue: [
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1825
	sign := -1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1826
	absValue := aSmallInteger negated
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1827
    ] ifFalse: [
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1828
	sign := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1829
	absValue := aSmallInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1830
    ].
3431
ae8f96921fcc tuning & comments
Claus Gittinger <cg@exept.de>
parents: 3428
diff changeset
  1831
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1832
    b1 := absValue bitAnd:16rFF.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1833
    absValue := absValue bitShift:-8.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1834
    absValue == 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1835
	digitByteArray := ByteArray with:b1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1836
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1837
	b2 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1838
	absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1839
	absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1840
	    digitByteArray := ByteArray with:b1 with:b2
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1841
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1842
	    b3 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1843
	    absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1844
	    absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1845
		digitByteArray := ByteArray with:b1 with:b2 with:b3
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1846
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1847
		b4 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1848
		absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1849
		absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1850
		    digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1851
		] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1852
		    b5 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1853
		    absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1854
		    absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1855
			digitByteArray := ByteArray new:5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1856
			digitByteArray at:1 put:b1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1857
			digitByteArray at:2 put:b2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1858
			digitByteArray at:3 put:b3.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1859
			digitByteArray at:4 put:b4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1860
			digitByteArray at:5 put:b5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1861
		    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1862
			b6 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1863
			absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1864
			absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1865
			    digitByteArray := ByteArray new:6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1866
			    digitByteArray at:1 put:b1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1867
			    digitByteArray at:2 put:b2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1868
			    digitByteArray at:3 put:b3.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1869
			    digitByteArray at:4 put:b4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1870
			    digitByteArray at:5 put:b5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1871
			    digitByteArray at:6 put:b6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1872
			] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1873
			    b7 := absValue bitAnd:16rFF.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1874
			    absValue := absValue bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1875
			    absValue == 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1876
				digitByteArray := ByteArray new:7.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1877
				digitByteArray at:1 put:b1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1878
				digitByteArray at:2 put:b2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1879
				digitByteArray at:3 put:b3.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1880
				digitByteArray at:4 put:b4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1881
				digitByteArray at:5 put:b5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1882
				digitByteArray at:6 put:b6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1883
				digitByteArray at:7 put:b7.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1884
			    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1885
				digitByteArray := ByteArray new:8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1886
				digitByteArray at:1 put:b1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1887
				digitByteArray at:2 put:b2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1888
				digitByteArray at:3 put:b3.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1889
				digitByteArray at:4 put:b4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1890
				digitByteArray at:5 put:b5.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1891
				digitByteArray at:6 put:b6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1892
				digitByteArray at:7 put:b7.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1893
				digitByteArray at:8 put:absValue.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1894
			    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1895
			]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1896
		    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1897
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1898
	    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  1899
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1900
    ]
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  1901
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  1902
    "Modified: / 26.5.1999 / 22:18:14 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1903
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1904
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1905
!LargeInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1906
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1907
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1908
    "return true, if the argument, aNumber is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1909
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1910
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1911
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1912
    (aNumber class == self class) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1913
	otherSign := aNumber sign.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1914
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1915
	(sign > 0) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1916
	    "I am positive"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1917
	    (otherSign > 0) ifTrue:[^ self absLess:aNumber].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1918
	    ^ false "aNumber is <= 0"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1919
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1920
	"I am negative"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1921
	(otherSign > 0) ifTrue:[^ true].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1922
	(otherSign == 0) ifTrue:[^ true].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1923
	^ (aNumber absLess:self)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1924
    ].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1925
    (aNumber class == SmallInteger) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1926
	otherSign := aNumber sign.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1927
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1928
	(sign > 0) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1929
	    "I am positive"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1930
	    ^ false "aNumber is <= 0"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1931
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1932
	(sign == 0) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1933
	    (otherSign > 0) ifTrue:[^ true].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1934
	    ^ false
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1935
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1936
	"I am negative"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1937
	^ true
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1938
    ].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1939
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1940
    ^ aNumber lessFromInteger:self
3178
649320240430 fixed #> (-1234567890 > -10)
Claus Gittinger <cg@exept.de>
parents: 3161
diff changeset
  1941
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1942
    "Modified: / 31.7.2002 / 10:08:19 / cg"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1943
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  1944
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1945
= aNumber
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1946
    "return true, if the argument represents the same numeric value
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1947
     as the receiver, false otherwise"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1948
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1949
    "/ speed up compare to 0
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1950
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1951
    (aNumber == 0) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1952
	^ sign == 0
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1953
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1954
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1955
    (aNumber class == self class) ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1956
	"/
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1957
	"/ here, we depend on the fact, that largeinteger
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1958
	"/ results are always converted to smallInts, if possible.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1959
	"/ therefore, a largeInt in the smallInt range is not allowed (possible)
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1960
	"/
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1961
	aNumber class == SmallInteger ifTrue:[^ false ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  1962
	^ aNumber equalFromInteger:self
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1963
    ].
7356
fe8fb0a571f2 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7288
diff changeset
  1964
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1965
    (aNumber sign == sign) ifFalse:[^ false].
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  1966
    ^ digitByteArray = aNumber digitBytes "/ ^ self absEq:aNumber
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1967
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  1968
    "Modified: / 13.2.1998 / 11:43:15 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1969
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1970
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1971
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1972
    "return true, if the argument, aNumber is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1973
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1974
    |otherSign|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1975
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1976
    (aNumber class == self class) ifFalse:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1977
	^ (aNumber < self)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1978
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1979
    otherSign := aNumber sign.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1980
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1981
    (sign > 0) ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1982
	"I am positive"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1983
	(otherSign > 0) ifTrue:[^ aNumber absLess:self].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1984
	^ true "aNumber is <= 0"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1985
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1986
    (sign == 0) ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1987
	"I am zero"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1988
	(otherSign > 0) ifTrue:[^ false].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  1989
	^ true
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1990
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1991
    "I am negative"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1992
    (otherSign > 0) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  1993
    (otherSign == 0) ifTrue:[^ false].
6677
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1994
    ^ (self absLess:aNumber)
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1995
6467fed79219 double dispatch fallback code in comparing fixed
Claus Gittinger <cg@exept.de>
parents: 6665
diff changeset
  1996
    "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
  1997
!
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1998
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  1999
hash
6055c1b2fc3b better bitAnd: for non-LSB machines;
Claus Gittinger <cg@exept.de>
parents: 4612
diff changeset
  2000
    "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
  2001
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2002
    |l h m|
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2003
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2004
    h := self bitAnd:16r3FFFFFFF.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2005
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2006
    l := digitByteArray size.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2007
    l >= 8 ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2008
	h := h bitXor:(digitByteArray at:l).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2009
	h := h bitXor:((digitByteArray at:l-1) bitShift:8).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2010
	h := h bitXor:((digitByteArray at:l-2) bitShift:16).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2011
	h := h bitXor:((digitByteArray at:l-3) bitShift:22).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2012
	l >= 12 ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2013
	    m := l // 2.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2014
	    h := h bitXor:(digitByteArray at:m-1).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2015
	    h := h bitXor:((digitByteArray at:m) bitShift:8).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2016
	    h := h bitXor:((digitByteArray at:m+1) bitShift:16).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2017
	    h := h bitXor:((digitByteArray at:m+2) bitShift:22).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2018
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2019
	^ h
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2020
    ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2021
    ^ (h bitShift:3) + l
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2022
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2023
    "
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2024
     16r80000000 hash
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2025
     16r80000008 hash
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2026
     16r8000000000008 hash
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2027
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2028
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2029
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2030
!LargeInteger methodsFor:'double dispatching'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2031
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2032
differenceFromInteger:anInteger
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2033
    "sent, when anInteger does not know how to subtract the receiver.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2034
     Return the result of 'anInteger - self'. The argument must be a SmallInteger."
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2035
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2036
    anInteger > 0 ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2037
	sign > 0 ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2038
	    ^ self absFastMinus:anInteger sign:-1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2039
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2040
	^ self absFastPlus:anInteger sign:1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2041
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2042
    anInteger == 0 ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2043
	^ self negated
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2044
    ].
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2045
    sign > 0 ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2046
	^ self absFastPlus:anInteger negated sign:-1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2047
    ].
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2048
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2049
    self > anInteger ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2050
	^ self absFastMinus:anInteger asLargeInteger sign:-1
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2051
    ] ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2052
	^ anInteger asLargeInteger absFastMinus:self sign:-1
10728
ec5790d03608 another difference bug
sr
parents: 10726
diff changeset
  2053
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2054
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2055
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2056
     12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2057
     -12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2058
     12345678901234567890 differenceFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2059
     12345678901234567890 differenceFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2060
     12345678901234567890 differenceFromInteger:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2061
     -12345678901234567890 differenceFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2062
     -12345678901234567890 differenceFromInteger:-1
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2063
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2064
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2065
    "Modified: 20.10.1996 / 18:41:54 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2066
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2067
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2068
equalFromInteger:anInteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2069
    "sent when an integer does not know how to compare to the receiver, a largeInt"
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2070
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2071
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2072
    "/ here, we depend on the fact, that largeinteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2073
    "/ results are always converted to smallInts, if possible.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2074
    "/ therefore, a largeInt in the smallInt range is not allowed (possible)
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2075
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2076
    anInteger class == SmallInteger ifTrue:[^ false ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2077
    anInteger class == self class ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2078
	^ super equalFromInteger:anInteger
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2079
    ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2080
    (anInteger sign == sign) ifFalse:[^ false].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2081
    ^ self absEq:anInteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2082
!
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2083
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2084
lessFromInteger:anInteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2085
    "sent when an integer does not know how to compare to the receiver, a largeInt"
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2086
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2087
    |otherSign|
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2088
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2089
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2090
    "/ here, we depend on the fact, that largeinteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2091
    "/ results are always converted to smallInts, if possible.
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2092
    "/ therefore, a largeInt in the smallInt range is not allowed (possible)
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2093
    "/
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2094
    (anInteger class == SmallInteger) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2095
	otherSign := anInteger sign.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2096
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2097
	(sign > 0) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2098
	    "I am positive"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2099
	    ^ true "aNumber is <= 0"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2100
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2101
	"I am negative"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2102
	^ false
11507
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2103
    ].
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2104
    ^ super lessFromInteger:anInteger
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2105
!
111d9a470036 tuned < and =;
Claus Gittinger <cg@exept.de>
parents: 11501
diff changeset
  2106
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2107
productFromInteger:anInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2108
    "sent, when anInteger does not know how to multiply the receiver.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2109
     Return the product of the receiver and the argument, aSmallInteger"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2110
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2111
    |num result
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2112
     resultDigitByteArray
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2113
     val     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2114
     len     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2115
     carry   "{ Class: SmallInteger }"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2116
     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
  2117
     ok lResult|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2118
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2119
    "multiplying by a small integer is done here"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2120
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2121
    "trivial cases"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2122
    anInteger == 0 ifTrue:[^ 0].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2123
    anInteger == 1 ifTrue:[^ self].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2124
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2125
    num := anInteger abs.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2126
    (num > 16r3FFFFF) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2127
	"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
  2128
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2129
	^ anInteger retry:#* coercing:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2130
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2131
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2132
    len := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2133
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2134
    val := num.
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  2135
    val <= 16rFF ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2136
	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
  2137
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2138
	val <= 16rFFFF ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2139
	    lResult := len + 2
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2140
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2141
	    val <= 16rFFFFFF ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2142
		lResult := len + 4.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2143
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2144
		lResult := len + 6.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2145
	    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2146
	]
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2147
    ].
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  2148
    resultDigitByteArray := ByteArray uninitializedNew:lResult.
2897
0b6b43d0a300 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2855
diff changeset
  2149
    result := self class basicNew setDigits:resultDigitByteArray.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2150
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2151
    anInteger < 0 ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2152
	sign > 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2153
	    result sign:-1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2154
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2155
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2156
	sign < 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2157
	    result sign:sign
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2158
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2159
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2160
85
claus
parents: 77
diff changeset
  2161
    ok := false.
claus
parents: 77
diff changeset
  2162
%{
2471
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2163
    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
  2164
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2165
    if (__isSmallInteger(len)
035dbf8db9f3 faster large*small on i386 - use 32*32->64 bit multiplication.
Claus Gittinger <cg@exept.de>
parents: 2267
diff changeset
  2166
     && __isByteArray(__digitByteArray)
85
claus
parents: 77
diff changeset
  2167
     && __isByteArray(resultDigitByteArray)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2168
	INT _l = __intVal(len);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2169
	INT _v = __intVal(val);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2170
	unsigned INT _carry = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2171
	unsigned INT _prod;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2172
	unsigned char *digitP = __ByteArrayInstPtr(__digitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2173
	unsigned char *resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2174
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2175
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2176
	 * skipping zeros does not help much (a few percent) on
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2177
	 * a P5 or other CPUS with a fast multiplier.
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2178
	 * 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
  2179
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2180
	while ((_l >= sizeof(INT)) && (((unsigned INT *)digitP)[0] == 0)) {
8907
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  2181
	    ((unsigned INT *)resultP)[0] = 0;
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2182
	    digitP += sizeof(INT);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2183
	    resultP += sizeof(INT);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2184
	    _l -= sizeof(INT);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2185
	}
2923
fbb470bc7e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2897
diff changeset
  2186
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2187
#if defined(__LSBFIRST__)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2188
# if defined (__GNUC__) && defined(__i386__) && (__POINTER_SIZE__ == 4)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2189
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2190
	 * can do it long-word-wise;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2191
	 * 32*32 -> 64 multiplication
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2192
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2193
	while (_l > 3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2194
	    unsigned __pHi, __pLow;
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2195
	    unsigned __digit;
4260
7c70ef5ea136 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4256
diff changeset
  2196
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2197
	    /*
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2198
	     * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2199
	     * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2200
	     */
4293
11ef4c35818c avoid illegal code with gcc
Claus Gittinger <cg@exept.de>
parents: 4292
diff changeset
  2201
	    __digit = ((unsigned long *)digitP)[0];
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2202
	    asm ("mull %3               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2203
		  addl %4,%%eax         \n\
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2204
		  adcl $0,%%edx"
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2205
		    : "=a"  (__pLow),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2206
		      "=d"  (__pHi)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2207
		    : "0"   (__digit),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2208
		      "1"   ((unsigned long)(_v)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2209
		      "rm"  ((unsigned long)(_carry)) );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2210
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2211
	    ((unsigned long *)resultP)[0] = __pLow;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2212
	    _carry = __pHi;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2213
	    digitP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2214
	    resultP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2215
	    _l -= 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2216
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2217
# else /* not GNU-i386 */
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8929
diff changeset
  2218
#  if defined(WIN32) && defined(__BORLANDC__) && defined(__i386__) && (__POINTER_SIZE__ == 4)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2219
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2220
	 * can do it long-word-wise;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2221
	 * 32*32 -> 64 multiplication
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2222
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2223
	while (_l > 3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2224
	    unsigned __pLow;
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2225
	    unsigned digit;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2226
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2227
	    /*
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2228
	     * max: 0xFFFF.FFFF * 0xFFFF.FFFF -> 0xFFFF.FFFE.0000.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2229
	     * + maxCarry (0xFFFF.FFFF)  -> 0xFFFF.FFFF.0000.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2230
	     */
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2231
/*
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2232
	    digit = ((unsigned long *)digitP)[0];
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2233
	    edx::eax = (digit * _v);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2234
	    edx::eax += _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2235
	    ((unsigned long *)resultP)[0] = eax; -- pLow
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2236
	    _carry = edx; -- pHigh
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2237
	    digitP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2238
	    resultP += 4;
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2239
*/
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2240
	    digit = ((unsigned long *)digitP)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2241
	    asm {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2242
		mov   eax, digit
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2243
		mov   edx, _v
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2244
		mul   edx
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2245
		add   eax, _carry
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2246
		adc   edx, 0
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2247
		mov   __pLow, eax
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2248
		mov   _carry, edx
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2249
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2250
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2251
	    ((unsigned long *)resultP)[0] = __pLow;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2252
	    digitP += 4;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2253
	    resultP += 4;
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2254
	    _l -= 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2255
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2256
#  else /* not WIN32-i386 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2257
#   if defined(INT64)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2258
	if (_v <= 0xFFFFFFFFL) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2259
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2260
	     * have a 64bit int type ... good
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2261
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2262
	    UINT64 _prod64;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2263
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2264
	    /* have 64bit ints; can do it int-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2265
	     *
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2266
	     * max: 0xFFFFFFFF * 0xFFFFFFFF -> 0xFFFFFFFE.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2267
	     * + maxCarry (0xFFFFFFFF)  -> 0xFFFFFFFF.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2268
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2269
	    while (_l > 3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2270
		unsigned __t;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2271
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2272
		__t = ((unsigned *)digitP)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2273
		digitP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2274
		_prod64 = (INT64)_v;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2275
		_prod64 *= __t;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2276
		_prod64 += _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2277
		((unsigned *)resultP)[0] = _prod64 /* & 0xFFFFFFFFL */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2278
		_carry = _prod64 >> 32;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2279
		resultP += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2280
		_l -= 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2281
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2282
	    if (_l > 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2283
		unsigned short __t;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2284
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2285
		__t = ((unsigned short *)digitP)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2286
		digitP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2287
		_prod64 = (INT64)_v;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2288
		_prod64 *= __t;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2289
		_prod64 += _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2290
		((unsigned short *)resultP)[0] = _prod64 /* & 0xFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2291
		_carry = _prod64 >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2292
		resultP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2293
		_l -= 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2294
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2295
	    if (_l > 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2296
		_prod64 = *digitP++ * _v + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2297
		*resultP++ = _prod64 /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2298
		_carry = _prod64 >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2299
		_l--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2300
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2301
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2302
#   else /* no INT64 type */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2303
	if (_v <= 0xFFFF) {
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2304
	    /* can do it short-wise
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2305
	     *
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2306
	     * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2307
	     * + maxCarry (0xFFFF)  -> 0xFFFF.0000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2308
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2309
	    while (_l > 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2310
		_prod = ((unsigned short *)digitP)[0] * _v + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2311
		((unsigned short *)resultP)[0] = _prod /* & 0xFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2312
		_carry = _prod >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2313
		digitP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2314
		resultP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2315
		_l -= 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2316
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2317
	}
4170
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2318
#   endif /* no INT64 */
4b7dee48537e inline asm for mul with WIN32
Claus Gittinger <cg@exept.de>
parents: 4164
diff changeset
  2319
#  endif /* not WIN32-i386 */
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  2320
# endif /* not GNU-i386 */
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  2321
#else /* not LSB_FIRST */
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2322
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2323
# ifdef __mips__
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2324
#  define LOAD_WORD_WISE
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2325
   /* 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
  2326
# endif
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2327
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2328
	if (_v <= 0xFFFF) {
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2329
	    /* can do it short-wise
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2330
	     *
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2331
	     * max: 0xFFFF * 0xFFFF -> 0xFFFE.0001
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2332
	     * + maxCarry (0xFFFF)  -> 0xFFFF.0000
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 (_l > 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2335
		unsigned int t;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2336
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2337
#if defined(LOAD_WORD_WISE)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2338
		/* better fetch short-wise */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2339
		t = ((unsigned short *)digitP)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2340
		digitP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2341
		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
  2342
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2343
		t = (digitP[1]<<8) + digitP[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2344
		digitP += 2;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2345
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2346
		_prod = t * _v + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2347
		_carry = _prod >> 16;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2348
#if defined(STORE_WORD_WISE)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2349
		/* better store short-wise */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2350
		_prod = ((_prod >> 8) | (_prod << 8)) & 0xFFFF;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2351
		((unsigned short *)resultP)[0] = _prod;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2352
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2353
		resultP[0] = _prod /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2354
		resultP[1] = (_prod>>8) /* & 0xFF */;
4192
8ee270c413a0 slightly faster largeInt * smallInt for mips (msb machines)
Claus Gittinger <cg@exept.de>
parents: 4191
diff changeset
  2355
#endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2356
		resultP += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2357
		_l -= 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2358
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2359
	}
3099
9b76bb13bc5e 16bit-wise multiplication (non LSB machines)
Claus Gittinger <cg@exept.de>
parents: 3040
diff changeset
  2360
3040
ea839412d642 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2964
diff changeset
  2361
#endif /* LSB_FIRST */
1797
8dafe47b33fd faster multiplication by an integer.
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
  2362
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2363
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2364
	 * rest is done byte-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2365
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2366
	while (_l > 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2367
	    _prod = *digitP++ * _v + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2368
	    *resultP++ = _prod /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2369
	    _carry = _prod >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2370
	    _l--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2371
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2372
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2373
	_l = __intVal(lResult) - __intVal(len);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2374
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2375
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2376
	 * remaining carry
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2377
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2378
	while (_carry) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2379
	    *resultP++ = _carry /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2380
	    _carry >>= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2381
	    _l--;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2382
	}
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
	 * remaining zeros
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2386
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2387
	while (_l--) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2388
	    *resultP++ = 0;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2389
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2390
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2391
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2392
	 * need compress ?
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2393
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2394
	if (resultP[-1]) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2395
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2396
	     * no
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2397
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2398
	    RETURN(result);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2399
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2400
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2401
	ok = true;
85
claus
parents: 77
diff changeset
  2402
    }
claus
parents: 77
diff changeset
  2403
%}.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2404
    "
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2405
     fall back - normally not reached
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2406
     (could make it a primitive-failure as well)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2407
    "
85
claus
parents: 77
diff changeset
  2408
    ok ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2409
	carry := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2410
	1 to:len do:[:i |
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2411
	    prod := (digitByteArray basicAt:i) * val + carry.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2412
	    resultDigitByteArray basicAt:i put:(prod bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2413
	    carry := prod bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2414
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2415
	[carry ~~ 0] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2416
	    len := len + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2417
	    resultDigitByteArray basicAt:len put:(carry bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2418
	    carry := carry bitShift:-8
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2419
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2420
	[len < lResult] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2421
	    len := len + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2422
	    resultDigitByteArray basicAt:len put:0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2423
	]
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2424
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2425
    ^ result compressed
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2426
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2427
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2428
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2429
    "sent, when anInteger does not know how to add the receiver.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2430
     Return the sum of the receiver and the argument, (which must be a SmallInteger)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2431
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2432
    anInteger > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2433
	sign > 0 ifTrue:[
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2434
	    ^ self absFastPlus:anInteger sign:1
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2435
	].
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2436
	^ self absFastMinus:anInteger sign:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2437
    ].
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2438
    anInteger == 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2439
	^ self
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2440
    ].
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2441
    sign > 0 ifTrue:[
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  2442
	^ self absFastMinus:anInteger sign:1
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2443
    ].
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2444
    ^ self absFastPlus:anInteger sign:-1
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2445
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2446
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2447
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2448
     12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2449
     -12345678901234567890
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2450
     12345678901234567890 sumFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2451
     -12345678901234567890 sumFromInteger:0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2452
     12345678901234567890 sumFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2453
     12345678901234567890 sumFromInteger:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2454
     -12345678901234567890 sumFromInteger:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2455
     -12345678901234567890 sumFromInteger:-1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2456
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2457
3161
923a6931dded avoid sending #class twice in +/-
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
  2458
    "Modified: / 9.1.1998 / 13:27:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2459
! !
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2460
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2461
!LargeInteger methodsFor:'modulu arithmetic'!
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2462
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2463
plus32:aNumber
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2464
    "return the sum of the receiver and the argument, as SmallInteger.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2465
     The argument must be another SmallInteger.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2466
     If the result overflows the 32 bit range, the value modulo 16rFFFFFFFF is returned.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2467
     This is of course not always correct, but allows for C/Java behavior to be emulated."
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2468
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2469
%{  /* NOCONTEXT */
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2470
    INT sum;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2471
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2472
    sum =  __unsignedLongIntVal(self) + __unsignedLongIntVal(aNumber);
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2473
#if __POINTER_SIZE__ == 8
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2474
    sum &= 0xFFFFFFFFL;
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2475
#endif
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2476
    RETURN ( __MKUINT(sum));
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2477
%}.
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2478
    self primitiveFailed
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2479
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2480
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2481
     16r7FFFFFFF + 1       ->  2147483648
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2482
     16r7FFFFFFF plus32: 1 ->  -2147483648  
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2483
    "
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2484
! !
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2485
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2486
!LargeInteger methodsFor:'printing & storing'!
345
claus
parents: 250
diff changeset
  2487
5682
a1a516779f72 remove storeOn: use insteat the default printString
ca
parents: 5437
diff changeset
  2488
xxxstoreOn:aStream
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2489
    "append a representation of the receiver to aStream, which can
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2490
     be used to reconstruct the receiver."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2491
5682
a1a516779f72 remove storeOn: use insteat the default printString
ca
parents: 5437
diff changeset
  2492
    aStream nextPutAll:'('.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2493
    self printOn:aStream.
5954
d706efecb134 ZeroDivide has a parameter
Claus Gittinger <cg@exept.de>
parents: 5682
diff changeset
  2494
    aStream nextPutAll:' asLargeInteger)'
d706efecb134 ZeroDivide has a parameter
Claus Gittinger <cg@exept.de>
parents: 5682
diff changeset
  2495
! !
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2496
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2497
!LargeInteger methodsFor:'private'!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2498
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2499
absDivMod:anInteger
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2500
    "return an array with two LargeIntegers representing
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2501
     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
  2502
     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
  2503
     This method needs a rewrite."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2504
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2505
    |dividend divisor
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2506
     quo digits
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2507
     shift "{ Class: SmallInteger }" |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2508
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2509
    anInteger == 0 ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2510
	^ ZeroDivide raiseRequestWith:thisContext
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2511
    ].
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2512
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  2513
    self = anInteger ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2514
	^ Array with:1 with:0
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2515
    ].
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2516
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2517
    shift := self highBit - anInteger highBit.
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  2518
    dividend := LargeInteger digitBytes:digitByteArray copy. "/ self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2519
    shift < 0 ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2520
	^ Array with:0 with:dividend compressed.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2521
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  2522
    shift == 0 ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2523
	divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy.
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  2524
    ] ifFalse:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2525
	divisor := anInteger bitShift:shift.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2526
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2527
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2528
    quo := self class basicNew numberOfDigits:((shift // 8) + 1).
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2529
    digits := quo digitBytes.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2530
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2531
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2532
    [shift > 0] whileTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2533
	(dividend absLess:divisor) ifFalse:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2534
	    digits bitSetAt:shift.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2535
	    (dividend absSubtract: divisor) ifFalse:[ "result == 0"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2536
		^ Array with:quo compressed with:dividend compressed
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2537
	    ].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2538
	].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2539
	shift := shift - 1.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2540
	divisor div2.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2541
    ].
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2542
    ^ 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
  2543
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2544
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2545
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:4000000000] ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2546
     Time millisecondsToRun:[ 10000 timesRepeat:[  16000000000 absDivMod:3000000000] ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2547
     16000000000 absDivMod:4000000000
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2548
     16000000000 absDivMod:3000000000
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2549
    "
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2550
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2551
    "Modified: / 5.11.1996 / 18:40:24 / cg"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2552
    "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
  2553
    "Modified: / 26.7.1999 / 10:46:36 / stefan"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2554
!
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2555
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2556
absEq:aLargeInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2557
    "return true, if abs(self) = abs(theArgument)"
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2558
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2559
    |len1 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2560
     len2 "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2561
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2562
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2563
     otherDigitByteArray |
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2564
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  2565
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  2566
    if (__isLargeInteger(aLargeInteger)) {
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2567
    	OBJ _digitByteArray = __INST(digitByteArray);
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2568
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2569
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2570
	if (__isByteArray(_digitByteArray)
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2571
	 && __isByteArray(_otherDigitByteArray)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2572
	    INT _myLen = __byteArraySize(_digitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2573
	    INT _otherLen = __byteArraySize(_otherDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2574
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2575
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2576
	    unsigned char *_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2577
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2578
	    if (_myLen == _otherLen) {
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  2579
tryAgain:
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2580
		while (_myLen >= (sizeof(INT)*4)) {
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2581
		    if ( ((unsigned INT *)_myDigits)[0] != ((unsigned INT *)_otherDigits)[0]) {
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2582
			RETURN(false);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2583
		    }
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2584
		    if ( ((unsigned INT *)_myDigits)[1] != ((unsigned INT *)_otherDigits)[1]) {
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2585
			RETURN(false);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2586
		    }
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2587
		    if ( ((unsigned INT *)_myDigits)[2] != ((unsigned INT *)_otherDigits)[2]) {
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2588
			RETURN(false);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2589
		    }
17763
019bb9c842c5 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17761
diff changeset
  2590
		    if ( ((unsigned INT *)_myDigits)[3] != ((unsigned INT *)_otherDigits)[3]) {
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2591
			RETURN(false);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2592
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2593
		    _myDigits += sizeof(INT)*4;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2594
		    _otherDigits += sizeof(INT)*4;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2595
		    _myLen -= sizeof(INT)*4;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2596
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2597
		while (_myLen >= (sizeof(INT))) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2598
		    if ( *(unsigned INT *)_myDigits != *(unsigned INT *)_otherDigits) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2599
			RETURN(false);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2600
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2601
		    _myDigits += sizeof(INT);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2602
		    _otherDigits += sizeof(INT);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2603
		    _myLen -= sizeof(INT);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2604
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2605
		while (_myLen > 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2606
		    if ( *_myDigits != *_otherDigits) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2607
			RETURN(false);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2608
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2609
		    _myDigits++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2610
		    _otherDigits++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2611
		    _myLen--;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2612
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2613
		RETURN(true);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2614
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2615
	    /* care for unnormalized ints */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2616
	    while ((_myLen > 0) && (_myDigits[_myLen-1] == 0)) _myLen--;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2617
	    while ((_otherLen > 0) && (_otherDigits[_otherLen-1] == 0)) _otherLen--;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2618
	    if (_myLen == _otherLen) goto tryAgain;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2619
	    RETURN(false);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2620
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  2621
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  2622
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  2623
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2624
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2625
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2626
    len2 := otherDigitByteArray size.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2627
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2628
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2629
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2630
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2631
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2632
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2633
    [(digitByteArray basicAt:len1) == 0] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2634
	len1 := len1 - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2635
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2636
    [(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2637
	len2 := len2 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2638
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2639
    (len1 ~~ len2) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2640
    [len1 > 0] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2641
	d1 := digitByteArray basicAt:len1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2642
	d2 := otherDigitByteArray basicAt:len1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2643
	(d1 ~~ d2) ifTrue:[^ false].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2644
	len1 := len1 - 1
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2645
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2646
    ^ true
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2647
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2648
    "Modified: / 8.5.1999 / 18:37:02 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2649
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2650
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  2651
absFastDivMod:aPositiveSmallInteger
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2652
    "return an array with two LargeIntegers representing
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2653
     abs(self) // aPositiveSmallInteger and
4180
cdfbc649b10d slight speedup in productFromInteger for WIN32 (eliminated a move)
Claus Gittinger <cg@exept.de>
parents: 4179
diff changeset
  2654
     abs(self) \\ aPositiveSmallInteger."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2655
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2656
    |tmp1     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2657
     prevRest "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2658
     count    "{ Class: SmallInteger }"
85
claus
parents: 77
diff changeset
  2659
     newDigitByteArray result
claus
parents: 77
diff changeset
  2660
     ok|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2661
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2662
    aPositiveSmallInteger == 0 ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2663
	^ ZeroDivide raiseRequestWith:thisContext
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2664
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2665
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2666
"This cannot happen (if always normalized)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2667
    self < aPositiveSmallInteger ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2668
	^ Array with:0 with:self
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2669
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2670
"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2671
    count := digitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2672
    result := self class basicNew numberOfDigits:count.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2673
    newDigitByteArray := result digitBytes.
85
claus
parents: 77
diff changeset
  2674
    ok := false.
claus
parents: 77
diff changeset
  2675
%{
1842
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2676
    OBJ __digits;
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2677
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2678
    __digits = __INST(digitByteArray);
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2679
b28609c73839 added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents: 1797
diff changeset
  2680
    if (__isByteArray(__digits)
85
claus
parents: 77
diff changeset
  2681
     && __isByteArray(newDigitByteArray)
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  2682
     && __bothSmallInteger(count, aPositiveSmallInteger)) {
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2683
	unsigned INT rest = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2684
	int index = __intVal(count);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2685
	int index0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2686
	unsigned INT divisor = __intVal(aPositiveSmallInteger);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2687
	unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2688
	unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2689
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2690
	index0 = index - 1;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2691
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2692
	/*
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2693
	 * divide short-wise
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2694
	 */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2695
	if (divisor <= 0xFFFF) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2696
	    if ((index & 1) == 0) { /* even number of bytes */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2697
		while (index > 1) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2698
		    unsigned INT t;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2699
		    unsigned INT div;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2700
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2701
		    index -= 2;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2702
#if defined(__LSBFIRST__)
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2703
		    t = *((unsigned short *)(&digitBytes[index]));
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2704
#else
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2705
		    t = digitBytes[index+1];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2706
		    t = (t << 8) | digitBytes[index];
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2707
#endif
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2708
		    t = t | (rest << 16);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2709
		    div = t / divisor;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2710
		    rest = t % divisor;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2711
#if defined(__LSBFIRST__)
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2712
		    *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2713
#else
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2714
		    resultBytes[index+1] = div >> 8;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2715
		    resultBytes[index] = div /* & 0xFF */;
5014
fa22b711e749 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5008
diff changeset
  2716
#endif
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2717
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2718
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2719
	}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2720
	while (index > 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2721
	    unsigned INT t;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2722
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2723
	    index--;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2724
	    t = digitBytes[index];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2725
	    t = t | (rest << 8);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2726
	    resultBytes[index] = t / divisor;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2727
	    rest = t % divisor;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2728
	}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2729
	prevRest = __mkSmallInteger(rest);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2730
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2731
	/*
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2732
	 * no need to normalize ?
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2733
	 */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2734
	index = index0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2735
	while ((index >= sizeof(INT)) && (resultBytes[index]==0)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2736
	    index--;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2737
	}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2738
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2739
	if (index == index0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2740
	    if (index > sizeof(INT)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2741
		RETURN ( __ARRAY_WITH2(result, prevRest));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2742
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2743
	    if ((index == sizeof(INT))
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2744
	    && resultBytes[index0] >= 0x40) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2745
		RETURN ( __ARRAY_WITH2(result, prevRest));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2746
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2747
	}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2748
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2749
	/*
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2750
	 * must compress
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2751
	 */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2752
	ok = true;
85
claus
parents: 77
diff changeset
  2753
    }
claus
parents: 77
diff changeset
  2754
%}.
claus
parents: 77
diff changeset
  2755
    "
claus
parents: 77
diff changeset
  2756
     slow code - not normally reached
claus
parents: 77
diff changeset
  2757
     (could also do a primitiveFailure here)
claus
parents: 77
diff changeset
  2758
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2759
    ok ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  2760
	^ self absDivMod:(LargeInteger value:aPositiveSmallInteger).
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2761
    ].
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2762
2933
8b65cb642d91 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2923
diff changeset
  2763
    ^ 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
  2764
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2765
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2766
     16r123412341234 asLargeInteger absDivMod:(LargeInteger value:10)
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  2767
     ((16r1234 asLargeInteger absFastDivMod:16rffff) at:2) printStringRadix:16
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2768
     ((16r00123456 asLargeInteger absFastDivMod:16rffffff) at:2) printStringRadix:16
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2769
     ((666666666666666666 asLargeInteger absFastDivMod:16r3))
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2770
     ((1666666666 asLargeInteger absFastDivMod:16r3))
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  2771
    "
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2772
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2773
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2774
absFastMinus:aSmallInteger sign:newSign
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2775
    "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
  2776
     with sign: newSign.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2777
     The result is normalized.
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2778
     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
  2779
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2780
    |result resultDigitByteArray lastDigit ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2781
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2782
     rsltLen "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2783
     index   "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2784
     borrow  "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2785
     diff    "{ Class: SmallInteger }" |
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2786
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2787
    "/ the following code only works with
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2788
    "/ 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
  2789
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2790
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2791
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2792
	^ self absMinus:(LargeInteger value:aSmallInteger) sign:newSign.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2793
    ].
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2794
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2795
    len := digitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2796
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2797
    rsltLen := len "+ 1".
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2798
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2799
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2800
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2801
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2802
    borrow := aSmallInteger abs.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2803
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2804
%{
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2805
    if (__isByteArray(__INST(digitByteArray))
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2806
     && __isByteArray(resultDigitByteArray)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2807
	unsigned INT __borrow = __intVal(borrow);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2808
	INT __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2809
	int __index = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2810
	int __len = __intVal(len);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2811
	unsigned char *__digitP = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2812
	unsigned char *__resultP = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2813
	int __len3;
4230
e1cfaecf453c alpha64 bug fixes
Claus Gittinger <cg@exept.de>
parents: 4229
diff changeset
  2814
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2815
#if defined(__LSBFIRST__)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2816
# if (__POINTER_SIZE__ == 8)
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2817
	/*
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2818
	 * subtract int-wise
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2819
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2820
	__len3 = __len - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2821
	while (__index < __len3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2822
	    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2823
	    __diff = ((unsigned int *)(__digitP + __index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2824
	    __diff -= (__borrow & 0xFFFFFFFFL);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2825
	    __borrow >>= 32;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2826
	    if (__diff < 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2827
		/* __diff += 0x100000000; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2828
		__borrow++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2829
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2830
	    ((unsigned int *)(__resultP+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2831
	    __index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2832
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2833
# endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2834
	/*
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2835
	 * subtract short-wise
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2836
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2837
	while (__index < __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2838
	    /* do not make this into one expression - ask cg why */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2839
	    __diff = ((unsigned short *)(__digitP+__index-1))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2840
	    __diff -= (__borrow & 0xFFFF);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2841
	    __borrow >>= 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2842
	    if (__diff < 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2843
		/* __diff += 0x10000; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2844
		__borrow++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2845
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2846
		if (__borrow == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2847
		    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2848
		    __index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2849
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2850
		    /* nothing more to subtract .. */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2851
		    while (__index < __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2852
			((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
  2853
			__index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2854
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2855
		    if (__index <= __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2856
			__resultP[__index-1] = __digitP[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2857
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2858
		    break;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2859
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2860
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2861
	    ((unsigned short *)(__resultP+__index-1))[0] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2862
	    __index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2863
	}
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2864
#endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2865
	/*
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2866
	 * subtract byte-wise
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2867
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2868
	while (__index <= __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2869
	    __diff = __digitP[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2870
	    __diff -= (__borrow & 0xFF);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2871
	    __borrow >>= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2872
	    if (__diff < 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2873
		/* __diff += 0x100; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2874
		__borrow++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2875
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2876
		if (__borrow == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2877
		    __resultP[__index-1] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2878
		    __index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2879
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2880
		    /* nothing more to subtract .. */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2881
		    while (__index <= __len) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2882
			__resultP[__index-1] = __digitP[__index-1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2883
			__index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2884
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2885
		    break;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2886
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2887
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2888
	    __resultP[__index-1] = __diff;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2889
	    __index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2890
	}
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2891
	lastDigit = __mkSmallInteger( __resultP[__index-1-1] );
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2892
	ok = true;
4181
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2893
    }
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2894
%}.
94ac48d3a3c8 tuned absFastMinus - buggy
Claus Gittinger <cg@exept.de>
parents: 4180
diff changeset
  2895
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2896
    ok == true ifFalse:[        "/ cannot happen
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2897
	index := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2898
	[borrow ~~ 0] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2899
	    (index <= len) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2900
		diff := (digitByteArray basicAt:index) - (borrow bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2901
		borrow := borrow bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2902
		diff < 0 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2903
		    diff := diff + 256.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2904
		    borrow := borrow + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2905
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2906
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2907
		diff := borrow bitAnd:255.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2908
		borrow := borrow bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2909
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2910
	    resultDigitByteArray basicAt:index put:(lastDigit := diff).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2911
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2912
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2913
	[index <= len] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2914
	    resultDigitByteArray basicAt:index put:(lastDigit := digitByteArray basicAt:index).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2915
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2916
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2917
	(index <= rsltLen) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2918
	    lastDigit := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2919
	]
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2920
    ].
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2921
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2922
    (lastDigit == 0 or:[rsltLen <= SmallInteger maxBytes]) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2923
	^ result compressed.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2924
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2925
    ^ result
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2926
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2927
    "
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2928
     12345678900000000000 absFastMinus:1 sign:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2929
     12345678900000000000 absFastMinus:1 sign:-1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2930
     12345678900000000000 absFastMinus:1000000 sign:1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2931
     12345678900000000000 absFastMinus:255 sign:1
4191
d6376725d99d tuned largeInt - smallInt
Claus Gittinger <cg@exept.de>
parents: 4190
diff changeset
  2932
     (SmallInteger maxVal + 1) absFastMinus:1 sign:1
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2933
     (SmallInteger minVal - 1) absFastMinus:1 sign:1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2934
    "
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2935
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2936
    "Modified: 24.3.1997 / 21:33:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2937
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2938
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2939
absFastPlus:aSmallInteger sign:newSign
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2940
    "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
  2941
     with sign: newSign.
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  2942
     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
  2943
     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
  2944
     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
  2945
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  2946
    |result resultDigitByteArray lastDigit
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2947
     ok
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2948
     len     "{ Class: SmallInteger }"
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2949
     rsltLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2950
     index "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2951
     carry "{ Class: SmallInteger }" |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2952
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2953
    "/ the following code only works with
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  2954
    "/ 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
  2955
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2956
    ((aSmallInteger < (SmallInteger minVal + 255))
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2957
    or:[aSmallInteger > (SmallInteger maxVal - 255)]) ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2958
	^ self absPlus:(LargeInteger value:aSmallInteger) sign:newSign.
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  2959
    ].
3440
ac93772ac2ca oops absFastPlus/Minus must care for the arguments range.
Claus Gittinger <cg@exept.de>
parents: 3438
diff changeset
  2960
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2961
    len := rsltLen := digitByteArray size.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2962
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2963
    "/ 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
  2964
    "/ 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
  2965
    "/
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2966
    (digitByteArray at:len) == 16rFF ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2967
	rsltLen := len + 1.
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2968
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2969
	"/ 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
  2970
%{
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  2971
#if __POINTER_SIZE__ == 8
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2972
	if (__intVal(aSmallInteger) & 0xFF00000000000000L) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2973
	    rsltLen = __mkSmallInteger(__intVal(len) + 1);
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2974
	}
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2975
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2976
	if (__intVal(aSmallInteger) & 0xFF000000) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  2977
	    rsltLen = __mkSmallInteger(__intVal(len) + 1);
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2978
	}
4950
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2979
#endif
c16f86f9f098 oops - bug when adding a largeInt
Claus Gittinger <cg@exept.de>
parents: 4948
diff changeset
  2980
%}
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  2981
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2982
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  2983
    result := self class basicNew numberOfDigits:rsltLen.
4173
0e74ef3ec49d pass the new sign to absFastPlus/absFastMinus,
Claus Gittinger <cg@exept.de>
parents: 4172
diff changeset
  2984
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  2985
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  2986
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2987
%{
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2988
    if (__isByteArray(__INST(digitByteArray))
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2989
     && __isByteArray(resultDigitByteArray)
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  2990
     && __isSmallInteger(aSmallInteger)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2991
	/* carry is NOT unsigned (see negation below) */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2992
	INT __carry = __intVal(aSmallInteger);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2993
	int __index = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2994
	int __len = __intVal(len);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2995
	unsigned char *__src = (unsigned char *)(__ByteArrayInstPtr(__INST(digitByteArray))->ba_element);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2996
	unsigned char *__dst = (unsigned char *)(__ByteArrayInstPtr(resultDigitByteArray)->ba_element);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2997
	INT __ptrDelta = __dst - __src;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2998
	unsigned char *__srcLast = __src + __len - 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  2999
	int __rsltLen = __intVal(rsltLen);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3000
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3001
	if (__carry < 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3002
	    __carry = -__carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3003
	}
4171
afd926573419 tuned largeInt + smallInt
Claus Gittinger <cg@exept.de>
parents: 4170
diff changeset
  3004
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3005
#if defined(__LSBFIRST__)
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  3006
# if defined(__i386__) && defined(__GNUC__) && (__POINTER_SIZE__ == 4)
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3007
#  if 0 /* NOTICE - the code below is 20% slower ... - why */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3008
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3009
	 * add long-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3010
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3011
	asm("  jecxz nothingToDo                                      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3012
	       movl  %%eax, %%esi      /* __src input */              \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3013
	       movl  %%ebx, %%edi      /* __dst input */              \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3014
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3015
	       /* the first 4-byte int */                             \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3016
	       lodsl                   /* fetch */                    \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3017
	       addl  %%edx, %%eax      /* add */                      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3018
	       stosl                   /* store */                    \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3019
	       leal  -1(%%ecx),%%ecx   /* do not clobber carry */     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3020
	       jecxz doneLoop          /* any more ? */               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3021
	       /* remaining 4-byte ints */                            \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3022
	       jmp   addLoop                                          \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3023
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3024
	       .align 8                                               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3025
	     addLoop:                                                 \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3026
	       movl  0(%%esi), %%ebx   /* fetch  */                   \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3027
	       jnc   copyLoop2                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3028
	       movl  $0, %%eax                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3029
	       leal  4(%%esi), %%esi                                  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3030
	       adcl  %%ebx, %%eax      /* & add carry from prev int */\n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3031
	       leal  8(%%edi), %%edi                                  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3032
	       movl  %%eax, -8(%%edi)  /* store */                    \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3033
	       leal  -1(%%ecx),%%ecx   /* do not clobber carry */     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3034
	       jecxz doneLoop          /* any more ? */               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3035
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3036
	       movl  0(%%esi), %%ebx   /* fetch  */                   \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3037
	       movl  $0, %%eax                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3038
	       leal  4(%%esi), %%esi                                  \
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3039
	       adcl  %%ebx, %%eax      /* & add carry from prev int */\n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3040
	       movl  %%eax, -4(%%edi)  /* store */                    \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3041
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3042
	       loop  addLoop                                          \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3043
	       jmp   doneLoop                                         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3044
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3045
	       .align 8                                               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3046
	     copyLoop:                                                \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3047
	       movl  0(%%esi), %%ebx                                  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3048
	     copyLoop2:                                               \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3049
	       add   $4, %%esi                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3050
	       add   $4, %%edi                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3051
	       movl  %%ebx, -4(%%edi)                                 \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3052
	       loop  copyLoop                                         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3053
								      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3054
	     doneLoop:                                                \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3055
	       movl  $0, %%edx         /* do not clobber carry (xorl clears it) */   \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3056
	       adcl  $0, %%edx                                        \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3057
	       movl  %%esi, %%eax      /* __src output */             \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3058
	     nothingToDo:                                             \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3059
	    " : "=d"  ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3060
		"=a"  (__src)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3061
	      : "1"   (__src),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3062
		"b"   (__dst),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3063
		"c"   (__len / 4),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3064
		"0"   (__carry)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3065
	      : "esi", "edi");
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3066
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3067
#  else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3068
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3069
	    unsigned char *__srcLastX;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3070
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3071
	    __srcLastX = __srcLast - 3 - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3072
	    while (__src <= __srcLastX) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3073
		unsigned int __sum, __sum2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3074
		unsigned __digit1, __digit2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3075
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3076
		__digit1 = ((unsigned *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3077
		__digit2 = ((unsigned *)__src)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3078
		asm ("addl %%edx,%%ecx          \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3079
		      adcl $0, %%eax            \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3080
		      movl $0, %%edx            \n\
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3081
		      adcl $0, %%edx"
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3082
			: "=d"  ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3083
			  "=c"  ((unsigned long)(__sum)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3084
			  "=a"  ((unsigned long)(__sum2))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3085
			: "0"   ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3086
			  "1"   (__digit1),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3087
			  "2"   (__digit2));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3088
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3089
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3090
		((unsigned int *)(__src + __ptrDelta))[1] = __sum2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3091
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3092
		__src += 8;
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3093
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3094
		if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3095
		    while (__src <= __srcLastX) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3096
			/* copy over words */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3097
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3098
			((unsigned int *)(__src + __ptrDelta))[1] = ((unsigned int *)__src)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3099
			__src += 8;
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
		    while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3102
			/* copy over bytes */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3103
			__src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3104
			__src ++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3105
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3106
		    goto doneSource;
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
	    __srcLastX = __srcLastX + 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3111
	    if (__src <= __srcLastX) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3112
		unsigned int __sum, __digit;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3113
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3114
		__digit = ((unsigned *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3115
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3116
		asm ("addl %%eax,%%edx  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3117
		      movl $0,%%eax     \n\
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3118
		      adcl $0,%%eax"
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3119
			: "=a"  ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3120
			  "=d"  ((unsigned long)(__sum))
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3121
			: "0"   ((unsigned long)(__carry)),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3122
			  "1"   (__digit) );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3123
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3124
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3125
		__src += 4;
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3126
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3127
		if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3128
		    while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3129
			/* copy over bytes */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3130
			__src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3131
			__src ++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3132
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3133
		    goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3134
		}
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
	}
4281
2acfd4c8b638 large + small
Claus Gittinger <cg@exept.de>
parents: 4276
diff changeset
  3137
#  endif
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3138
# else /* not i386-GNUC */
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8929
diff changeset
  3139
#  if defined(WIN32) && defined(__BORLANDC__) && defined(__i386__) && (__POINTER_SIZE__ == 4)
6665
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
	    unsigned char *__srcLast4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3142
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3143
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3144
	     * add long-wise
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
	    __srcLast4 = __srcLast - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3147
	    while (__src <= __srcLast4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3148
		unsigned int __sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3149
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3150
		__sum = ((unsigned int *)__src)[0];
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3151
		asm {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3152
		      mov eax, __sum
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3153
		      add eax, __carry
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3154
		      mov edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3155
		      adc edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3156
		      mov __sum, eax
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3157
		      mov __carry, edx
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3158
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3159
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3160
		((unsigned int *)(__src + __ptrDelta))[0] = __sum;
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3161
		__src += 4;
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3162
		if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3163
		    while (__src <= __srcLast4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3164
			/* copy over words */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3165
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3166
			__src += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3167
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3168
		    while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3169
			/* copy over bytes */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3170
			__src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3171
			__src ++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3172
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3173
		    goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3174
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3175
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3176
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3177
#  else /* not i386-WIN32 */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3178
#   if defined(__LSBFIRST__) && (__POINTER_SIZE__ == 8)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3179
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3180
	    unsigned char *__srcLast4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3181
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3182
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3183
	     * add long-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3184
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3185
	    __srcLast4 = __srcLast - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3186
	    while (__src <= __srcLast4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3187
		unsigned INT __sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3188
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3189
		__sum = ((unsigned int *)__src)[0] + __carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3190
		((unsigned int *)(__src + __ptrDelta))[0] = __sum /* & 0xFFFF */;
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3191
		__src += 4;
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3192
		__carry = __sum >> 32;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3193
		if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3194
		    while (__src <= __srcLast4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3195
			/* copy over words */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3196
			((unsigned int *)(__src + __ptrDelta))[0] = ((unsigned int *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3197
			__src += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3198
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3199
		    while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3200
			/* copy over bytes */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3201
			__src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3202
			__src ++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3203
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3204
		    goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3205
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3206
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3207
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3208
#   endif /* LSB+64bit */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3209
#  endif /* __i386__ & WIN32 */
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3210
# endif /* __i386__ & GNUC */
4178
e7121285caa8 inline asm for absPlus: for WIN32
Claus Gittinger <cg@exept.de>
parents: 4175
diff changeset
  3211
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3212
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3213
	 * add short-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3214
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3215
	while (__src < __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3216
	    __carry += ((unsigned short *)__src)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3217
	    ((unsigned short *)(__src + __ptrDelta))[0] = __carry /* & 0xFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3218
	    __carry >>= 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3219
	    __src += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3220
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3221
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3222
	 * last (odd) byte
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3223
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3224
	if (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3225
	    __carry += __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3226
	    __src[__ptrDelta] = __carry /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3227
	    __carry >>= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3228
	    __src++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3229
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3230
#else /* not __LSBFIRST__ */
4292
1a12f88acb8f sparc tuning (large + small)
Claus Gittinger <cg@exept.de>
parents: 4291
diff changeset
  3231
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3232
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3233
	 * add byte-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3234
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3235
	while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3236
	    __carry += __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3237
	    __src[__ptrDelta] = __carry /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3238
	    __src++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3239
	    __carry >>= 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3240
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3241
	    if (__carry == 0) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3242
		while (__src <= __srcLast) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3243
		    /* copy over rest */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3244
		    __src[__ptrDelta] = __src[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3245
		    __src++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3246
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3247
		goto doneSource;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3248
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3249
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3250
#endif /* __LSBFIRST__ */
4185
375439993eb7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4182
diff changeset
  3251
4255
73212f63b6a6 slight speedup in large + small
Claus Gittinger <cg@exept.de>
parents: 4254
diff changeset
  3252
    doneSource: ;
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3253
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3254
	 * now, at most one other byte is to be stored ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3255
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3256
	if (__len < __rsltLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3257
	    __src[__ptrDelta] = __carry /* & 0xFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3258
	    __src++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3259
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3260
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3261
	if (__src[__ptrDelta-1]) {      /* lastDigit */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3262
	    RETURN (result);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3263
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3264
	ok = true;
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3265
    }
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3266
%}.
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3267
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3268
    ok ~~ true ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3269
	index := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3270
	carry := aSmallInteger abs.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3271
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3272
	[carry ~~ 0] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3273
	    (index <= len) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3274
		carry := (digitByteArray basicAt:index) + carry.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3275
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3276
	    resultDigitByteArray basicAt:index put:(lastDigit := carry bitAnd:16rFF).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3277
	    carry := carry bitShift:-8.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3278
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3279
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3280
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3281
	(index <= rsltLen) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3282
	    [index <= len] whileTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3283
		resultDigitByteArray basicAt:index put:(digitByteArray basicAt:index).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3284
		index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3285
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3286
	    lastDigit := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3287
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3288
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3289
	(lastDigit ~~ 0 and:[rsltLen > SmallInteger maxBytes]) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3290
	    ^ result
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  3291
	].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3292
    ].
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3293
2952
2cf2ae894c4d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2935
diff changeset
  3294
    ^ result compressed
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3295
2495
0e6c781fd370 care to not create uncompressed largeInts
Claus Gittinger <cg@exept.de>
parents: 2471
diff changeset
  3296
    "Modified: 24.3.1997 / 21:32:41 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3297
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3298
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3299
absLess:aLargeInteger
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3300
    "return true, if abs(self) < abs(theArgument).
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3301
     This handles unnormalized largeIntegers."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3302
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3303
    |myLen "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3304
     otherLen "{ Class: SmallInteger }"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3305
     d1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3306
     d2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3307
     otherDigitByteArray |
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3308
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3309
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3310
#if defined(__LSBFIRST__)
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3311
    if (__isByteArray(__INST(digitByteArray))
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3312
     && __isLargeInteger(aLargeInteger)) {
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3313
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3314
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3315
	if (__isByteArray(_otherDigitByteArray)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3316
	    unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3317
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3318
	    INT _myLen = __byteArraySize(__INST(digitByteArray));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3319
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3320
	    if (_myLen == __POINTER_SIZE__) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3321
		INT _otherLen = __byteArraySize(_otherDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3322
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3323
		if (_otherLen == __POINTER_SIZE__) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3324
		    unsigned INT _myVal = *((unsigned INT *)_myDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3325
		    unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3326
		    RETURN( (_myVal < _otherVal) ? true : false );
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3327
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3328
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3329
# if defined(UINT64) && (__POINTER_SIZE__ != 8)
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3330
	    if (_myLen == __POINTER_SIZE__) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3331
		INT _otherLen = __byteArraySize(_otherDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3332
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3333
		if (_otherLen <= 8) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3334
		    UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3335
		    UINT64 _otherVal = *((UINT64 *)_otherDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3336
		    RETURN( (_myVal < _otherVal) ? true : false );
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3337
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3338
	    } else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3339
		if (_myLen <= 8) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3340
		    INT _otherLen = __byteArraySize(_otherDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3341
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3342
		    if (_otherLen <= 8) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3343
			UINT64 _myVal = (*((UINT64 *)_myDigits));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3344
			UINT64 _otherVal = *((UINT64 *)_otherDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3345
			RETURN( (_myVal < _otherVal) ? true : false );
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3346
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3347
		    if (_otherLen == __POINTER_SIZE__) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3348
			UINT64 _myVal = (*((UINT64 *)_myDigits));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3349
			UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3350
			RETURN( (_myVal < _otherVal) ? true : false );
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3351
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3352
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3353
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3354
# endif /* UINT64 */
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3355
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3356
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3357
#endif /* LSBFIRST */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3358
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3359
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3360
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3361
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3362
    otherLen := otherDigitByteArray size.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3363
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3364
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3365
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3366
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3367
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3368
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3369
    [myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3370
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3371
    ].
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3372
    [otherLen > 0 and:[(otherDigitByteArray basicAt:otherLen) == 0]] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3373
	otherLen := otherLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3374
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3375
    (myLen < otherLen) ifTrue:[^ true].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3376
    (myLen > otherLen) ifTrue:[^ false].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3377
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3378
    [myLen > 0] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3379
	d1 := digitByteArray basicAt:myLen.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3380
	d2 := otherDigitByteArray basicAt:myLen.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3381
	d1 == d2 ifFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3382
	    (d1 < d2) ifTrue:[^ true].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3383
	    ^ false
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3384
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3385
	myLen := myLen - 1
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3386
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3387
    ^ false
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  3388
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3389
    "
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3390
     |a b|
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3391
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3392
     a := 16rFEFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3393
     b := 16rFFFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3394
     Time millisecondsToRun:[
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3395
       10000000 timesRepeat:[ a absLess_old:b ]
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3396
     ]    1185 1233 1185
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3397
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3398
     |a b|
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3399
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3400
     a := 16rFEFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3401
     b := 16rFFFFFFFF.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3402
     Time millisecondsToRun:[
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3403
       10000000 timesRepeat:[ a absLess_n:b ]
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3404
     ] 686 655 702 702
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3405
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3406
     16rEFFFFFFF  absLess_n: 16rFFFFFFFF
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3407
     16rEFFFFFFF  absLess: 16rFFFFFFFF
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3408
    "
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3409
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3410
    "Modified: / 3.5.1999 / 08:06:28 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3411
    "Modified: / 8.5.1999 / 18:37:11 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3412
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3413
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3414
absLessEq:aLargeInteger
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3415
    "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
  3416
     This handles unnormalized largeIntegers."
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3417
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3418
    |myLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3419
     otherLen "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3420
     d1   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3421
     d2   "{ Class: SmallInteger }"
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3422
     otherDigitByteArray |
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3423
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3424
%{  /* NOCONTEXT */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3425
#if defined(__LSBFIRST__)
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3426
    if (__isByteArray(__INST(digitByteArray))
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3427
     && __isLargeInteger(aLargeInteger)) {
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3428
	OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3429
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3430
	if (__isByteArray(_otherDigitByteArray)) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3431
	    unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3432
	    unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3433
	    INT _myLen = __byteArraySize(__INST(digitByteArray));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3434
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3435
	    if (_myLen == __POINTER_SIZE__) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3436
		INT _otherLen = __byteArraySize(_otherDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3437
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3438
		if (_otherLen == __POINTER_SIZE__) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3439
		    unsigned INT _myVal = *((unsigned INT *)_myDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3440
		    unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3441
		    RETURN( (_myVal <= _otherVal) ? true : false );
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3442
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3443
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3444
# if defined(UINT64) && (__POINTER_SIZE__ != 8)
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3445
	    if (_myLen == __POINTER_SIZE__) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3446
		INT _otherLen = __byteArraySize(_otherDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3447
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3448
		if (_otherLen <= 8) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3449
		    UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3450
		    UINT64 _otherVal = *((UINT64 *)_otherDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3451
		    RETURN( (_myVal <= _otherVal) ? true : false );
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3452
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3453
	    } else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3454
		if (_myLen <= 8) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3455
		    INT _otherLen = __byteArraySize(_otherDigitByteArray);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3456
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3457
		    if (_otherLen <= 8) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3458
			UINT64 _myVal = (*((UINT64 *)_myDigits));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3459
			UINT64 _otherVal = *((UINT64 *)_otherDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3460
			RETURN( (_myVal <= _otherVal) ? true : false );
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3461
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3462
		    if (_otherLen == __POINTER_SIZE__) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3463
			UINT64 _myVal = (*((UINT64 *)_myDigits));
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3464
			UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3465
			RETURN( (_myVal <= _otherVal) ? true : false );
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3466
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3467
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3468
	    }
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3469
# endif /* UINT64 */
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3470
	}
11604
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3471
    }
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3472
#endif /* LSBFIRST */
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3473
%}.
64df3632e526 tuned absEq, absLess and absLessEq
Claus Gittinger <cg@exept.de>
parents: 11564
diff changeset
  3474
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3475
    myLen := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3476
    otherDigitByteArray := aLargeInteger digitBytes.
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3477
    otherLen := otherDigitByteArray size.
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3478
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3479
    "/ the highest digit(s) should not be zero
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3480
    "/ when properly normalized;
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3481
    "/ but we are tolerant here, to allow for unnormalized
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3482
    "/ numbers to be compared ...
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3483
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3484
    [(digitByteArray basicAt:myLen) == 0] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3485
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3486
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3487
    [(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3488
	otherLen := otherLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3489
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3490
    (myLen < otherLen) ifTrue:[^ true].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3491
    (myLen > otherLen) ifTrue:[^ false].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3492
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3493
    [myLen > 0] whileTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3494
	d1 := digitByteArray basicAt:myLen.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3495
	d2 := otherDigitByteArray basicAt:myLen.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3496
	d1 == d2 ifFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3497
	    (d1 < d2) ifTrue:[^ true].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3498
	    ^ false.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3499
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3500
	myLen := myLen - 1
3984
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3501
    ].
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3502
    ^ true
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3503
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3504
    "Created: / 13.2.1998 / 12:19:45 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3505
    "Modified: / 30.4.1999 / 12:46:31 / stefan"
4157
f9a673441ba5 comments
Claus Gittinger <cg@exept.de>
parents: 4151
diff changeset
  3506
    "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
  3507
!
45a76e2f4236 Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents: 3910
diff changeset
  3508
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3509
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
  3510
    "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
  3511
     with sign: newSign.
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3512
     The result is normalized. The argument must be a largeInteger
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  3513
     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
  3514
     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
  3515
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3516
    |result done
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3517
     otherDigitByteArray resultDigitByteArray
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3518
     len1   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3519
     len2   "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3520
     index  "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3521
     borrow "{ Class: SmallInteger }"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3522
     diff   "{ Class: SmallInteger }"
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3523
     carry  "{ Class: SmallInteger }"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3524
     lastDigit
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3525
     lResult ok|
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3526
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3527
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3528
    otherDigitByteArray := aLargeInteger digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3529
    len2 := otherDigitByteArray size.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3530
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3531
    len1 > len2 ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3532
	lResult := len1
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3533
    ] ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3534
	lResult := (len1 max: len2) + 1.
4251
6f215cab1ea9 oops - absMinus error.
Claus Gittinger <cg@exept.de>
parents: 4231
diff changeset
  3535
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3536
    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
  3537
    result sign:newSign.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3538
    resultDigitByteArray := result digitBytes.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3539
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3540
    lastDigit := 0.
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3541
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3542
%{
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3543
    OBJ _digitByteArray = __INST(digitByteArray);
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3544
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3545
    if (__isByteArray(_digitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3546
     && __isByteArray(otherDigitByteArray)
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3547
     && __isByteArray(resultDigitByteArray)) {
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3548
	int __len1 = __intVal(len1);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3549
	int __len2 = __intVal(len2);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3550
	int __minLen = __len1 < __len2 ? __len1 : __len2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3551
	int __index, __borrow = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3552
	INT __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3553
	unsigned char *__myDigits, *__otherDigits, *__resultDigits;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3554
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3555
	ok = true;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3556
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3557
	__resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3558
	__otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3559
	__myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3560
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3561
	__index = 1;
4942
de4ae3110e9b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4920
diff changeset
  3562
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3563
#if defined(__LSBFIRST__)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3564
# if __POINTER_SIZE__ == 8
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3565
	/*
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3566
	 * subtract int-wise
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3567
	 */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3568
	while ((__index+3) <= __minLen) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3569
	    /* do not make this into one expression - ask cg why */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3570
	    __diff = ((unsigned int *)(__myDigits+__index-1))[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3571
	    __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3572
	    __diff -= __borrow;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3573
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3574
	    if (__diff >= 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3575
		__borrow = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3576
	    } else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3577
		__borrow = 1;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3578
		/* __diff += 0x10000; */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3579
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3580
	    ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3581
	    __index += 4;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3582
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  3583
# endif /* 64bit */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3584
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3585
	/*
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3586
	 * subtract short-wise
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3587
	 */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3588
	while (__index < __minLen) {   /* i.e. index+1 <= minLen */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3589
	    /* do not make this into one expression - ask cg why */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3590
	    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3591
	    __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3592
	    __diff -= __borrow;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3593
	    if (__diff >= 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3594
		__borrow = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3595
	    } else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3596
		__borrow = 1;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3597
		/* __diff += 0x10000; */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3598
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3599
	    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3600
	    __index += 2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3601
	}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3602
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3603
	if (__index == __minLen) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3604
	    /* one of the operands has odd length - cannot continue short-wise */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3605
	} else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3606
	    if (__len1 > __len2) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3607
		while (__index < __len1) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3608
		    /* do not make this into one expression - ask cg why */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3609
		    __diff = ((unsigned short *)(__myDigits+__index-1))[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3610
		    __diff -= __borrow;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3611
		    if (__diff >= 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3612
			__borrow = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3613
			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3614
			__index += 2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3615
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3616
			/* copy over rest */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3617
			while (__index < __len1) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3618
			    ((unsigned short *)(__resultDigits+__index-1))[0] = ((unsigned short *)(__myDigits+__index-1))[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3619
			    __index+=2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3620
			}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3621
			if (__index <= __len1) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3622
			    __resultDigits[__index-1] = __myDigits[__index-1];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3623
			    __index++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3624
			}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3625
			break;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3626
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3627
		    __borrow = 1;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3628
		    /* __diff += 0x10000; */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3629
		    ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3630
		    __index += 2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3631
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3632
	    } else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3633
		if (__len2 > __len1) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3634
		    while (__index < __len2) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3635
			/* do not make this into one expression - ask cg why */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3636
			__diff = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3637
			__diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3638
			__diff -= __borrow;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3639
			if (__diff >= 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3640
			    __borrow = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3641
			} else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3642
			    __borrow = 1;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3643
			    /* __diff += 0x10000; */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3644
			}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3645
			((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3646
			__index += 2;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3647
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3648
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3649
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3650
	}
4214
ba20de3793e2 slightly tuned largeInt - largeInt for intel
Claus Gittinger <cg@exept.de>
parents: 4213
diff changeset
  3651
#endif
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3652
	/*
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3653
	 * subtract byte-wise
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3654
	 */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3655
	while (__index <= __minLen) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3656
	    /* do not make this into one expression - ask cg why */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3657
	    __diff = __myDigits[__index-1];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3658
	    __diff -= __otherDigits[__index-1];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3659
	    __diff -= __borrow;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3660
	    if (__diff >= 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3661
		__borrow = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3662
	    } else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3663
		__borrow = 1;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3664
		/* __diff += 0x100; */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3665
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3666
	    __resultDigits[__index-1] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3667
	    __index++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3668
	}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3669
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3670
	if (__len1 > __len2) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3671
	    while (__index <= __len1) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3672
		/* do not make this into one expression - ask cg why */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3673
		__diff = __myDigits[__index-1];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3674
		__diff -= __borrow;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3675
		if (__diff >= 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3676
		    __borrow = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3677
		    /* copy over rest */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3678
		    __resultDigits[__index-1] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3679
		    __index++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3680
		    while (__index <= __len1) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3681
			__resultDigits[__index-1] = __myDigits[__index-1];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3682
			__index++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3683
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3684
		    break;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3685
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3686
		__borrow = 1;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3687
		/* __diff += 0x100; */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3688
		__resultDigits[__index-1] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3689
		__index++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3690
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3691
	} else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3692
	    if (__len2 > __len1) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3693
		while (__index <= __len2) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3694
		    /* do not make this into one expression - ask cg why */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3695
		    __diff = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3696
		    __diff -= __otherDigits[__index-1];
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3697
		    __diff -= __borrow;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3698
		    if (__diff >= 0) {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3699
			__borrow = 0;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3700
		    } else {
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3701
			__borrow = 1;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3702
			/* __diff += 0x100; */
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3703
		    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3704
		    __resultDigits[__index-1] = __diff;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3705
		    __index++;
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3706
		}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3707
	    }
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3708
	}
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3709
	borrow = __mkSmallInteger(__borrow);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3710
	index = __mkSmallInteger(__index);
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3711
	lastDigit = __mkSmallInteger(__resultDigits[__intVal(lResult)-1]);
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3712
    }
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3713
%}.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3714
    ok == true ifFalse:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3715
	index := 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3716
	borrow := 0.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3717
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3718
	done := false.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3719
	[done] whileFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3720
	    diff := borrow.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3721
	    (index <= len1) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3722
		diff := diff + (digitByteArray basicAt:index).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3723
		(index <= len2) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3724
		    diff := diff - (otherDigitByteArray basicAt:index)
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3725
		]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3726
	    ] ifFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3727
		(index <= len2) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3728
		    diff := diff - (otherDigitByteArray basicAt:index)
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3729
		] ifFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3730
		    "end reached"
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3731
		    done := true
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3732
		]
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3733
	    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3734
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3735
	    "/ workaround for
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3736
	    "/ gcc code generator bug
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3737
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3738
	    (diff >= 0) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3739
		borrow := 0
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3740
	    ] ifFalse:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3741
		borrow := -1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3742
		diff := diff + 16r100
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3743
	    ].
4190
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3744
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3745
    "/        (diff < 0) ifTrue:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3746
    "/            borrow := -1.
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3747
    "/            diff := diff + 16r100
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3748
    "/        ] ifFalse:[
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3749
    "/            borrow := 0
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3750
    "/        ].
9fdc42eea567 tuned largeInt - largeInt
Claus Gittinger <cg@exept.de>
parents: 4189
diff changeset
  3751
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3752
	    resultDigitByteArray basicAt:index put:diff.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3753
	    index := index + 1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3754
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3755
	lastDigit := resultDigitByteArray basicAt:lResult.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3756
    ].
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3757
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3758
    (borrow ~~ 0) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3759
	"/ must generate 255's complement
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3760
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3761
	result sign:newSign negated.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3762
	[index <= lResult] whileTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3763
	    resultDigitByteArray basicAt:index put:16rFF.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3764
	    index := index + 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3765
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3766
	index := lResult.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3767
	[index > 0] whileTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3768
	    resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3769
	    index := index - 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3770
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3771
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3772
	index := 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3773
	carry := 1.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3774
	[carry ~~ 0] whileTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3775
	    (index <= lResult) ifTrue:[
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3776
		carry := (resultDigitByteArray basicAt:index) + carry.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3777
	    ].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3778
	    resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3779
	    carry := carry bitShift:-8.
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3780
	    index := index + 1
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3781
	].
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3782
	lastDigit := resultDigitByteArray basicAt:lResult.
4213
a66f711d86df slightly tuned +/- for non-lsb machines
Claus Gittinger <cg@exept.de>
parents: 4211
diff changeset
  3783
    ].
5000
46a73184be0d Fix arithmethic bugs (+, -)
Stefan Vogel <sv@exept.de>
parents: 4950
diff changeset
  3784
    (lastDigit ~~ 0 and:[lResult > SmallInteger maxBytes]) ifTrue:[
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  3785
	^ result
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3786
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3787
    ^ result compressed
1408
e9db184b34ee oops - large-minus was wrong when sign changes
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  3788
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  3789
    "Modified: 5.11.1996 / 14:09:25 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3790
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3791
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3792
absMod:anInteger
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3793
    "return a LargeIntegers representing
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3794
     abs(self) \\ abs(theArgument).
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3795
     Used as a helper for \\ and rem:"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3796
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3797
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3798
    |dividend divisor
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3799
     shift "{ Class: SmallInteger }" |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3800
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3801
    anInteger == 0 ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3802
	^ ZeroDivide raiseRequestWith:thisContext
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3803
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3804
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3805
    self = anInteger ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3806
	^ 0
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3807
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3808
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3809
    shift := self highBit - anInteger highBit.
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  3810
    dividend := LargeInteger digitBytes:digitByteArray copy. "/ self simpleDeepCopy sign:1.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3811
    shift < 0 ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3812
	^ dividend compressed.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3813
    ].
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3814
    shift == 0 ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3815
	divisor := LargeInteger digitBytes:(anInteger digitBytes copy). "/ anInteger simpleDeepCopy
4139
2942f4bd2862 Fix absMod: and absDivMod:
Stefan Vogel <sv@exept.de>
parents: 4137
diff changeset
  3816
    ] ifFalse:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3817
	divisor := anInteger bitShift:shift.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3818
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3819
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3820
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3821
    shift := shift + 1.
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3822
    [shift > 0] whileTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3823
	(dividend absLess:divisor) ifFalse:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3824
	    (dividend absSubtract: divisor) ifFalse:[ "result == 0"
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3825
		^ dividend compressed
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3826
	    ].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3827
	].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3828
	shift := shift - 1.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3829
	divisor div2.
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3830
    ].
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3831
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3832
    ^ dividend compressed
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3833
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3834
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3835
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absMod:4000000001] ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3836
Time millisecondsToRun:[   10000 timesRepeat:[  16000000001 absDivMod:4000000001] ]
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3837
     16000000000 absMod:4000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3838
     16000000000 absMod:3000000000
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3839
    "
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3840
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3841
    "Modified: / 5.11.1996 / 18:40:24 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3842
    "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
  3843
    "Modified: / 26.7.1999 / 10:46:18 / stefan"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3844
!
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  3845
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3846
absMul:aLargeInteger
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3847
    "return a LargeInteger representing abs(self) * abs(theArgument)"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3848
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3849
    |result otherDigitByteArray resultDigitByteArray ok
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3850
     idx      "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3851
     carry    "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3852
     len1     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3853
     len2     "{ Class: SmallInteger }"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3854
     dstIndex "{ Class: SmallInteger }"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3855
     prod     "{ Class: SmallInteger }"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3856
     v        "{ Class: SmallInteger }"|
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3857
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3858
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3859
    otherDigitByteArray := aLargeInteger digitBytes.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3860
    len2 := otherDigitByteArray size.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3861
4151
6d6971c27567 Some speedups.
Stefan Vogel <sv@exept.de>
parents: 4140
diff changeset
  3862
    result := LargeInteger basicNew numberOfDigits:(len1 + len2).
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  3863
    resultDigitByteArray := result digitBytes.
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3864
    ok := false.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3865
%{
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1065
diff changeset
  3866
    if (__isByteArray(__INST(digitByteArray))
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3867
     && __isByteArray(otherDigitByteArray)
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3868
     && __isByteArray(resultDigitByteArray)
250
a5deb61ffdac *** empty log message ***
claus
parents: 175
diff changeset
  3869
     && __bothSmallInteger(len1, len2)) {
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3870
	unsigned char *myBytes = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3871
	unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3872
	unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3873
	unsigned char *_p1, *_p2, *_pResult, *_pResult0, *_pResult1, *_p1Last, *_p2Last;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3874
	unsigned char *_pResultLast1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3875
	unsigned INT _v;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3876
	int _len1 = __intVal(len1);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3877
	int _len2 = __intVal(len2);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3878
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3879
	_p1Last = myBytes    + _len1 - 1;  /* the last byte */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3880
	_p2Last = otherBytes + _len2 - 1;  /* the last byte */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3881
	_pResult0 = resultBytes;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3882
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3883
	/*
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3884
	 *        aaa...aaa      f1[0] * f2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3885
	 *       bbb...bbb       f1[1] * f2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3886
	 *      ccc...ccc        f1[2] * f2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3887
	 *     ...
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3888
	 *    xxx...xxx          f1[high] * f2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3889
	 *
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3890
	 * start short-wise
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3891
	 * bounds: (16rFFFF * 16rFFFF) + 16rFFFF -> FFFF0000
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3892
	 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3893
	_p1 = myBytes;
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3894
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3895
#if defined(__LSBFIRST__) && (__POINTER_SIZE__ == 8)
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3896
	/* loop over ints of f1 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3897
	for (; _p1 < _p1Last-2; _p1 += 4, _pResult0 += 4) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3898
	    unsigned INT word1 = ((unsigned int *)_p1)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3899
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3900
	    _pResult = _pResult0;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3901
	    _p2 = otherBytes;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3902
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3903
	    /* loop over ints of f2 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3904
	    while (_p2 < (_p2Last-2)) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3905
		_v = (word1 * ((unsigned int *)_p2)[0]) + ((unsigned int *)_pResult)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3906
		((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3907
		_v >>= 32; /* now _v contains the carry*/
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3908
		_pResult += 4;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3909
		if (_v) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3910
		    unsigned char *_pResultLast3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3911
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3912
		    /* distribute carry - int-wise, then byte-wise */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3913
		    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3914
		    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3915
			if (_pResult1 > _pResultLast3) break;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3916
			_v += ((unsigned int *)_pResult1)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3917
			((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3918
			_v >>= 32;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3919
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3920
		    for (; _v; _pResult1++) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3921
			_v += _pResult1[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3922
			_pResult1[0] = _v /* & 0xFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3923
			_v >>= 8;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3924
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3925
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3926
		_p2 += 4;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3927
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3928
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3929
	    /* possible odd highByte of f2 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3930
	    while (_p2 <= _p2Last) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3931
		_v = (word1 * _p2[0]) + ((unsigned int *)_pResult)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3932
		((unsigned int *)_pResult)[0] = _v /* & 0xFFFFFFFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3933
		_v >>= 32; /* now _v contains the carry*/
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3934
		_pResult += 4;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3935
		if (_v) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3936
		    unsigned char *_pResultLast3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3937
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3938
		    /* distribute carry - int-wise, then byte-wise */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3939
		    _pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3940
		    for (_pResult1 = _pResult; _v; _pResult1 += 4) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3941
			if (_pResult1 > _pResultLast3) break;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3942
			_v += ((unsigned int *)_pResult1)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3943
			((unsigned int *)_pResult1)[0] = _v /* & 0xFFFFFFFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3944
			_v >>= 32;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3945
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3946
		    for (; _v; _pResult1++) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3947
			_v += _pResult1[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3948
			_pResult1[0] = _v /* & 0xFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3949
			_v >>= 8;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3950
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3951
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3952
		_p2++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3953
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3954
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  3955
#endif /* 64bit */
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  3956
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3957
	/* loop over shorts of f1 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3958
	for (; _p1 < _p1Last; _p1 += 2, _pResult0 += 2) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3959
	    unsigned int short1 = ((unsigned short *)_p1)[0];
4231
5e9e9319a9de alpha large*large speedup
Claus Gittinger <cg@exept.de>
parents: 4230
diff changeset
  3960
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3961
#if !defined(__LSBFIRST__)
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3962
	    short1 = ((short1 >> 8) & 0xFF) | ((short1 & 0xFF) << 8);
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3963
#endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3964
	    _pResult = _pResult0;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3965
	    _p2 = otherBytes;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3966
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3967
	    /* loop over shorts of f2 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3968
	    while (_p2 < _p2Last) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3969
#if !defined(__LSBFIRST__)
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3970
		unsigned int _short2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3971
		unsigned int _short3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3972
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3973
		_short2 = ((unsigned short *)_p2)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3974
		_short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3975
		_short3 = ((unsigned short *)_pResult)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3976
		_short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3977
		_v = (short1 * _short2) + _short3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3978
		_pResult[0] = _v;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3979
		_pResult[1] = _v >> 8;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  3980
#else /* __LSBFIRST__ */
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3981
		_v = (short1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3982
		((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3983
#endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3984
		_v >>= 16; /* now _v contains the carry*/
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3985
		_pResult += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3986
		if (_v) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3987
		    /* distribute carry - short-wise, then byte-wise */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3988
		    _pResult1 = _pResult;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3989
#if defined(__LSBFIRST__)
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3990
		    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3991
		    for (; _v; _pResult1 += 2) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3992
			if (_pResult1 > _pResultLast1) break;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3993
			_v += ((unsigned short *)_pResult1)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3994
			((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3995
			_v >>= 16;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3996
		    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  3997
#endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3998
		    for (; _v; _pResult1++) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  3999
			_v += _pResult1[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4000
			_pResult1[0] = _v /* & 0xFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4001
			_v >>= 8;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4002
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4003
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4004
		_p2 += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4005
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4006
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4007
	    /* possible odd highByte of f2 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4008
	    if (_p2 <= _p2Last) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4009
#if !defined(__LSBFIRST__)
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4010
		unsigned int _short3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4011
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4012
		_short3 = ((unsigned short *)_pResult)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4013
		_short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4014
		_v = (short1 * _p2[0]) + _short3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4015
		_pResult[0] = _v;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4016
		_pResult[1] = _v >> 8;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4017
#else /* __LSBFIRST__ */
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4018
		_v = (short1 * _p2[0]) + ((unsigned short *)_pResult)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4019
		((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  4020
#endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4021
		_v >>= 16; /* now _v contains the carry*/
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4022
		_pResult += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4023
		if (_v) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4024
		    /* distribute carry - short-wise, then byte-wise */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4025
		    _pResult1 = _pResult;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4026
#if defined(__LSBFIRST__)
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4027
		    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4028
		    for (; _v; _pResult1 += 2) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4029
			if (_pResult1 > _pResultLast1) break;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4030
			_v += ((unsigned short *)_pResult1)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4031
			((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4032
			_v >>= 16;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4033
		    }
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  4034
#endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4035
		    for (; _v; _pResult1++) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4036
			_v += _pResult1[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4037
			_pResult1[0] = _v /* & 0xFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4038
			_v >>= 8;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4039
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4040
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4041
		_p2++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4042
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4043
	}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4044
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4045
	/* possible odd highByte of f1 (or byteLoop, if not __LSBFIRST__) */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4046
	for (; _p1 <= _p1Last; _p1++, _pResult0++) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4047
	    unsigned int byte1 = _p1[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4048
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4049
	    _pResult = _pResult0;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4050
	    _p2 = otherBytes;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4051
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4052
	    /* loop over shorts of f2 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4053
	    while (_p2 < _p2Last) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4054
#if !defined(__LSBFIRST__)
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4055
		unsigned int _short2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4056
		unsigned int _short3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4057
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4058
		_short2 = ((unsigned short *)_p2)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4059
		_short2 = ((_short2 >> 8) /* & 0xFF */) | ((_short2 & 0xFF) << 8);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4060
		_short3 = ((unsigned short *)_pResult)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4061
		_short3 = ((_short3 >> 8) /* & 0xFF */) | ((_short3 & 0xFF) << 8);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4062
		_v = (byte1 * _short2) + _short3;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4063
		_pResult[0] = _v;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4064
		_pResult[1] = _v >> 8;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4065
#else /* __LSBFIRST__ */
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4066
		_v = (byte1 * ((unsigned short *)_p2)[0]) + ((unsigned short *)_pResult)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4067
		((unsigned short *)_pResult)[0] = _v /* & 0xFFFF */;
4266
de62998499ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4265
diff changeset
  4068
#endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4069
		_v >>= 16; /* now _v contains the carry*/
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4070
		_pResult += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4071
		if (_v) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4072
		    /* distribute carry - short-wise, then byte-wise */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4073
		    _pResult1 = _pResult;
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4074
#if defined(__LSBFIRST__)
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4075
		    _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4076
		    for (_pResult1 = _pResult; _v; _pResult1 += 2) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4077
			if (_pResult1 > _pResultLast1) break;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4078
			_v += ((unsigned short *)_pResult1)[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4079
			((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4080
			_v >>= 16;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4081
		    }
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4082
#endif /* __LSBFIRST__ */
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4083
		    for (; _v; _pResult1++) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4084
			_v += _pResult1[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4085
			_pResult1[0] = _v /* & 0xFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4086
			_v >>= 8;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4087
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4088
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4089
		_p2 += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4090
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4091
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4092
	    /* possible odd highByte of f2 (or byteLoop, if not __LSBFIRST__) */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4093
	    while (_p2 <= _p2Last) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4094
		_v = (byte1 * _p2[0]) + _pResult[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4095
		_pResult[0] = _v /* & 0xFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4096
		_v >>= 8; /* now _v contains the carry*/
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4097
		_pResult++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4098
		if (_v) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4099
		    /* distribute carry */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4100
		    for (_pResult1 = _pResult; _v; _pResult1++) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4101
			_v += _pResult1[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4102
			_pResult1[0] = _v /* & 0xFF */;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4103
			_v >>= 8;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4104
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4105
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4106
		_p2++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4107
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4108
	}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4109
	ok = true;
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4110
    }
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4111
%}.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4112
    ok ifFalse:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4113
	1 to:len1 do:[:index1 |
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4114
	    1 to:len2 do:[:index2 |
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4115
		dstIndex := index1 + index2 - 1.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4116
		prod := (digitByteArray basicAt:index1) * (otherDigitByteArray basicAt:index2).
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4117
		prod := prod + (resultDigitByteArray basicAt:dstIndex).
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4118
		resultDigitByteArray basicAt:dstIndex put:(prod bitAnd:16rFF).
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4119
		carry := prod bitShift:-8.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4120
		carry ~~ 0 ifTrue:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4121
		    idx := dstIndex + 1.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4122
		    [carry ~~ 0] whileTrue:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4123
			v := (resultDigitByteArray basicAt:idx) + carry.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4124
			resultDigitByteArray basicAt:idx put:(v bitAnd:255).
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4125
			carry := v bitShift:-8.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4126
			idx := idx + 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4127
		    ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4128
		]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4129
	    ]
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4130
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4131
    ].
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4132
    ^ result compressed
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4133
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4134
4174
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4135
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
  4136
    "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
  4137
     with sign: newSign.
62498b719e87 pass new sign to absPlus/absMinus, to allow for compress optimizations
Claus Gittinger <cg@exept.de>
parents: 4173
diff changeset
  4138
     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
  4139
     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
  4140
     This is a helper for addition and subtraction - not for public use."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4141
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4142
    |result done otherDigitByteArray resultDigitByteArray
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4143
     len1   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4144
     len2   "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4145
     newLen "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4146
     index  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4147
     carry  "{ Class: SmallInteger }"
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4148
     sum    "{ Class: SmallInteger }" |
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4149
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4150
    otherDigitByteArray := aLargeInteger digitBytes.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4151
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4152
%{
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4153
    OBJ _digitByteArray = __INST(digitByteArray);
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4154
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4155
    if (__isByteArray(_digitByteArray)
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4156
     && __isByteArray(otherDigitByteArray)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4157
	int _len1, _len2, _newLen;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4158
	unsigned char *_myDigits, *_otherDigits, *_newDigits;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4159
	int _index, _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4160
	int _comLen;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4161
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4162
	_len1 = __byteArraySize(_digitByteArray);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4163
	_len2 = __byteArraySize(otherDigitByteArray);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4164
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4165
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4166
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4167
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4168
	if (_len1 < _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4169
	    _comLen = _len1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4170
	    _newLen = _len2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4171
	    if (_otherDigits[_len2 - 1] == 0xFF) _newLen++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4172
	} else if (_len2 < _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4173
	    _comLen = _len2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4174
	    _newLen = _len1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4175
	    if (_myDigits[_len1 - 1] == 0xFF) _newLen++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4176
	} else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4177
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4178
	     * there can only be an overflow from the high bytes,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4179
	     * if their sum is >= 255
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4180
	     * (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
  4181
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4182
	    _newLen = _len1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4183
	    if ((_otherDigits[_len2 - 1] + _myDigits[_len1 - 1]) >= 0xFF) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4184
		_newLen++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4185
	    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4186
		if (_newLen == sizeof(INT)) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4187
		    OBJ _uint;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4188
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4189
		    /*
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4190
		     * two word-sized numbers, no carry - a very common case ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4191
		     */
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4192
#if defined(__LSB_FIRST__)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4193
		    unsigned INT _sum = *(unsigned INT *)_otherDigits + *(unsigned INT *)_myDigits;
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  4194
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4195
		    unsigned INT _sum = __unsignedLongIntVal(self) + __unsignedLongIntVal(aLargeInteger);
4216
65f14da89fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4215
diff changeset
  4196
#endif /* not LSB_FIRST */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4197
		    if (_sum <= _MAX_INT) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  4198
			_uint = __mkSmallInteger(_sum * __intVal(newSign));
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4199
		    } else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4200
			_uint = __MKULARGEINT(_sum);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4201
			__LargeIntegerInstPtr(_uint)->l_sign = newSign;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4202
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4203
		    RETURN (_uint);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4204
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4205
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4206
	    _comLen = _len1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4207
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4208
	resultDigitByteArray = __BYTEARRAY_UNINITIALIZED_NEW_INT(_newLen);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4209
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4210
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4211
	 * must refetch - GC could have been invoked
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4212
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4213
	_digitByteArray = __INST(digitByteArray);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4214
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4215
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4216
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4217
	_newDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4218
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4219
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4220
	 * add them ...
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4221
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4222
	_index = 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4223
	_carry = 0;
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  4224
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4225
#if defined(__LSBFIRST__)
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4226
# if (__POINTER_SIZE__ == 8) && defined(__GNUC__)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4227
#  if 0  /* not faster (on alpha) */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4228
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4229
	    int _comLen7;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4230
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4231
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4232
	     * have a 64bit integers;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4233
	     * add quad-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4234
	     * accessing bytes at: [index-1][index][index+1]..[index+6]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4235
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4236
	    _comLen7 = _comLen - 3 - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4237
	    while (_index <= _comLen7) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4238
		UINT64 _sum, _t1, _t2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4239
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4240
		asm ("addq   %5,%6,%1         /* sum */                  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4241
		      addq   %0,%1,%1         /* plus carryIn */         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4242
		      cmpult %1,%5,%2         /* was there a carry ? */  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4243
		      cmpult %1,%6,%3         /* was there a carry ? */  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4244
		      bis    %2,%3,%0         /* carryOut */             \n\
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4245
		     "
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4246
			: "=r"  (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4247
			  "=r"  (_sum),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4248
			  "r"   (_t1),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4249
			  "r"   (_t2)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4250
			: "r"   (_carry),
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4251
			  "r"   (((unsigned long *)(&(_myDigits[_index - 1])))[0]),
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4252
			  "r"   (((unsigned long *)(&(_otherDigits[_index - 1])))[0])
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4253
		    );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4254
		/* _sum = _sum & 0xFFFFFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4255
		((unsigned long *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4256
		_index += 8;
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
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4259
#  endif
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4260
# endif /* 64bit */
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4261
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4262
# if (__POINTER_SIZE__ == 8)
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4263
# if 0  /* not faster (on alpha) */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4264
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4265
	    int _comLen7;
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
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4268
	     * have a 64bit integers;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4269
	     * add quad-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4270
	     * accessing bytes at: [index-1][index][index+1]..[index+6]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4271
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4272
	    _comLen7 = _comLen - 3 - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4273
	    while (_index <= _comLen7) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4274
		UINT64 _sum, _t1, _t2;
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
		_t1 = ((UINT64 *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4277
		_t2 = ((UINT64 *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4278
		_sum = _t1 + _t2 + _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4279
		((UINT64 *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4280
		_carry = (_sum < _t1) | (_sum < _t2);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4281
		_index += 8;
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
	}
8908
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4284
#  endif
68017b13590b 64bit cleanup
Claus Gittinger <cg@exept.de>
parents: 8907
diff changeset
  4285
# endif /* 64bit */
4263
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  4286
7f7caf39ebb4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4261
diff changeset
  4287
# ifdef UINT64
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4288
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4289
	    int _comLen3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4290
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4291
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4292
	     * have a 64bit integer type;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4293
	     * add int-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4294
	     * accessing bytes at: [index-1][index][index+1][index+2]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4295
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4296
	    _comLen3 = _comLen - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4297
	    while (_index <= _comLen3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4298
		UINT64 _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4299
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4300
		/* do not merge the 3 lines below into one -
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4301
		 * (will do sign extension then, which is wrong here)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4302
		 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4303
		_sum = (unsigned)_carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4304
		_sum += ((unsigned int *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4305
		_sum += ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4306
		_carry = _sum >> 32;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4307
		/* _sum = _sum & 0xFFFFFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4308
		((unsigned int *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4309
		_index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4310
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4311
	}
4172
3fb2b94e7535 tune largeInt + largeInt (for i386)
Claus Gittinger <cg@exept.de>
parents: 4171
diff changeset
  4312
# else
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8908
diff changeset
  4313
#  if defined(__i386__) && defined(__GNUC__) && (__POINTER_SIZE__ == 4)
6665
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
	    int _comLen3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4316
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4317
	    _comLen3 = _comLen - 3 - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4318
	    while (_index <= _comLen3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4319
		unsigned int _sum, _sum2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4320
		unsigned int __in1A, __in1B, __in2A, __in2B;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4321
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4322
		__in1A = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4323
		__in2A = ((unsigned int *)(&(_myDigits[_index - 1])))[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4324
		__in1B = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4325
		__in2B = ((unsigned int *)(&(_otherDigits[_index - 1])))[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4326
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4327
		asm ("addl %%edx,%%eax  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4328
		      movl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4329
		      adcl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4330
		      addl %5,%%eax     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4331
		      adcl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4332
					\n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4333
		      addl %%edx,%%ecx  \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4334
		      movl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4335
		      adcl $0,%%edx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4336
		      addl %7,%%ecx     \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4337
		      adcl $0,%%edx     \n\
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4338
		     "
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4339
			: "=d"  (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4340
			  "=a"  (_sum),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4341
			  "=c"  (_sum2)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4342
			: "0"   (_carry),
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4343
			  "1"   (__in1A),
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4344
			  "rm"  (__in1B),
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4345
			  "2"   (__in2A),
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4346
			  "rm"  (__in2B)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4347
		    );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4348
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4349
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4350
		((unsigned *)(&(_newDigits[_index - 1])))[1] = _sum2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4351
		_index += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4352
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4353
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4354
	     * add int-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4355
	     * accessing bytes at: [index-1][index][index+1][index+2]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4356
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4357
	    _comLen3 = _comLen3 + 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4358
	    if (_index <= _comLen3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4359
		unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4360
		unsigned int __inA, __inB;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4361
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4362
		__inA = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4363
		__inB = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4364
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4365
		asm ("addl %%edx,%%eax      \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4366
		      movl $0,%%edx         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4367
		      adcl $0,%%edx         \n\
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4368
		      addl %4,%%eax         \n\
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4369
		      adcl $0,%%edx"
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4370
			: "=d"  (_carry),
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4371
			  "=a"  (_sum)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4372
			: "0"   (_carry),
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4373
			  "1"   (__inA),
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4374
			  "rm"  (__inB)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4375
		    );
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4376
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4377
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4378
		_index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4379
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4380
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4381
#  endif /* __i386__ && GNUC */
10342
58ce3aabaa4b Visual-C support
Stefan Vogel <sv@exept.de>
parents: 8929
diff changeset
  4382
#  if defined(WIN32) && defined(__BORLANDC__) && defined(__i386__) && (__POINTER_SIZE__ == 4)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4383
	{
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4384
	    int _comLen3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4385
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4386
	    /*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4387
	     * add long-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4388
	     * accessing bytes at: [index-1][index][index+1][index+2]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4389
	     */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4390
	    _comLen3 = _comLen - 3;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4391
	    while (_index <= _comLen3) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4392
		unsigned int _sum, _v1, _v2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4393
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4394
		_v1 = ((unsigned int *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4395
		_v2 = ((unsigned int *)(&(_otherDigits[_index - 1])))[0];
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4396
		asm {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4397
		      mov eax, _v1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4398
		      add eax, _v2
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4399
		      mov edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4400
		      adc edx, 0
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4401
		      add eax, _carry
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4402
		      adc edx, 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4403
		      mov _carry, edx
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4404
		      mov _sum, eax
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4405
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4406
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4407
		((unsigned *)(&(_newDigits[_index - 1])))[0] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4408
		_index += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4409
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4410
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4411
#  endif /* __i386__ && WIN32 */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4412
# endif /* INT64 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4413
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4414
	 * add short-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4415
	 * accessing bytes at: [index-1][index]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4416
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4417
	while (_index < _comLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4418
	    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4419
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4420
	    _sum = _carry
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4421
		   + ((unsigned short *)(&(_myDigits[_index - 1])))[0]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4422
		   + ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4423
	    _carry = _sum >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4424
	    /* _sum = _sum & 0xFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4425
	    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4426
	    _index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4427
	}
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  4428
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4429
# ifdef __sparc__
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4430
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4431
	 * add short-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4432
	 * accessing bytes at: [index-1][index]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4433
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4434
	while (_index < _comLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4435
	    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4436
	    unsigned short _v1, _v2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4437
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4438
	    _v1 = ((unsigned short *)(&(_myDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4439
	    _v2 = ((unsigned short *)(&(_otherDigits[_index - 1])))[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4440
	    _sum = _carry + (_v1>>8) + (_v2>>8);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4441
	    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4442
	    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4443
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4444
	    _sum = _carry + (_v1 & 0xFF) + (_v2 & 0xFF);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4445
	    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4446
	    _newDigits[_index] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4447
	    _index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4448
	}
4284
20f47ad19322 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4283
diff changeset
  4449
# endif
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4450
#endif /* __LSBFIRST__ */
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4451
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4452
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4453
	 * add byte-wise
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4454
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4455
	while (_index <= _comLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4456
	    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4457
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4458
	    _sum = _carry
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4459
		   + _myDigits[_index - 1]
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4460
		   + _otherDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4461
	    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4462
	    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4463
	    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4464
	    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4465
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4466
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4467
	/*
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4468
	 * rest
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4469
	 */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4470
	if (_len1 > _len2) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4471
#if defined(__LSBFIRST__)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4472
	    if (_index <= _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4473
		if ((_index - 1) & 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4474
		    /* odd byte */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4475
		    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4476
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4477
		    _sum = _carry + _myDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4478
		    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4479
		    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4480
		    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4481
		    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4482
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4483
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4484
		while (_index < _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4485
		    /* shorts */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4486
		    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4487
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4488
		    _sum = _carry + *(unsigned short *)(&(_myDigits[_index - 1]));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4489
		    _carry = _sum >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4490
		    /* _sum = _sum & 0xFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4491
		    *(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4492
		    _index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4493
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4494
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4495
		if (_index <= _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4496
		    /* last byte */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4497
		    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4498
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4499
		    _sum = _carry + _myDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4500
		    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4501
		    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4502
		    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4503
		    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4504
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4505
	    }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  4506
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4507
	    while (_index <= _len1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4508
		unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4509
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4510
		_sum = _carry + _myDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4511
		_carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4512
		/* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4513
		_newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4514
		_index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4515
	    }
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  4516
#endif /* not LSB */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4517
	} else {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4518
	    if (_len2 > _len1) {
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4519
#if defined(__LSBFIRST__)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4520
		if (_index <= _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4521
		    if ((_index - 1) & 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4522
			/* odd byte */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4523
			unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4524
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4525
			_sum = _carry + _otherDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4526
			_carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4527
			/* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4528
			_newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4529
			_index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4530
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4531
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4532
		    while (_index < _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4533
			/* shorts */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4534
			unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4535
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4536
			_sum = _carry + *(unsigned short *)(&(_otherDigits[_index - 1]));
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4537
			_carry = _sum >> 16;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4538
			/* _sum = _sum & 0xFFFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4539
			*(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4540
			_index += 2;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4541
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4542
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4543
		    if (_index <= _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4544
			/* last byte */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4545
			unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4546
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4547
			_sum = _carry + _otherDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4548
			_carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4549
			/* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4550
			_newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4551
			_index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4552
		    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4553
		}
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  4554
#else
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4555
		while (_index <= _len2) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4556
		    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4557
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4558
		    _sum = _carry + _otherDigits[_index - 1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4559
		    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4560
		    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4561
		    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4562
		    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4563
		}
4256
04905f1fa63f more fixes
Claus Gittinger <cg@exept.de>
parents: 4255
diff changeset
  4564
#endif /* not LSB */
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4565
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4566
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4567
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4568
	while (_index <= _newLen) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4569
	    unsigned int _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4570
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4571
	    _sum = _carry;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4572
	    _carry = _sum >> 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4573
	    /* _sum = _sum & 0xFF; */
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4574
	    _newDigits[_index - 1] = _sum;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4575
	    _index++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4576
	}
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4577
    }
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4578
%}.
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4579
    resultDigitByteArray notNil ifTrue:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4580
	result := self class basicNew.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4581
	result setDigits:resultDigitByteArray.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4582
	result sign:newSign.
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4583
    ] ifFalse:[
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4584
	len1 := digitByteArray size.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4585
	len2 := otherDigitByteArray size.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4586
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4587
	"/ earlier versions estimated the newLength as:
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4588
	"/ (len1 max:len2) + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4589
	"/ and reduced the result.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4590
	"/ however, if one of the addends is smaller,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4591
	"/ the result will never require another digit,
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4592
	"/ if the highest digit of the larger addent is
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4593
	"/ not equal to 255. Therefore, in most cases,
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4594
	"/ we can avoid the computation and resizing
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4595
	"/ in #reduced.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4596
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4597
	len1 < len2 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4598
	    newLen := len2.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4599
	    (otherDigitByteArray at:len2) == 16rFF ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4600
		newLen := newLen + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4601
	    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4602
	] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4603
	    len2 < len1 ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4604
		newLen := len1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4605
		(digitByteArray at:len1) == 16rFF ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4606
		    newLen := newLen + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4607
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4608
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4609
		newLen := len1 + 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4610
	    ]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4611
	].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4612
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4613
	result := self class basicNew numberOfDigits:newLen.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4614
	result sign:newSign.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4615
	resultDigitByteArray := result digitBytes.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4616
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4617
	index := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4618
	carry := 0.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4619
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4620
	done := false.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4621
	[done] whileFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4622
	    sum := carry.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4623
	    (index <= len1) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4624
		sum := sum + (digitByteArray basicAt:index).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4625
		(index <= len2) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4626
		    sum := sum + (otherDigitByteArray basicAt:index)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4627
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4628
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4629
		(index <= len2) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4630
		    sum := sum + (otherDigitByteArray basicAt:index)
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4631
		] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4632
		    "end reached"
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4633
		    done := true
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4634
		]
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4635
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4636
	    (sum >= 16r100) ifTrue:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4637
		carry := 1.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4638
		sum := sum - 16r100
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4639
	    ] ifFalse:[
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4640
		carry := 0
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4641
	    ].
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4642
	    resultDigitByteArray basicAt:index put:sum.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4643
	    index := index + 1
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4644
	].
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4645
    ].
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4646
1883
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4647
    ^ result compressed
d3fbf4b36be7 renamed #normalize to #compressed (ST_80 compat)
Claus Gittinger <cg@exept.de>
parents: 1857
diff changeset
  4648
2848
8be5134b3679 tuned addition - especially for 4-byte largeInts
Claus Gittinger <cg@exept.de>
parents: 2816
diff changeset
  4649
    "Modified: 11.8.1997 / 03:23:37 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4650
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4651
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4652
absSubtract:aLargeInteger
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4653
    "private helper for division:
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4654
	destructively subtract aLargeInteger from myself
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4655
	AND return true, if the result is non-zero, false otherwise.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4656
	(i.e. this method has both a return value and a side-effect
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4657
	 on the receiver)
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4658
	Only allowed for positive receiver and argument
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4659
	The receiver must be >= the argument.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4660
	The receiver must be a temporary scratch-number"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4661
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4662
    |otherDigitByteArray
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4663
     len1   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4664
     len2   "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4665
     index  "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4666
     borrow "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4667
     diff   "{ Class: SmallInteger }"
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4668
     notZero
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4669
    |
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4670
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4671
    notZero := false.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4672
    len1 := digitByteArray size.
4828
796dcc9903cf New:#digitBytesMSB:
Claus Gittinger <cg@exept.de>
parents: 4806
diff changeset
  4673
    otherDigitByteArray := aLargeInteger digitBytes.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4674
    len2 := otherDigitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4675
    len2 > len1 ifTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4676
	[(otherDigitByteArray at:len2) == 0] whileTrue:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4677
	    len2 := len2 - 1
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4678
	].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4679
	len2 > len1 ifTrue:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4680
	    self error:'operation failed' "/ may not be called that way
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4681
	].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4682
    ].
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4683
    "/ knowing that len2 is <= len1
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4684
%{
4189
Claus Gittinger <cg@exept.de>
parents: 4188
diff changeset
  4685
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4686
    OBJ _digitByteArray = __INST(digitByteArray);
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4687
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4688
    if (__isByteArray(_digitByteArray)
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4689
     && __isByteArray(otherDigitByteArray)) {
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4690
	int _len1 = __intVal(len1),
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4691
	    _len2 = __intVal(len2);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4692
	unsigned char *_myDigits, *_otherDigits;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4693
	int _index = 1, _borrow = 0;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4694
	INT _diff;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4695
	INT anyBitNonZero = 0;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4696
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4697
	_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4698
	_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4699
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4700
#if defined(__LSBFIRST__)
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4701
# if __POINTER_SIZE__ == 8
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4702
	{
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4703
	    int _len2Q;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4704
	    /*
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4705
	     * subtract int-wise
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4706
	     */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4707
	    _len2Q = _len2-2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4708
	    while (_index < _len2Q) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4709
		/* do not combine the expression below (may lead to unsigned result on some machines */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4710
		_diff = ((unsigned int *)(_myDigits+_index-1))[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4711
		_diff -= ((unsigned int *)(_otherDigits+_index-1))[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4712
		_diff -= _borrow;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4713
		if (_diff >= 0) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4714
		    _borrow = 0;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4715
		} else {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4716
		    _borrow = 1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4717
		    /* _diff += 0x10000; */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4718
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4719
		((unsigned int *)(_myDigits+_index-1))[0] = _diff;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4720
		anyBitNonZero |= (_diff & 0xFFFFFFFFL);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4721
		_index += 4;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4722
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4723
	}
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4724
# endif
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4725
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4726
	/*
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4727
	 * subtract short-wise
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4728
	 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4729
	while (_index < _len2) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4730
	    /* do not combine the expression below (may lead to unsigned result on some machines */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4731
	    _diff = ((unsigned short *)(_myDigits+_index-1))[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4732
	    _diff -= ((unsigned short *)(_otherDigits+_index-1))[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4733
	    _diff -= _borrow;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4734
	    if (_diff >= 0) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4735
		_borrow = 0;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4736
	    } else {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4737
		_borrow = 1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4738
		/* _diff += 0x10000; */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4739
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4740
	    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4741
	    anyBitNonZero |= (_diff & 0xFFFF);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4742
	    _index += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4743
	}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4744
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4745
	if (_index <= _len2) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4746
	    /*
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4747
	     * cannot continue with shorts - there is an odd number of
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4748
	     * bytes in the minuent
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4749
	     */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4750
	} else {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4751
	    while (_index < _len1) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4752
		/* do not combine the expression below (may lead to unsigned result on some machines */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4753
		_diff = ((unsigned short *)(_myDigits+_index-1))[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4754
		_diff -= _borrow;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4755
		if (_diff >= 0) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4756
		    /* _borrow = 0; */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4757
		    ((unsigned short *)(_myDigits+_index-1))[0] = _diff;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4758
		    anyBitNonZero |= (_diff & 0xFFFF);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4759
		    _index += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4760
		    while (_index < _len1) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4761
			anyBitNonZero |= ((unsigned short *)(_myDigits+_index-1))[0];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4762
			if (anyBitNonZero) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4763
			    RETURN (true);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4764
			}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4765
			_index += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4766
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4767
		    /* last odd index */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4768
		    if (_index <= _len1) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4769
			anyBitNonZero |= _myDigits[_index - 1];;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4770
			if (anyBitNonZero) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4771
			    RETURN (true);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4772
			}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4773
			_index++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4774
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4775
		    RETURN (anyBitNonZero ? true : false);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4776
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4777
		_borrow = 1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4778
		/* _diff += 0x10000; */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4779
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4780
		((unsigned short *)(_myDigits+_index-1))[0] = _diff;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4781
		anyBitNonZero |= (_diff & 0xFFFF);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4782
		_index += 2;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4783
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4784
	}
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4785
#endif
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4786
	/*
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4787
	 * subtract byte-wise
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4788
	 */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4789
	while (_index <= _len2) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4790
	    /* do not combine the expression below (may lead to unsigned result on some machines */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4791
	    _diff = _myDigits[_index - 1];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4792
	    _diff -= _otherDigits[_index - 1];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4793
	    _diff -= _borrow;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4794
	    if (_diff >= 0) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4795
		_borrow = 0;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4796
	    } else {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4797
		_borrow = 1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4798
		/* _diff += 0x100; */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4799
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4800
	    _myDigits[_index - 1] = _diff;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4801
	    anyBitNonZero |= (_diff & 0xFF);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4802
	    _index++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4803
	}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4804
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4805
	while (_index <= _len1) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4806
	    /* do not combine the expression below (may lead to unsigned result on some machines */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4807
	    _diff = _myDigits[_index - 1];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4808
	    _diff -= _borrow;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4809
	    if (_diff >= 0) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4810
		/* _borrow = 0; */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4811
		_myDigits[_index - 1] = _diff;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4812
		anyBitNonZero |= (_diff & 0xFF);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4813
		_index++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4814
		while (_index <= _len1) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4815
		    anyBitNonZero |= _myDigits[_index - 1];
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4816
		    if (anyBitNonZero) {
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4817
			RETURN (true);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4818
		    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4819
		    _index++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4820
		}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4821
		break;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4822
	    }
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4823
	    _borrow = 1;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4824
	    /* _diff += 0x100; */
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4825
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4826
	    _myDigits[_index - 1] = _diff;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4827
	    anyBitNonZero |= (_diff & 0xFF);
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4828
	    _index++;
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4829
	}
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4830
	RETURN (anyBitNonZero ? true : false);
4187
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4831
    }
3dc575bd3915 tuned absSubtract: (which is a helper for large-division)
Claus Gittinger <cg@exept.de>
parents: 4185
diff changeset
  4832
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4833
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4834
    index := 1.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4835
    borrow := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4836
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4837
    [index <= len1] whileTrue:[
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4838
	diff := borrow.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4839
	diff := diff + (digitByteArray basicAt:index).
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4840
	index <= len2 ifTrue:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4841
	    diff := diff - (otherDigitByteArray basicAt:index).
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4842
	].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4843
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4844
	"/ workaround for
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4845
	"/ gcc code generator bug
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4846
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4847
	(diff >= 0) ifTrue:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4848
	    borrow := 0
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4849
	] ifFalse:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4850
	    borrow := -1.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4851
	    diff := diff + 16r100
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4852
	].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4853
	diff ~~ 0 ifTrue:[
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4854
	    notZero := true
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4855
	].
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4856
	digitByteArray basicAt:index put:diff.
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4857
	index := index + 1
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4858
    ].
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4859
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4860
    ^ notZero
4137
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4861
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4862
    "Created: / 5.11.1996 / 16:23:47 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4863
    "Modified: / 5.11.1996 / 18:56:50 / cg"
f85d341a13e4 Optimisations and modulo arithmethic
Stefan Vogel <sv@exept.de>
parents: 3984
diff changeset
  4864
    "Modified: / 27.4.1999 / 18:08:23 / stefan"
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4865
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4866
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4867
div2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4868
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4869
       destructively divide the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4870
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4871
    |prevBit|
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4872
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4873
%{  /* NOCONTEXT */
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4874
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4875
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4876
    if (__isByteArray(__digits)) {
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4877
	int __nBytes = __byteArraySize(__digits);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4878
	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4879
	unsigned INT __this, __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4880
	int __idx;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4881
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4882
	if (__nBytes == 1) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4883
	    __bp[0] >>= 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4884
	    RETURN (self);
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4885
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4886
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4887
	__idx = 1;
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4888
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4889
#if defined(__LSBFIRST__) && (__POINTER_SIZE__ == 8)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4890
	if (sizeof(unsigned INT) == 8) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4891
	    int __endIndex = __nBytes - 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4892
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4893
	    if (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4894
		__this = ((unsigned INT *)__bp)[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4895
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4896
		while (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4897
		    __next = ((unsigned INT *)__bp)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4898
		    __this = (__this >> 1) /* & 0x7FFFFFFFFFFFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4899
		    __this |= __next << 63;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4900
		    ((unsigned INT *)__bp)[0] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4901
		    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4902
		    __bp += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4903
		    __idx += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4904
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4905
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4906
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4907
#else
8901
824a89d0b5c7 alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents: 8628
diff changeset
  4908
# if defined(__LSBFIRST__)
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4909
	if (sizeof(unsigned int) == 4) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4910
	    int __endIndex = __nBytes - 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4911
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4912
	    if (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4913
		__this = ((unsigned INT *)__bp)[0];
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4914
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  4915
# if 0
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4916
		__idx += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4917
		while (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4918
		    __next = ((unsigned int *)__bp)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4919
		    __this = (__this >> 1) /* & 0x7FFFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4920
		    __this |= __next << 31;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4921
		    ((unsigned int *)__bp)[0] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4922
		    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4923
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4924
		    __next = ((unsigned int *)__bp)[2];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4925
		    __this = (__this >> 1) /* & 0x7FFFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4926
		    __this |= __next << 31;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4927
		    ((unsigned int *)__bp)[1] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4928
		    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4929
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4930
		    __bp += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4931
		    __idx += 8;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4932
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4933
		__idx -= 4;
5023
5e98a2a3ea6f slightly faster #negated
Claus Gittinger <cg@exept.de>
parents: 5022
diff changeset
  4934
# endif
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4935
		while (__idx < __endIndex) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4936
		    __next = ((unsigned int *)__bp)[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4937
		    __this = (__this >> 1) /* & 0x7FFFFFF */;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4938
		    __this |= __next << 31;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4939
		    ((unsigned int *)__bp)[0] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4940
		    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4941
		    __bp += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4942
		    __idx += 4;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4943
		}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4944
	    }
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4945
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  4946
# endif
3119
65247b9d1201 oops - mul2 was wrong for MSB-First machines
Claus Gittinger <cg@exept.de>
parents: 3099
diff changeset
  4947
#endif
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4948
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4949
	__this = __bp[0];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4950
	while (__idx < __nBytes) {
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4951
	    __next = __bp[1];
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4952
	    __this >>= 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4953
	    __this |= __next << 7;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4954
	    __bp[0] = __this;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4955
	    __this = __next;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4956
	    __bp++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4957
	    __idx++;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4958
	}
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4959
	__bp[0] = __this >> 1;
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4960
	RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4961
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4962
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4963
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4964
    prevBit := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4965
    digitByteArray size to:1 by:-1 do:[:idx |
6665
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4966
	|thisByte|
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4967
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4968
	thisByte := digitByteArray at:idx.
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4969
	digitByteArray at:idx put:((thisByte bitShift:-1) bitOr:prevBit).
8698bfaf34e2 Fixes for gcc3
Stefan Vogel <sv@exept.de>
parents: 6480
diff changeset
  4970
	prevBit := (thisByte bitAnd:1) bitShift:7.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4971
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4972
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4973
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4974
     100000 asLargeInteger div2
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4975
     1000000000000000000000000000 div2
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4976
     10000000000000000000000000000000000000000000 div2
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  4977
    "
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4978
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4979
    "Modified: 5.11.1996 / 16:12:56 / cg"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4980
!
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4981
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4982
mul2
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4983
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  4984
       destructively multiply the receiver by 2."
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4985
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4986
    |nBytes "{ Class: SmallInteger }"
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4987
     b      "{ Class: SmallInteger }"
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  4988
     t prevBit|
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4989
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4990
    nBytes := digitByteArray size.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4991
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4992
    b := digitByteArray at:nBytes.
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  4993
    (b bitAnd:16r80) ~~ 0 ifTrue:[
8907
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  4994
	"/ need another byte
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  4995
	nBytes := nBytes + 1.
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  4996
	t := ByteArray uninitializedNew:nBytes.
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  4997
	t replaceFrom:1 to:nBytes-1 with:digitByteArray startingAt:1.
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  4998
	t at:nBytes put:0.
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  4999
	digitByteArray := t.
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5000
    ].
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5001
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5002
%{
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5003
    OBJ __digits = __INST(digitByteArray);
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5004
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5005
    if (__isByteArray(__digits)) {
8907
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5006
	int __nBytes = __intVal(nBytes);
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5007
	unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5008
	unsigned INT __carry = 0, __newCarry;
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5009
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5010
#if defined(__LSBFIRST__)
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5011
# if (__POINTER_SIZE__ == 8)
8907
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5012
	if (sizeof(unsigned INT) == 8) {
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5013
	    while (__nBytes >= 8) {
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5014
		unsigned INT __this;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5015
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5016
		__this = ((unsigned INT *)__bp)[0];
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5017
		__newCarry = (__this >> 63) /* & 1 */;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5018
		((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5019
		__carry = __newCarry;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5020
		__bp += 8;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5021
		__nBytes -= 8;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5022
	    }
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5023
	}
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5024
# endif
8907
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5025
	if (sizeof(unsigned int) == 4) {
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5026
	    while (__nBytes >= 4) {
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5027
		unsigned int __this;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5028
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5029
		__this = ((unsigned int *)__bp)[0];
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5030
		__newCarry = (__this >> 31) /* & 1 */;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5031
		((unsigned int *)__bp)[0] = (__this << 1) | __carry;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5032
		__carry = __newCarry;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5033
		__bp += 4;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5034
		__nBytes -= 4;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5035
	    }
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5036
	}
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5037
#endif /* LSBFIRST */
8907
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5038
	while (__nBytes) {
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5039
	    unsigned char __this;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5040
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5041
	    __this = __bp[0];
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5042
	    __newCarry = (__this >> 7) /* & 1 */;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5043
	    __bp[0] = (__this << 1) | __carry;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5044
	    __carry = __newCarry;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5045
	    __bp++;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5046
	    __nBytes--;
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5047
	}
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5048
	RETURN (self);
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5049
    }
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5050
%}.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5051
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5052
    prevBit := 0.
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5053
    1 to:digitByteArray size do:[:idx |
8907
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5054
	|thisByte|
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5055
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5056
	thisByte := digitByteArray at:idx.
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5057
	digitByteArray at:idx put:(((thisByte bitShift:1) bitAnd:16rFF) bitOr:prevBit).
9575741eeda7 tuned =
Claus Gittinger <cg@exept.de>
parents: 8905
diff changeset
  5058
	prevBit := (thisByte bitShift:-7) bitAnd:1.
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5059
    ].
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5060
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5061
    "
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5062
     100000 asLargeInteger mul2
5437
4d49a24f861b added fallback st-code (for rel5 migration)
Claus Gittinger <cg@exept.de>
parents: 5382
diff changeset
  5063
     16r7FFFFFFFFFFF copy mul2 hexPrintString
8905
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5064
     16rFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5065
     16r7FFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5066
     16rFFFFFFFFFFFFFF copy mul2 hexPrintString
303421b7345a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8901
diff changeset
  5067
     10000000000000000000000000000 mul2
1890
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5068
    "
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5069
aca066e06680 division, again
Claus Gittinger <cg@exept.de>
parents: 1883
diff changeset
  5070
    "Modified: 5.11.1996 / 16:37:32 / cg"
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5071
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5072
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5073
mul256
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5074
    "private helper for division:
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5075
       destructively multiply the receiver by 256."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5076
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5077
    |newDigits newSize|
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5078
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5079
    newSize := digitByteArray size + 1.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5080
    newDigits := ByteArray uninitializedNew:newSize.
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5081
    newDigits replaceBytesFrom:2 to:newSize with:digitByteArray startingAt:1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5082
    newDigits at:1 put:0.
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5083
    digitByteArray := newDigits
4160
5fb87a530e29 tuned div2, mul2 for alpha64;
Claus Gittinger <cg@exept.de>
parents: 4157
diff changeset
  5084
4215
d3d8a954cd3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4214
diff changeset
  5085
    "Modified: / 20.5.1999 / 09:16:42 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5086
!
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5087
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5088
numberOfDigits:nDigits
2001
8c2b957f0cb3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
  5089
"/    digitByteArray := ByteArray uninitializedNew:nDigits.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5090
    digitByteArray := ByteArray new:nDigits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5091
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5092
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5093
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5094
setDigits:digits
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5095
    digitByteArray := digits.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5096
    sign := 1.
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5097
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5098
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5099
sign:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5100
    sign := aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5101
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5102
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5103
!LargeInteger methodsFor:'testing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5104
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5105
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5106
    "return true if the receiver is even"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5107
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5108
    ^ (digitByteArray at:1) even
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5109
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5110
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5111
negative
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5112
    "return true, if the receiver is < 0"
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5113
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5114
    ^ (sign < 0)
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5115
!
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5116
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5117
odd
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5118
    "return true if the receiver is odd"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5119
1983
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5120
    ^ (digitByteArray at:1) odd
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5121
c5a2c4655d10 oops - odd was wrong
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
  5122
    "Modified: 18.11.1996 / 22:19:19 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5123
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5124
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5125
positive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5126
    "return true, if the receiver is >= 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5127
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5128
    ^ (sign >= 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5129
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5130
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5131
sign
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7446
diff changeset
  5132
    "return the sign of the receiver (-1, 0 or 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5133
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5134
    ^ sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5135
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5136
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5137
strictlyPositive
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5138
    "return true, if the receiver is > 0"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5139
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5140
    ^ (sign > 0)
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5141
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5142
1794
c8f7736d1c12 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1717
diff changeset
  5143
!LargeInteger class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5144
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5145
version
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
  5146
    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.203 2011/05/17 13:18:34 stefan Exp $'
17732
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  5147
!
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  5148
a1892eeca6c0 trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
  5149
version_CVS
17845
7e0cfaac936d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17841
diff changeset
  5150
    ^ '§Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.203 2011/05/17 13:18:34 stefan Exp §'
17865
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
  5151
!
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
  5152
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
  5153
version_SVN
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
  5154
    ^ '$Id: LargeInteger.st 10729 2011-10-31 22:19:21Z vranyj1 $'
17846
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
  5155
! !
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
  5156