diff -r 501217c542a5 -r 6fe0dc1d5377 SmallInteger.st --- a/SmallInteger.st Fri Jan 04 17:19:30 2013 +0100 +++ b/SmallInteger.st Tue Jan 08 18:55:11 2013 +0100 @@ -213,161 +213,161 @@ #endif if (__isSmallInteger(aNumber)) { - myValue = __intVal(self); - otherValue = __intVal(aNumber); + myValue = __intVal(self); + otherValue = __intVal(aNumber); #if defined(USE_LONGLONG_FOR_MUL) - { + { # if defined(__alpha__) && !defined(__alpha64__) # define LONGLONG INT64 # else # define LONGLONG long long # endif - LONGLONG product; - - product = (LONGLONG)myValue * (LONGLONG)otherValue; - if ((product >= (LONGLONG)_MIN_INT) - && (product <= (LONGLONG)_MAX_INT)) { - RETURN ( __mkSmallInteger((INT)product) ); - } - if (product < 0) { - negative = -1; - product = -product; - } else { - negative = 1; - } - productHi = product >> 32; - productLow = product & 0xFFFFFFFFL; - } + LONGLONG product; + + product = (LONGLONG)myValue * (LONGLONG)otherValue; + if ((product >= (LONGLONG)_MIN_INT) + && (product <= (LONGLONG)_MAX_INT)) { + RETURN ( __mkSmallInteger((INT)product) ); + } + if (product < 0) { + negative = -1; + product = -product; + } else { + negative = 1; + } + productHi = product >> 32; + productLow = product & 0xFFFFFFFFL; + } #else /* no long-long */ - negative = 1; - if (myValue < 0) { - negative = -1; - myValue = -myValue; - } - if (otherValue < 0) { - negative = -negative; - otherValue = -otherValue; - } + negative = 1; + if (myValue < 0) { + negative = -1; + myValue = -myValue; + } + if (otherValue < 0) { + negative = -negative; + otherValue = -otherValue; + } # if defined(__GNUC__) && defined(__mc68k__) - asm ("mulu%.l %3,%1:%0" - : "=d" ((unsigned long)(productLow)), - "=d" ((unsigned long)(productHi)) - : "%0" ((unsigned long)(myValue)), - "dmi" ((unsigned long)(otherValue))); + asm ("mulu%.l %3,%1:%0" + : "=d" ((unsigned long)(productLow)), + "=d" ((unsigned long)(productHi)) + : "%0" ((unsigned long)(myValue)), + "dmi" ((unsigned long)(otherValue))); # else # if defined (__GNUC__) && defined(__i386__) - asm ("mull %3" - : "=a" ((unsigned long)(productLow)), - "=d" ((unsigned long)(productHi)) - : "%0" ((unsigned long)(myValue)), - "rm" ((unsigned long)(otherValue))); + asm ("mull %3" + : "=a" ((unsigned long)(productLow)), + "=d" ((unsigned long)(productHi)) + : "%0" ((unsigned long)(myValue)), + "rm" ((unsigned long)(otherValue))); # else # if defined(WIN32) && defined(__BORLANDC__) - asm { - mov eax, myValue - mov edx, otherValue - mul edx - mov productLow, eax - mov productHi, edx - } + asm { + mov eax, myValue + mov edx, otherValue + mul edx + mov productLow, eax + mov productHi, edx + } # else /* generic */ - { - unsigned INT pHH, pHL, pLH, pLL; - unsigned INT low1, low2, hi1, hi2; - unsigned INT t; - - /* unsigned multiply myValue * otherValue -> productHi, productLow - * - * this is too slow: - * since most machines can do 32*32 to 64 bit multiply, - * (or at least 32*32 with Overflow check) - * - need more assembler (inline) functions here - */ + { + unsigned INT pHH, pHL, pLH, pLL; + unsigned INT low1, low2, hi1, hi2; + unsigned INT t; + + /* unsigned multiply myValue * otherValue -> productHi, productLow + * + * this is too slow: + * since most machines can do 32*32 to 64 bit multiply, + * (or at least 32*32 with Overflow check) + * - need more assembler (inline) functions here + */ # if __POINTER_SIZE__ == 8 - low1 = low32Bits((unsigned INT)myValue); - hi1 = hi32Bits((unsigned INT)myValue); - low2 = low32Bits((unsigned INT)otherValue); - hi2 = hi32Bits((unsigned INT)otherValue); + low1 = low32Bits((unsigned INT)myValue); + hi1 = hi32Bits((unsigned INT)myValue); + low2 = low32Bits((unsigned INT)otherValue); + hi2 = hi32Bits((unsigned INT)otherValue); # define LLMASK 0xC000000000000000L # else - low1 = low16Bits((unsigned INT)myValue); - hi1 = hi16Bits((unsigned INT)myValue); - low2 = low16Bits((unsigned INT)otherValue); - hi2 = hi16Bits((unsigned INT)otherValue); + low1 = low16Bits((unsigned INT)myValue); + hi1 = hi16Bits((unsigned INT)myValue); + low2 = low16Bits((unsigned INT)otherValue); + hi2 = hi16Bits((unsigned INT)otherValue); # define LLMASK 0xC0000000 # endif - pLH = low1 * hi2; - pHL = hi1 * low2; - pLL = low1 * low2; - pHH = hi1 * hi2; - - /* - * the common case ... - */ - if ((pHL == 0) - && (pLH == 0) - && (pHH == 0) - && ((pLL & LLMASK) == 0)) { - if (negative < 0) { - RETURN ( __mkSmallInteger(- ((INT)pLL)) ); - } - RETURN ( __mkSmallInteger((INT)pLL) ); - } - - /* - * pHH |--------|--------| - * pLH |--------|--------| - * pHL |--------|--------| - * pLL |--------|--------| - */ + pLH = low1 * hi2; + pHL = hi1 * low2; + pLL = low1 * low2; + pHH = hi1 * hi2; + + /* + * the common case ... + */ + if ((pHL == 0) + && (pLH == 0) + && (pHH == 0) + && ((pLL & LLMASK) == 0)) { + if (negative < 0) { + RETURN ( __mkSmallInteger(- ((INT)pLL)) ); + } + RETURN ( __mkSmallInteger((INT)pLL) ); + } + + /* + * pHH |--------|--------| + * pLH |--------|--------| + * pHL |--------|--------| + * pLL |--------|--------| + */ # if __POINTER_SIZE__ == 8 - t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL); - productLow = (t << 32) + low32Bits(pLL); - productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH); + t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL); + productLow = (t << 32) + low32Bits(pLL); + productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH); # else - t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); - productLow = (t << 16) + low16Bits(pLL); - productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); + t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); + productLow = (t << 16) + low16Bits(pLL); + productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); # endif - } + } # endif /* ! WIN32 */ # endif /* ! (__GNUC__ && __i386__) */ # endif /* ! (__GNUC__ && __mc68k__) */ - if (productHi == 0) { - if (negative < 0) { - if (productLow <= -(_MIN_INT)) { - RETURN ( __mkSmallInteger(-((INT)productLow)) ); - } - } else { - if (productLow <= _MAX_INT) { - RETURN ( __mkSmallInteger(productLow) ); - } - } - } + if (productHi == 0) { + if (negative < 0) { + if (productLow <= -(_MIN_INT)) { + RETURN ( __mkSmallInteger(-((INT)productLow)) ); + } + } else { + if (productLow <= _MAX_INT) { + RETURN ( __mkSmallInteger(productLow) ); + } + } + } #endif /* ! USE_LONGLONG */ #if __POINTER_SIZE__ == 8 - RETURN (__MKLARGEINT128(negative, productLow, productHi)); + RETURN (__MKLARGEINT128(negative, productLow, productHi)); #else - RETURN (__MKLARGEINT64(negative, productLow, productHi)); + RETURN (__MKLARGEINT64(negative, productLow, productHi)); #endif } else if (__isFloatLike(aNumber)) { - OBJ newFloat; - double val = (double)__intVal(self) * __floatVal(aNumber); - - __qMKFLOAT(newFloat, val); - RETURN ( newFloat ); + OBJ newFloat; + double val = (double)__intVal(self) * __floatVal(aNumber); + + __qMKFLOAT(newFloat, val); + RETURN ( newFloat ); } else if (__isShortFloat(aNumber)) { - OBJ newFloat; - float val = (float)__intVal(self) * __shortFloatVal(aNumber); - - __qMKSFLOAT(newFloat, val); - RETURN ( newFloat ); + OBJ newFloat; + float val = (float)__intVal(self) * __shortFloatVal(aNumber); + + __qMKSFLOAT(newFloat, val); + RETURN ( newFloat ); } %}. ^ aNumber productFromInteger:self @@ -545,7 +545,7 @@ Be careful with negative results: 9 // 4 = 2, while -9 // 4 = -3. The following is always true: - (receiver // aNumber) * aNumber + (receiver \\ aNUmber) = receiver + (receiver // aNumber) * aNumber + (receiver \\ aNUmber) = receiver See #quo: which returns -2 in the latter." %{ /* NOCONTEXT */ @@ -563,59 +563,59 @@ INT dividend, divisor, rslt; if (__isSmallInteger(aNumber)) { - divisor = __intVal(aNumber); - if (divisor != 0) { - dividend = __intVal(self); - rslt = dividend / divisor; - /* - * Optimized to speed up positive result - */ - if (rslt <= 0) { - if (rslt == 0) { - if ((dividend ^ divisor) < 0) { - /* - * result (negative) has been truncated toward 0. - * Return -1, because we truncate toward negative inf. - */ - rslt = -1; - } - } else { - /* - * If result (negative) has been truncated toward 0, - * subtract 1, because we truncate toward negative inf. - */ - if (divisor > 0) { - if (rslt * divisor > dividend) { - rslt--; - } - } else { - if (rslt * divisor < dividend) { - rslt--; - } - } - } - } - RETURN ( __mkSmallInteger(rslt) ); - } + divisor = __intVal(aNumber); + if (divisor != 0) { + dividend = __intVal(self); + rslt = dividend / divisor; + /* + * Optimized to speed up positive result + */ + if (rslt <= 0) { + if (rslt == 0) { + if ((dividend ^ divisor) < 0) { + /* + * result (negative) has been truncated toward 0. + * Return -1, because we truncate toward negative inf. + */ + rslt = -1; + } + } else { + /* + * If result (negative) has been truncated toward 0, + * subtract 1, because we truncate toward negative inf. + */ + if (divisor > 0) { + if (rslt * divisor > dividend) { + rslt--; + } + } else { + if (rslt * divisor < dividend) { + rslt--; + } + } + } + } + RETURN ( __mkSmallInteger(rslt) ); + } } else { - if (__isFraction(aNumber)) { - OBJ t; - INT num, den; - - t = __FractionInstPtr(aNumber)->f_numerator; - if (__isSmallInteger(t)) { - num = __intVal(t); - t = __FractionInstPtr(aNumber)->f_denominator; - if (__isSmallInteger(t)) { - den = __intVal(t); - RETURN ( __mkSmallInteger(__intVal(self) * den / num )); - } - } - } + if (__isFraction(aNumber)) { + OBJ t; + INT num, den; + + t = __FractionInstPtr(aNumber)->f_numerator; + if (__isSmallInteger(t)) { + num = __intVal(t); + t = __FractionInstPtr(aNumber)->f_denominator; + if (__isSmallInteger(t)) { + den = __intVal(t); + RETURN ( __mkSmallInteger(__intVal(self) * den / num )); + } + } + } } %}. (aNumber = 0) ifTrue:[ - ^ ZeroDivide raiseRequestWith:thisContext. + ^ ZeroDivide raiseRequestWith:thisContext. ]. ^ aNumber integerQuotientFromInteger:self @@ -644,7 +644,7 @@ negative infinity. The remainder has the same sign as aNumber. m < |aNumber| AND there is an integer k with (k * aNumber + m) = self The following is always true: - (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver + (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver Compare with #rem: Redefined for speed." @@ -664,32 +664,32 @@ INT dividend, divisor, rem; if (__isSmallInteger(aNumber) - && (divisor = __intVal(aNumber)) != 0) { - /* - * Note that the sign of something modulo a negative number is undefined - * in C! - */ - dividend = __intVal(self); - rem = dividend % divisor; - if (rem) { - if ((rem ^ divisor) < 0) { - /* sign of remainder is different from sign of divisor */ - rem = -rem; - } - if ((dividend ^ divisor) < 0) { - /* different signs, so division would have returned a - * negative number. - * C rounds toward zero, this code will simulate - * rounding towards negative infinity. - */ - rem = divisor - rem; - } - } - RETURN ( __mkSmallInteger(rem) ); + && (divisor = __intVal(aNumber)) != 0) { + /* + * Note that the sign of something modulo a negative number is undefined + * in C! + */ + dividend = __intVal(self); + rem = dividend % divisor; + if (rem) { + if ((rem ^ divisor) < 0) { + /* sign of remainder is different from sign of divisor */ + rem = -rem; + } + if ((dividend ^ divisor) < 0) { + /* different signs, so division would have returned a + * negative number. + * C rounds toward zero, this code will simulate + * rounding towards negative infinity. + */ + rem = divisor - rem; + } + } + RETURN ( __mkSmallInteger(rem) ); } %}. (aNumber = 0) ifTrue:[ - ^ ZeroDivide raiseRequestWith:thisContext. + ^ ZeroDivide raiseRequestWith:thisContext. ]. ^ aNumber moduloFromInteger:self @@ -818,25 +818,25 @@ 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); - if (idx > 0) { - if (idx > N_INT_BITS) { - RETURN(__mkSmallInteger(0)); - } - RETURN((__smallIntegerVal(self) & (1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0)); - } + INT idx = __smallIntegerVal(anIntegerIndex); + if (idx > 0) { + if (idx > N_INT_BITS) { + RETURN(__mkSmallInteger(0)); + } + RETURN((__smallIntegerVal(self) & (1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0)); + } } %}. ^ SubscriptOutOfBoundsSignal - raiseRequestWith:anIntegerIndex - errorString:'index out of bounds' + raiseRequestWith:anIntegerIndex + errorString:'index out of bounds' " 16r00000001 bitAt:0 @@ -856,9 +856,9 @@ |mask| anIntegerIndex <= 0 ifTrue:[ - ^ SubscriptOutOfBoundsSignal - raiseRequestWith:anIntegerIndex - errorString:'index out of bounds' + ^ SubscriptOutOfBoundsSignal + raiseRequestWith:anIntegerIndex + errorString:'index out of bounds' ]. (anIntegerIndex > SmallInteger maxBits) ifTrue:[^ 0]. mask := 1 bitShift:(anIntegerIndex - 1). @@ -900,8 +900,8 @@ _cnt = 0; while (_self) { - _cnt++; - _self = _self & (_self - 1); + _cnt++; + _self = _self & (_self - 1); } #else # ifdef ALGORITHM_2 @@ -911,8 +911,8 @@ _cnt = 0; while (_self) { - _cnt += table[ _self & 0x0F ]; - _self >>= 4; + _cnt += table[ _self & 0x0F ]; + _self >>= 4; } # else # ifdef ALGORIHTM_3 @@ -948,25 +948,25 @@ " 1 to:1000000 do:[:n | - self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1)) + self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1)) ]. - #( - 16r00010000 16r00100000 16r01000000 16r10000000 - 16r00020000 16r00200000 16r02000000 16r20000000 - 16r00040000 16r00400000 16r04000000 16r40000000 - 16r00080000 16r00800000 16r08000000 16r80000000 - - 16rFFFFFFFF 16r7FFFFFFF 16r3FFFFFFF 16r1FFFFFFF - 16rEEEEEEEE 16r7EEEEEEE 16r3EEEEEEE 16r1EEEEEEE - 16rDDDDDDDD 16r7DDDDDDD 16r3DDDDDDD 16r1DDDDDDD - 16rCCCCCCCC 16r7CCCCCCC 16r3CCCCCCC 16r1CCCCCCC + #( + 16r00010000 16r00100000 16r01000000 16r10000000 + 16r00020000 16r00200000 16r02000000 16r20000000 + 16r00040000 16r00400000 16r04000000 16r40000000 + 16r00080000 16r00800000 16r08000000 16r80000000 + + 16rFFFFFFFF 16r7FFFFFFF 16r3FFFFFFF 16r1FFFFFFF + 16rEEEEEEEE 16r7EEEEEEE 16r3EEEEEEE 16r1EEEEEEE + 16rDDDDDDDD 16r7DDDDDDD 16r3DDDDDDD 16r1DDDDDDD + 16rCCCCCCCC 16r7CCCCCCC 16r3CCCCCCC 16r1CCCCCCC ) do:[:n | - self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1)) + self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1)) ] 1 to:10000000 do:[:n | - (n bitCount) + (n bitCount) ] " @@ -1091,22 +1091,22 @@ /* and all bits except tag */ if (__isSmallInteger(aMask)) { - RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false ); + RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false ); } %}. aMask class == LargeInteger ifTrue:[ - ^ (aMask bitAnd:self) ~~ 0 + ^ (aMask bitAnd:self) ~~ 0 ]. ^ self retry:#bitTest: coercing:aMask " - 2r10001 bitTest:2r00001 - 2r10001 bitTest:2r00010 - 2r10001 bitTest:2r00100 - 2r10001 bitTest:2r01000 - 2r10001 bitTest:2r10000 - 2r10001 bitTest:2r10001 - 2r10001 bitTest:2r10010 + 2r10001 bitTest:2r00001 + 2r10001 bitTest:2r00010 + 2r10001 bitTest:2r00100 + 2r10001 bitTest:2r01000 + 2r10001 bitTest:2r10000 + 2r10001 bitTest:2r10001 + 2r10001 bitTest:2r10010 " ! @@ -1181,10 +1181,10 @@ bits = __intVal(self); if (bits == 0) { - RETURN ( __mkSmallInteger(0) ); + RETURN ( __mkSmallInteger(0) ); } -#ifdef __BSR +#ifdef __BSR /* * so much for CISC CPUS: * the following code is not faster on a PIII-400 @@ -1197,23 +1197,23 @@ # if __POINTER_SIZE__ == 8 if (bits & 0xFFFFFFFF00000000L) { - index += 32; bits = bits >> 32; + index += 32; bits = bits >> 32; } # endif if (bits & 0xFFFF0000L) { - index += 16; bits = bits >> 16; + index += 16; bits = bits >> 16; } if (bits & 0xFF00) { - index += 8; bits = bits >> 8; + index += 8; bits = bits >> 8; } if (bits & 0xF0) { - index += 4; bits = bits >> 4; + index += 4; bits = bits >> 4; } if (bits & 0xC) { - index += 2; bits = bits >> 2; + index += 2; bits = bits >> 2; } if (bits & 0x2) { - index += 1; bits = bits >> 1; + index += 1; bits = bits >> 1; } #endif /* no BSR instruction */ @@ -1228,38 +1228,38 @@ 2r100000000000 highBit ((0 to:64) collect:[:s | 1 bitShift:s]) - collect:[:n | n highBit] + collect:[:n | n highBit] (((0 to:64) collect:[:s | 1 bitShift:s]) - collect:[:n | n highBit]) = (1 to:65) + collect:[:n | n highBit]) = (1 to:65) " " Time millisecondsToRun:[ - 1000000 timesRepeat:[ - 2r1 highBit - ] + 1000000 timesRepeat:[ + 2r1 highBit + ] ] " " Time millisecondsToRun:[ - 1000000 timesRepeat:[ - 2r1111 highBit - ] + 1000000 timesRepeat:[ + 2r1111 highBit + ] ] " " Time millisecondsToRun:[ - 1000000 timesRepeat:[ - 2r11111111111111 highBit - ] + 1000000 timesRepeat:[ + 2r11111111111111 highBit + ] ] " " Time millisecondsToRun:[ - 1000000 timesRepeat:[ - 2r11111111111111111111111111 highBit - ] + 1000000 timesRepeat:[ + 2r11111111111111111111111111 highBit + ] ] " @@ -1413,83 +1413,83 @@ "return the value of the receiver shifted by shiftCount bits; right shift if shiftCount > 0; left shift otherwise. Notice: the result of bitShift: on negative receivers is not - defined in the language standard (since the implementation - is free to choose any internal representation for integers). - However, ST/X preserves the sign." + defined in the language standard (since the implementation + is free to choose any internal representation for integers). + However, ST/X preserves the sign." %{ /* NOCONTEXT */ INT bits, count; if (__isSmallInteger(shiftCount)) { - bits = __intVal(self); - if (bits == 0) { - RETURN (self); - } - - count = __intVal(shiftCount); - - if (count < 0) { - /* - * a left shift - */ - count = -count; + bits = __intVal(self); + if (bits == 0) { + RETURN (self); + } + + count = __intVal(shiftCount); + + if (count < 0) { + /* + * a left shift + */ + count = -count; #if defined(USE_LONGLONG_FOR_SHIFT) - if (count <= N_INT_BITS) { - unsigned LONGLONG result; - - result = (unsigned LONGLONG)bits; - result <<= count; - if (result <= _MAX_INT) { - RETURN ( __mkSmallInteger(result) ); - } - { - RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF))); - } - } + if (count <= N_INT_BITS) { + unsigned LONGLONG result; + + result = (unsigned LONGLONG)bits; + result <<= count; + if (result <= _MAX_INT) { + RETURN ( __mkSmallInteger(result) ); + } + { + RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF))); + } + } #else - /* - * check for overflow - */ - if (count < (N_INT_BITS-1)) { - if (! (bits >> (N_INT_BITS - 1 - count))) { - RETURN ( __mkSmallInteger(bits << count) ); - } - /* - * so, there is an overflow ... - * handle it as largeInteger - */ - /* FALL THROUGH */ - } + /* + * check for overflow + */ + if (count < (N_INT_BITS-1)) { + if (! (bits >> (N_INT_BITS - 1 - count))) { + RETURN ( __mkSmallInteger(bits << count) ); + } + /* + * so, there is an overflow ... + * handle it as largeInteger + */ + /* FALL THROUGH */ + } #endif - } else { - if (count == 0) { - RETURN (self); - } - - /* - * right shifts cannot overflow - * - * some machines ignore shifts bigger than - * the number of bits in an int ... - */ - if (count > (N_INT_BITS-1)) { - RETURN (__mkSmallInteger(0)); - } - - RETURN ( __mkSmallInteger(bits >> count) ); - } + } else { + if (count == 0) { + RETURN (self); + } + + /* + * right shifts cannot overflow + * + * some machines ignore shifts bigger than + * the number of bits in an int ... + */ + if (count > (N_INT_BITS-1)) { + RETURN (__mkSmallInteger(0)); + } + + RETURN ( __mkSmallInteger(bits >> count) ); + } } %}. (shiftCount isMemberOf:SmallInteger) ifTrue:[ - ^ (LargeInteger value:self) rightShift:shiftCount + ^ (LargeInteger value:self) rightShift:shiftCount ]. ^ self rightShift:(1 coerce:shiftCount) "/ is this a good idea ? " - 16 rightShift:2 - 4 rightShift:-2 + 16 rightShift:2 + 4 rightShift:-2 " ! @@ -1594,19 +1594,19 @@ int count; if (__isSmallInteger(shiftCount)) { - count = __intVal(shiftCount); - count = count % 32; - - bits = __intVal(self); - if (count > 0) { - bits = (bits << count) | (bits >> (32-count)); - } else { - bits = (bits >> (-count)) | (bits << (32-(-count))); - } + count = __intVal(shiftCount); + count = count % 32; + + bits = __intVal(self); + if (count > 0) { + bits = (bits << count) | (bits >> (32-count)); + } else { + bits = (bits >> (-count)) | (bits << (32-(-count))); + } #if __POINTER_SIZE__ == 8 - bits &= 0xFFFFFFFFL; + bits &= 0xFFFFFFFFL; #endif - RETURN (__MKUINT(bits)); + RETURN (__MKUINT(bits)); } %}. ^ self primitiveFailed @@ -1614,15 +1614,15 @@ " 128 rotate32:1 - 1 rotate32:1 - 1 rotate32:2 + 1 rotate32:1 + 1 rotate32:2 1 rotate32:31 1 rotate32:32 - 1 rotate32:-1 - 1 rotate32:-2 - 1 rotate32:-3 - 1 rotate32:-32 + 1 rotate32:-1 + 1 rotate32:-2 + 1 rotate32:-3 + 1 rotate32:-32 " ! @@ -1742,23 +1742,23 @@ %{ /* NOCONTEXT */ #if __POINTER_SIZE__ == 4 - unsigned int v = __intVal(self); - unsigned int swapped; + unsigned int v = __intVal(self); + unsigned int swapped; # ifdef __BORLANDC__ # ifdef USE_BSWAP _asm { - mov eax, v - bswap eax - mov swapped, eax + mov eax, v + bswap eax + mov swapped, eax }; # else _asm { - mov eax, v - xchg al, ah - rol eax, 16 - xchg al, ah - mov swapped, eax + mov eax, v + xchg al, ah + rol eax, 16 + xchg al, ah + mov swapped, eax }; # endif # else @@ -1770,8 +1770,8 @@ ^ super byteSwapped " - 16r11223344 byteSwapped hexPrintString - 16r44332211 byteSwapped hexPrintString + 16r11223344 byteSwapped hexPrintString + 16r44332211 byteSwapped hexPrintString " "Created: / 09-01-2012 / 23:01:33 / cg" @@ -1927,83 +1927,83 @@ overhead of producing any intermediate byte-arrays (and the scanning) " self == 0 ifTrue: [ - ^ ByteArray with:0. + ^ ByteArray with:0. ]. self < 0 ifTrue: [ - absValue := self negated + absValue := self negated ] ifFalse: [ - absValue := self. + absValue := self. ]. b1 := absValue bitAnd:16rFF. absValue := absValue bitShift:-8. absValue == 0 ifTrue:[ - digitByteArray := ByteArray with:b1 + digitByteArray := ByteArray with:b1 ] ifFalse:[ - b2 := absValue bitAnd:16rFF. - absValue := absValue bitShift:-8. - absValue == 0 ifTrue:[ - digitByteArray := ByteArray with:b1 with:b2 - ] ifFalse:[ - b3 := absValue bitAnd:16rFF. - absValue := absValue bitShift:-8. - absValue == 0 ifTrue:[ - digitByteArray := ByteArray with:b1 with:b2 with:b3 - ] ifFalse:[ - b4 := absValue bitAnd:16rFF. - absValue := absValue bitShift:-8. - absValue == 0 ifTrue:[ - digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4 - ] ifFalse:[ - b5 := absValue bitAnd:16rFF. - absValue := absValue bitShift:-8. - absValue == 0 ifTrue:[ - digitByteArray := ByteArray new:5. - digitByteArray at:1 put:b1. - digitByteArray at:2 put:b2. - digitByteArray at:3 put:b3. - digitByteArray at:4 put:b4. - digitByteArray at:5 put:b5. - ] ifFalse:[ - b6 := absValue bitAnd:16rFF. - absValue := absValue bitShift:-8. - absValue == 0 ifTrue:[ - digitByteArray := ByteArray new:6. - digitByteArray at:1 put:b1. - digitByteArray at:2 put:b2. - digitByteArray at:3 put:b3. - digitByteArray at:4 put:b4. - digitByteArray at:5 put:b5. - digitByteArray at:6 put:b6. - ] ifFalse:[ - b7 := absValue bitAnd:16rFF. - absValue := absValue bitShift:-8. - absValue == 0 ifTrue:[ - digitByteArray := ByteArray new:7. - digitByteArray at:1 put:b1. - digitByteArray at:2 put:b2. - digitByteArray at:3 put:b3. - digitByteArray at:4 put:b4. - digitByteArray at:5 put:b5. - digitByteArray at:6 put:b6. - digitByteArray at:7 put:b7. - ] ifFalse:[ - digitByteArray := ByteArray new:8. - digitByteArray at:1 put:b1. - digitByteArray at:2 put:b2. - digitByteArray at:3 put:b3. - digitByteArray at:4 put:b4. - digitByteArray at:5 put:b5. - digitByteArray at:6 put:b6. - digitByteArray at:7 put:b7. - digitByteArray at:8 put:absValue. - ] - ] - ] - ] - ] - ] + b2 := absValue bitAnd:16rFF. + absValue := absValue bitShift:-8. + absValue == 0 ifTrue:[ + digitByteArray := ByteArray with:b1 with:b2 + ] ifFalse:[ + b3 := absValue bitAnd:16rFF. + absValue := absValue bitShift:-8. + absValue == 0 ifTrue:[ + digitByteArray := ByteArray with:b1 with:b2 with:b3 + ] ifFalse:[ + b4 := absValue bitAnd:16rFF. + absValue := absValue bitShift:-8. + absValue == 0 ifTrue:[ + digitByteArray := ByteArray with:b1 with:b2 with:b3 with:b4 + ] ifFalse:[ + b5 := absValue bitAnd:16rFF. + absValue := absValue bitShift:-8. + absValue == 0 ifTrue:[ + digitByteArray := ByteArray new:5. + digitByteArray at:1 put:b1. + digitByteArray at:2 put:b2. + digitByteArray at:3 put:b3. + digitByteArray at:4 put:b4. + digitByteArray at:5 put:b5. + ] ifFalse:[ + b6 := absValue bitAnd:16rFF. + absValue := absValue bitShift:-8. + absValue == 0 ifTrue:[ + digitByteArray := ByteArray new:6. + digitByteArray at:1 put:b1. + digitByteArray at:2 put:b2. + digitByteArray at:3 put:b3. + digitByteArray at:4 put:b4. + digitByteArray at:5 put:b5. + digitByteArray at:6 put:b6. + ] ifFalse:[ + b7 := absValue bitAnd:16rFF. + absValue := absValue bitShift:-8. + absValue == 0 ifTrue:[ + digitByteArray := ByteArray new:7. + digitByteArray at:1 put:b1. + digitByteArray at:2 put:b2. + digitByteArray at:3 put:b3. + digitByteArray at:4 put:b4. + digitByteArray at:5 put:b5. + digitByteArray at:6 put:b6. + digitByteArray at:7 put:b7. + ] ifFalse:[ + digitByteArray := ByteArray new:8. + digitByteArray at:1 put:b1. + digitByteArray at:2 put:b2. + digitByteArray at:3 put:b3. + digitByteArray at:4 put:b4. + digitByteArray at:5 put:b5. + digitByteArray at:6 put:b6. + digitByteArray at:7 put:b7. + digitByteArray at:8 put:absValue. + ] + ] + ] + ] + ] + ] ]. ^ digitByteArray @@ -2022,7 +2022,7 @@ otherwise least significant byte is first" msbFlag ifTrue:[ - ^ self digitBytes reversed. "digitBytes has been just created - reverse inplace" + ^ self digitBytes reversed. "digitBytes has been just created - reverse inplace" ]. ^ self digitBytes @@ -2104,8 +2104,8 @@ %{ /* NOCONTEXT */ #if __POINTER_SIZE__ == 4 - unsigned int v = __intVal(self); - unsigned int swapped; + unsigned int v = __intVal(self); + unsigned int swapped; swapped = ((v&0xFF000000)>>8) | ((v&0xFF0000) << 8) | ((v & 0xFF00)>>8) | ((v & 0xFF)<<8); RETURN (__MKUINT(swapped)); @@ -2114,8 +2114,8 @@ ^ super swapBytes " - 16r11223344 swapBytes hexPrintString - 16r44332211 swapBytes hexPrintString + 16r11223344 swapBytes hexPrintString + 16r44332211 swapBytes hexPrintString " "Created: / 09-01-2012 / 23:01:33 / cg" @@ -2222,9 +2222,9 @@ INT i = __intVal(self); if (i & 0x800000) { - i = i | ~0xFFFFFFL; + i = i | ~0xFFFFFFL; } else { - i = i & 0x7FFFFF; + i = i & 0x7FFFFF; } RETURN (__mkSmallInteger(i)); @@ -2246,9 +2246,9 @@ INT i = __intVal(self); if (i & 0x80) { - i = i | ~0xFFL; + i = i | ~0xFFL; } else { - i = i & 0x7F; + i = i & 0x7F; } RETURN (__mkSmallInteger(i)); @@ -2256,9 +2256,9 @@ ^ self primitiveFailed " - 16rFF signExtendedByteValue - 16r80 signExtendedByteValue - 16r7F signExtendedByteValue + 16rFF signExtendedByteValue + 16r80 signExtendedByteValue + 16r7F signExtendedByteValue " ! @@ -2270,9 +2270,9 @@ INT i = __intVal(self); if (i & 0x8000) { - i = i | ~0xFFFFL; + i = i | ~0xFFFFL; } else { - i = i & 0x7FFF; + i = i & 0x7FFF; } RETURN (__mkSmallInteger(i)); @@ -2280,9 +2280,9 @@ ^ self primitiveFailed " - 16rFFFF signExtendedShortValue - 16r8000 signExtendedShortValue - 16r7FFF signExtendedShortValue + 16rFFFF signExtendedShortValue + 16r8000 signExtendedShortValue + 16r7FFF signExtendedShortValue " ! ! @@ -3358,33 +3358,33 @@ (i.e. without log)." self <= 0 ifTrue:[ - ^ self class - raise:#domainErrorSignal - receiver:self - selector:#intlog10 - arguments:#() - errorString:'logarithm of negative integer' + ^ self class + raise:#domainErrorSignal + receiver:self + selector:#intlog10 + arguments:#() + errorString:'logarithm of negative integer' ]. self < 10000 ifTrue:[ - self < 10 ifTrue:[^ 0]. - self < 100 ifTrue:[^ 1]. - self < 1000 ifTrue:[^ 2]. - ^ 3 + self < 10 ifTrue:[^ 0]. + self < 100 ifTrue:[^ 1]. + self < 1000 ifTrue:[^ 2]. + ^ 3 ]. self < 100000000 ifTrue:[ - self < 100000 ifTrue:[^ 4]. - self < 1000000 ifTrue:[^ 5]. - self < 10000000 ifTrue:[^ 6]. - ^ 7 + self < 100000 ifTrue:[^ 4]. + self < 1000000 ifTrue:[^ 5]. + self < 10000000 ifTrue:[^ 6]. + ^ 7 ]. self < 1000000000 ifTrue:[^ 8]. ^ 9 " 99 intlog10 - 100 intlog10 - 101 intlog10 - (101 log:10) floor + 100 intlog10 + 101 intlog10 + (101 log:10) floor 120 intlog10 -1 intlog10 " @@ -3411,7 +3411,7 @@ " 16r7FFFFFFF + 1 2147483648 - 16r7FFFFFFF plus32: 1 + 16r7FFFFFFF plus32: 1 " ! @@ -3514,127 +3514,127 @@ #endif if (__isSmallInteger(aNumber)) { - myValue = __intVal(self); - otherValue = __intVal(aNumber); + myValue = __intVal(self); + otherValue = __intVal(aNumber); #if defined(USE_LONGLONG_FOR_MUL) - { + { # if defined(__alpha__) && !defined(__alpha64__) # define LONGLONG INT64 # else # define LONGLONG long long # endif - LONGLONG product; - - product = (LONGLONG)myValue * (LONGLONG)otherValue; - if (product < 0) { - RETURN ( __mkSmallInteger(-(INT)(-product & _MAX_INT))); - } - RETURN ( __mkSmallInteger((INT)(product & _MAX_INT))); - } + LONGLONG product; + + product = (LONGLONG)myValue * (LONGLONG)otherValue; + if (product < 0) { + RETURN ( __mkSmallInteger(-(INT)(-product & _MAX_INT))); + } + RETURN ( __mkSmallInteger((INT)(product & _MAX_INT))); + } #else /* no long-long */ - negative = 1; - if (myValue < 0) { - negative = -1; - myValue = -myValue; - } - if (otherValue < 0) { - negative = -negative; - otherValue = -otherValue; - } + negative = 1; + if (myValue < 0) { + negative = -1; + myValue = -myValue; + } + if (otherValue < 0) { + negative = -negative; + otherValue = -otherValue; + } # if defined(__GNUC__) && defined(__mc68k__) - asm ("mulu%.l %3,%1:%0" - : "=d" ((unsigned long)(productLow)), - "=d" ((unsigned long)(productHi)) - : "%0" ((unsigned long)(myValue)), - "dmi" ((unsigned long)(otherValue))); + asm ("mulu%.l %3,%1:%0" + : "=d" ((unsigned long)(productLow)), + "=d" ((unsigned long)(productHi)) + : "%0" ((unsigned long)(myValue)), + "dmi" ((unsigned long)(otherValue))); # else # if defined (__GNUC__) && defined(__i386__) - asm ("mull %3" - : "=a" ((unsigned long)(productLow)), - "=d" ((unsigned long)(productHi)) - : "%0" ((unsigned long)(myValue)), - "rm" ((unsigned long)(otherValue))); + asm ("mull %3" + : "=a" ((unsigned long)(productLow)), + "=d" ((unsigned long)(productHi)) + : "%0" ((unsigned long)(myValue)), + "rm" ((unsigned long)(otherValue))); # else # if defined(WIN32) && defined(__BORLANDC__) - asm { - mov eax, myValue - mov edx, otherValue - mul edx - mov productLow, eax - mov productHi, edx - } + asm { + mov eax, myValue + mov edx, otherValue + mul edx + mov productLow, eax + mov productHi, edx + } # else /* generic */ - { - unsigned INT pHH, pHL, pLH, pLL; - unsigned INT low1, low2, hi1, hi2; - unsigned INT t; - - /* unsigned multiply myValue * otherValue -> productHi, productLow - * - * this is too slow: - * since most machines can do 32*32 to 64 bit multiply, - * (or at least 32*32 with Overflow check) - * - need more assembler (inline) functions here - */ + { + unsigned INT pHH, pHL, pLH, pLL; + unsigned INT low1, low2, hi1, hi2; + unsigned INT t; + + /* unsigned multiply myValue * otherValue -> productHi, productLow + * + * this is too slow: + * since most machines can do 32*32 to 64 bit multiply, + * (or at least 32*32 with Overflow check) + * - need more assembler (inline) functions here + */ # if __POINTER_SIZE__ == 8 - low1 = low32Bits((unsigned INT)myValue); - hi1 = hi32Bits((unsigned INT)myValue); - low2 = low32Bits((unsigned INT)otherValue); - hi2 = hi32Bits((unsigned INT)otherValue); + low1 = low32Bits((unsigned INT)myValue); + hi1 = hi32Bits((unsigned INT)myValue); + low2 = low32Bits((unsigned INT)otherValue); + hi2 = hi32Bits((unsigned INT)otherValue); # define LLMASK 0xC000000000000000L # else - low1 = low16Bits((unsigned INT)myValue); - hi1 = hi16Bits((unsigned INT)myValue); - low2 = low16Bits((unsigned INT)otherValue); - hi2 = hi16Bits((unsigned INT)otherValue); + low1 = low16Bits((unsigned INT)myValue); + hi1 = hi16Bits((unsigned INT)myValue); + low2 = low16Bits((unsigned INT)otherValue); + hi2 = hi16Bits((unsigned INT)otherValue); # define LLMASK 0xC0000000 # endif - pLH = low1 * hi2; - pHL = hi1 * low2; - pLL = low1 * low2; - pHH = hi1 * hi2; - - /* - * the common case ... - */ - if ((pHL == 0) - && (pLH == 0) - && (pHH == 0) - && ((pLL & LLMASK) == 0)) { - if (negative < 0) { - RETURN ( __mkSmallInteger(- ((INT)pLL)) ); - } - RETURN ( __mkSmallInteger((INT)pLL) ); - } - - /* - * pHH |--------|--------| - * pLH |--------|--------| - * pHL |--------|--------| - * pLL |--------|--------| - */ + pLH = low1 * hi2; + pHL = hi1 * low2; + pLL = low1 * low2; + pHH = hi1 * hi2; + + /* + * the common case ... + */ + if ((pHL == 0) + && (pLH == 0) + && (pHH == 0) + && ((pLL & LLMASK) == 0)) { + if (negative < 0) { + RETURN ( __mkSmallInteger(- ((INT)pLL)) ); + } + RETURN ( __mkSmallInteger((INT)pLL) ); + } + + /* + * pHH |--------|--------| + * pLH |--------|--------| + * pHL |--------|--------| + * pLL |--------|--------| + */ # if __POINTER_SIZE__ == 8 - t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL); - productLow = (t << 32) + low32Bits(pLL); - productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH); + t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL); + productLow = (t << 32) + low32Bits(pLL); + productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH); # else - t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); - productLow = (t << 16) + low16Bits(pLL); - productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); + t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); + productLow = (t << 16) + low16Bits(pLL); + productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); # endif - } + } # endif /* ! WIN32 */ # endif /* ! (__GNUC__ && __i386__) */ # endif /* ! (__GNUC__ && __mc68k__) */ - if (negative < 0) { - RETURN ( __mkSmallInteger(-(INT)(productLow & _MAX_INT))); - } - RETURN ( __mkSmallInteger((INT)(productLow & _MAX_INT))); + if (negative < 0) { + RETURN ( __mkSmallInteger(-(INT)(productLow & _MAX_INT))); + } + RETURN ( __mkSmallInteger((INT)(productLow & _MAX_INT))); #endif /* ! USE_LONGLONG */ } %}. @@ -3642,11 +3642,11 @@ self primitiveFailed " - 5 times:-1 - 5 times:1 - self maxVal-1 times:2 - self maxVal-1 times:-2 - self maxVal-1 * 2 bitAnd:16r3fffffff + 5 times:-1 + 5 times:1 + self maxVal-1 times:2 + self maxVal-1 times:-2 + self maxVal-1 * 2 bitAnd:16r3fffffff " ! ! @@ -3664,14 +3664,14 @@ The base argument should be between 2 and 36." showRadix ifTrue:[ - base printOn:aStream. - aStream nextPut:$r. + base printOn:aStream. + aStream nextPut:$r. ]. - (base isInteger and:[ base between:2 and:36 ]) ifTrue:[ - aStream nextPutAll:(self printStringRadix:base) + (base isInteger and:[ base between:2 and:36 ]) ifTrue:[ + aStream nextPutAll:(self printStringRadix:base) ] ifFalse:[ - super printOn:aStream base:base showRadix:false. + super printOn:aStream base:base showRadix:false. ]. "Created: / 07-09-2001 / 13:54:40 / cg" @@ -3696,7 +3696,7 @@ myValue = __intVal(self); if (myValue == 0) { - RETURN (__MKSTRING_L("0", 1)); + RETURN (__MKSTRING_L("0", 1)); } #ifdef SLOW_CODE /* @@ -3710,32 +3710,32 @@ * manually save it here - very stupid ... */ __BEGIN_PROTECT_REGISTERS__ - len = snprintf(buffer, sizeof(buffer), "%ld", (long)myValue); + len = snprintf(buffer, sizeof(buffer), "%"_ld_"", (long)myValue); __END_PROTECT_REGISTERS__ if (len >= 0 && len <= sizeof(buffer)) { - newString = __MKSTRING_L(buffer, len); + newString = __MKSTRING_L(buffer, len); } #else if (myValue < 0) { - negative = 1; - myValue = -myValue; + negative = 1; + myValue = -myValue; } cp = buffer + sizeof(buffer) - 1; *cp-- = '\0'; while (myValue != 0) { - *cp = '0' + (myValue % 10); - myValue = myValue / 10; - cp--; + *cp = '0' + (myValue % 10); + myValue = myValue / 10; + cp--; } if (negative) { - *cp-- = '-'; + *cp-- = '-'; } newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); #endif if (newString != nil) { - RETURN (newString); + RETURN (newString); } %}. "/ only arrive here, @@ -3763,72 +3763,72 @@ INT __base; if (__isSmallInteger(base)) { - myValue = __intVal(self); - if (myValue == 0) { - RETURN (__MKSTRING_L("0", 1)); - } - __base = __intVal(base); + myValue = __intVal(self); + if (myValue == 0) { + RETURN (__MKSTRING_L("0", 1)); + } + __base = __intVal(base); #ifdef SLOW_CODE - switch (__base) { - case 10: - format = "%ld"; - break; - case 16: - format = "%lx"; - break; - case 8: - format = "%lo"; - break; - } - - if (format) { - /* - * actually only needed on sparc: since thisContext is - * in a global register, which gets destroyed by printf, - * manually save it here - very stupid ... - */ - __BEGIN_PROTECT_REGISTERS__ - - len = snprintf(buffer, sizeof(buffer), format, (long)myValue); - - __END_PROTECT_REGISTERS__ - - if (len > 0 && len <= sizeof(buffer)) { - newString = __MKSTRING_L(buffer, len); - if (newString != nil) { - RETURN (newString); - } - } - } + switch (__base) { + case 10: + format = "%"_ld_""; + break; + case 16: + format = "%"_lx_""; + break; + case 8: + format = "%"_lo_""; + break; + } + + if (format) { + /* + * actually only needed on sparc: since thisContext is + * in a global register, which gets destroyed by printf, + * manually save it here - very stupid ... + */ + __BEGIN_PROTECT_REGISTERS__ + + len = snprintf(buffer, sizeof(buffer), format, (long)myValue); + + __END_PROTECT_REGISTERS__ + + if (len > 0 && len <= sizeof(buffer)) { + newString = __MKSTRING_L(buffer, len); + if (newString != nil) { + RETURN (newString); + } + } + } #else - if ((__base <= 36) && (__base > 1)) { - if (myValue < 0) { - negative = 1; - myValue = -myValue; - } - cp = buffer + sizeof(buffer) - 1; - *cp-- = '\0'; - while (myValue != 0) { - int digit; - - digit = myValue % __base; - if (digit <= 9) { - *cp = '0' + digit; - } else { - *cp = 'A' + digit - 10; - } - myValue = myValue / __base; - cp--; - } - if (negative) { - *cp-- = '-'; - } - newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); - if (newString != nil) { - RETURN (newString); - } - } + if ((__base <= 36) && (__base > 1)) { + if (myValue < 0) { + negative = 1; + myValue = -myValue; + } + cp = buffer + sizeof(buffer) - 1; + *cp-- = '\0'; + while (myValue != 0) { + int digit; + + digit = myValue % __base; + if (digit <= 9) { + *cp = '0' + digit; + } else { + *cp = 'A' + digit - 10; + } + myValue = myValue / __base; + cp--; + } + if (negative) { + *cp-- = '-'; + } + newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); + if (newString != nil) { + RETURN (newString); + } + } #endif } %}. @@ -3875,7 +3875,9 @@ situaltions. Notice that a conversion may not be portable; for example, to correctly convert an int on a 64-bit alpha, a %ld is required, - while other systems may be happy with a %d ... + on 64bit mingw or visualc, %lld is required, + while other systems may be happy with a %d. + (We cannot use lld unconditionally, because some (old) c compilers do not support it!!) Use at your own risk (if at all). WARNNG: this goes directly to the C-printf function and may therefore me inherently unsafe. Please use the printf: method, which is safe as it is completely implemented in Smalltalk." @@ -3886,34 +3888,34 @@ int len; if (__isStringLike(formatString)) { - /* - * actually only needed on sparc: since thisContext is - * in a global register, which gets destroyed by printf, - * manually save it here - very stupid ... - */ - __BEGIN_PROTECT_REGISTERS__ - - len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __intVal(self)); - - __END_PROTECT_REGISTERS__ - - if (len < 0) goto fail; - - s = __MKSTRING_L(buffer, len); - if (s != nil) { - RETURN (s); - } + /* + * actually only needed on sparc: since thisContext is + * in a global register, which gets destroyed by printf, + * manually save it here - very stupid ... + */ + __BEGIN_PROTECT_REGISTERS__ + + len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __intVal(self)); + + __END_PROTECT_REGISTERS__ + + if (len < 0) goto fail; + + s = __MKSTRING_L(buffer, len); + if (s != nil) { + RETURN (s); + } } fail: ; %}. self primitiveFailed " - 123 printfPrintString:'%%d -> %d' - 123 printfPrintString:'%%6d -> %6d' - 123 printfPrintString:'%%x -> %x' - 123 printfPrintString:'%%4x -> %4x' - 123 printfPrintString:'%%04x -> %04x' + 123 printfPrintString:'%%d -> %d' + 123 printfPrintString:'%%6d -> %6d' + 123 printfPrintString:'%%x -> %x' + 123 printfPrintString:'%%4x -> %4x' + 123 printfPrintString:'%%04x -> %04x' " ! ! @@ -3990,13 +3992,13 @@ 0 isPowerOfTwo 1 isPowerOfTwo 2 isPowerOfTwo - 3 isPowerOfTwo - 4 isPowerOfTwo - 16r8000000000000000 isPowerOfTwo - 16r8000000000000001 isPowerOfTwo + 3 isPowerOfTwo + 4 isPowerOfTwo + 16r8000000000000000 isPowerOfTwo + 16r8000000000000001 isPowerOfTwo 10000 factorial isPowerOfTwo - |n| n := 10000 factorial. Time millisecondsToRun:[1000 timesRepeat:[ n isPowerOfTwo]] + |n| n := 10000 factorial. Time millisecondsToRun:[1000 timesRepeat:[ n isPowerOfTwo]] " "Modified: / 20-06-2011 / 12:41:18 / cg" @@ -4038,7 +4040,7 @@ // tricky, but very fast (google for it, to understand) #if __POINTER_SIZE__ == 4 - unsigned int v = __intVal(self); + unsigned int v = __intVal(self); v ^= v >> 16; v ^= v >> 8; @@ -4050,17 +4052,17 @@ ^ super parityOdd " - self assert: - (((0 to:255) collect:[:i | i parityOdd ifTrue:1 ifFalse:0]) - asByteArray collect:[:c | c + $0 asciiValue]) asString - = - '0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110' - - self assert:(16r0FFFFFFF parityOdd = 16r0FFFFFFF bitCount odd). - self assert:(16r1FFFFFFF parityOdd = 16r1FFFFFFF bitCount odd). - self assert:(16r3FFFFFFF parityOdd = 16r3FFFFFFF bitCount odd). - self assert:(16r7FFFFFFF parityOdd = 16r7FFFFFFF bitCount odd). - self assert:(16rFFFFFFFF parityOdd = 16rFFFFFFFF bitCount odd). + self assert: + (((0 to:255) collect:[:i | i parityOdd ifTrue:1 ifFalse:0]) + asByteArray collect:[:c | c + $0 asciiValue]) asString + = + '0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110' + + self assert:(16r0FFFFFFF parityOdd = 16r0FFFFFFF bitCount odd). + self assert:(16r1FFFFFFF parityOdd = 16r1FFFFFFF bitCount odd). + self assert:(16r3FFFFFFF parityOdd = 16r3FFFFFFF bitCount odd). + self assert:(16r7FFFFFFF parityOdd = 16r7FFFFFFF bitCount odd). + self assert:(16rFFFFFFFF parityOdd = 16rFFFFFFFF bitCount odd). " "Modified (comment): / 09-01-2012 / 19:55:37 / cg" @@ -4121,9 +4123,9 @@ !SmallInteger class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.198 2012-11-28 12:49:35 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.199 2013-01-08 17:55:11 cg Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.198 2012-11-28 12:49:35 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.199 2013-01-08 17:55:11 cg Exp $' ! !