LargeInteger.st
changeset 15262 5047292c9107
parent 15242 4539185c87ed
child 15276 a25ed9d7c50a
child 18060 3708e12e9aa8
--- a/LargeInteger.st	Tue May 21 22:26:48 2013 +0200
+++ b/LargeInteger.st	Tue May 21 22:44:47 2013 +0200
@@ -1139,7 +1139,7 @@
 	unsigned char *__bP = __byteArrayVal(__digitByteArray);
 	unsigned char *__bP0 = __bP;
 
-	sz = _MKSMALLINT(__sz);
+	sz = __MKSMALLINT(__sz);
 
 #ifdef __UNROLL_LOOPS__
 	while (__sz > (sizeof(INT) * 4)) {
@@ -3592,9 +3592,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.
@@ -3608,202 +3608,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.
@@ -3812,40 +3812,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 or:[lResult <= SmallInteger maxBytes]) ifTrue:[
-        ^ result compressed.
+	^ result compressed.
     ].
     ^ result
 
@@ -5206,10 +5206,10 @@
 !LargeInteger class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.208 2013-05-13 14:56:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.209 2013-05-21 20:44:47 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.208 2013-05-13 14:56:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/LargeInteger.st,v 1.209 2013-05-21 20:44:47 cg Exp $'
 ! !