--- a/LargeInteger.st Fri Jun 04 23:17:10 1999 +0200
+++ b/LargeInteger.st Sat Jun 05 00:00:26 1999 +0200
@@ -2758,7 +2758,7 @@
unsigned char *otherBytes = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
unsigned char *resultBytes = __ByteArrayInstPtr(resultDigitByteArray)->ba_element;
unsigned char *_p1, *_p2, *_pResult, *_pResult0, *_pResult1, *_p1Last, *_p2Last;
- unsigned char *_pResultLast3, *_pResultLast1;
+ unsigned char *_pResultLast1;
unsigned INT _v;
int _len1 = __intVal(len1);
int _len2 = __intVal(len2);
@@ -2794,6 +2794,8 @@
_v >>= 32; /* now _v contains the carry*/
_pResult += 4;
if (_v) {
+ unsigned char *_pResultLast3;
+
/* distribute carry - int-wise, then byte-wise */
_pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
for (_pResult1 = _pResult; _v; _pResult1 += 4) {
@@ -2818,6 +2820,8 @@
_v >>= 32; /* now _v contains the carry*/
_pResult += 4;
if (_v) {
+ unsigned char *_pResultLast3;
+
/* distribute carry - int-wise, then byte-wise */
_pResultLast3 = _pResult0 + _len1 + _len2 - 1 - 3;
for (_pResult1 = _pResult; _v; _pResult1 += 4) {
@@ -3451,20 +3455,46 @@
_len2 = __intVal(len2);
unsigned char *_myDigits, *_otherDigits;
int _index = 1, _borrow = 0;
- int _diff;
- int anyBitNonZero = 0;
+ INT _diff;
+ INT anyBitNonZero = 0;
_otherDigits = __ByteArrayInstPtr(otherDigitByteArray)->ba_element;
_myDigits = __ByteArrayInstPtr(_digitByteArray)->ba_element;
+#if defined(alpha64)
+ {
+ int _len2Q;
+ /*
+ * subtract int-wise
+ */
+ _len2Q = _len2-2;
+ while (_index < _len2Q) {
+ /* do not combine the expression below (may lead to unsigned result on some machines */
+ _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 *)(_myDigits+_index-1))[0] = _diff;
+ anyBitNonZero |= (_diff & 0xFFFFFFFFL);
+ _index += 4;
+ }
+ }
+#endif
+
#if defined(i386) || defined(__LSBFIRST)
/*
* subtract short-wise
*/
while (_index < _len2) {
- _diff = ((unsigned short *)(_myDigits+_index-1))[0]
- - ((unsigned short *)(_otherDigits+_index-1))[0]
- - _borrow;
+ /* do not combine the expression below (may lead to unsigned result on some machines */
+ _diff = ((unsigned short *)(_myDigits+_index-1))[0];
+ _diff -= ((unsigned short *)(_otherDigits+_index-1))[0];
+ _diff -= _borrow;
if (_diff >= 0) {
_borrow = 0;
} else {
@@ -3483,7 +3513,9 @@
*/
} else {
while (_index < _len1) {
- _diff = ((unsigned short *)(_myDigits+_index-1))[0] - _borrow;
+ /* do not combine the expression below (may lead to unsigned result on some machines */
+ _diff = ((unsigned short *)(_myDigits+_index-1))[0];
+ _diff -= _borrow;
if (_diff >= 0) {
/* _borrow = 0; */
((unsigned short *)(_myDigits+_index-1))[0] = _diff;
@@ -3491,11 +3523,17 @@
_index += 2;
while (_index < _len1) {
anyBitNonZero |= ((unsigned short *)(_myDigits+_index-1))[0];
+ if (anyBitNonZero) {
+ RETURN (true);
+ }
_index += 2;
}
/* last odd index */
if (_index <= _len1) {
anyBitNonZero |= _myDigits[_index - 1];;
+ if (anyBitNonZero) {
+ RETURN (true);
+ }
_index++;
}
RETURN (anyBitNonZero ? true : false);
@@ -3513,9 +3551,10 @@
* subtract byte-wise
*/
while (_index <= _len2) {
- _diff = _myDigits[_index - 1]
- - _otherDigits[_index - 1]
- - _borrow;
+ /* do not combine the expression below (may lead to unsigned result on some machines */
+ _diff = _myDigits[_index - 1];
+ _diff -= _otherDigits[_index - 1];
+ _diff -= _borrow;
if (_diff >= 0) {
_borrow = 0;
} else {
@@ -3528,7 +3567,9 @@
}
while (_index <= _len1) {
- _diff = _myDigits[_index - 1] - _borrow;
+ /* do not combine the expression below (may lead to unsigned result on some machines */
+ _diff = _myDigits[_index - 1];
+ _diff -= _borrow;
if (_diff >= 0) {
/* _borrow = 0; */
_myDigits[_index - 1] = _diff;
@@ -3536,6 +3577,9 @@
_index++;
while (_index <= _len1) {
anyBitNonZero |= _myDigits[_index - 1];
+ if (anyBitNonZero) {
+ RETURN (true);
+ }
_index++;
}
break;
@@ -3625,17 +3669,17 @@
}
#else
# if defined(__LSBFIRST) || defined(i386)
- if (sizeof(unsigned INT) == 4) {
+ if (sizeof(unsigned int) == 4) {
int __endIndex = __nBytes - 4;
if (__idx < __endIndex) {
__this = ((unsigned INT *)__bp)[0];
while (__idx < __endIndex) {
- __next = ((unsigned INT *)__bp)[1];
+ __next = ((unsigned int *)__bp)[1];
__this = (__this >> 1) /* & 0x7FFFFFF */;
__this |= __next << 31;
- ((unsigned INT *)__bp)[0] = __this;
+ ((unsigned int *)__bp)[0] = __this;
__this = __next;
__bp += 4;
__idx += 4;
@@ -3711,11 +3755,11 @@
}
#else
# if defined(__LSBFIRST) || defined(i386) /* XXX actually: LSB_FIRST */
- if (sizeof(unsigned INT) == 4) {
+ if (sizeof(unsigned int) == 4) {
while (__nBytes >= 4) {
- __this = ((unsigned INT *)__bp)[0];
+ __this = ((unsigned int *)__bp)[0];
__newCarry = (__this >> 31) /* & 1 */;
- ((unsigned INT *)__bp)[0] = (__this << 1) | __carry;
+ ((unsigned int *)__bp)[0] = (__this << 1) | __carry;
__carry = __newCarry;
__bp += 4;
__nBytes -= 4;
@@ -3818,5 +3862,5 @@
!LargeInteger class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.122 1999-06-04 19:48:59 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.123 1999-06-04 22:00:26 cg Exp $'
! !