--- a/LargeInteger.st Fri Jun 04 10:36:28 1999 +0200
+++ b/LargeInteger.st Fri Jun 04 10:51:35 1999 +0200
@@ -2757,7 +2757,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;
+ unsigned char *_pResultLast3, *_pResultLast1;
unsigned INT _v;
int _len1 = __intVal(len1);
int _len2 = __intVal(len2);
@@ -2851,8 +2851,15 @@
_v >>= 16; /* now _v contains the carry*/
_pResult += 2;
if (_v) {
- /* distribute carry */
- for (_pResult1 = _pResult; _v; _pResult1++) {
+ /* distribute carry - short-wise, then byte-wise */
+ _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
+ for (_pResult1 = _pResult; _v; _pResult1 += 2) {
+ if (_pResult1 > _pResultLast3) break;
+ _v += ((unsigned short *)_pResult1)[0];
+ ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
+ _v >>= 16;
+ }
+ for (; _v; _pResult1++) {
_v += _pResult1[0];
_pResult1[0] = _v /* & 0xFF */;
_v >>= 8;
@@ -2868,8 +2875,15 @@
_v >>= 16; /* now _v contains the carry*/
_pResult += 2;
if (_v) {
- /* distribute carry */
- for (_pResult1 = _pResult; _v; _pResult1++) {
+ /* distribute carry - short-wise, then byte-wise */
+ _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
+ for (_pResult1 = _pResult; _v; _pResult1 += 2) {
+ if (_pResult1 > _pResultLast3) break;
+ _v += ((unsigned short *)_pResult1)[0];
+ ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
+ _v >>= 16;
+ }
+ for (; _v; _pResult1++) {
_v += _pResult1[0];
_pResult1[0] = _v /* & 0xFF */;
_v >>= 8;
@@ -2895,8 +2909,15 @@
_v >>= 16; /* now _v contains the carry*/
_pResult += 2;
if (_v) {
- /* distribute carry */
- for (_pResult1 = _pResult; _v; _pResult1++) {
+ /* distribute carry - short-wise, then byte-wise */
+ _pResultLast1 = _pResult0 + _len1 + _len2 - 1 - 1;
+ for (_pResult1 = _pResult; _v; _pResult1 += 2) {
+ if (_pResult1 > _pResultLast3) break;
+ _v += ((unsigned short *)_pResult1)[0];
+ ((unsigned short *)_pResult1)[0] = _v /* & 0xFFFF */;
+ _v >>= 16;
+ }
+ for (; _v; _pResult1++) {
_v += _pResult1[0];
_pResult1[0] = _v /* & 0xFF */;
_v >>= 8;
@@ -3703,5 +3724,5 @@
!LargeInteger class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.116 1999-06-04 08:36:28 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.117 1999-06-04 08:51:35 cg Exp $'
! !