--- a/LargeInteger.st Wed Nov 26 20:23:50 1997 +0100
+++ b/LargeInteger.st Wed Nov 26 22:35:43 1997 +0100
@@ -2056,7 +2056,8 @@
_index = 1;
_carry = 0;
-#ifdef INT64
+#if defined(i386) || defined(alpha) /* actually: LSB first */
+# ifdef INT64
/*
* have a 64bit integer type;
* add long-wise
@@ -2072,7 +2073,7 @@
*(unsigned *)(&(_newDigits[_index - 1])) = _sum;
_index += 4;
}
-#endif
+# endif
/*
* add short-wise
*/
@@ -2087,6 +2088,8 @@
*(unsigned short *)(&(_newDigits[_index - 1])) = _sum;
_index += 2;
}
+#endif
+
/*
* add byte
*/
@@ -2268,7 +2271,7 @@
if (__isByteArray(__digits)) {
int __nBytes = __byteArraySize(__digits);
unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
- unsigned __this, __next;
+ unsigned int __this, __next;
int __idx;
if (__nBytes == 1) {
@@ -2278,19 +2281,23 @@
__idx = 1;
- if ((__idx+4) < __nBytes) {
- __this = ((unsigned *)__bp)[0];
+#if defined(i386) /* XXX actually: LSB_FIRST */
+ if (sizeof(unsigned int) == 4) {
+ if ((__idx + 4) < __nBytes) {
+ __this = ((unsigned int *)__bp)[0];
- while ((__idx+4) < __nBytes) {
- __next = ((unsigned *)__bp)[1];
- __this >>= 1;
- __this |= __next << 31;
- ((unsigned *)__bp)[0] = __this;
- __this = __next;
- __bp += 4;
- __idx += 4;
+ while ((__idx + 4) < __nBytes) {
+ __next = ((unsigned int *)__bp)[1];
+ __this = (__this >> 1) /* & 0x7FFFFFF */;
+ __this |= __next << 31;
+ ((unsigned int *)__bp)[0] = __this;
+ __this = __next;
+ __bp += 4;
+ __idx += 4;
+ }
}
}
+#endif
__this = __bp[0];
while (__idx < __nBytes) {
@@ -2331,7 +2338,7 @@
"/ need another byte
nBytes := nBytes + 1.
t := ByteArray uninitializedNew:nBytes.
- t replaceFrom:1 with:digitByteArray startingAt:1.
+ t replaceFrom:1 to:nBytes-1 with:digitByteArray startingAt:1.
t at:nBytes put:0.
digitByteArray := t.
].
@@ -2342,23 +2349,27 @@
if (__isByteArray(__digits)) {
int __nBytes = __intVal(nBytes);
unsigned char *__bp = __ByteArrayInstPtr(__digits)->ba_element;
- unsigned __carry = 0, __newCarry, __this;
+ unsigned int __carry = 0, __newCarry, __this;
int __idx;
- while (__nBytes >= 4) {
- __this = ((unsigned *)__bp)[0];
- __newCarry = __this >> 31;
- ((unsigned *)__bp)[0] = (__this << 1) | __carry;
- __carry = __newCarry;
- __bp += 4;
- __nBytes -= 4;
+#if defined(i386) /* XXX actually: LSB_FIRST */
+ if (sizeof(unsigned int) == 4) {
+ while (__nBytes >= 4) {
+ __this = ((unsigned int *)__bp)[0];
+ __newCarry = (__this >> 31) /* & 1 */;
+ ((unsigned int *)__bp)[0] = (__this << 1) | __carry;
+ __carry = __newCarry;
+ __bp += 4;
+ __nBytes -= 4;
+ }
}
+#endif
while (__nBytes) {
__this = __bp[0];
- __newCarry = __this >> 7;
+ __newCarry = (__this >> 7) /* & 1 */;
__bp[0] = (__this << 1) | __carry;
__carry = __newCarry;
- __bp ++;
+ __bp++;
__nBytes--;
}
RETURN (self);
@@ -2443,5 +2454,5 @@
!LargeInteger class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.60 1997-11-11 14:08:29 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.61 1997-11-26 21:35:43 cg Exp $'
! !