--- a/LargeInteger.st Tue Sep 15 00:01:07 2009 +0200
+++ b/LargeInteger.st Tue Sep 15 00:16:50 2009 +0200
@@ -315,14 +315,14 @@
Use a special method for this case ...
"
((numberClass := aNumber class) == SmallInteger) ifTrue:[
- ^ self productFromInteger:aNumber
+ ^ self productFromInteger:aNumber
].
"
if the argument is not a largeInteger, coerce
"
(numberClass == self class) ifFalse:[
- ^ self retry:#* coercing:aNumber
+ ^ self retry:#* coercing:aNumber
].
otherSign := aNumber sign.
@@ -388,47 +388,47 @@
Use a special method for this case ...
"
((numberClass := aNumber class) == SmallInteger) ifTrue:[
- sign > 0 ifTrue:[
- aNumber > 0 ifTrue:[
- ^ self absFastMinus:aNumber sign:1
- ].
- ^ self absFastPlus:aNumber sign:1
- ].
- aNumber > 0 ifTrue:[
- ^ self absFastPlus:aNumber sign:-1
- ].
- ^ self absFastMinus:aNumber sign:-1
+ sign > 0 ifTrue:[
+ aNumber > 0 ifTrue:[
+ ^ self absFastMinus:aNumber sign:1
+ ].
+ ^ self absFastPlus:aNumber sign:1
+ ].
+ aNumber > 0 ifTrue:[
+ ^ self absFastPlus:aNumber sign:-1
+ ].
+ ^ self absFastMinus:aNumber sign:-1
].
"
if the argument is not a largeInteger, coerce
"
(numberClass == self class) ifFalse:[
- ^ self retry:#- coercing:aNumber
+ ^ self retry:#- coercing:aNumber
].
otherSign := aNumber sign.
(sign > 0) ifTrue:[
- "I am positive"
- (otherSign > 0) ifTrue:[
- "+large - +large"
- ^ self absMinus:aNumber sign:1
- ].
- (otherSign < 0) ifTrue:[
- "+large - -large"
- ^ self absPlus:aNumber sign:1
- ].
- "should not happen"
- ^ self
+ "I am positive"
+ (otherSign > 0) ifTrue:[
+ "+large - +large"
+ ^ self absMinus:aNumber sign:1
+ ].
+ (otherSign < 0) ifTrue:[
+ "+large - -large"
+ ^ self absPlus:aNumber sign:1
+ ].
+ "should not happen"
+ ^ self
].
"I am negative"
(otherSign > 0) ifTrue:[
- "-large - +large"
- ^ self absPlus:aNumber sign:-1
+ "-large - +large"
+ ^ self absPlus:aNumber sign:-1
].
(otherSign < 0) ifTrue:[
- "-large - -large"
- ^ self absMinus:aNumber sign:-1
+ "-large - -large"
+ ^ self absMinus:aNumber sign:-1
].
^ self
@@ -872,25 +872,25 @@
%{ /* NOCONTEXT */
if (__isSmallInteger(anInteger)) {
- INT v2 = __intVal(anInteger);
- INT v1;
+ INT v2 = __intVal(anInteger);
+ INT v1;
#if defined(__LSBFIRST__)
- v1 = *(INT *)(__byteArrayVal(__INST(digitByteArray)));
+ v1 = *(INT *)(__byteArrayVal(__INST(digitByteArray)));
#else
- unsigned char *digits = (unsigned char *)(__byteArrayVal(__INST(digitByteArray)));
-
- v1 = digits[0] & 0xFF;
- v1 = v1 | ((digits[1] & 0xFF)<<8);
- v1 = v1 | ((digits[2] & 0xFF)<<16);
- v1 = v1 | ((digits[3] & 0xFF)<<24);
+ unsigned char *digits = (unsigned char *)(__byteArrayVal(__INST(digitByteArray)));
+
+ v1 = digits[0] & 0xFF;
+ v1 = v1 | ((digits[1] & 0xFF)<<8);
+ v1 = v1 | ((digits[2] & 0xFF)<<16);
+ v1 = v1 | ((digits[3] & 0xFF)<<24);
# if (__POINTER_SIZE__ == 8)
- v1 = v1 | ((digits[4] & 0xFF)<<32);
- v1 = v1 | ((digits[5] & 0xFF)<<40);
- v1 = v1 | ((digits[6] & 0xFF)<<48);
- v1 = v1 | ((digits[7] & 0xFF)<<56);
+ v1 = v1 | ((digits[4] & 0xFF)<<32);
+ v1 = v1 | ((digits[5] & 0xFF)<<40);
+ v1 = v1 | ((digits[6] & 0xFF)<<48);
+ v1 = v1 | ((digits[7] & 0xFF)<<56);
#endif
#endif
- RETURN ( __mkSmallInteger(v1 & v2) );
+ RETURN ( __mkSmallInteger(v1 & v2) );
}
%}.
^ super bitAnd:anInteger
@@ -912,29 +912,29 @@
bitAt:anIntegerIndex
"return the value of the index's bit (index starts at 1) as 0 or 1.
Notice: the result of bitAt: on negative receivers is not
- defined in the language standard (since the implementation
- is free to choose any internal representation for integers)"
+ defined in the language standard (since the implementation
+ is free to choose any internal representation for integers)"
%{ /* NOCONTEXT */
if (__isSmallInteger(anIntegerIndex)) {
- INT idx = __smallIntegerVal(anIntegerIndex) - 1;
-
- if (idx >= 0) {
- int v1;
- int byteOffset = idx / 8;
- int digitLen = __stringSize(__INST(digitByteArray));
-
- if (digitLen < byteOffset) {
- RETURN(__mkSmallInteger(0));
- }
-
- v1 = (__byteArrayVal(__INST(digitByteArray)))[byteOffset];
- if (v1 & (1 << (idx % 8))) {
- RETURN(__mkSmallInteger(1));
- } else {
- RETURN(__mkSmallInteger(0));
- }
- }
+ INT idx = __smallIntegerVal(anIntegerIndex) - 1;
+
+ if (idx >= 0) {
+ int v1;
+ int byteOffset = idx / 8;
+ int digitLen = __stringSize(__INST(digitByteArray));
+
+ if (digitLen < byteOffset) {
+ RETURN(__mkSmallInteger(0));
+ }
+
+ v1 = (__byteArrayVal(__INST(digitByteArray)))[byteOffset];
+ if (v1 & (1 << (idx % 8))) {
+ RETURN(__mkSmallInteger(1));
+ } else {
+ RETURN(__mkSmallInteger(0));
+ }
+ }
}
%}.
^ super bitAt:anIntegerIndex
@@ -1010,99 +1010,99 @@
* quickly advance over full 0-words
*/
if (__isByteArray(__INST(digitByteArray))) {
- int __sz = __intVal(sz);
- unsigned char *__bP = __byteArrayVal(__INST(digitByteArray));
- unsigned char *__bP0 = __bP;
+ int __sz = __intVal(sz);
+ unsigned char *__bP = __byteArrayVal(__INST(digitByteArray));
+ unsigned char *__bP0 = __bP;
#ifdef __UNROLL_LOOPS__
- while (__sz > (sizeof(INT) * 4)) {
- if ( ((INT *)__bP)[0] != 0 ) break;
- if ( ((INT *)__bP)[1] != 0 ) {
- __sz -= sizeof(INT);
- __bP += sizeof(INT);
- break;
- }
- if ( ((INT *)__bP)[2] != 0 ) {
- __sz -= sizeof(INT) * 2;
- __bP += sizeof(INT) * 2;
- break;
- }
- if ( ((INT *)__bP)[3] != 0 ) {
- __sz -= sizeof(INT) * 3;
- __bP += sizeof(INT) * 3;
- break;
- }
- __sz -= sizeof(INT) * 4;
- __bP += sizeof(INT) * 4;
- }
+ while (__sz > (sizeof(INT) * 4)) {
+ if ( ((INT *)__bP)[0] != 0 ) break;
+ if ( ((INT *)__bP)[1] != 0 ) {
+ __sz -= sizeof(INT);
+ __bP += sizeof(INT);
+ break;
+ }
+ if ( ((INT *)__bP)[2] != 0 ) {
+ __sz -= sizeof(INT) * 2;
+ __bP += sizeof(INT) * 2;
+ break;
+ }
+ if ( ((INT *)__bP)[3] != 0 ) {
+ __sz -= sizeof(INT) * 3;
+ __bP += sizeof(INT) * 3;
+ break;
+ }
+ __sz -= sizeof(INT) * 4;
+ __bP += sizeof(INT) * 4;
+ }
#endif
- while (__sz > sizeof(INT)) {
- if ( ((INT *)__bP)[0] != 0 ) break;
- __sz -= sizeof(INT);
- __bP += sizeof(INT);
- }
- while (__sz > 0) {
- unsigned int c;
-
- if ( (c = *__bP) != 0 ) {
- int bitIdx = (__bP - __bP0) * 8;
+ while (__sz > sizeof(INT)) {
+ if ( ((INT *)__bP)[0] != 0 ) break;
+ __sz -= sizeof(INT);
+ __bP += sizeof(INT);
+ }
+ while (__sz > 0) {
+ unsigned int c;
+
+ if ( (c = *__bP) != 0 ) {
+ int bitIdx = (__bP - __bP0) * 8;
#ifdef __BSF
- {
- int index;
- int t = c;
-
- index = __BSF(t);
- RETURN ( __mkSmallInteger(index + 1 + bitIdx) );
- }
+ {
+ int index;
+ int t = c;
+
+ index = __BSF(t);
+ RETURN ( __mkSmallInteger(index + 1 + bitIdx) );
+ }
#else
- if (c & 0x0F) {
- if (c & 0x03) {
- if (c & 0x01) {
- RETURN ( __mkSmallInteger( bitIdx + 1) );
- } else {
- RETURN ( __mkSmallInteger( bitIdx + 2) );
- }
- } else {
- if (c & 0x04) {
- RETURN ( __mkSmallInteger( bitIdx + 3) );
- } else {
- RETURN ( __mkSmallInteger( bitIdx + 4) );
- }
- }
- } else {
- if (c & 0x30) {
- if (c & 0x10) {
- RETURN ( __mkSmallInteger( bitIdx + 5) );
- } else {
- RETURN ( __mkSmallInteger( bitIdx + 6) );
- }
- } else {
- if (c & 0x40) {
- RETURN ( __mkSmallInteger( bitIdx + 7) );
- } else {
- RETURN ( __mkSmallInteger( bitIdx + 8) );
- }
- }
- }
+ if (c & 0x0F) {
+ if (c & 0x03) {
+ if (c & 0x01) {
+ RETURN ( __mkSmallInteger( bitIdx + 1) );
+ } else {
+ RETURN ( __mkSmallInteger( bitIdx + 2) );
+ }
+ } else {
+ if (c & 0x04) {
+ RETURN ( __mkSmallInteger( bitIdx + 3) );
+ } else {
+ RETURN ( __mkSmallInteger( bitIdx + 4) );
+ }
+ }
+ } else {
+ if (c & 0x30) {
+ if (c & 0x10) {
+ RETURN ( __mkSmallInteger( bitIdx + 5) );
+ } else {
+ RETURN ( __mkSmallInteger( bitIdx + 6) );
+ }
+ } else {
+ if (c & 0x40) {
+ RETURN ( __mkSmallInteger( bitIdx + 7) );
+ } else {
+ RETURN ( __mkSmallInteger( bitIdx + 8) );
+ }
+ }
+ }
#endif
- break;
- }
- __sz--;
- __bP++;
- }
- idx0 = __mkSmallInteger( __bP - __bP0 + 1 );
+ break;
+ }
+ __sz--;
+ __bP++;
+ }
+ idx0 = __mkSmallInteger( __bP - __bP0 + 1 );
}
%}.
"/ never actually reached
idx0 to:sz do:[:digitIndex |
- (byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
- ^ (digitIndex-1)*8 + (byte lowBit)
- ]
+ (byte := digitByteArray at:digitIndex) ~~ 0 ifTrue:[
+ ^ (digitIndex-1)*8 + (byte lowBit)
+ ]
].
^ 0 "/ should not happen
"
- (1 bitShift:0) lowBit
+ (1 bitShift:0) lowBit
(1 bitShift:10) lowBit
(1 bitShift:20) lowBit
(1 bitShift:30) lowBit
@@ -1114,31 +1114,31 @@
(1 bitShift:33) lowBit
(1 bitShift:33) highBit
(1 bitShift:64) lowBit
- (1 bitShift:64) highBit
+ (1 bitShift:64) highBit
(1 bitShift:1000) lowBit
(1 bitShift:1000) highBit
((1 bitShift:64)-1) lowBit
((1 bitShift:64)-1) highBit
1 to:1000 do:[:idx |
- self assert:(( 1 bitShift:idx) lowBit = (idx+1)).
- self assert:(( 1 bitShift:idx) lowBit = ( 1 bitShift:idx) highBit).
- self assert:(( 3 bitShift:idx) lowBit = (idx+1)).
- self assert:(( 7 bitShift:idx) lowBit = (idx+1)).
- self assert:(( 15 bitShift:idx) lowBit = (idx+1)).
- self assert:(( 31 bitShift:idx) lowBit = (idx+1)).
- self assert:(( 63 bitShift:idx) lowBit = (idx+1)).
- self assert:(( 127 bitShift:idx) lowBit = (idx+1)).
- self assert:(( 255 bitShift:idx) lowBit = (idx+1)).
+ self assert:(( 1 bitShift:idx) lowBit = (idx+1)).
+ self assert:(( 1 bitShift:idx) lowBit = ( 1 bitShift:idx) highBit).
+ self assert:(( 3 bitShift:idx) lowBit = (idx+1)).
+ self assert:(( 7 bitShift:idx) lowBit = (idx+1)).
+ self assert:(( 15 bitShift:idx) lowBit = (idx+1)).
+ self assert:(( 31 bitShift:idx) lowBit = (idx+1)).
+ self assert:(( 63 bitShift:idx) lowBit = (idx+1)).
+ self assert:(( 127 bitShift:idx) lowBit = (idx+1)).
+ self assert:(( 255 bitShift:idx) lowBit = (idx+1)).
]
|num|
num := (1 bitShift:1000).
Time millisecondsToRun:[
- 100000 timesRepeat:[
- num lowBit
- ]
+ 100000 timesRepeat:[
+ num lowBit
+ ]
]
"
@@ -1154,28 +1154,28 @@
|myDigitLength newDigitLength newDigitBytes byteIndexOfBitToSet|
index <= 0 ifTrue:[
- ^ SubscriptOutOfBoundsSignal
- raiseRequestWith:index
- errorString:'index out of bounds'
+ ^ SubscriptOutOfBoundsSignal
+ raiseRequestWith:index
+ errorString:'index out of bounds'
].
myDigitLength := digitByteArray size.
byteIndexOfBitToSet := ((index-1)//8)+1.
byteIndexOfBitToSet > myDigitLength ifTrue:[
- newDigitLength := myDigitLength max:byteIndexOfBitToSet.
- newDigitBytes := ByteArray new:newDigitLength.
- newDigitBytes replaceFrom:1 to:myDigitLength with:digitByteArray startingAt:1.
+ newDigitLength := myDigitLength max:byteIndexOfBitToSet.
+ newDigitBytes := ByteArray new:newDigitLength.
+ newDigitBytes replaceFrom:1 to:myDigitLength with:digitByteArray startingAt:1.
] ifFalse:[
- newDigitBytes := digitByteArray copy
+ newDigitBytes := digitByteArray copy
].
- newDigitBytes
- at:byteIndexOfBitToSet
- put:((newDigitBytes at:byteIndexOfBitToSet) setBit:(((index-1)\\8)+1)).
+ newDigitBytes
+ at:byteIndexOfBitToSet
+ put:((newDigitBytes at:byteIndexOfBitToSet) setBit:(((index-1)\\8)+1)).
^ (self class digitBytes:newDigitBytes) sign:sign
"
- TestCase assert:( 16r80000000 setBit:3 ) = 16r80000004
- TestCase assert:( 16r80000000 setBit:33 ) = 16r180000000
+ TestCase assert:( 16r80000000 setBit:3 ) = 16r80000004
+ TestCase assert:( 16r80000000 setBit:33 ) = 16r180000000
"
! !
@@ -1630,31 +1630,31 @@
|otherSign|
(aNumber class == self class) ifTrue:[
- otherSign := aNumber sign.
-
- (sign > 0) ifTrue:[
- "I am positive"
- (otherSign > 0) ifTrue:[^ self absLess:aNumber].
- ^ false "aNumber is <= 0"
- ].
- "I am negative"
- (otherSign > 0) ifTrue:[^ true].
- (otherSign == 0) ifTrue:[^ true].
- ^ (aNumber absLess:self)
+ otherSign := aNumber sign.
+
+ (sign > 0) ifTrue:[
+ "I am positive"
+ (otherSign > 0) ifTrue:[^ self absLess:aNumber].
+ ^ false "aNumber is <= 0"
+ ].
+ "I am negative"
+ (otherSign > 0) ifTrue:[^ true].
+ (otherSign == 0) ifTrue:[^ true].
+ ^ (aNumber absLess:self)
].
(aNumber class == SmallInteger) ifTrue:[
- otherSign := aNumber sign.
-
- (sign > 0) ifTrue:[
- "I am positive"
- ^ false "aNumber is <= 0"
- ].
- (sign == 0) ifTrue:[
- (otherSign > 0) ifTrue:[^ true].
- ^ false
- ].
- "I am negative"
- ^ true
+ otherSign := aNumber sign.
+
+ (sign > 0) ifTrue:[
+ "I am positive"
+ ^ false "aNumber is <= 0"
+ ].
+ (sign == 0) ifTrue:[
+ (otherSign > 0) ifTrue:[^ true].
+ ^ false
+ ].
+ "I am negative"
+ ^ true
].
^ aNumber lessFromInteger:self
@@ -1669,17 +1669,17 @@
"/ speed up compare to 0
(aNumber == 0) ifTrue:[
- ^ sign == 0
+ ^ sign == 0
].
(aNumber class == self class) ifFalse:[
- "/
- "/ here, we depend on the fact, that largeinteger
- "/ results are always converted to smallInts, if possible.
- "/ therefore, a largeInt in the smallInt range is not allowed (possible)
- "/
- aNumber class == SmallInteger ifTrue:[^ false ].
- ^ aNumber equalFromInteger:self
+ "/
+ "/ here, we depend on the fact, that largeinteger
+ "/ results are always converted to smallInts, if possible.
+ "/ therefore, a largeInt in the smallInt range is not allowed (possible)
+ "/
+ aNumber class == SmallInteger ifTrue:[^ false ].
+ ^ aNumber equalFromInteger:self
].
(aNumber sign == sign) ifFalse:[^ false].
@@ -1725,25 +1725,25 @@
l := digitByteArray size.
l >= 8 ifTrue:[
- h := h bitXor:(digitByteArray at:l).
- h := h bitXor:((digitByteArray at:l-1) bitShift:8).
- h := h bitXor:((digitByteArray at:l-2) bitShift:16).
- h := h bitXor:((digitByteArray at:l-3) bitShift:22).
- l >= 12 ifTrue:[
- m := l // 2.
- h := h bitXor:(digitByteArray at:m-1).
- h := h bitXor:((digitByteArray at:m) bitShift:8).
- h := h bitXor:((digitByteArray at:m+1) bitShift:16).
- h := h bitXor:((digitByteArray at:m+2) bitShift:22).
- ].
- ^ h
+ h := h bitXor:(digitByteArray at:l).
+ h := h bitXor:((digitByteArray at:l-1) bitShift:8).
+ h := h bitXor:((digitByteArray at:l-2) bitShift:16).
+ h := h bitXor:((digitByteArray at:l-3) bitShift:22).
+ l >= 12 ifTrue:[
+ m := l // 2.
+ h := h bitXor:(digitByteArray at:m-1).
+ h := h bitXor:((digitByteArray at:m) bitShift:8).
+ h := h bitXor:((digitByteArray at:m+1) bitShift:16).
+ h := h bitXor:((digitByteArray at:m+2) bitShift:22).
+ ].
+ ^ h
].
^ (h bitShift:3) + l
"
- 16r80000000 hash
- 16r80000008 hash
- 16r8000000000008 hash
+ 16r80000000 hash
+ 16r80000008 hash
+ 16r8000000000008 hash
"
! !
@@ -1754,22 +1754,22 @@
Return the result of 'anInteger - self'. The argument must be a SmallInteger."
anInteger > 0 ifTrue:[
- sign > 0 ifTrue:[
- ^ self absFastMinus:anInteger sign:-1
- ].
- ^ self absFastPlus:anInteger sign:1
+ sign > 0 ifTrue:[
+ ^ self absFastMinus:anInteger sign:-1
+ ].
+ ^ self absFastPlus:anInteger sign:1
].
anInteger == 0 ifTrue:[
- ^ self negated
+ ^ self negated
].
sign > 0 ifTrue:[
- ^ self absFastPlus:anInteger negated sign:-1
+ ^ self absFastPlus:anInteger negated sign:-1
].
self > anInteger ifTrue:[
- ^ self absFastMinus:anInteger asLargeInteger sign:-1
+ ^ self absFastMinus:anInteger asLargeInteger sign:-1
] ifFalse:[
- ^ anInteger asLargeInteger absFastMinus:self sign:-1
+ ^ anInteger asLargeInteger absFastMinus:self sign:-1
].
"
@@ -1795,7 +1795,7 @@
"/
anInteger class == SmallInteger ifTrue:[^ false ].
anInteger class == self class ifFalse:[
- ^ super equalFromInteger:anInteger
+ ^ super equalFromInteger:anInteger
].
(anInteger sign == sign) ifFalse:[^ false].
^ self absEq:anInteger
@@ -1812,14 +1812,14 @@
"/ therefore, a largeInt in the smallInt range is not allowed (possible)
"/
(anInteger class == SmallInteger) ifTrue:[
- otherSign := anInteger sign.
-
- (sign > 0) ifTrue:[
- "I am positive"
- ^ true "aNumber is <= 0"
- ].
- "I am negative"
- ^ false
+ otherSign := anInteger sign.
+
+ (sign > 0) ifTrue:[
+ "I am positive"
+ ^ true "aNumber is <= 0"
+ ].
+ "I am negative"
+ ^ false
].
^ super lessFromInteger:anInteger
!
@@ -2261,42 +2261,59 @@
OBJ _digitByteArray = __INST(digitByteArray);
if (__isLargeInteger(aLargeInteger)) {
- OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
-
- if (__isByteArray(_digitByteArray)
- && __isByteArray(_otherDigitByteArray)) {
- INT _myLen = __byteArraySize(_digitByteArray);
- INT _otherLen = __byteArraySize(_otherDigitByteArray);
-
- unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
- unsigned char *_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
-
- if (_myLen == _otherLen) {
+ OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
+
+ if (__isByteArray(_digitByteArray)
+ && __isByteArray(_otherDigitByteArray)) {
+ INT _myLen = __byteArraySize(_digitByteArray);
+ INT _otherLen = __byteArraySize(_otherDigitByteArray);
+
+ unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
+ unsigned char *_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
+
+ if (_myLen == _otherLen) {
tryAgain:
- while (_myLen >= (sizeof(INT))) {
- if ( *(unsigned INT *)_myDigits != *(unsigned INT *)_otherDigits) {
- RETURN(false);
- }
- _myDigits += sizeof(INT);
- _otherDigits += sizeof(INT);
- _myLen -= sizeof(INT);
- }
- while (_myLen > 0) {
- if ( *_myDigits != *_otherDigits) {
- RETURN(false);
- }
- _myDigits++;
- _otherDigits++;
- _myLen--;
- }
- RETURN(true);
- }
- /* care for unnormalized ints */
- while ((_myLen > 0) && (_myDigits[_myLen-1] == 0)) _myLen--;
- while ((_otherLen > 0) && (_otherDigits[_otherLen-1] == 0)) _otherLen--;
- if (_myLen == _otherLen) goto tryAgain;
- RETURN(false);
- }
+ while (_myLen >= (sizeof(INT)*4)) {
+ if ( (unsigned INT *)_myDigits[0] != (unsigned INT *)_otherDigits[0]) {
+ RETURN(false);
+ }
+ if ( (unsigned INT *)_myDigits[1] != (unsigned INT *)_otherDigits[1]) {
+ RETURN(false);
+ }
+ if ( (unsigned INT *)_myDigits[2] != (unsigned INT *)_otherDigits[2]) {
+ RETURN(false);
+ }
+ if ( (unsigned INT *)_myDigits[3] != (unsigned INT *)_otherDigits[3]) {
+ RETURN(false);
+ }
+ _myDigits += sizeof(INT)*4;
+ _otherDigits += sizeof(INT)*4;
+ _myLen -= sizeof(INT)*4;
+ }
+ while (_myLen >= (sizeof(INT))) {
+ if ( *(unsigned INT *)_myDigits != *(unsigned INT *)_otherDigits) {
+ RETURN(false);
+ }
+ _myDigits += sizeof(INT);
+ _otherDigits += sizeof(INT);
+ _myLen -= sizeof(INT);
+ }
+ while (_myLen > 0) {
+ if ( *_myDigits != *_otherDigits) {
+ RETURN(false);
+ }
+ _myDigits++;
+ _otherDigits++;
+ _myLen--;
+ }
+ RETURN(true);
+ }
+ /* care for unnormalized ints */
+ while ((_myLen > 0) && (_myDigits[_myLen-1] == 0)) _myLen--;
+ while ((_otherLen > 0) && (_otherDigits[_otherLen-1] == 0)) _otherLen--;
+ if (_myLen == _otherLen) goto tryAgain;
+ RETURN(false);
+ }
}
%}.
@@ -2310,17 +2327,17 @@
"/ numbers to be compared ...
[(digitByteArray basicAt:len1) == 0] whileTrue:[
- len1 := len1 - 1
+ len1 := len1 - 1
].
[(otherDigitByteArray basicAt:len2) == 0] whileTrue:[
- len2 := len2 - 1
+ len2 := len2 - 1
].
(len1 ~~ len2) ifTrue:[^ false].
[len1 > 0] whileTrue:[
- d1 := digitByteArray basicAt:len1.
- d2 := otherDigitByteArray basicAt:len1.
- (d1 ~~ d2) ifTrue:[^ false].
- len1 := len1 - 1
+ d1 := digitByteArray basicAt:len1.
+ d2 := otherDigitByteArray basicAt:len1.
+ (d1 ~~ d2) ifTrue:[^ false].
+ len1 := len1 - 1
].
^ true
@@ -2339,12 +2356,12 @@
ok|
aPositiveSmallInteger == 0 ifTrue:[
- ^ ZeroDivide raiseRequestWith:thisContext
+ ^ ZeroDivide raiseRequestWith:thisContext
].
"This cannot happen (if always normalized)
self < aPositiveSmallInteger ifTrue:[
- ^ Array with:0 with:self
+ ^ Array with:0 with:self
].
"
count := digitByteArray size.
@@ -2359,76 +2376,76 @@
if (__isByteArray(__digits)
&& __isByteArray(newDigitByteArray)
&& __bothSmallInteger(count, aPositiveSmallInteger)) {
- unsigned INT rest = 0;
- int index = __intVal(count);
- int index0;
- unsigned INT divisor = __intVal(aPositiveSmallInteger);
- unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
- unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
-
- index0 = index - 1;
-
- /*
- * divide short-wise
- */
- if (divisor <= 0xFFFF) {
- if ((index & 1) == 0) { /* even number of bytes */
- while (index > 1) {
- unsigned INT t;
- unsigned INT div;
-
- index -= 2;
+ unsigned INT rest = 0;
+ int index = __intVal(count);
+ int index0;
+ unsigned INT divisor = __intVal(aPositiveSmallInteger);
+ unsigned char *digitBytes = __ByteArrayInstPtr(__digits)->ba_element;
+ unsigned char *resultBytes = __ByteArrayInstPtr(newDigitByteArray)->ba_element;
+
+ index0 = index - 1;
+
+ /*
+ * divide short-wise
+ */
+ if (divisor <= 0xFFFF) {
+ if ((index & 1) == 0) { /* even number of bytes */
+ while (index > 1) {
+ unsigned INT t;
+ unsigned INT div;
+
+ index -= 2;
#if defined(__LSBFIRST__)
- t = *((unsigned short *)(&digitBytes[index]));
+ t = *((unsigned short *)(&digitBytes[index]));
#else
- t = digitBytes[index+1];
- t = (t << 8) | digitBytes[index];
+ t = digitBytes[index+1];
+ t = (t << 8) | digitBytes[index];
#endif
- t = t | (rest << 16);
- div = t / divisor;
- rest = t % divisor;
+ t = t | (rest << 16);
+ div = t / divisor;
+ rest = t % divisor;
#if defined(__LSBFIRST__)
- *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
+ *((unsigned short *)(&resultBytes[index])) = (div & 0xFFFF);
#else
- resultBytes[index+1] = div >> 8;
- resultBytes[index] = div /* & 0xFF */;
+ resultBytes[index+1] = div >> 8;
+ resultBytes[index] = div /* & 0xFF */;
#endif
- }
- }
- }
- while (index > 0) {
- unsigned INT t;
-
- index--;
- t = digitBytes[index];
- t = t | (rest << 8);
- resultBytes[index] = t / divisor;
- rest = t % divisor;
- }
- prevRest = __mkSmallInteger(rest);
-
- /*
- * no need to normalize ?
- */
- index = index0;
- while ((index >= sizeof(INT)) && (resultBytes[index]==0)) {
- index--;
- }
-
- if (index == index0) {
- if (index > sizeof(INT)) {
- RETURN ( __ARRAY_WITH2(result, prevRest));
- }
- if ((index == sizeof(INT))
- && resultBytes[index0] >= 0x40) {
- RETURN ( __ARRAY_WITH2(result, prevRest));
- }
- }
-
- /*
- * must compress
- */
- ok = true;
+ }
+ }
+ }
+ while (index > 0) {
+ unsigned INT t;
+
+ index--;
+ t = digitBytes[index];
+ t = t | (rest << 8);
+ resultBytes[index] = t / divisor;
+ rest = t % divisor;
+ }
+ prevRest = __mkSmallInteger(rest);
+
+ /*
+ * no need to normalize ?
+ */
+ index = index0;
+ while ((index >= sizeof(INT)) && (resultBytes[index]==0)) {
+ index--;
+ }
+
+ if (index == index0) {
+ if (index > sizeof(INT)) {
+ RETURN ( __ARRAY_WITH2(result, prevRest));
+ }
+ if ((index == sizeof(INT))
+ && resultBytes[index0] >= 0x40) {
+ RETURN ( __ARRAY_WITH2(result, prevRest));
+ }
+ }
+
+ /*
+ * must compress
+ */
+ ok = true;
}
%}.
"
@@ -2436,7 +2453,7 @@
(could also do a primitiveFailure here)
"
ok ifFalse:[
- ^ self absDivMod:(LargeInteger value:aPositiveSmallInteger).
+ ^ self absDivMod:(LargeInteger value:aPositiveSmallInteger).
].
^ Array with:(result compressed) with:prevRest
@@ -2989,49 +3006,49 @@
#if defined(__LSBFIRST__)
if (__isByteArray(__INST(digitByteArray))
&& __isLargeInteger(aLargeInteger)) {
- OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
-
- if (__isByteArray(_otherDigitByteArray)) {
- unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
- unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
- INT _myLen = __byteArraySize(__INST(digitByteArray));
-
- if (_myLen == __POINTER_SIZE__) {
- INT _otherLen = __byteArraySize(_otherDigitByteArray);
-
- if (_otherLen == __POINTER_SIZE__) {
- unsigned INT _myVal = *((unsigned INT *)_myDigits);
- unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
- RETURN( (_myVal < _otherVal) ? true : false );
- }
- }
+ OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
+
+ if (__isByteArray(_otherDigitByteArray)) {
+ unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
+ unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
+ INT _myLen = __byteArraySize(__INST(digitByteArray));
+
+ if (_myLen == __POINTER_SIZE__) {
+ INT _otherLen = __byteArraySize(_otherDigitByteArray);
+
+ if (_otherLen == __POINTER_SIZE__) {
+ unsigned INT _myVal = *((unsigned INT *)_myDigits);
+ unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
+ RETURN( (_myVal < _otherVal) ? true : false );
+ }
+ }
# if defined(UINT64) && (__POINTER_SIZE__ != 8)
- if (_myLen == __POINTER_SIZE__) {
- INT _otherLen = __byteArraySize(_otherDigitByteArray);
-
- if (_otherLen <= 8) {
- UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
- UINT64 _otherVal = *((UINT64 *)_otherDigits);
- RETURN( (_myVal < _otherVal) ? true : false );
- }
- } else {
- if (_myLen <= 8) {
- INT _otherLen = __byteArraySize(_otherDigitByteArray);
-
- if (_otherLen <= 8) {
- UINT64 _myVal = (*((UINT64 *)_myDigits));
- UINT64 _otherVal = *((UINT64 *)_otherDigits);
- RETURN( (_myVal < _otherVal) ? true : false );
- }
- if (_otherLen == __POINTER_SIZE__) {
- UINT64 _myVal = (*((UINT64 *)_myDigits));
- UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
- RETURN( (_myVal < _otherVal) ? true : false );
- }
- }
- }
+ if (_myLen == __POINTER_SIZE__) {
+ INT _otherLen = __byteArraySize(_otherDigitByteArray);
+
+ if (_otherLen <= 8) {
+ UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
+ UINT64 _otherVal = *((UINT64 *)_otherDigits);
+ RETURN( (_myVal < _otherVal) ? true : false );
+ }
+ } else {
+ if (_myLen <= 8) {
+ INT _otherLen = __byteArraySize(_otherDigitByteArray);
+
+ if (_otherLen <= 8) {
+ UINT64 _myVal = (*((UINT64 *)_myDigits));
+ UINT64 _otherVal = *((UINT64 *)_otherDigits);
+ RETURN( (_myVal < _otherVal) ? true : false );
+ }
+ if (_otherLen == __POINTER_SIZE__) {
+ UINT64 _myVal = (*((UINT64 *)_myDigits));
+ UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
+ RETURN( (_myVal < _otherVal) ? true : false );
+ }
+ }
+ }
# endif /* UINT64 */
- }
+ }
}
#endif /* LSBFIRST */
%}.
@@ -3046,22 +3063,22 @@
"/ numbers to be compared ...
[myLen > 0 and:[(digitByteArray basicAt:myLen) == 0]] whileTrue:[
- myLen := myLen - 1
+ myLen := myLen - 1
].
[otherLen > 0 and:[(otherDigitByteArray basicAt:otherLen) == 0]] whileTrue:[
- otherLen := otherLen - 1
+ otherLen := otherLen - 1
].
(myLen < otherLen) ifTrue:[^ true].
(myLen > otherLen) ifTrue:[^ false].
[myLen > 0] whileTrue:[
- d1 := digitByteArray basicAt:myLen.
- d2 := otherDigitByteArray basicAt:myLen.
- d1 == d2 ifFalse:[
- (d1 < d2) ifTrue:[^ true].
- ^ false
- ].
- myLen := myLen - 1
+ d1 := digitByteArray basicAt:myLen.
+ d2 := otherDigitByteArray basicAt:myLen.
+ d1 == d2 ifFalse:[
+ (d1 < d2) ifTrue:[^ true].
+ ^ false
+ ].
+ myLen := myLen - 1
].
^ false
@@ -3080,10 +3097,10 @@
b := 16rFFFFFFFF.
Time millisecondsToRun:[
10000000 timesRepeat:[ a absLess_n:b ]
- ] 686 655 702 702
+ ] 686 655 702 702
16rEFFFFFFF absLess_n: 16rFFFFFFFF
- 16rEFFFFFFF absLess: 16rFFFFFFFF
+ 16rEFFFFFFF absLess: 16rFFFFFFFF
"
"Modified: / 3.5.1999 / 08:06:28 / stefan"
@@ -3104,49 +3121,49 @@
#if defined(__LSBFIRST__)
if (__isByteArray(__INST(digitByteArray))
&& __isLargeInteger(aLargeInteger)) {
- OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
-
- if (__isByteArray(_otherDigitByteArray)) {
- unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
- unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
- INT _myLen = __byteArraySize(__INST(digitByteArray));
-
- if (_myLen == __POINTER_SIZE__) {
- INT _otherLen = __byteArraySize(_otherDigitByteArray);
-
- if (_otherLen == __POINTER_SIZE__) {
- unsigned INT _myVal = *((unsigned INT *)_myDigits);
- unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
- RETURN( (_myVal <= _otherVal) ? true : false );
- }
- }
+ OBJ _otherDigitByteArray = __LargeIntegerInstPtr(aLargeInteger)->l_digits;
+
+ if (__isByteArray(_otherDigitByteArray)) {
+ unsigned char *_myDigits = __ByteArrayInstPtr(__INST(digitByteArray))->ba_element;
+ unsigned char *_otherDigits = __ByteArrayInstPtr(_otherDigitByteArray)->ba_element;
+ INT _myLen = __byteArraySize(__INST(digitByteArray));
+
+ if (_myLen == __POINTER_SIZE__) {
+ INT _otherLen = __byteArraySize(_otherDigitByteArray);
+
+ if (_otherLen == __POINTER_SIZE__) {
+ unsigned INT _myVal = *((unsigned INT *)_myDigits);
+ unsigned INT _otherVal = *((unsigned INT *)_otherDigits);
+ RETURN( (_myVal <= _otherVal) ? true : false );
+ }
+ }
# if defined(UINT64) && (__POINTER_SIZE__ != 8)
- if (_myLen == __POINTER_SIZE__) {
- INT _otherLen = __byteArraySize(_otherDigitByteArray);
-
- if (_otherLen <= 8) {
- UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
- UINT64 _otherVal = *((UINT64 *)_otherDigits);
- RETURN( (_myVal <= _otherVal) ? true : false );
- }
- } else {
- if (_myLen <= 8) {
- INT _otherLen = __byteArraySize(_otherDigitByteArray);
-
- if (_otherLen <= 8) {
- UINT64 _myVal = (*((UINT64 *)_myDigits));
- UINT64 _otherVal = *((UINT64 *)_otherDigits);
- RETURN( (_myVal <= _otherVal) ? true : false );
- }
- if (_otherLen == __POINTER_SIZE__) {
- UINT64 _myVal = (*((UINT64 *)_myDigits));
- UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
- RETURN( (_myVal <= _otherVal) ? true : false );
- }
- }
- }
+ if (_myLen == __POINTER_SIZE__) {
+ INT _otherLen = __byteArraySize(_otherDigitByteArray);
+
+ if (_otherLen <= 8) {
+ UINT64 _myVal = (UINT64)(*((UINT *)_myDigits));
+ UINT64 _otherVal = *((UINT64 *)_otherDigits);
+ RETURN( (_myVal <= _otherVal) ? true : false );
+ }
+ } else {
+ if (_myLen <= 8) {
+ INT _otherLen = __byteArraySize(_otherDigitByteArray);
+
+ if (_otherLen <= 8) {
+ UINT64 _myVal = (*((UINT64 *)_myDigits));
+ UINT64 _otherVal = *((UINT64 *)_otherDigits);
+ RETURN( (_myVal <= _otherVal) ? true : false );
+ }
+ if (_otherLen == __POINTER_SIZE__) {
+ UINT64 _myVal = (*((UINT64 *)_myDigits));
+ UINT64 _otherVal = (UINT64) *((UINT *)_otherDigits);
+ RETURN( (_myVal <= _otherVal) ? true : false );
+ }
+ }
+ }
# endif /* UINT64 */
- }
+ }
}
#endif /* LSBFIRST */
%}.
@@ -3161,22 +3178,22 @@
"/ numbers to be compared ...
[(digitByteArray basicAt:myLen) == 0] whileTrue:[
- myLen := myLen - 1
+ myLen := myLen - 1
].
[(otherDigitByteArray basicAt:otherLen) == 0] whileTrue:[
- otherLen := otherLen - 1
+ otherLen := otherLen - 1
].
(myLen < otherLen) ifTrue:[^ true].
(myLen > otherLen) ifTrue:[^ false].
[myLen > 0] whileTrue:[
- d1 := digitByteArray basicAt:myLen.
- d2 := otherDigitByteArray basicAt:myLen.
- d1 == d2 ifFalse:[
- (d1 < d2) ifTrue:[^ true].
- ^ false.
- ].
- myLen := myLen - 1
+ d1 := digitByteArray basicAt:myLen.
+ d2 := otherDigitByteArray basicAt:myLen.
+ d1 == d2 ifFalse:[
+ (d1 < d2) ifTrue:[^ true].
+ ^ false.
+ ].
+ myLen := myLen - 1
].
^ true
@@ -3208,9 +3225,9 @@
len2 := otherDigitByteArray size.
len1 > len2 ifTrue:[
- lResult := len1
+ lResult := len1
] ifFalse:[
- lResult := (len1 max: len2) + 1.
+ lResult := (len1 max: len2) + 1.
].
result := self class basicNew numberOfDigits:lResult.
result sign:newSign.
@@ -3224,202 +3241,202 @@
if (__isByteArray(_digitByteArray)
&& __isByteArray(otherDigitByteArray)
&& __isByteArray(resultDigitByteArray)) {
- int __len1 = __intVal(len1);
- int __len2 = __intVal(len2);
- int __minLen = __len1 < __len2 ? __len1 : __len2;
- int __index, __borrow = 0;
- INT __diff;
- unsigned char *__myDigits, *__otherDigits, *__resultDigits;
-
- ok = true;
-
- __resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
- __otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
- __myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
-
- __index = 1;
+ int __len1 = __intVal(len1);
+ int __len2 = __intVal(len2);
+ int __minLen = __len1 < __len2 ? __len1 : __len2;
+ int __index, __borrow = 0;
+ INT __diff;
+ unsigned char *__myDigits, *__otherDigits, *__resultDigits;
+
+ ok = true;
+
+ __resultDigits = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
+ __otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
+ __myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
+
+ __index = 1;
#if defined(__LSBFIRST__)
# if __POINTER_SIZE__ == 8
- /*
- * subtract int-wise
- */
- while ((__index+3) <= __minLen) {
- /* do not make this into one expression - ask cg why */
- __diff = ((unsigned int *)(__myDigits+__index-1))[0];
- __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
- __diff -= __borrow;
-
- if (__diff >= 0) {
- __borrow = 0;
- } else {
- __borrow = 1;
- /* __diff += 0x10000; */
- }
- ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
- __index += 4;
- }
+ /*
+ * subtract int-wise
+ */
+ while ((__index+3) <= __minLen) {
+ /* do not make this into one expression - ask cg why */
+ __diff = ((unsigned int *)(__myDigits+__index-1))[0];
+ __diff -= ((unsigned int *)(__otherDigits+__index-1))[0];
+ __diff -= __borrow;
+
+ if (__diff >= 0) {
+ __borrow = 0;
+ } else {
+ __borrow = 1;
+ /* __diff += 0x10000; */
+ }
+ ((unsigned int *)(__resultDigits+__index-1))[0] = __diff;
+ __index += 4;
+ }
# endif /* 64bit */
- /*
- * subtract short-wise
- */
- while (__index < __minLen) { /* i.e. index+1 <= minLen */
- /* do not make this into one expression - ask cg why */
- __diff = ((unsigned short *)(__myDigits+__index-1))[0];
- __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
- __diff -= __borrow;
- if (__diff >= 0) {
- __borrow = 0;
- } else {
- __borrow = 1;
- /* __diff += 0x10000; */
- }
- ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
- __index += 2;
- }
-
- if (__index == __minLen) {
- /* one of the operands has odd length - cannot continue short-wise */
- } else {
- if (__len1 > __len2) {
- while (__index < __len1) {
- /* do not make this into one expression - ask cg why */
- __diff = ((unsigned short *)(__myDigits+__index-1))[0];
- __diff -= __borrow;
- if (__diff >= 0) {
- __borrow = 0;
- ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
- __index += 2;
-
- /* copy over rest */
- while (__index < __len1) {
- ((unsigned short *)(__resultDigits+__index-1))[0] = ((unsigned short *)(__myDigits+__index-1))[0];
- __index+=2;
- }
- if (__index <= __len1) {
- __resultDigits[__index-1] = __myDigits[__index-1];
- __index++;
- }
- break;
- }
- __borrow = 1;
- /* __diff += 0x10000; */
- ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
- __index += 2;
- }
- } else {
- if (__len2 > __len1) {
- while (__index < __len2) {
- /* do not make this into one expression - ask cg why */
- __diff = 0;
- __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
- __diff -= __borrow;
- if (__diff >= 0) {
- __borrow = 0;
- } else {
- __borrow = 1;
- /* __diff += 0x10000; */
- }
- ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
- __index += 2;
- }
- }
- }
- }
+ /*
+ * subtract short-wise
+ */
+ while (__index < __minLen) { /* i.e. index+1 <= minLen */
+ /* do not make this into one expression - ask cg why */
+ __diff = ((unsigned short *)(__myDigits+__index-1))[0];
+ __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
+ __diff -= __borrow;
+ if (__diff >= 0) {
+ __borrow = 0;
+ } else {
+ __borrow = 1;
+ /* __diff += 0x10000; */
+ }
+ ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
+ __index += 2;
+ }
+
+ if (__index == __minLen) {
+ /* one of the operands has odd length - cannot continue short-wise */
+ } else {
+ if (__len1 > __len2) {
+ while (__index < __len1) {
+ /* do not make this into one expression - ask cg why */
+ __diff = ((unsigned short *)(__myDigits+__index-1))[0];
+ __diff -= __borrow;
+ if (__diff >= 0) {
+ __borrow = 0;
+ ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
+ __index += 2;
+
+ /* copy over rest */
+ while (__index < __len1) {
+ ((unsigned short *)(__resultDigits+__index-1))[0] = ((unsigned short *)(__myDigits+__index-1))[0];
+ __index+=2;
+ }
+ if (__index <= __len1) {
+ __resultDigits[__index-1] = __myDigits[__index-1];
+ __index++;
+ }
+ break;
+ }
+ __borrow = 1;
+ /* __diff += 0x10000; */
+ ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
+ __index += 2;
+ }
+ } else {
+ if (__len2 > __len1) {
+ while (__index < __len2) {
+ /* do not make this into one expression - ask cg why */
+ __diff = 0;
+ __diff -= ((unsigned short *)(__otherDigits+__index-1))[0];
+ __diff -= __borrow;
+ if (__diff >= 0) {
+ __borrow = 0;
+ } else {
+ __borrow = 1;
+ /* __diff += 0x10000; */
+ }
+ ((unsigned short *)(__resultDigits+__index-1))[0] = __diff;
+ __index += 2;
+ }
+ }
+ }
+ }
#endif
- /*
- * subtract byte-wise
- */
- while (__index <= __minLen) {
- /* do not make this into one expression - ask cg why */
- __diff = __myDigits[__index-1];
- __diff -= __otherDigits[__index-1];
- __diff -= __borrow;
- if (__diff >= 0) {
- __borrow = 0;
- } else {
- __borrow = 1;
- /* __diff += 0x100; */
- }
- __resultDigits[__index-1] = __diff;
- __index++;
- }
-
- if (__len1 > __len2) {
- while (__index <= __len1) {
- /* do not make this into one expression - ask cg why */
- __diff = __myDigits[__index-1];
- __diff -= __borrow;
- if (__diff >= 0) {
- __borrow = 0;
- /* copy over rest */
- __resultDigits[__index-1] = __diff;
- __index++;
- while (__index <= __len1) {
- __resultDigits[__index-1] = __myDigits[__index-1];
- __index++;
- }
- break;
- }
- __borrow = 1;
- /* __diff += 0x100; */
- __resultDigits[__index-1] = __diff;
- __index++;
- }
- } else {
- if (__len2 > __len1) {
- while (__index <= __len2) {
- /* do not make this into one expression - ask cg why */
- __diff = 0;
- __diff -= __otherDigits[__index-1];
- __diff -= __borrow;
- if (__diff >= 0) {
- __borrow = 0;
- } else {
- __borrow = 1;
- /* __diff += 0x100; */
- }
- __resultDigits[__index-1] = __diff;
- __index++;
- }
- }
- }
- borrow = __mkSmallInteger(__borrow);
- index = __mkSmallInteger(__index);
- lastDigit = __mkSmallInteger(__resultDigits[__intVal(lResult)-1]);
+ /*
+ * subtract byte-wise
+ */
+ while (__index <= __minLen) {
+ /* do not make this into one expression - ask cg why */
+ __diff = __myDigits[__index-1];
+ __diff -= __otherDigits[__index-1];
+ __diff -= __borrow;
+ if (__diff >= 0) {
+ __borrow = 0;
+ } else {
+ __borrow = 1;
+ /* __diff += 0x100; */
+ }
+ __resultDigits[__index-1] = __diff;
+ __index++;
+ }
+
+ if (__len1 > __len2) {
+ while (__index <= __len1) {
+ /* do not make this into one expression - ask cg why */
+ __diff = __myDigits[__index-1];
+ __diff -= __borrow;
+ if (__diff >= 0) {
+ __borrow = 0;
+ /* copy over rest */
+ __resultDigits[__index-1] = __diff;
+ __index++;
+ while (__index <= __len1) {
+ __resultDigits[__index-1] = __myDigits[__index-1];
+ __index++;
+ }
+ break;
+ }
+ __borrow = 1;
+ /* __diff += 0x100; */
+ __resultDigits[__index-1] = __diff;
+ __index++;
+ }
+ } else {
+ if (__len2 > __len1) {
+ while (__index <= __len2) {
+ /* do not make this into one expression - ask cg why */
+ __diff = 0;
+ __diff -= __otherDigits[__index-1];
+ __diff -= __borrow;
+ if (__diff >= 0) {
+ __borrow = 0;
+ } else {
+ __borrow = 1;
+ /* __diff += 0x100; */
+ }
+ __resultDigits[__index-1] = __diff;
+ __index++;
+ }
+ }
+ }
+ borrow = __mkSmallInteger(__borrow);
+ index = __mkSmallInteger(__index);
+ lastDigit = __mkSmallInteger(__resultDigits[__intVal(lResult)-1]);
}
%}.
ok == true ifFalse:[
- index := 1.
- borrow := 0.
-
- done := false.
- [done] whileFalse:[
- diff := borrow.
- (index <= len1) ifTrue:[
- diff := diff + (digitByteArray basicAt:index).
- (index <= len2) ifTrue:[
- diff := diff - (otherDigitByteArray basicAt:index)
- ]
- ] ifFalse:[
- (index <= len2) ifTrue:[
- diff := diff - (otherDigitByteArray basicAt:index)
- ] ifFalse:[
- "end reached"
- done := true
- ]
- ].
-
- "/ workaround for
- "/ gcc code generator bug
-
- (diff >= 0) ifTrue:[
- borrow := 0
- ] ifFalse:[
- borrow := -1.
- diff := diff + 16r100
- ].
+ index := 1.
+ borrow := 0.
+
+ done := false.
+ [done] whileFalse:[
+ diff := borrow.
+ (index <= len1) ifTrue:[
+ diff := diff + (digitByteArray basicAt:index).
+ (index <= len2) ifTrue:[
+ diff := diff - (otherDigitByteArray basicAt:index)
+ ]
+ ] ifFalse:[
+ (index <= len2) ifTrue:[
+ diff := diff - (otherDigitByteArray basicAt:index)
+ ] ifFalse:[
+ "end reached"
+ done := true
+ ]
+ ].
+
+ "/ workaround for
+ "/ gcc code generator bug
+
+ (diff >= 0) ifTrue:[
+ borrow := 0
+ ] ifFalse:[
+ borrow := -1.
+ diff := diff + 16r100
+ ].
"/ (diff < 0) ifTrue:[
"/ borrow := -1.
@@ -3428,40 +3445,40 @@
"/ borrow := 0
"/ ].
- resultDigitByteArray basicAt:index put:diff.
- index := index + 1
- ].
- lastDigit := resultDigitByteArray basicAt:lResult.
+ resultDigitByteArray basicAt:index put:diff.
+ index := index + 1
+ ].
+ lastDigit := resultDigitByteArray basicAt:lResult.
].
(borrow ~~ 0) ifTrue:[
- "/ must generate 255's complement
-
- result sign:newSign negated.
- [index <= lResult] whileTrue:[
- resultDigitByteArray basicAt:index put:16rFF.
- index := index + 1.
- ].
- index := lResult.
- [index > 0] whileTrue:[
- resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
- index := index - 1.
- ].
-
- index := 1.
- carry := 1.
- [carry ~~ 0] whileTrue:[
- (index <= lResult) ifTrue:[
- carry := (resultDigitByteArray basicAt:index) + carry.
- ].
- resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
- carry := carry bitShift:-8.
- index := index + 1
- ].
- lastDigit := resultDigitByteArray basicAt:lResult.
+ "/ must generate 255's complement
+
+ result sign:newSign negated.
+ [index <= lResult] whileTrue:[
+ resultDigitByteArray basicAt:index put:16rFF.
+ index := index + 1.
+ ].
+ index := lResult.
+ [index > 0] whileTrue:[
+ resultDigitByteArray basicAt:index put:(255 - (resultDigitByteArray at:index)).
+ index := index - 1.
+ ].
+
+ index := 1.
+ carry := 1.
+ [carry ~~ 0] whileTrue:[
+ (index <= lResult) ifTrue:[
+ carry := (resultDigitByteArray basicAt:index) + carry.
+ ].
+ resultDigitByteArray basicAt:index put:(carry bitAnd:16rFF).
+ carry := carry bitShift:-8.
+ index := index + 1
+ ].
+ lastDigit := resultDigitByteArray basicAt:lResult.
].
(lastDigit ~~ 0 and:[lResult > SmallInteger maxBytes]) ifTrue:[
- ^ result
+ ^ result
].
^ result compressed
@@ -4822,5 +4839,5 @@
!LargeInteger class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.194 2009-05-26 06:37:56 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.195 2009-09-14 22:16:50 cg Exp $'
! !