--- a/SmallInteger.st Wed Apr 12 19:05:40 2017 +0200
+++ b/SmallInteger.st Mon Apr 24 12:05:53 2017 +0200
@@ -1,6 +1,6 @@
"
COPYRIGHT (c) 1988 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -31,7 +31,7 @@
copyright
"
COPYRIGHT (c) 1988 by Claus Gittinger
- All Rights Reserved
+ All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
@@ -46,13 +46,13 @@
"
SmallIntegers are Integers in the range of at least +/- 2^30
i.e. 31 bits, but this is not a guaranteed:
- on an alpha or x86_64, 63 bits are used, if the system was configured for 64bit mode.
- under the Schteam-VM, 64 bits are used (i.e. a full long integer)
+ on an alpha or x86_64, 63 bits are used, if the system was configured for 64bit mode.
+ under the Schteam-VM, 64 bits are used (i.e. a full long integer)
These are no real objects - they have no instances (not even storage !!)
and cannot be subclassed.
The reason is to save both storage and runtime by not boxing and
- garbage collecting SmallIntegers in the system.
+ garbage collecting SmallIntegers in the system.
SmallInts are marked by having the TAG_INT
bit set, in contrast to all other objects which do not.
Since this knowledge is hardwired into the system (and there is no
@@ -65,16 +65,16 @@
Because the range and sharing of SmallIntegers is different among implementations
(both in different dialects, and in different architectures within the Smalltalk/X family),
you should not depend on the identity of two integers with the same value.
- For portable code, when comparing integers, use #'=' and #'~=' (instead of #'==' / #'~~'),
+ For portable code, when comparing integers, use #'=' and #'~=' (instead of #'==' / #'~~'),
unless you are comparing very small integers in the -1024 .. 0 .. 1024 range.
[author:]
- Claus Gittinger
+ Claus Gittinger
[see also:]
- Number
- Float Fraction FixedPoint
- LargeInteger
+ Number
+ Float Fraction FixedPoint
+ LargeInteger
"
! !
@@ -100,9 +100,9 @@
"return a bitmask for the index's bit (index starts at 1)"
(index between:1 and:SmallInteger maxBits) ifFalse:[
- ^ SubscriptOutOfBoundsSignal
- raiseRequestWith:index
- errorString:'index out of bounds'
+ ^ SubscriptOutOfBoundsSignal
+ raiseRequestWith:index
+ errorString:'index out of bounds'
].
^ 1 bitShift:(index - 1)
! !
@@ -263,190 +263,190 @@
# endif
if (__isSmallInteger(aNumber)) {
- otherValue = __intVal(aNumber);
+ 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 & 0xFFFFFFFFLL;
- }
+ 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 & 0xFFFFFFFFLL;
+ }
# 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(__x86__)
- 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 0xC000000000000000LL
# 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 0xC0000000L
# 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__ && __x86__) */
# 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)myValue * __floatVal(aNumber);
-
- __qMKFLOAT(newFloat, val);
- RETURN ( newFloat );
+ OBJ newFloat;
+ double val = (double)myValue * __floatVal(aNumber);
+
+ __qMKFLOAT(newFloat, val);
+ RETURN ( newFloat );
} else if (__isShortFloat(aNumber)) {
- OBJ newFloat;
- float val = (float)myValue * __shortFloatVal(aNumber);
-
- __qMKSFLOAT(newFloat, val);
- RETURN ( newFloat );
+ OBJ newFloat;
+ float val = (float)myValue * __shortFloatVal(aNumber);
+
+ __qMKSFLOAT(newFloat, val);
+ RETURN ( newFloat );
} else if (__isFractionLike(aNumber)) {
- OBJ t = __FractionInstPtr(aNumber)->f_numerator;
-
- if (myValue == 0) {
- RETURN(__mkSmallInteger(0));
- }
-
- if (__isSmallInteger(t)) {
- INT num = __intVal(t);
- t = __FractionInstPtr(aNumber)->f_denominator;
- if (__isSmallInteger(t)) {
- INT prod = myValue * num;
- if (prod / myValue == num) { // check for overflow
- INT den = __intVal(t);
- INT quo = prod / den;
- if (quo * den == prod) { // check for integer result
- RETURN ( __mkSmallInteger(quo) );
- }
- }
- }
- }
+ OBJ t = __FractionInstPtr(aNumber)->f_numerator;
+
+ if (myValue == 0) {
+ RETURN(__mkSmallInteger(0));
+ }
+
+ if (__isSmallInteger(t)) {
+ INT num = __intVal(t);
+ t = __FractionInstPtr(aNumber)->f_denominator;
+ if (__isSmallInteger(t)) {
+ INT prod = myValue * num;
+ if (prod / myValue == num) { // check for overflow
+ INT den = __intVal(t);
+ INT quo = prod / den;
+ if (quo * den == prod) { // check for integer result
+ RETURN ( __mkSmallInteger(quo) );
+ }
+ }
+ }
+ }
}
#endif /* not __SCHTEAM__ */
%}.
^ aNumber productFromInteger:self
"
- 3 * (1/2)
- 6 * (1/2)
- 6 * (-1/2)
+ 3 * (1/2)
+ 6 * (1/2)
+ 6 * (-1/2)
"
!
@@ -469,30 +469,30 @@
if (__isSmallInteger(aNumber)) {
# ifdef _ADD_IO_IO
- RETURN ( _ADD_IO_IO(self, aNumber) );
+ RETURN ( _ADD_IO_IO(self, aNumber) );
# else
- REGISTER INT sum;
-
- sum = __intVal(self) + __intVal(aNumber);
- if (__ISVALIDINTEGER(sum)) {
- RETURN ( __mkSmallInteger(sum) );
- }
- RETURN ( __MKLARGEINT(sum) );
+ REGISTER INT sum;
+
+ sum = __intVal(self) + __intVal(aNumber);
+ if (__ISVALIDINTEGER(sum)) {
+ RETURN ( __mkSmallInteger(sum) );
+ }
+ RETURN ( __MKLARGEINT(sum) );
# endif
}
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 );
}
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 );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -518,28 +518,28 @@
if (__isSmallInteger(aNumber)) {
# ifdef _SUB_IO_IO
- RETURN ( _SUB_IO_IO(self, aNumber) );
+ RETURN ( _SUB_IO_IO(self, aNumber) );
# else
- REGISTER INT diff = __intVal(self) - __intVal(aNumber);
- if (__ISVALIDINTEGER(diff)) {
- RETURN ( __mkSmallInteger(diff) );
- }
- RETURN ( __MKLARGEINT(diff) );
+ REGISTER INT diff = __intVal(self) - __intVal(aNumber);
+ if (__ISVALIDINTEGER(diff)) {
+ RETURN ( __mkSmallInteger(diff) );
+ }
+ RETURN ( __MKLARGEINT(diff) );
# endif
}
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 );
}
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 );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -569,44 +569,44 @@
INT myValue = __intVal(self);
if (__isSmallInteger(aNumber)) {
- val = __intVal(aNumber);
- if (val != 0) {
- t = myValue / val;
+ val = __intVal(aNumber);
+ if (val != 0) {
+ t = myValue / val;
# ifdef GOOD_OPTIMIZER
- if (myValue % val == 0) {
+ if (myValue % val == 0) {
# else
- /* this is stupid - all I want is to look for a remainder ...
- but most compilers are too stupid and generate an extra modulus
- instruction for "if (me % val)".
- Even if most divide instructions already leave the remainder in
- some register.
- Therefore I use a multiplication which is faster than a modulo
- on most machines. Hint to GNU people :-)
- */
- if ((t * val) == myValue) {
+ /* this is stupid - all I want is to look for a remainder ...
+ but most compilers are too stupid and generate an extra modulus
+ instruction for "if (me % val)".
+ Even if most divide instructions already leave the remainder in
+ some register.
+ Therefore I use a multiplication which is faster than a modulo
+ on most machines. Hint to GNU people :-)
+ */
+ if ((t * val) == myValue) {
# endif
- RETURN ( __mkSmallInteger(t) );
- }
- }
+ RETURN ( __mkSmallInteger(t) );
+ }
+ }
} else {
- if (__isFloatLike(aNumber)) {
- dval = __floatVal(aNumber);
- if (dval != 0.0) {
- OBJ newFloat;
- double val = (double)myValue / dval;
-
- __qMKFLOAT(newFloat, val);
- RETURN ( newFloat );
- }
- }
+ if (__isFloatLike(aNumber)) {
+ dval = __floatVal(aNumber);
+ if (dval != 0.0) {
+ OBJ newFloat;
+ double val = (double)myValue / dval;
+
+ __qMKFLOAT(newFloat, val);
+ RETURN ( newFloat );
+ }
+ }
}
#endif /* not __SCHTEAM__ */
%}.
aNumber isInteger ifTrue:[
- aNumber == 0 ifTrue:[
- ^ ZeroDivide raiseRequestWith:thisContext.
- ].
- ^ Fraction numerator:self denominator:aNumber
+ aNumber == 0 ifTrue:[
+ ^ ZeroDivide raiseRequestWith:thisContext.
+ ].
+ ^ Fraction numerator:self denominator:aNumber
].
^ aNumber quotientFromInteger:self
@@ -629,14 +629,14 @@
The result is truncated toward negative infinity
and will be negative, if the operands signs differ.
The following is always true:
- (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
+ (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
Especially surprising (because of truncation toward negative infinity):
- -1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
- -10 // 3 -> -4 (because -(10/3) is truncated towards next smaller integer, which is -4.
-
- See #quo: which truncates toward zero and returns -2 in the above case
+ -1 // 10 -> -1 (because -(1/10) is truncated towards next smaller integer, which is -1.
+ -10 // 3 -> -4 (because -(10/3) is truncated towards next smaller integer, which is -4.
+
+ See #quo: which truncates toward zero and returns -2 in the above case
and #rem: which is the corresponding remainder."
%{ /* NOCONTEXT */
@@ -657,95 +657,95 @@
INT dividend = __intVal(self);
if (__isSmallInteger(aNumber)) {
- divisor = __intVal(aNumber);
- if (divisor != 0) {
- 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) {
+ 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 (__isFractionLike(aNumber)) {
- OBJ t = __FractionInstPtr(aNumber)->f_numerator;
- if (__isSmallInteger(t)) {
- INT num = __intVal(t);
- t = __FractionInstPtr(aNumber)->f_denominator;
- if (__isSmallInteger(t)) {
- INT den = __intVal(t);
- INT prod;
+ if (__isFractionLike(aNumber)) {
+ OBJ t = __FractionInstPtr(aNumber)->f_numerator;
+ if (__isSmallInteger(t)) {
+ INT num = __intVal(t);
+ t = __FractionInstPtr(aNumber)->f_denominator;
+ if (__isSmallInteger(t)) {
+ INT den = __intVal(t);
+ INT prod;
#if 0 && defined(__GNUC__) // supported from GCC 5
- if (!__builtin_mul_overflow(myself, den, &prod)) {
- goto out; // overflow, try harder...
- }
+ if (!__builtin_mul_overflow(myself, den, &prod)) {
+ goto out; // overflow, try harder...
+ }
#else
- prod = dividend * den;
- // make sure, that no overflow occurred
- if (prod / den != dividend) {
- goto out; // overflow, try harder...
- }
+ prod = dividend * den;
+ // make sure, that no overflow occurred
+ if (prod / den != dividend) {
+ goto out; // overflow, try harder...
+ }
#endif
- rslt = prod / num;
-
- /*
- * Optimized to speed up positive result
- */
- if (rslt <= 0) {
- if (rslt == 0) {
- if ((dividend ^ num) < 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 (num > 0) {
- if (rslt * num > prod) rslt--;
- } else {
- if (rslt * num < prod) rslt--;
- }
- }
- }
- RETURN ( __mkSmallInteger(rslt) );
- }
- }
- }
+ rslt = prod / num;
+
+ /*
+ * Optimized to speed up positive result
+ */
+ if (rslt <= 0) {
+ if (rslt == 0) {
+ if ((dividend ^ num) < 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 (num > 0) {
+ if (rslt * num > prod) rslt--;
+ } else {
+ if (rslt * num < prod) rslt--;
+ }
+ }
+ }
+ RETURN ( __mkSmallInteger(rslt) );
+ }
+ }
+ }
}
out:;
#endif /* not __SCHTEAM__ */
%}.
(aNumber = 0) ifTrue:[
- ^ ZeroDivide raiseRequestWith:thisContext.
+ ^ ZeroDivide raiseRequestWith:thisContext.
].
^ aNumber integerQuotientFromInteger:self
@@ -786,14 +786,14 @@
The returned remainder has the same sign as aNumber.
The following is always true:
- (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
+ (receiver // aNumber) * aNumber + (receiver \\ aNumber) = receiver
Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
Especially surprising:
- -1 \\ 10 -> 9 (because -(1/10) is truncated towards next smaller integer, which is -1,
- and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
- -10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
- and -4 * 4 gives -12, so we need to add 2 to get the original -10.
+ -1 \\ 10 -> 9 (because -(1/10) is truncated towards next smaller integer, which is -1,
+ and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
+ -10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
+ and -4 * 4 gives -12, so we need to add 2 to get the original -10.
See #rem: which is the corresponding remainder for division via #quo:.
@@ -816,33 +816,33 @@
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) );
}
#endif /* not __SCHTEAM__ */
%}.
(aNumber = 0) ifTrue:[
- ^ ZeroDivide raiseRequestWith:thisContext.
+ ^ ZeroDivide raiseRequestWith:thisContext.
].
^ aNumber moduloFromInteger:self
@@ -870,10 +870,10 @@
INT val = __intVal(self);
if (val >= 0) {
- RETURN (self);
+ RETURN (self);
}
if (val != _MIN_INT) {
- RETURN ( __mkSmallInteger(-val) );
+ RETURN ( __mkSmallInteger(-val) );
}
/* only reached for minVal */
RETURN( __MKLARGEINT(-_MIN_INT));
@@ -893,7 +893,7 @@
INT val = __intVal(self);
if (val != _MIN_INT) {
- RETURN ( __mkSmallInteger(- val) );
+ RETURN ( __mkSmallInteger(- val) );
}
/* only reached for minVal */
RETURN (__MKLARGEINT( -_MIN_INT));
@@ -907,7 +907,7 @@
and the argument's value. The result is truncated towards zero
and negative, if the operands signs differ..
The following is always true:
- (receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
+ (receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
For positive results, this is the same as #//,
for negative results, the remainder is ignored.
I.e.: '9 // 4 = 2' and '-9 // 4 = -3'
@@ -918,39 +918,39 @@
return context._RETURN( self.quotient(aNumber));
#else
if (__isSmallInteger(aNumber)) {
- INT val = __intVal(aNumber);
- if (val != 0) {
- RETURN ( __mkSmallInteger(__intVal(self) / val) );
- }
+ INT val = __intVal(aNumber);
+ if (val != 0) {
+ RETURN ( __mkSmallInteger(__intVal(self) / val) );
+ }
} else {
- if (__isFractionLike(aNumber)) {
- OBJ t = __FractionInstPtr(aNumber)->f_numerator;
- if (__isSmallInteger(t)) {
- INT num = __intVal(t);
- t = __FractionInstPtr(aNumber)->f_denominator;
- if (__isSmallInteger(t)) {
- INT den = __intVal(t);
- INT myself = __intVal(self);
- INT prod;
+ if (__isFractionLike(aNumber)) {
+ OBJ t = __FractionInstPtr(aNumber)->f_numerator;
+ if (__isSmallInteger(t)) {
+ INT num = __intVal(t);
+ t = __FractionInstPtr(aNumber)->f_denominator;
+ if (__isSmallInteger(t)) {
+ INT den = __intVal(t);
+ INT myself = __intVal(self);
+ INT prod;
#if 0 && defined(__GNUC__) // supported from GCC 5
- if (__builtin_mul_overflow(myself, den, &prod)) {
- RETURN ( __mkSmallInteger(prod / num ));
- }
+ if (__builtin_mul_overflow(myself, den, &prod)) {
+ RETURN ( __mkSmallInteger(prod / num ));
+ }
#else
- prod = myself * den;
- // make sure, that no overflow occurred
- if (prod / den == myself) {
- RETURN ( __mkSmallInteger(prod / num ));
- }
+ prod = myself * den;
+ // make sure, that no overflow occurred
+ if (prod / den == myself) {
+ RETURN ( __mkSmallInteger(prod / num ));
+ }
#endif
- }
- }
- }
+ }
+ }
+ }
}
#endif /* not __SCHTEAM__ */
%}.
(aNumber = 0) ifTrue:[
- ^ ZeroDivide raiseRequestWith:thisContext.
+ ^ ZeroDivide raiseRequestWith:thisContext.
].
^ self retry:#quo: coercing:aNumber
@@ -981,12 +981,12 @@
#else
/* anding the tags doesn't change it */
if (__isSmallInteger(anInteger)) {
- RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) );
+ RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) );
}
#endif /* not __SCHTEAM__ */
%}.
anInteger class == LargeInteger ifTrue:[
- ^ anInteger bitAnd:self
+ ^ anInteger bitAnd:self
].
^ self retry:#bitAnd: coercing:anInteger
@@ -1006,7 +1006,7 @@
#else
/* anding the tags doesn't change it */
if (__isSmallInteger(anInteger)) {
- RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) );
+ RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -1058,8 +1058,8 @@
_cnt = 0;
while (_self) {
- _cnt++;
- _self = _self & (_self - 1);
+ _cnt++;
+ _self = _self & (_self - 1);
}
# else
@@ -1071,8 +1071,8 @@
_cnt = 0;
while (_self) {
- _cnt += table[ _self & 0x0F ];
- _self >>= 4;
+ _cnt += table[ _self & 0x0F ];
+ _self >>= 4;
}
# else
@@ -1109,13 +1109,13 @@
# define _POPCNT(__op) \
({ \
- INT __rslt; \
- asm("xor %%rax,%%rax \n \
- popcnt %1,%%rax \n \
- " : "=a" (__rslt) \
- : "g" ((INT)(__op)) \
- : "cc"); \
- (OBJ)__rslt; \
+ INT __rslt; \
+ asm("xor %%rax,%%rax \n \
+ popcnt %1,%%rax \n \
+ " : "=a" (__rslt) \
+ : "g" ((INT)(__op)) \
+ : "cc"); \
+ (OBJ)__rslt; \
})
_v = (INT)self;
@@ -1124,13 +1124,13 @@
# else
# define _POPCNT(__op) \
({ \
- INT __rslt; \
- asm("xor %%eax,%%eax \n \
- popcnt %1,%%eax \n \
- " : "=a" (__rslt) \
- : "g" ((INT)(__v)) \
- : "cc"); \
- (OBJ)__rslt; \
+ INT __rslt; \
+ asm("xor %%eax,%%eax \n \
+ popcnt %1,%%eax \n \
+ " : "=a" (__rslt) \
+ : "g" ((INT)(__v)) \
+ : "cc"); \
+ (OBJ)__rslt; \
})
_v = (INT)self;
@@ -1152,37 +1152,37 @@
"
1 to:1000000 do:[:n |
- self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
+ self assert:(n bitCount = ((n printStringRadix:2) occurrencesOf:$1))
].
#( 16r00000000
- 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
-
- 16r8000000000010000 16r8000000000100000 16r8000000001000000 16r8000000010000000
- 16r8000000000020000 16r8000000000200000 16r8000000002000000 16r8000000020000000
- 16r8000000000040000 16r8000000000400000 16r8000000004000000 16r8000000040000000
- 16r8000000000080000 16r8000000000800000 16r8000000008000000 16r8000000080000000
-
- 16r80000000FFFFFFFF 16r800000007FFFFFFF 16r800000003FFFFFFF 16r800000001FFFFFFF
- 16r80000000EEEEEEEE 16r800000007EEEEEEE 16r800000003EEEEEEE 16r800000001EEEEEEE
- 16r80000000DDDDDDDD 16r800000007DDDDDDD 16r800000003DDDDDDD 16r800000001DDDDDDD
- 16r80000000CCCCCCCC 16r800000007CCCCCCC 16r800000003CCCCCCC 16r800000001CCCCCCC
-
- 16rFFFFFFFFFFFFFFFF 16r7FFFFFFFFFFFFFFF 16r3FFFFFFFFFFFFFFF 16r1FFFFFFFFFFFFFFF
+ 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
+
+ 16r8000000000010000 16r8000000000100000 16r8000000001000000 16r8000000010000000
+ 16r8000000000020000 16r8000000000200000 16r8000000002000000 16r8000000020000000
+ 16r8000000000040000 16r8000000000400000 16r8000000004000000 16r8000000040000000
+ 16r8000000000080000 16r8000000000800000 16r8000000008000000 16r8000000080000000
+
+ 16r80000000FFFFFFFF 16r800000007FFFFFFF 16r800000003FFFFFFF 16r800000001FFFFFFF
+ 16r80000000EEEEEEEE 16r800000007EEEEEEE 16r800000003EEEEEEE 16r800000001EEEEEEE
+ 16r80000000DDDDDDDD 16r800000007DDDDDDD 16r800000003DDDDDDD 16r800000001DDDDDDD
+ 16r80000000CCCCCCCC 16r800000007CCCCCCC 16r800000003CCCCCCC 16r800000001CCCCCCC
+
+ 16rFFFFFFFFFFFFFFFF 16r7FFFFFFFFFFFFFFF 16r3FFFFFFFFFFFFFFF 16r1FFFFFFFFFFFFFFF
) 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)
]
"
@@ -1243,7 +1243,7 @@
#else
/* oring the tags doesn't change it */
if (__isSmallInteger(anInteger)) {
- RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) );
+ RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -1292,7 +1292,7 @@
# endif
if (v <= _MAX_INT) {
- RETURN ( __mkSmallInteger(v) );
+ RETURN ( __mkSmallInteger(v) );
}
RETURN (__MKUINT(v));
#endif /* not __SCHTEAM__ */
@@ -1325,7 +1325,7 @@
v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
if (v <= _MAX_INT) {
- RETURN ( __mkSmallInteger(v) );
+ RETURN ( __mkSmallInteger(v) );
}
RETURN (__MKUINT(v));
#endif /* not __SCHTEAM__ */
@@ -1360,7 +1360,7 @@
v = ((v >> 16) & 0x0000FFFF) | ((v & 0x0000FFFF) << 16);
if (v <= _MAX_INT) {
- RETURN ( __mkSmallInteger(v) );
+ RETURN ( __mkSmallInteger(v) );
}
RETURN (__MKUINT(v));
#endif /* not __SCHTEAM__ */
@@ -1391,7 +1391,7 @@
v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4);
if (v <= _MAX_INT) {
- RETURN ( __mkSmallInteger(v) );
+ RETURN ( __mkSmallInteger(v) );
}
RETURN (__MKUINT(v));
#endif /* not __SCHTEAM__ */
@@ -1410,9 +1410,9 @@
"return the value of the receiver shifted by shiftCount bits;
leftShift if shiftCount > 0; rightShift 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 */
#ifdef __SCHTEAM__
@@ -1421,80 +1421,80 @@
INT bits, count;
if (__isSmallInteger(shiftCount)) {
- bits = __intVal(self);
- if (bits == 0) {
- RETURN (self);
- }
- count = __intVal(shiftCount);
-
- if (count > 0) {
- INT sign = 1;
- if (bits < 0) {
- bits = -bits;
- sign = -1;
- }
- /*
- * a left shift
- */
+ bits = __intVal(self);
+ if (bits == 0) {
+ RETURN (self);
+ }
+ count = __intVal(shiftCount);
+
+ if (count > 0) {
+ INT sign = 1;
+ if (bits < 0) {
+ bits = -bits;
+ sign = -1;
+ }
+ /*
+ * a left shift
+ */
# if defined(USE_LONGLONG_FOR_SHIFT)
- if (count <= N_INT_BITS) {
- unsigned LONGLONG result;
-
- result = (unsigned LONGLONG)bits;
- result <<= count;
- if (result <= _MAX_INT) {
- if (sign < 0) {
- RETURN ( __MKINT(-result) );
- }
- RETURN ( __mkSmallInteger(result) );
- }
- {
- RETURN (__MKLARGEINT64(sign, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
- }
- }
+ if (count <= N_INT_BITS) {
+ unsigned LONGLONG result;
+
+ result = (unsigned LONGLONG)bits;
+ result <<= count;
+ if (result <= _MAX_INT) {
+ if (sign < 0) {
+ RETURN ( __MKINT(-result) );
+ }
+ RETURN ( __mkSmallInteger(result) );
+ }
+ {
+ RETURN (__MKLARGEINT64(sign, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
+ }
+ }
# else
- /*
- * check for overflow
- */
- if (count < (N_INT_BITS-1)) {
- if (! (bits >> (N_INT_BITS - 1 - count))) {
- INT result = bits << count;
-
- if (sign < 0) {
- RETURN ( __MKINT(-result) );
- }
- RETURN ( __mkSmallInteger(result) );
- }
- /*
- * 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))) {
+ INT result = bits << count;
+
+ if (sign < 0) {
+ RETURN ( __MKINT(-result) );
+ }
+ RETURN ( __mkSmallInteger(result) );
+ }
+ /*
+ * 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 ...
- */
- count = -count;
- 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 ...
+ */
+ count = -count;
+ if (count > (N_INT_BITS-1)) {
+ RETURN (__mkSmallInteger(0));
+ }
+
+ RETURN ( __mkSmallInteger(bits >> count) );
+ }
}
#endif /* not __SCHTEAM__ */
%}.
(shiftCount isMemberOf:SmallInteger) ifTrue:[
- ^ (LargeInteger value:self) bitShift:shiftCount
+ ^ (LargeInteger value:self) bitShift:shiftCount
].
^ self bitShift:shiftCount asInteger "/ is this a good idea ?
!
@@ -1507,18 +1507,18 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
return context._RETURN(
- ( self.bitAnd( aMask ) == STInteger._0 )
- ? STObject.False : STObject.True );
+ ( self.bitAnd( aMask ) == STInteger._0 )
+ ? STObject.False : STObject.True );
/* NOTREACHED */
#else
/* 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 );
}
#endif /* not __SCHTEAM__ */
%}.
aMask class == LargeInteger ifTrue:[
- ^ (aMask bitAnd:self) ~~ 0
+ ^ (aMask bitAnd:self) ~~ 0
].
^ self retry:#bitTest: coercing:aMask
@@ -1542,7 +1542,7 @@
#else
/* xoring the tags turns it off - or it in again */
if (__isSmallInteger(anInteger)) {
- RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) );
+ RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -1557,31 +1557,31 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
{
- long bits = self.longValue();
- int bitNr = 0;
-
- if (bits != 0) {
- if ((bits & 0xFFFFFFFF00000000L) != 0) {
- bitNr += 32; bits >>= 32;
- }
- if ((bits & 0xFFFF0000L) != 0) {
- bitNr += 16; bits >>= 16;
- }
- if ((bits & 0xFF00) != 0) {
- bitNr += 8; bits >>= 8;
- }
- if ((bits & 0xF0) != 0) {
- bitNr += 4; bits >>= 4;
- }
- if ((bits & 0xC) != 0) {
- bitNr += 2; bits >>= 2;
- }
- if ((bits & 0x2) != 0) {
- bitNr += 1; bits >>= 1;
- }
- bitNr += 1;
- }
- return context._RETURN( STInteger._new(bitNr) );
+ long bits = self.longValue();
+ int bitNr = 0;
+
+ if (bits != 0) {
+ if ((bits & 0xFFFFFFFF00000000L) != 0) {
+ bitNr += 32; bits >>= 32;
+ }
+ if ((bits & 0xFFFF0000L) != 0) {
+ bitNr += 16; bits >>= 16;
+ }
+ if ((bits & 0xFF00) != 0) {
+ bitNr += 8; bits >>= 8;
+ }
+ if ((bits & 0xF0) != 0) {
+ bitNr += 4; bits >>= 4;
+ }
+ if ((bits & 0xC) != 0) {
+ bitNr += 2; bits >>= 2;
+ }
+ if ((bits & 0x2) != 0) {
+ bitNr += 1; bits >>= 1;
+ }
+ bitNr += 1;
+ }
+ return context._RETURN( STInteger._new(bitNr) );
}
/* NOTREACHED */
#else
@@ -1590,7 +1590,7 @@
bits = __intVal(self);
if (bits == 0) {
- RETURN ( __mkSmallInteger(0) );
+ RETURN ( __mkSmallInteger(0) );
}
# ifdef __BSR
@@ -1606,23 +1606,23 @@
# if __POINTER_SIZE__ == 8
if (bits & 0xFFFFFFFF00000000L) {
- index += 32; bits >>= 32;
+ index += 32; bits >>= 32;
}
# endif
if (bits & 0xFFFF0000L) {
- index += 16; bits >>= 16;
+ index += 16; bits >>= 16;
}
if (bits & 0xFF00) {
- index += 8; bits >>= 8;
+ index += 8; bits >>= 8;
}
if (bits & 0xF0) {
- index += 4; bits >>= 4;
+ index += 4; bits >>= 4;
}
if (bits & 0xC) {
- index += 2; bits >>= 2;
+ index += 2; bits >>= 2;
}
if (bits & 0x2) {
- index += 1; bits >>= 1;
+ index += 1; bits >>= 1;
}
# endif /* no BSR instruction */
@@ -1640,38 +1640,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
+ ]
]
"
@@ -1695,24 +1695,24 @@
int index = 0;
if (bits != 0) {
- if ((bits & 0xFFFFFFFFL)==0) {
- index += 32; bits >>= 32;
- }
- if ((bits & 0xFFFFL)==0) {
- index += 16; bits >>= 16;
- }
- if ((bits & 0xFFL)==0) {
- index += 8; bits >>= 8;
- }
- if ((bits & 0xFL)==0) {
- index += 4; bits >>= 4;
- }
- if ((bits & 0x3L)==0) {
- index += 2; bits >>= 2;
- }
- if ((bits & 0x1L)==0) {
- index += 1;
- }
+ if ((bits & 0xFFFFFFFFL)==0) {
+ index += 32; bits >>= 32;
+ }
+ if ((bits & 0xFFFFL)==0) {
+ index += 16; bits >>= 16;
+ }
+ if ((bits & 0xFFL)==0) {
+ index += 8; bits >>= 8;
+ }
+ if ((bits & 0xFL)==0) {
+ index += 4; bits >>= 4;
+ }
+ if ((bits & 0x3L)==0) {
+ index += 2; bits >>= 2;
+ }
+ if ((bits & 0x1L)==0) {
+ index += 1;
+ }
}
return __c__._RETURN( STInteger._qnew( index ) );
#else
@@ -1721,7 +1721,7 @@
bits = __intVal(self);
if (bits == 0) {
- RETURN ( __mkSmallInteger(0) );
+ RETURN ( __mkSmallInteger(0) );
}
# ifdef __BSF
@@ -1739,24 +1739,24 @@
# if __POINTER_SIZE__ == 8
if ((bits<<32) == 0) {
- index += 32; bits >>= 32;
+ index += 32; bits >>= 32;
}
# endif
if ((bits & 0xFFFF)==0) {
- index += 16; bits >>= 16;
+ index += 16; bits >>= 16;
}
if ((bits & 0xFF)==0) {
- index += 8; bits >>= 8;
+ index += 8; bits >>= 8;
}
if ((bits & 0xF)==0) {
- index += 4; bits >>= 4;
+ index += 4; bits >>= 4;
}
if ((bits & 0x3)==0) {
- index += 2; bits >>= 2;
+ index += 2; bits >>= 2;
}
if ((bits & 0x1)==0) {
- index += 1;
+ index += 1;
}
# endif
@@ -1780,27 +1780,27 @@
16r1000000000000000 lowBit
Time millisecondsToRun:[
- 1000000 timesRepeat:[
- 2r1000 lowBit
- ]
+ 1000000 timesRepeat:[
+ 2r1000 lowBit
+ ]
]
Time millisecondsToRun:[
- 1000000 timesRepeat:[
- 2r11110000000 lowBit
- ]
+ 1000000 timesRepeat:[
+ 2r11110000000 lowBit
+ ]
]
Time millisecondsToRun:[
- 1000000 timesRepeat:[
- 2r1000000000000 lowBit
- ]
+ 1000000 timesRepeat:[
+ 2r1000000000000 lowBit
+ ]
]
Time millisecondsToRun:[
- 1000000 timesRepeat:[
- 2r1000000000000000000000000000 lowBit
- ]
+ 1000000 timesRepeat:[
+ 2r1000000000000000000000000000 lowBit
+ ]
]
"
!
@@ -1809,9 +1809,9 @@
"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 */
#ifdef __SCHTEAM__
@@ -1819,75 +1819,75 @@
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) );
+ }
}
#endif /* not __SCHTEAM__ */
%}.
(shiftCount isMemberOf:SmallInteger) ifTrue:[
- ^ (LargeInteger value:self) rightShift:shiftCount
+ ^ (LargeInteger value:self) rightShift:shiftCount
].
^ self rightShift:shiftCount asInteger "/ is this a good idea ?
"
- 16 rightShift:2
- 4 rightShift:-2
+ 16 rightShift:2
+ 4 rightShift:-2
"
! !
@@ -1896,28 +1896,28 @@
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 */
#ifdef __SCHTEAM__
return context._RETURN( self.bitAt(anIntegerIndex));
#else
if (__isSmallInteger(anIntegerIndex)) {
- INT idx = __smallIntegerVal(anIntegerIndex);
- if (idx > 0) {
- if (idx > N_INT_BITS) {
- RETURN(__mkSmallInteger(0));
- }
- RETURN((__smallIntegerVal(self) & ((INT)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) & ((INT)1 << (idx-1))) ? __mkSmallInteger(1) : __mkSmallInteger(0));
+ }
}
#endif /* not __SCHTEAM__ */
%}.
^ SubscriptOutOfBoundsError
- raiseRequestWith:anIntegerIndex
- errorString:'index out of bounds'
+ raiseRequestWith:anIntegerIndex
+ errorString:'index out of bounds'
"
16r000000001 bitAt:0 -> error
@@ -1937,9 +1937,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).
@@ -1957,21 +1957,21 @@
%{ /* NOCONTEXT */
#ifndef __SCHTEAM__
if (__isSmallInteger(anInteger)) {
- int index = __intVal(anInteger);
-
- if (index > 0) {
+ int index = __intVal(anInteger);
+
+ if (index > 0) {
# if __POINTER_SIZE__ == 8
- if (index <= 62)
+ if (index <= 62)
# else
- if (index <= 30)
+ if (index <= 30)
# endif
- {
- INT mask = __MASKSMALLINT( ((INT)1 << (index-1)));
-
- RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
- }
- RETURN (self); /* nothing to do ... */
- }
+ {
+ INT mask = __MASKSMALLINT( ((INT)1 << (index-1)));
+
+ RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) );
+ }
+ RETURN (self); /* nothing to do ... */
+ }
}
#endif /* not __SCHTEAM__ */
%}.
@@ -2005,20 +2005,20 @@
%{ /* NOCONTEXT */
#ifndef __SCHTEAM__
if (__isSmallInteger(anInteger)) {
- int index = __intVal(anInteger);
-
- if (index > 0) {
+ int index = __intVal(anInteger);
+
+ if (index > 0) {
# if __POINTER_SIZE__ == 8
- if (index <= 62)
+ if (index <= 62)
# else
- if (index <= 30)
+ if (index <= 30)
# endif
- {
- INT mask = __MASKSMALLINT((INT)1 << (index-1));
-
- RETURN ( ((OBJ) ((INT)self ^ (INT)mask)) );
- }
- }
+ {
+ INT mask = __MASKSMALLINT((INT)1 << (index-1));
+
+ RETURN ( ((OBJ) ((INT)self ^ (INT)mask)) );
+ }
+ }
}
#endif /* not __SCHTEAM__ */
%}.
@@ -2047,20 +2047,20 @@
%{ /* NOCONTEXT */
#ifndef __SCHTEAM__
if (__isSmallInteger(anInteger)) {
- int index = __intVal(anInteger);
-
- if (index > 0) {
+ int index = __intVal(anInteger);
+
+ if (index > 0) {
# if __POINTER_SIZE__ == 8
- if (index <= 62)
+ if (index <= 62)
# else
- if (index <= 30)
+ if (index <= 30)
# endif
- {
- INT mask = __MASKSMALLINT((INT)1 << (index-1));
-
- RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
- }
- }
+ {
+ INT mask = __MASKSMALLINT((INT)1 << (index-1));
+
+ RETURN ( ((OBJ) ((INT)self | (INT)mask)) );
+ }
+ }
}
#endif /* not __SCHTEAM__ */
%}.
@@ -2086,9 +2086,9 @@
i.e. a.b.c.d -> d.c.b.a"
SmallInteger maxBytes == 8 ifTrue:[
- ^ self byteSwapped64
+ ^ self byteSwapped64
] ifFalse:[
- ^ self byteSwapped32
+ ^ self byteSwapped32
].
"
@@ -2139,31 +2139,31 @@
# define HAVE_BSWAP
_asm {
- mov eax, v
- bswap eax
- mov swapped, eax
+ mov eax, v
+ bswap eax
+ mov swapped, eax
};
# endif
# if defined(USE_BSWAP) && defined(__VISUALC__)
# define HAVE_BSWAP
_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
# if defined(USE_BSWAP) && defined(__GNUC__)
# define HAVE_BSWAP
asm("movl %1, %%eax \n\
- bswap %%eax \n\
- movl %%eax, %0 \n\
- "
- : "=rm" (swapped)
- : "rm" (v));
+ bswap %%eax \n\
+ movl %%eax, %0 \n\
+ "
+ : "=rm" (swapped)
+ : "rm" (v));
# endif
# endif /* __POINTER_SIZE__ == 4 */
@@ -2174,11 +2174,11 @@
# define HAVE_BSWAP
asm("movq %1, %%rax \n\
- bswap %%eax \n\
- movq %%rax, %0 \n\
- "
- : "=rm" (swapped)
- : "rm" (v));
+ bswap %%eax \n\
+ movq %%rax, %0 \n\
+ "
+ : "=rm" (swapped)
+ : "rm" (v));
# endif
# endif
@@ -2222,8 +2222,8 @@
// xxxxxxxx xxxxxxxx
// xxxxxxxx xxxxxxxx
swapped = (v>>56) | ((v>>40)&0xFF00) | ((v>>24) & 0xFF0000) | ((v>>8) & 0xFF000000)
- | ((v & 0xFF000000)<<8) | ((v & 0x00FF0000)<<24) | ((v & 0x0000FF00)<<40)
- | ((v & 0xFF)<<56);
+ | ((v & 0xFF000000)<<8) | ((v & 0x00FF0000)<<24) | ((v & 0x0000FF00)<<40)
+ | ((v & 0xFF)<<56);
# endif
RETURN(__MKUINT( swapped ));
#endif /* not __SCHTEAM__ */
@@ -2246,65 +2246,65 @@
int idx0Based = index.intValue() - 1;
if (idx0Based <= 7) {
- long myVal = self.longValue();
- if (myVal < 0) {
- myVal = -myVal;
- }
- int byteVal = (int)((myVal >> (idx0Based * 8)) & 0xFF);
- return __c__._RETURN( STInteger._qnew(byteVal) );
+ long myVal = self.longValue();
+ if (myVal < 0) {
+ myVal = -myVal;
+ }
+ int byteVal = (int)((myVal >> (idx0Based * 8)) & 0xFF);
+ return __c__._RETURN( STInteger._qnew(byteVal) );
}
if (idx0Based > 0) {
- return __c__._RETURN( STInteger._0 );
+ return __c__._RETURN( STInteger._0 );
}
#else
REGISTER INT val;
INT idx;
if (__isSmallInteger(index)) {
- val = __intVal(self);
- if (val < 0)
- val = -val;
- switch (idx = __intVal(index)) {
- case 1:
- break;
- case 2:
- val = (val >> 8);
- break;
- case 3:
- val = (val >> 16);
- break;
- case 4:
- val = (val >> 24);
- break;
+ val = __intVal(self);
+ if (val < 0)
+ val = -val;
+ switch (idx = __intVal(index)) {
+ case 1:
+ break;
+ case 2:
+ val = (val >> 8);
+ break;
+ case 3:
+ val = (val >> 16);
+ break;
+ case 4:
+ val = (val >> 24);
+ break;
# if __POINTER_SIZE__ == 8
- case 5:
- val = (val >> 32);
- break;
- case 6:
- val = (val >> 40);
- break;
- case 7:
- val = (val >> 48);
- break;
- case 8:
- val = (val >> 56);
- break;
+ case 5:
+ val = (val >> 32);
+ break;
+ case 6:
+ val = (val >> 40);
+ break;
+ case 7:
+ val = (val >> 48);
+ break;
+ case 8:
+ val = (val >> 56);
+ break;
# endif
- default:
- if (idx < 1)
- goto bad; /* sorry */
- RETURN (__mkSmallInteger(0));
- }
- RETURN ( __mkSmallInteger( val & 0xFF) );
+ default:
+ if (idx < 1)
+ goto bad; /* sorry */
+ RETURN (__mkSmallInteger(0));
+ }
+ RETURN ( __mkSmallInteger( val & 0xFF) );
}
bad: ;
#endif /* not __SCHTEAM__ */
%}.
index > 0 ifFalse:[
- "
- index less than 1 - not allowed
- "
- ^ self primitiveFailed
+ "
+ index less than 1 - not allowed
+ "
+ ^ self primitiveFailed
].
^ 0
@@ -2328,66 +2328,66 @@
long myVal = self.longValue();
if (idx0Based <= 7) {
- int byteVal = (int)((myVal >> (idx0Based * 8)) & 0xFF);
- return __c__._RETURN( STInteger._qnew(byteVal) );
+ int byteVal = (int)((myVal >> (idx0Based * 8)) & 0xFF);
+ return __c__._RETURN( STInteger._qnew(byteVal) );
}
if (idx0Based > 0) {
- if (myVal < 0) {
- return __c__._RETURN( STInteger._M1 );
- } else {
- return __c__._RETURN( STInteger._0 );
- }
+ if (myVal < 0) {
+ return __c__._RETURN( STInteger._M1 );
+ } else {
+ return __c__._RETURN( STInteger._0 );
+ }
}
#else
REGISTER INT val;
INT idx;
if (__isSmallInteger(index)) {
- val = __intVal(self);
- switch (idx = __intVal(index)) {
- case 1:
- break;
- case 2:
- val = (val >> 8);
- break;
- case 3:
- val = (val >> 16);
- break;
- case 4:
- val = (val >> 24);
- break;
+ val = __intVal(self);
+ switch (idx = __intVal(index)) {
+ case 1:
+ break;
+ case 2:
+ val = (val >> 8);
+ break;
+ case 3:
+ val = (val >> 16);
+ break;
+ case 4:
+ val = (val >> 24);
+ break;
# if __POINTER_SIZE__ == 8
- case 5:
- val = (val >> 32);
- break;
- case 6:
- val = (val >> 40);
- break;
- case 7:
- val = (val >> 48);
- break;
- case 8:
- val = (val >> 56);
- break;
+ case 5:
+ val = (val >> 32);
+ break;
+ case 6:
+ val = (val >> 40);
+ break;
+ case 7:
+ val = (val >> 48);
+ break;
+ case 8:
+ val = (val >> 56);
+ break;
# endif
- default:
- if (idx < 1)
- goto bad; /* sorry */
- if (val < 0) {
- RETURN (__mkSmallInteger(0xFF));
- }
- RETURN (__mkSmallInteger(0));
- }
- RETURN ( __mkSmallInteger( val & 0xFF) );
+ default:
+ if (idx < 1)
+ goto bad; /* sorry */
+ if (val < 0) {
+ RETURN (__mkSmallInteger(0xFF));
+ }
+ RETURN (__mkSmallInteger(0));
+ }
+ RETURN ( __mkSmallInteger( val & 0xFF) );
}
bad: ;
#endif /* not __SCHTEAM__ */
%}.
index > 0 ifFalse:[
- "
- index less than 1 - not allowed
- "
- ^ self primitiveFailed
+ "
+ index less than 1 - not allowed
+ "
+ ^ self primitiveFailed
].
^ 0
@@ -2419,83 +2419,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
@@ -2527,83 +2527,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:b2 with:b1
- ] ifFalse:[
- b3 := absValue bitAnd:16rFF.
- absValue := absValue bitShift:-8.
- absValue == 0 ifTrue:[
- digitByteArray := ByteArray with:b3 with:b2 with:b1
- ] ifFalse:[
- b4 := absValue bitAnd:16rFF.
- absValue := absValue bitShift:-8.
- absValue == 0 ifTrue:[
- digitByteArray := ByteArray with:b4 with:b3 with:b2 with:b1
- ] ifFalse:[
- b5 := absValue bitAnd:16rFF.
- absValue := absValue bitShift:-8.
- absValue == 0 ifTrue:[
- digitByteArray := ByteArray new:5.
- digitByteArray at:1 put:b5.
- digitByteArray at:2 put:b4.
- digitByteArray at:3 put:b3.
- digitByteArray at:4 put:b2.
- digitByteArray at:5 put:b1.
- ] ifFalse:[
- b6 := absValue bitAnd:16rFF.
- absValue := absValue bitShift:-8.
- absValue == 0 ifTrue:[
- digitByteArray := ByteArray new:6.
- digitByteArray at:1 put:b6.
- digitByteArray at:2 put:b5.
- digitByteArray at:3 put:b4.
- digitByteArray at:4 put:b3.
- digitByteArray at:5 put:b2.
- digitByteArray at:6 put:b1.
- ] ifFalse:[
- b7 := absValue bitAnd:16rFF.
- absValue := absValue bitShift:-8.
- absValue == 0 ifTrue:[
- digitByteArray := ByteArray new:7.
- digitByteArray at:1 put:b7.
- digitByteArray at:2 put:b6.
- digitByteArray at:3 put:b5.
- digitByteArray at:4 put:b4.
- digitByteArray at:5 put:b3.
- digitByteArray at:6 put:b2.
- digitByteArray at:7 put:b1.
- ] ifFalse:[
- digitByteArray := ByteArray new:8.
- digitByteArray at:1 put:absValue.
- digitByteArray at:2 put:b7.
- digitByteArray at:3 put:b6.
- digitByteArray at:4 put:b5.
- digitByteArray at:5 put:b4.
- digitByteArray at:6 put:b3.
- digitByteArray at:7 put:b2.
- digitByteArray at:8 put:b1.
- ]
- ]
- ]
- ]
- ]
- ]
+ b2 := absValue bitAnd:16rFF.
+ absValue := absValue bitShift:-8.
+ absValue == 0 ifTrue:[
+ digitByteArray := ByteArray with:b2 with:b1
+ ] ifFalse:[
+ b3 := absValue bitAnd:16rFF.
+ absValue := absValue bitShift:-8.
+ absValue == 0 ifTrue:[
+ digitByteArray := ByteArray with:b3 with:b2 with:b1
+ ] ifFalse:[
+ b4 := absValue bitAnd:16rFF.
+ absValue := absValue bitShift:-8.
+ absValue == 0 ifTrue:[
+ digitByteArray := ByteArray with:b4 with:b3 with:b2 with:b1
+ ] ifFalse:[
+ b5 := absValue bitAnd:16rFF.
+ absValue := absValue bitShift:-8.
+ absValue == 0 ifTrue:[
+ digitByteArray := ByteArray new:5.
+ digitByteArray at:1 put:b5.
+ digitByteArray at:2 put:b4.
+ digitByteArray at:3 put:b3.
+ digitByteArray at:4 put:b2.
+ digitByteArray at:5 put:b1.
+ ] ifFalse:[
+ b6 := absValue bitAnd:16rFF.
+ absValue := absValue bitShift:-8.
+ absValue == 0 ifTrue:[
+ digitByteArray := ByteArray new:6.
+ digitByteArray at:1 put:b6.
+ digitByteArray at:2 put:b5.
+ digitByteArray at:3 put:b4.
+ digitByteArray at:4 put:b3.
+ digitByteArray at:5 put:b2.
+ digitByteArray at:6 put:b1.
+ ] ifFalse:[
+ b7 := absValue bitAnd:16rFF.
+ absValue := absValue bitShift:-8.
+ absValue == 0 ifTrue:[
+ digitByteArray := ByteArray new:7.
+ digitByteArray at:1 put:b7.
+ digitByteArray at:2 put:b6.
+ digitByteArray at:3 put:b5.
+ digitByteArray at:4 put:b4.
+ digitByteArray at:5 put:b3.
+ digitByteArray at:6 put:b2.
+ digitByteArray at:7 put:b1.
+ ] ifFalse:[
+ digitByteArray := ByteArray new:8.
+ digitByteArray at:1 put:absValue.
+ digitByteArray at:2 put:b7.
+ digitByteArray at:3 put:b6.
+ digitByteArray at:4 put:b5.
+ digitByteArray at:5 put:b4.
+ digitByteArray at:6 put:b3.
+ digitByteArray at:7 put:b2.
+ digitByteArray at:8 put:b1.
+ ]
+ ]
+ ]
+ ]
+ ]
+ ]
].
^ digitByteArray
@@ -2627,21 +2627,21 @@
if (val < 0) val = -val;
if ((val & 0xFFFFFFFF00000000L) != 0) {
- val >>= 32;
- offs = 4;
+ val >>= 32;
+ offs = 4;
}
if ((val & 0xFFFF0000) != 0) {
- if ((val & 0xFF000000) != 0) {
- offs += 4;
- } else {
- offs += 3;
- }
+ if ((val & 0xFF000000) != 0) {
+ offs += 4;
+ } else {
+ offs += 3;
+ }
} else {
- if ((val & 0x0000FF00)!= 0) {
- offs += 2;
- } else {
- offs += 1;
- }
+ if ((val & 0x0000FF00)!= 0) {
+ offs += 2;
+ } else {
+ offs += 1;
+ }
}
return __c__._RETURN( STInteger._qnew(offs) );
#else
@@ -2649,27 +2649,27 @@
int offs = 0;
if (val < 0) {
- val = -val;
+ val = -val;
}
# if __POINTER_SIZE__ == 8
if (val & 0xFFFFFFFF00000000L) {
- val >>= 32;
- offs = 4;
+ val >>= 32;
+ offs = 4;
}
# endif
if (val & 0xFFFF0000) {
- if (val & 0xFF000000) {
- RETURN ( __mkSmallInteger(4+offs));
- } else {
- RETURN ( __mkSmallInteger(3+offs));
- }
+ if (val & 0xFF000000) {
+ RETURN ( __mkSmallInteger(4+offs));
+ } else {
+ RETURN ( __mkSmallInteger(3+offs));
+ }
} else {
- if (val & 0x0000FF00) {
- RETURN ( __mkSmallInteger(2+offs));
- } else {
- RETURN ( __mkSmallInteger(1+offs));
- }
+ if (val & 0x0000FF00) {
+ RETURN ( __mkSmallInteger(2+offs));
+ } else {
+ RETURN ( __mkSmallInteger(1+offs));
+ }
}
#endif /* not SCHTEAM */
%}.
@@ -2705,19 +2705,19 @@
unsigned INT v = __intVal(self);
if ((INT)v >= 0) {
- unsigned INT swapped;
+ unsigned INT swapped;
# if __POINTER_SIZE__ == 8
- swapped = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
+ swapped = ((v >> 8) & 0x00FF00FF00FF00FF) | ((v & 0x00FF00FF00FF00FF) << 8);
# else
- swapped = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
+ swapped = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8);
# endif /* __POINTER_SIZE__ */
- //if (__ISVALIDINTEGER(swapped)) { // sorry, but this does not work here if (INT)swapped would be negative
- if (swapped <= _MAX_INT) {
- RETURN ( __mkSmallInteger(swapped) );
- }
- RETURN (__MKUINT(swapped));
+ //if (__ISVALIDINTEGER(swapped)) { // sorry, but this does not work here if (INT)swapped would be negative
+ if (swapped <= _MAX_INT) {
+ RETURN ( __mkSmallInteger(swapped) );
+ }
+ RETURN (__MKUINT(swapped));
}
#endif
%}.
@@ -2876,9 +2876,9 @@
INT i = __intVal(self);
if (i & 0x800000L) {
- i = i | ~((INT)0xFFFFFF);
+ i = i | ~((INT)0xFFFFFF);
} else {
- i = i & 0x7FFFFF;
+ i = i & 0x7FFFFF;
}
RETURN (__mkSmallInteger(i));
@@ -2902,9 +2902,9 @@
INT i = __intVal(self);
if (i & 0x80) {
- i = i | ~((INT)0xFF);
+ i = i | ~((INT)0xFF);
} else {
- i = i & 0x7F;
+ i = i & 0x7F;
}
RETURN (__mkSmallInteger(i));
@@ -2928,9 +2928,9 @@
INT i = __intVal(self);
if (i & 0x80000000L) {
- i = i | ~((INT)0xFFFFFFFF);
+ i = i | ~((INT)0xFFFFFFFF);
} else {
- i = i & 0x7FFFFFFFL;
+ i = i & 0x7FFFFFFFL;
}
RETURN (__MKINT(i));
@@ -2954,9 +2954,9 @@
INT i = __intVal(self);
if (i & 0x8000) {
- i = i | ~((INT)0xFFFF);
+ i = i | ~((INT)0xFFFF);
} else {
- i = i & 0x7FFF;
+ i = i & 0x7FFF;
}
RETURN (__mkSmallInteger(i));
@@ -2982,14 +2982,14 @@
#else
if (__isSmallInteger(aNumber)) {
# ifdef POSITIVE_ADDRESSES
- RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false );
+ RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false );
# else
- /* tag bit does not change ordering */
- RETURN ( ((INT)self < (INT)aNumber) ? true : false );
+ /* tag bit does not change ordering */
+ RETURN ( ((INT)self < (INT)aNumber) ? true : false );
# endif
}
if (__isFloatLike(aNumber)) {
- RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false );
+ RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3007,14 +3007,14 @@
if (__isSmallInteger(aNumber)) {
# ifdef POSITIVE_ADDRESSES
- RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false );
+ RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false );
# else
- /* tag bit does not change ordering */
- RETURN ( ((INT)self <= (INT)aNumber) ? true : false );
+ /* tag bit does not change ordering */
+ RETURN ( ((INT)self <= (INT)aNumber) ? true : false );
# endif
}
if (__isFloatLike(aNumber)) {
- RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false );
+ RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3030,23 +3030,23 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( aNumber.eqvP( self.longValue() ));
+ return context._RETURN( aNumber.eqvP( self.longValue() ));
}
#else
if (aNumber == self) {
- RETURN ( true );
+ RETURN ( true );
}
if (! __isNonNilObject(aNumber)) {
- /* a smallint or nil */
- RETURN ( false );
+ /* a smallint or nil */
+ RETURN ( false );
}
if (__qIsFloatLike(aNumber)) {
- RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false );
+ RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false );
}
if (__qIsShortFloat(aNumber)) {
- RETURN ( ((double)__intVal(self) == __shortFloatVal(aNumber)) ? true : false );
+ RETURN ( ((double)__intVal(self) == __shortFloatVal(aNumber)) ? true : false );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3063,14 +3063,14 @@
if (__isSmallInteger(aNumber)) {
# ifdef POSITIVE_ADDRESSES
- RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false );
+ RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false );
# else
- /* tag bit does not change ordering */
- RETURN ( ((INT)self > (INT)aNumber) ? true : false );
+ /* tag bit does not change ordering */
+ RETURN ( ((INT)self > (INT)aNumber) ? true : false );
# endif
}
if (__isFloatLike(aNumber)) {
- RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false );
+ RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3089,14 +3089,14 @@
if (__isSmallInteger(aNumber)) {
# ifdef POSITIVE_ADDRESSES
- RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false );
+ RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false );
# else
- /* tag bit does not change ordering */
- RETURN ( ((INT)self >= (INT)aNumber) ? true : false );
+ /* tag bit does not change ordering */
+ RETURN ( ((INT)self >= (INT)aNumber) ? true : false );
# endif
}
if (__isFloatLike(aNumber)) {
- RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false );
+ RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3120,7 +3120,7 @@
low := self bitAnd: 16r3FFF.
^ (9741 * low
+ ((9741 * (self bitShift: -14) + (101 * low) bitAnd: 16383) * 16384))
- bitAnd: 16r0FFFFFFF
+ bitAnd: 16r0FFFFFFF
"
1 hashMultiply
@@ -3147,21 +3147,21 @@
if (__isSmallInteger(aNumber)) {
# if TAG_INT == 1
- /* tag bit does not change ordering */
- if ((INT)(self) > (INT)(aNumber))
+ /* tag bit does not change ordering */
+ if ((INT)(self) > (INT)(aNumber))
# else
- if (__intVal(self) > __intVal(aNumber))
+ if (__intVal(self) > __intVal(aNumber))
# endif
- {
- RETURN ( self );
- }
- RETURN ( aNumber );
+ {
+ RETURN ( self );
+ }
+ RETURN ( aNumber );
}
if (__isFloatLike(aNumber)) {
- if ( (double)__intVal(self) > __floatVal(aNumber) ) {
- RETURN ( self );
- }
- RETURN ( aNumber );
+ if ( (double)__intVal(self) > __floatVal(aNumber) ) {
+ RETURN ( self );
+ }
+ RETURN ( aNumber );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3179,21 +3179,21 @@
if (__isSmallInteger(aNumber)) {
# if TAG_INT == 1
- /* tag bit does not change ordering */
- if ((INT)(self) < (INT)(aNumber))
+ /* tag bit does not change ordering */
+ if ((INT)(self) < (INT)(aNumber))
# else
- if (__intVal(self) < __intVal(aNumber))
+ if (__intVal(self) < __intVal(aNumber))
# endif
- {
- RETURN ( self );
- }
- RETURN ( aNumber );
+ {
+ RETURN ( self );
+ }
+ RETURN ( aNumber );
}
if (__isFloatLike(aNumber)) {
- if ( (double)__intVal(self) < __floatVal(aNumber) ) {
- RETURN ( self );
- }
- RETURN ( aNumber );
+ if ( (double)__intVal(self) < __floatVal(aNumber) ) {
+ RETURN ( self );
+ }
+ RETURN ( aNumber );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3209,24 +3209,24 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (aNumber.isNumber()) {
- return context._RETURN( (aNumber.isEqv( self.longValue() )) ? STObject.False : STObject.True);
- /* NOTREACHED */
+ return context._RETURN( (aNumber.isEqv( self.longValue() )) ? STObject.False : STObject.True);
+ /* NOTREACHED */
}
#else
if (aNumber == self) {
- RETURN ( false );
+ RETURN ( false );
}
if (! __isNonNilObject(aNumber)) {
- /* a smallint or nil */
- RETURN ( true );
+ /* a smallint or nil */
+ RETURN ( true );
}
if (__qIsFloatLike(aNumber)) {
- RETURN ( ((double)__intVal(self) != __floatVal(aNumber)) ? true : false );
+ RETURN ( ((double)__intVal(self) != __floatVal(aNumber)) ? true : false );
}
if (__qIsShortFloat(aNumber)) {
- RETURN ( ((double)__intVal(self) != __shortFloatVal(aNumber)) ? true : false );
+ RETURN ( ((double)__intVal(self) != __shortFloatVal(aNumber)) ? true : false );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3277,20 +3277,20 @@
tmp = __intVal(self);
if (tmp > 0) {
- if (__isBlockLike(aBlock)
- && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(0))) {
- {
- REGISTER OBJFUNC codeVal;
-
- /*
- * specially tuned version for compiled blocks,
- * (the most common case)
- */
- if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
+ if (__isBlockLike(aBlock)
+ && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(0))) {
+ {
+ REGISTER OBJFUNC codeVal;
+
+ /*
+ * specially tuned version for compiled blocks,
+ * (the most common case)
+ */
+ if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
# ifdef PARANOIA
- && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
+ && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
# endif
- ) {
+ ) {
# ifdef NEW_BLOCK_CALL
@@ -3299,80 +3299,80 @@
# else
# define BLOCK_ARG rHome
- REGISTER OBJ rHome;
-
- /*
- * home on stack - no need to refetch
- */
- rHome = __BlockInstPtr(aBlock)->b_home;
- if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
+ REGISTER OBJ rHome;
+
+ /*
+ * home on stack - no need to refetch
+ */
+ rHome = __BlockInstPtr(aBlock)->b_home;
+ if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
# endif
- {
+ {
# ifdef __UNROLL_LOOPS__
- /*
- * you are not supposed to program like this - I know what I do
- */
- while (tmp > 8) {
- if (InterruptPending != nil) goto interrupted0;
- continue0:
- (*codeVal)(BLOCK_ARG);
- if (InterruptPending != nil) goto interrupted1;
- continue1:
- (*codeVal)(BLOCK_ARG);
- if (InterruptPending != nil) goto interrupted2;
- continue2:
- (*codeVal)(BLOCK_ARG);
- if (InterruptPending != nil) goto interrupted3;
- continue3:
- (*codeVal)(BLOCK_ARG);
- if (InterruptPending != nil) goto interrupted4;
- continue4:
- (*codeVal)(BLOCK_ARG);
- if (InterruptPending != nil) goto interrupted5;
- continue5:
- (*codeVal)(BLOCK_ARG);
- if (InterruptPending != nil) goto interrupted6;
- continue6:
- (*codeVal)(BLOCK_ARG);
- if (InterruptPending != nil) goto interrupted7;
- continue7:
- (*codeVal)(BLOCK_ARG);
- tmp -= 8;
- }
+ /*
+ * you are not supposed to program like this - I know what I do
+ */
+ while (tmp > 8) {
+ if (InterruptPending != nil) goto interrupted0;
+ continue0:
+ (*codeVal)(BLOCK_ARG);
+ if (InterruptPending != nil) goto interrupted1;
+ continue1:
+ (*codeVal)(BLOCK_ARG);
+ if (InterruptPending != nil) goto interrupted2;
+ continue2:
+ (*codeVal)(BLOCK_ARG);
+ if (InterruptPending != nil) goto interrupted3;
+ continue3:
+ (*codeVal)(BLOCK_ARG);
+ if (InterruptPending != nil) goto interrupted4;
+ continue4:
+ (*codeVal)(BLOCK_ARG);
+ if (InterruptPending != nil) goto interrupted5;
+ continue5:
+ (*codeVal)(BLOCK_ARG);
+ if (InterruptPending != nil) goto interrupted6;
+ continue6:
+ (*codeVal)(BLOCK_ARG);
+ if (InterruptPending != nil) goto interrupted7;
+ continue7:
+ (*codeVal)(BLOCK_ARG);
+ tmp -= 8;
+ }
# endif /* __UNROLL_LOOPS__ */
- do {
- if (InterruptPending != nil) goto interruptedX;
- continueX:
- (*codeVal)(BLOCK_ARG);
- } while(--tmp);
-
- RETURN (self);
- if (0) {
+ do {
+ if (InterruptPending != nil) goto interruptedX;
+ continueX:
+ (*codeVal)(BLOCK_ARG);
+ } while(--tmp);
+
+ RETURN (self);
+ if (0) {
# ifdef __UNROLL_LOOPS__
- interrupted0:
- __interruptL(@line); goto continue0;
- interrupted1:
- __interruptL(@line); goto continue1;
- interrupted2:
- __interruptL(@line); goto continue2;
- interrupted3:
- __interruptL(@line); goto continue3;
- interrupted4:
- __interruptL(@line); goto continue4;
- interrupted5:
- __interruptL(@line); goto continue5;
- interrupted6:
- __interruptL(@line); goto continue6;
- interrupted7:
- __interruptL(@line); goto continue7;
+ interrupted0:
+ __interruptL(@line); goto continue0;
+ interrupted1:
+ __interruptL(@line); goto continue1;
+ interrupted2:
+ __interruptL(@line); goto continue2;
+ interrupted3:
+ __interruptL(@line); goto continue3;
+ interrupted4:
+ __interruptL(@line); goto continue4;
+ interrupted5:
+ __interruptL(@line); goto continue5;
+ interrupted6:
+ __interruptL(@line); goto continue6;
+ interrupted7:
+ __interruptL(@line); goto continue7;
# endif /* __UNROLL_LOOPS__ */
- interruptedX:
- __interruptL(@line); goto continueX;
- }
- }
- }
- }
+ interruptedX:
+ __interruptL(@line); goto continueX;
+ }
+ }
+ }
+ }
# undef BLOCK_ARG
@@ -3384,58 +3384,58 @@
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
# endif
- /*
- * sorry - must check for the blocks code within the loops;
- * it could be recompiled or flushed (in the interrupt)
- */
- do {
- REGISTER OBJFUNC codeVal;
-
- if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
- /*
- * arg is a compiled block with code -
- * directly call it without going through Block>>value
- * however, if there is an interrupt, refetch the code pointer.
- */
- /* stay here, while no interrupts are pending ... */
- do {
- (*codeVal)(BLOCK_ARG);
- if (InterruptPending != nil) goto outerLoop;
- } while (--tmp);
- RETURN (self);
- } else {
- if (InterruptPending != nil) __interruptL(@line);
-
- if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
- /*
- * arg is a compiled block with bytecode -
- * directly call interpreter without going through Block>>value
- */
- __interpret(aBlock, 0, nil, IBLOCK_ARG, nil, nil);
- } else {
- /*
- * arg is something else - call it with #value
- */
- (*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
- }
- }
+ /*
+ * sorry - must check for the blocks code within the loops;
+ * it could be recompiled or flushed (in the interrupt)
+ */
+ do {
+ REGISTER OBJFUNC codeVal;
+
+ if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
+ /*
+ * arg is a compiled block with code -
+ * directly call it without going through Block>>value
+ * however, if there is an interrupt, refetch the code pointer.
+ */
+ /* stay here, while no interrupts are pending ... */
+ do {
+ (*codeVal)(BLOCK_ARG);
+ if (InterruptPending != nil) goto outerLoop;
+ } while (--tmp);
+ RETURN (self);
+ } else {
+ if (InterruptPending != nil) __interruptL(@line);
+
+ if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
+ /*
+ * arg is a compiled block with bytecode -
+ * directly call interpreter without going through Block>>value
+ */
+ __interpret(aBlock, 0, nil, IBLOCK_ARG, nil, nil);
+ } else {
+ /*
+ * arg is something else - call it with #value
+ */
+ (*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
+ }
+ }
outerLoop: ;
- } while (--tmp);
+ } while (--tmp);
# undef BLOCK_ARG
# undef IBLOCK_ARG
- RETURN (self);
- }
-
- /*
- * not a block-like thingy - call it with #value
- */
- do {
- if (InterruptPending != nil) __interruptL(@line);
- (*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
- } while(--tmp);
- RETURN (self);
+ RETURN (self);
+ }
+
+ /*
+ * not a block-like thingy - call it with #value
+ */
+ do {
+ if (InterruptPending != nil) __interruptL(@line);
+ (*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal);
+ } while(--tmp);
+ RETURN (self);
}
#endif
%}.
@@ -3460,24 +3460,24 @@
static struct inlineCache blockVal = __ILC1(0);
if (__bothSmallInteger(incr, stop)) {
- tmp = __intVal(self);
- final = __intVal(stop);
- step = __intVal(incr);
-
- if (__isBlockLike(aBlock)
- && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
- {
- REGISTER OBJFUNC codeVal;
-
- /*
- * specially tuned version for static compiled blocks, called with
- * home on the stack (the most common case)
- */
- if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
+ tmp = __intVal(self);
+ final = __intVal(stop);
+ step = __intVal(incr);
+
+ if (__isBlockLike(aBlock)
+ && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
+ {
+ REGISTER OBJFUNC codeVal;
+
+ /*
+ * specially tuned version for static compiled blocks, called with
+ * home on the stack (the most common case)
+ */
+ if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
# ifdef PARANOIA
- && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
+ && (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
# endif
- ) {
+ ) {
# ifdef NEW_BLOCK_CALL
@@ -3486,50 +3486,50 @@
# else
# define BLOCK_ARG rHome
- REGISTER OBJ rHome;
- rHome = __BlockInstPtr(aBlock)->b_home;
- if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
+ REGISTER OBJ rHome;
+ rHome = __BlockInstPtr(aBlock)->b_home;
+ if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
# endif
- {
- if (step < 0) {
- if (step == -1) {
- while (tmp >= final) {
- if (InterruptPending != nil) __interruptL(@line);
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- tmp--;
- }
- } else {
- while (tmp >= final) {
- if (InterruptPending != nil) __interruptL(@line);
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- tmp += step;
- }
- }
- } else {
- if (step == 1) {
- while (tmp <= final) {
- if (InterruptPending != nil) __interruptL(@line);
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- tmp++;
- }
- } else {
- while (tmp <= final) {
- if (InterruptPending != nil) __interruptL(@line);
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- tmp += step;
- }
- }
- }
- RETURN (self);
- }
- }
- }
-
- /*
- * sorry - must check for the blocks code within the loops;
- * it could be recompiled or flushed (in the interrupt)
- */
+ {
+ if (step < 0) {
+ if (step == -1) {
+ while (tmp >= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ tmp--;
+ }
+ } else {
+ while (tmp >= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ tmp += step;
+ }
+ }
+ } else {
+ if (step == 1) {
+ while (tmp <= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ tmp++;
+ }
+ } else {
+ while (tmp <= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ tmp += step;
+ }
+ }
+ }
+ RETURN (self);
+ }
+ }
+ }
+
+ /*
+ * sorry - must check for the blocks code within the loops;
+ * it could be recompiled or flushed (in the interrupt)
+ */
# undef BLOCK_ARG
@@ -3541,114 +3541,114 @@
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
# endif
- if (step < 0) {
- while (tmp >= final) {
- REGISTER OBJFUNC codeVal;
-
- if (InterruptPending != nil) __interruptL(@line);
-
- if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
- /*
- * arg is a compiled block with code -
- * directly call it without going through Block>>value
- */
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- } else {
- if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
- /*
- * arg is a compiled block with bytecode -
- * directly call interpreter without going through Block>>value
- */
+ if (step < 0) {
+ while (tmp >= final) {
+ REGISTER OBJFUNC codeVal;
+
+ if (InterruptPending != nil) __interruptL(@line);
+
+ if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
+ /*
+ * arg is a compiled block with code -
+ * directly call it without going through Block>>value
+ */
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ } else {
+ if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
+ /*
+ * arg is a compiled block with bytecode -
+ * directly call interpreter without going through Block>>value
+ */
# ifdef PASS_ARG_POINTER
- {
- OBJ idx;
-
- idx = __mkSmallInteger(tmp);
- __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
- }
+ {
+ OBJ idx;
+
+ idx = __mkSmallInteger(tmp);
+ __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
+ }
# else
- __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
+ __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
# endif
- } else {
- /*
- * arg is something else - call it with #value
- */
- (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
- }
- }
- tmp += step;
- }
- } else {
- while (tmp <= final) {
- REGISTER OBJFUNC codeVal;
-
- if (InterruptPending != nil) __interruptL(@line);
-
- if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
- /*
- * arg is a compiled block with code -
- * directly call it without going through Block>>value
- */
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- } else {
- if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
- /*
- * arg is a compiled block with bytecode -
- * directly call interpreter without going through Block>>value
- */
+ } else {
+ /*
+ * arg is something else - call it with #value
+ */
+ (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
+ }
+ }
+ tmp += step;
+ }
+ } else {
+ while (tmp <= final) {
+ REGISTER OBJFUNC codeVal;
+
+ if (InterruptPending != nil) __interruptL(@line);
+
+ if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
+ /*
+ * arg is a compiled block with code -
+ * directly call it without going through Block>>value
+ */
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ } else {
+ if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
+ /*
+ * arg is a compiled block with bytecode -
+ * directly call interpreter without going through Block>>value
+ */
# ifdef PASS_ARG_POINTER
- {
- OBJ idx;
-
- idx = __mkSmallInteger(tmp);
- __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
- }
+ {
+ OBJ idx;
+
+ idx = __mkSmallInteger(tmp);
+ __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
+ }
# else
- __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
+ __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
# endif
- } else {
- /*
- * arg is something else - call it with #value:
- */
- (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
- }
- }
- tmp += step;
- }
- }
+ } else {
+ /*
+ * arg is something else - call it with #value:
+ */
+ (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
+ }
+ }
+ tmp += step;
+ }
+ }
# undef BLOCK_ARG
# undef IBLOCK_ARG
- } else {
- /*
- * arg is something else - call it with #value:
- */
- if (step < 0) {
- while (tmp >= final) {
- if (InterruptPending != nil) __interruptL(@line);
-
- (*blockVal.ilc_func)(aBlock,
- @symbol(value:),
- nil, &blockVal,
- __mkSmallInteger(tmp));
- tmp += step;
- }
- } else {
- while (tmp <= final) {
- if (InterruptPending != nil) __interruptL(@line);
-
- (*blockVal.ilc_func)(aBlock,
- @symbol(value:),
- nil, &blockVal,
- __mkSmallInteger(tmp));
- tmp += step;
- }
- }
- }
- RETURN ( self );
+ } else {
+ /*
+ * arg is something else - call it with #value:
+ */
+ if (step < 0) {
+ while (tmp >= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+
+ (*blockVal.ilc_func)(aBlock,
+ @symbol(value:),
+ nil, &blockVal,
+ __mkSmallInteger(tmp));
+ tmp += step;
+ }
+ } else {
+ while (tmp <= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+
+ (*blockVal.ilc_func)(aBlock,
+ @symbol(value:),
+ nil, &blockVal,
+ __mkSmallInteger(tmp));
+ tmp += step;
+ }
+ }
+ }
+ RETURN ( self );
}
#endif
%}.
@@ -3675,19 +3675,19 @@
static struct inlineCache blockVal = __ILC1(0);
if (__isSmallInteger(stop)) {
- tmp = __intVal(self);
- final = __intVal(stop);
-
- if (__isBlockLike(aBlock)
- && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
- {
- /*
- * specially tuned version for the most common case,
- * where called with home on the stack
- */
- REGISTER OBJFUNC codeVal;
-
- if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
+ tmp = __intVal(self);
+ final = __intVal(stop);
+
+ if (__isBlockLike(aBlock)
+ && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) {
+ {
+ /*
+ * specially tuned version for the most common case,
+ * where called with home on the stack
+ */
+ REGISTER OBJFUNC codeVal;
+
+ if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
# ifdef NEW_BLOCK_CALL
@@ -3696,173 +3696,173 @@
# else
# define BLOCK_ARG rHome
- REGISTER OBJ rHome;
- rHome = __BlockInstPtr(aBlock)->b_home;
- if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
+ REGISTER OBJ rHome;
+ rHome = __BlockInstPtr(aBlock)->b_home;
+ if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE))
# endif
- {
+ {
# ifdef PARANOIA
- if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
+ if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))
# endif
- {
- /*
- * static compiled blocks ...
- */
+ {
+ /*
+ * static compiled blocks ...
+ */
# ifdef __UNROLL_LOOPS__
- /*
- * The following code is designed to run as fast as possible;
- * - taken branches only if interrupts are pending
- * - only forward branches (which are usually predicted as not taken)
- * - unrolled the loop
- *
- * you are not supposed to program like this - I know what I do
- */
+ /*
+ * The following code is designed to run as fast as possible;
+ * - taken branches only if interrupts are pending
+ * - only forward branches (which are usually predicted as not taken)
+ * - unrolled the loop
+ *
+ * you are not supposed to program like this - I know what I do
+ */
# if TAG_INT==1
- INT t8 = (INT)(__mkSmallInteger(tmp+8));
- tmp = (INT)(__mkSmallInteger(tmp));
- final = (INT)(__mkSmallInteger(final));
+ INT t8 = (INT)(__mkSmallInteger(tmp+8));
+ tmp = (INT)(__mkSmallInteger(tmp));
+ final = (INT)(__mkSmallInteger(final));
# else
- INT t8 = tmp+8;
+ INT t8 = tmp+8;
# endif
- for (;;) {
-
- while (t8 <= final) {
+ for (;;) {
+
+ while (t8 <= final) {
# if TAG_INT==1
- t8 += (INT)(__MASKSMALLINT(8));
+ t8 += (INT)(__MASKSMALLINT(8));
# else
- t8 += 8;
+ t8 += 8;
# endif
- if (InterruptPending != nil) goto interrupted0;
- continue0:
+ if (InterruptPending != nil) goto interrupted0;
+ continue0:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp);
+ (*codeVal)(BLOCK_ARG, tmp);
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
# endif
- if (InterruptPending != nil) goto interrupted1;
- continue1:
+ if (InterruptPending != nil) goto interrupted1;
+ continue1:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) );
+ (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) );
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+1));
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+1));
# endif
- if (InterruptPending != nil) goto interrupted2;
- continue2:
+ if (InterruptPending != nil) goto interrupted2;
+ continue2:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) );
+ (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) );
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+2));
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+2));
# endif
- if (InterruptPending != nil) goto interrupted3;
- continue3:
+ if (InterruptPending != nil) goto interrupted3;
+ continue3:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) );
+ (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) );
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+3));
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+3));
# endif
- if (InterruptPending != nil) goto interrupted4;
- continue4:
+ if (InterruptPending != nil) goto interrupted4;
+ continue4:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) );
+ (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) );
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+4));
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+4));
# endif
- if (InterruptPending != nil) goto interrupted5;
- continue5:
+ if (InterruptPending != nil) goto interrupted5;
+ continue5:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) );
+ (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) );
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+5));
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+5));
# endif
- if (InterruptPending != nil) goto interrupted6;
- continue6:
+ if (InterruptPending != nil) goto interrupted6;
+ continue6:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) );
+ (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) );
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+6));
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+6));
# endif
- if (InterruptPending != nil) goto interrupted7;
- continue7:
+ if (InterruptPending != nil) goto interrupted7;
+ continue7:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) );
+ (*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) );
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+7));
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp+7));
# endif
# if TAG_INT==1
- tmp += (INT)(__MASKSMALLINT(8));
+ tmp += (INT)(__MASKSMALLINT(8));
# else
- tmp += 8;
+ tmp += 8;
# endif
- }
- while (tmp <= final) {
- if (InterruptPending != nil) goto interruptedX;
- continueX:
+ }
+ while (tmp <= final) {
+ if (InterruptPending != nil) goto interruptedX;
+ continueX:
# if TAG_INT==1
- (*codeVal)(BLOCK_ARG, tmp);
- tmp += (INT)(__MASKSMALLINT(1));
+ (*codeVal)(BLOCK_ARG, tmp);
+ tmp += (INT)(__MASKSMALLINT(1));
# else
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- tmp++;
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ tmp++;
# endif
- }
- RETURN (self);
-
- if (0) {
- /*
- * no discussion about those gotos ...
- * ... its better for your CPU's pipelines
- * (if you don't understand why, just don't argue).
- */
- interrupted7:
- __interruptL(@line); goto continue7;
- interrupted6:
- __interruptL(@line); goto continue6;
- interrupted5:
- __interruptL(@line); goto continue5;
- interrupted4:
- __interruptL(@line); goto continue4;
- interrupted3:
- __interruptL(@line); goto continue3;
- interrupted2:
- __interruptL(@line); goto continue2;
- interrupted1:
- __interruptL(@line); goto continue1;
- interrupted0:
- __interruptL(@line); goto continue0;
- interruptedX:
- __interruptL(@line); goto continueX;
- }
- }
+ }
+ RETURN (self);
+
+ if (0) {
+ /*
+ * no discussion about those gotos ...
+ * ... its better for your CPU's pipelines
+ * (if you don't understand why, just don't argue).
+ */
+ interrupted7:
+ __interruptL(@line); goto continue7;
+ interrupted6:
+ __interruptL(@line); goto continue6;
+ interrupted5:
+ __interruptL(@line); goto continue5;
+ interrupted4:
+ __interruptL(@line); goto continue4;
+ interrupted3:
+ __interruptL(@line); goto continue3;
+ interrupted2:
+ __interruptL(@line); goto continue2;
+ interrupted1:
+ __interruptL(@line); goto continue1;
+ interrupted0:
+ __interruptL(@line); goto continue0;
+ interruptedX:
+ __interruptL(@line); goto continueX;
+ }
+ }
# else
- while (tmp <= final) {
- if (InterruptPending != nil) __interruptL(@line);
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- tmp ++;
- }
- RETURN (self);
+ while (tmp <= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ tmp ++;
+ }
+ RETURN (self);
# endif /* __UNROLL_LOOPS__ */
- }
-
- /*
- * mhmh - seems to be a block with dynamic code
- * must refetch, to allow dynamic recompilation or code flush.
- */
- while (tmp <= final) {
- if (InterruptPending != nil) __interruptL(@line);
- if ((codeVal = __BlockInstPtr(aBlock)->b_code) == (OBJFUNC)nil) break;
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- tmp ++;
- }
-
- if (tmp > final) {
- RETURN (self);
- }
- }
- }
- }
+ }
+
+ /*
+ * mhmh - seems to be a block with dynamic code
+ * must refetch, to allow dynamic recompilation or code flush.
+ */
+ while (tmp <= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+ if ((codeVal = __BlockInstPtr(aBlock)->b_code) == (OBJFUNC)nil) break;
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ tmp ++;
+ }
+
+ if (tmp > final) {
+ RETURN (self);
+ }
+ }
+ }
+ }
# undef BLOCK_ARG
@@ -3874,74 +3874,74 @@
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home)
# endif
- /*
- * sorry - must check for the blocks code within the loops;
- * it could be recompiled or flushed (in the interrupt)
- */
- while (tmp <= final) {
- REGISTER OBJFUNC codeVal;
-
- if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
- /*
- * arg is a compiled block with code -
- * directly call it without going through Block>>value
- */
-
- /* stay here, while no interrupts are pending ... */
- do {
- (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
- if (InterruptPending != nil) goto outerLoop;
- tmp++;
- } while (tmp <= final);
- RETURN (self);
- } else {
- if (InterruptPending != nil) __interruptL(@line);
-
- if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
- /*
- * arg is a compiled block with bytecode -
- * directly call interpreter without going through Block>>value
- */
+ /*
+ * sorry - must check for the blocks code within the loops;
+ * it could be recompiled or flushed (in the interrupt)
+ */
+ while (tmp <= final) {
+ REGISTER OBJFUNC codeVal;
+
+ if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
+ /*
+ * arg is a compiled block with code -
+ * directly call it without going through Block>>value
+ */
+
+ /* stay here, while no interrupts are pending ... */
+ do {
+ (*codeVal)(BLOCK_ARG, __mkSmallInteger(tmp));
+ if (InterruptPending != nil) goto outerLoop;
+ tmp++;
+ } while (tmp <= final);
+ RETURN (self);
+ } else {
+ if (InterruptPending != nil) __interruptL(@line);
+
+ if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
+ /*
+ * arg is a compiled block with bytecode -
+ * directly call interpreter without going through Block>>value
+ */
# ifdef PASS_ARG_POINTER
- {
- OBJ idx;
-
- idx = __mkSmallInteger(tmp);
- __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
- }
+ {
+ OBJ idx;
+
+ idx = __mkSmallInteger(tmp);
+ __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx);
+ }
# else
- __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
+ __interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __mkSmallInteger(tmp));
# endif
- } else {
- /*
- * arg is something else - call it with #value:
- */
- (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
- }
- }
- outerLoop: ;
- tmp++;
- }
+ } else {
+ /*
+ * arg is something else - call it with #value:
+ */
+ (*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __mkSmallInteger(tmp));
+ }
+ }
+ outerLoop: ;
+ tmp++;
+ }
# undef BLOCK_ARG
# undef IBLOCK_ARG
- RETURN (self);
- }
- /*
- * arg is something else - call it with #value:
- */
- while (tmp <= final) {
- if (InterruptPending != nil) __interruptL(@line);
-
- (*blockVal.ilc_func)(aBlock,
- @symbol(value:),
- nil, &blockVal,
- __mkSmallInteger(tmp));
- tmp++;
- }
- RETURN ( self );
+ RETURN (self);
+ }
+ /*
+ * arg is something else - call it with #value:
+ */
+ while (tmp <= final) {
+ if (InterruptPending != nil) __interruptL(@line);
+
+ (*blockVal.ilc_func)(aBlock,
+ @symbol(value:),
+ nil, &blockVal,
+ __mkSmallInteger(tmp));
+ tmp++;
+ }
+ RETURN ( self );
}
#endif /* not __SCHTEAM__ */
%}.
@@ -3962,7 +3962,7 @@
bernoulli
"returns the nth Bernoulli number.
The series runs this:
- 1/6, 1/30, 1/42, 1/30, 5/66, 691/2730, etc
+ 1/6, 1/30, 1/42, 1/30, 5/66, 691/2730, etc
Uses a table of the first 20 bernoulli numbers.
So bernoulli(42) will fail for now.
Used with taylor series for tan"
@@ -3970,32 +3970,32 @@
|table p|
table := #(
- (1 6)
- (-1 30)
- (1 42)
- (-1 30)
- (5 66)
- (-691 2730)
- (7 6)
- (-3617 510)
- (43867 798)
- (-174611 330)
- (854513 138)
- (-236364091 2730)
- (8553103 6)
- (-23749461029 870)
- (8615841276005 14322)
- (-7709321041217 510)
- (2577687858367 6)
- (-26315271553053477373 1919190)
- (2929993913841559 6)
- (-261082718496449122051 13530)
- ).
+ (1 6)
+ (-1 30)
+ (1 42)
+ (-1 30)
+ (5 66)
+ (-691 2730)
+ (7 6)
+ (-3617 510)
+ (43867 798)
+ (-174611 330)
+ (854513 138)
+ (-236364091 2730)
+ (8553103 6)
+ (-23749461029 870)
+ (8615841276005 14322)
+ (-7709321041217 510)
+ (2577687858367 6)
+ (-26315271553053477373 1919190)
+ (2929993913841559 6)
+ (-261082718496449122051 13530)
+ ).
self even ifTrue:[
- self == 0 ifTrue:[^1].
- p := table at:(self / 2).
- ^ Fraction numerator:(p first) denominator:(p second).
+ self == 0 ifTrue:[^1].
+ p := table at:(self / 2).
+ ^ Fraction numerator:(p first) denominator:(p second).
].
self == 1 ifTrue:[ ^ (1 / 2) ].
^ 0.
@@ -4018,17 +4018,17 @@
divMod:aNumber
"return an array filled with
- (self // aNumber) and (self \\ aNumber).
+ (self // aNumber) and (self \\ aNumber).
The returned remainder has the same sign as aNumber.
The following is always true:
- (receiver // something) * something + (receiver \\ something) = receiver
+ (receiver // something) * something + (receiver \\ something) = receiver
Be careful with negative results: 9 // 4 -> 2, while -9 // 4 -> -3.
Especially surprising:
- -1 \\ 10 -> 9 (because -(1/10) is truncated towards next smaller integer, which is -1,
- and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
- -10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
- and -4 * 4 gives -12, so we need to add 2 to get the original -10.
+ -1 \\ 10 -> 9 (because -(1/10) is truncated towards next smaller integer, which is -1,
+ and -1 multiplied by 10 gives -10, so we have to add 9 to get the original -1).
+ -10 \\ 3 -> 2 (because -(10/3) is truncated towards next smaller integer, which is -4,
+ and -4 * 4 gives -12, so we need to add 2 to get the original -10.
This is redefined here for more performance"
@@ -4039,10 +4039,10 @@
if (__isSmallInteger(aNumber)
&& ((val = __intVal(aNumber)) > 0)
&& ((mySelf = __intVal(self)) >= 0)) {
- div = mySelf / val;
- mod = mySelf % val;
-
- RETURN (__ARRAY_WITH2( __mkSmallInteger(div), __mkSmallInteger(mod)));
+ div = mySelf / val;
+ mod = mySelf % val;
+
+ RETURN (__ARRAY_WITH2( __mkSmallInteger(div), __mkSmallInteger(mod)));
}
#endif
%}.
@@ -4086,30 +4086,30 @@
%{ /* NOCONTEXT */
#ifndef __SCHTEAM__
if (__isSmallInteger(anInteger)) {
- INT orgArg, ttt, selfInt, orgSelfInt, temp;
-
- ttt = orgArg = __intVal(anInteger);
- if (ttt) {
- selfInt = orgSelfInt = __intVal(self);
- while (ttt != 0) {
- temp = selfInt % ttt;
- selfInt = ttt;
- ttt = temp;
- }
- /*
- * since its not defined in C, what the sign of
- * a modulus result is when the arg is negative,
- * change it explicitely here ...
- */
- if (orgArg < 0) {
- /* result should be negative */
- if (orgSelfInt > 0) selfInt = -selfInt;
- } else {
- /* result should be positive */
- if (orgSelfInt < 0) selfInt = -selfInt;
- }
- RETURN ( __mkSmallInteger(selfInt) );
- }
+ INT orgArg, ttt, selfInt, orgSelfInt, temp;
+
+ ttt = orgArg = __intVal(anInteger);
+ if (ttt) {
+ selfInt = orgSelfInt = __intVal(self);
+ while (ttt != 0) {
+ temp = selfInt % ttt;
+ selfInt = ttt;
+ ttt = temp;
+ }
+ /*
+ * since its not defined in C, what the sign of
+ * a modulus result is when the arg is negative,
+ * change it explicitely here ...
+ */
+ if (orgArg < 0) {
+ /* result should be negative */
+ if (orgSelfInt > 0) selfInt = -selfInt;
+ } else {
+ /* result should be positive */
+ if (orgSelfInt < 0) selfInt = -selfInt;
+ }
+ RETURN ( __mkSmallInteger(selfInt) );
+ }
}
#endif
%}.
@@ -4133,45 +4133,45 @@
(i.e. without log)."
self > 0 ifTrue:[
- self < 10000 ifTrue:[
- 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 < 1000000000 ifTrue:[^ 8].
- SmallInteger maxBytes == 4 ifTrue:[
- "/ on a 32 bit machine, SmallInt cannot be larger
- ^ 9
- ].
-
- "/ 64 bit machine
- self < 100000000000000 ifTrue:[
- self < 10000000000 ifTrue:[^ 9].
- self < 100000000000 ifTrue:[^ 10].
- self < 1000000000000 ifTrue:[^ 11].
- self < 10000000000000 ifTrue:[^ 12].
- ^ 13
- ].
- self < 1000000000000000 ifTrue:[^ 14].
- self < 10000000000000000 ifTrue:[^ 15].
- self < 100000000000000000 ifTrue:[^ 16].
- self < 1000000000000000000 ifTrue:[^ 17].
- ^ 18.
+ self < 10000 ifTrue:[
+ 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 < 1000000000 ifTrue:[^ 8].
+ SmallInteger maxBytes == 4 ifTrue:[
+ "/ on a 32 bit machine, SmallInt cannot be larger
+ ^ 9
+ ].
+
+ "/ 64 bit machine
+ self < 100000000000000 ifTrue:[
+ self < 10000000000 ifTrue:[^ 9].
+ self < 100000000000 ifTrue:[^ 10].
+ self < 1000000000000 ifTrue:[^ 11].
+ self < 10000000000000 ifTrue:[^ 12].
+ ^ 13
+ ].
+ self < 1000000000000000 ifTrue:[^ 14].
+ self < 10000000000000000 ifTrue:[^ 15].
+ self < 100000000000000000 ifTrue:[^ 16].
+ self < 1000000000000000000 ifTrue:[^ 17].
+ ^ 18.
].
^ self class
- raise:#domainErrorSignal
- receiver:self
- selector:#intlog10
- arguments:#()
- errorString:'logarithm of negative integer'
+ raise:#domainErrorSignal
+ receiver:self
+ selector:#intlog10
+ arguments:#()
+ errorString:'logarithm of negative integer'
"
99 intlog10
@@ -4207,47 +4207,47 @@
unsigned INT rslt;
if (b <= 99999999) {
- if (b <= 255) {
- // the most common case: convert bytes
- for (i=7; i>=0; i--) {
- if (_100s >= 5) _100s += 3;
- if (_10s >= 5) _10s += 3;
- if (_1s >= 5) _1s += 3;
-
- _100s = (_100s<<1) | (_10s >> 3 & 1); _100s &= 0xF;
- _10s = (_10s<<1) | (_1s >> 3 & 1); _10s &= 0xF;
- _1s = (_1s<<1) | (b >> 7 & 1); _1s &= 0xF;
- b <<= 1;
- }
- rslt = (_100s<<8) | (_10s<<4) | _1s;
- RETURN (__MKSMALLINT( rslt) );
- }
-
- for (i=26; i>=0; i--) {
- if (_10000000s >= 5) _10000000s += 3;
- if (_1000000s >= 5) _1000000s += 3;
- if (_100000s >= 5) _100000s += 3;
- if (_10000s >= 5) _10000s += 3;
- if (_1000s >= 5) _1000s += 3;
- if (_100s >= 5) _100s += 3;
- if (_10s >= 5) _10s += 3;
- if (_1s >= 5) _1s += 3;
-
- _10000000s = (_10000000s<<1) | (_1000000s >> 3 & 1); _10000000s &= 0xF;
- _1000000s = (_1000000s<<1) | (_100000s >> 3 & 1); _1000000s &= 0xF;
- _100000s = (_100000s<<1) | (_10000s >> 3 & 1); _100000s &= 0xF;
- _10000s = (_10000s<<1) | (_1000s >> 3 & 1); _10000s &= 0xF;
- _1000s = (_1000s<<1) | (_100s >> 3 & 1); _1000s &= 0xF;
- _100s = (_100s<<1) | (_10s >> 3 & 1); _100s &= 0xF;
- _10s = (_10s<<1) | (_1s >> 3 & 1); _10s &= 0xF;
- _1s = (_1s<<1) | (b >> 26 & 1); _1s &= 0xF;
- b <<= 1;
- }
-
- rslt = (_10000000s<<28)
- | (_1000000s<<24) | (_100000s<<20) | (_10000s<<16)
- | (_1000s<<12) | (_100s<<8) | (_10s<<4) | _1s;
- RETURN (__MKUINT( rslt) );
+ if (b <= 255) {
+ // the most common case: convert bytes
+ for (i=7; i>=0; i--) {
+ if (_100s >= 5) _100s += 3;
+ if (_10s >= 5) _10s += 3;
+ if (_1s >= 5) _1s += 3;
+
+ _100s = (_100s<<1) | (_10s >> 3 & 1); _100s &= 0xF;
+ _10s = (_10s<<1) | (_1s >> 3 & 1); _10s &= 0xF;
+ _1s = (_1s<<1) | (b >> 7 & 1); _1s &= 0xF;
+ b <<= 1;
+ }
+ rslt = (_100s<<8) | (_10s<<4) | _1s;
+ RETURN (__MKSMALLINT( rslt) );
+ }
+
+ for (i=26; i>=0; i--) {
+ if (_10000000s >= 5) _10000000s += 3;
+ if (_1000000s >= 5) _1000000s += 3;
+ if (_100000s >= 5) _100000s += 3;
+ if (_10000s >= 5) _10000s += 3;
+ if (_1000s >= 5) _1000s += 3;
+ if (_100s >= 5) _100s += 3;
+ if (_10s >= 5) _10s += 3;
+ if (_1s >= 5) _1s += 3;
+
+ _10000000s = (_10000000s<<1) | (_1000000s >> 3 & 1); _10000000s &= 0xF;
+ _1000000s = (_1000000s<<1) | (_100000s >> 3 & 1); _1000000s &= 0xF;
+ _100000s = (_100000s<<1) | (_10000s >> 3 & 1); _100000s &= 0xF;
+ _10000s = (_10000s<<1) | (_1000s >> 3 & 1); _10000s &= 0xF;
+ _1000s = (_1000s<<1) | (_100s >> 3 & 1); _1000s &= 0xF;
+ _100s = (_100s<<1) | (_10s >> 3 & 1); _100s &= 0xF;
+ _10s = (_10s<<1) | (_1s >> 3 & 1); _10s &= 0xF;
+ _1s = (_1s<<1) | (b >> 26 & 1); _1s &= 0xF;
+ b <<= 1;
+ }
+
+ rslt = (_10000000s<<28)
+ | (_1000000s<<24) | (_100000s<<20) | (_10000s<<16)
+ | (_1000s<<12) | (_100s<<8) | (_10s<<4) | _1s;
+ RETURN (__MKUINT( rslt) );
}
#endif
%}.
@@ -4286,13 +4286,13 @@
|absBase|
(base isInteger and:[absBase := base abs. absBase between:2 and:36]) ifTrue:[
- showRadix ifTrue:[
- absBase printOn:aStream.
- aStream nextPut:$r.
- ].
- aStream nextPutAll:(self printStringRadix:base)
+ showRadix ifTrue:[
+ absBase printOn:aStream.
+ aStream nextPut:$r.
+ ].
+ aStream nextPutAll:(self printStringRadix:base)
] ifFalse:[
- super printOn:aStream base:base showRadix:true.
+ super printOn:aStream base:base showRadix:true.
].
"Created: / 07-09-2001 / 13:54:40 / cg"
@@ -4317,26 +4317,26 @@
int negative = 0;
if (self == __MKSMALLINT(0)) {
- RETURN (@global(ZeroString));
+ RETURN (@global(ZeroString));
// RETURN (__MKSTRING_L("0", 1));
}
myValue = __intVal(self);
if (myValue < 0) {
- negative = 1;
- myValue = -myValue;
+ negative = 1;
+ myValue = -myValue;
}
cp = buffer + sizeof(buffer) - 1;
*cp-- = '\0';
for ( ; myValue != 0; cp--) {
- *cp = '0' + (myValue % 10);
- myValue /= 10;
+ *cp = '0' + (myValue % 10);
+ myValue /= 10;
}
if (negative) {
- *cp-- = '-';
+ *cp-- = '-';
}
newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
if (newString != nil) {
- RETURN (newString);
+ RETURN (newString);
}
#endif /* not __SCHTEAM__ */
%}.
@@ -4367,57 +4367,57 @@
%{
#ifdef __SCHTEAM__
- int __base = base.intValue().abs();
+ int __base = Math.abs(base.intValue());
long myValue = self.longValue();
java.lang.String __s;
switch (__base) {
- case 2:
- __s = java.lang.Long.toBinaryString(myValue);
- break;
-
- case 8:
- __s = java.lang.Long.toOctalString(myValue);
- break;
-
- case 10:
- __s = java.lang.Long.toString(myValue);
- break;
-
- case 16:
- __s = java.lang.Long.toHexString(myValue);
- break;
-
- default:
- {
- boolean negative = false;
- __s = "";
-
- if ((__base > 36) || (__base < 2)) {
- throw new SmalltalkError("invalid base: ", base);
- }
- if (myValue < 0) {
- negative = true;
- myValue = -myValue;
- }
- while (myValue != 0) {
- int digit;
- char ch;
-
- digit = (int)(myValue % __base);
- if (digit <= 9) {
- ch = (char)('0' + digit);
- } else {
- ch = (char)('A' + digit - 10);
- }
- __s = ch + __s;
- myValue = myValue / __base;
- }
- if (negative) {
- __s = "-" + __s;
- }
- break;
- }
+ case 2:
+ __s = java.lang.Long.toBinaryString(myValue);
+ break;
+
+ case 8:
+ __s = java.lang.Long.toOctalString(myValue);
+ break;
+
+ case 10:
+ __s = java.lang.Long.toString(myValue);
+ break;
+
+ case 16:
+ __s = java.lang.Long.toHexString(myValue);
+ break;
+
+ default:
+ {
+ boolean negative = false;
+ __s = "";
+
+ if ((__base > 36) || (__base < 2)) {
+ throw new SmalltalkError("invalid base: ", base);
+ }
+ if (myValue < 0) {
+ negative = true;
+ myValue = -myValue;
+ }
+ while (myValue != 0) {
+ int digit;
+ char ch;
+
+ digit = (int)(myValue % __base);
+ if (digit <= 9) {
+ ch = (char)('0' + digit);
+ } else {
+ ch = (char)('A' + digit - 10);
+ }
+ __s = ch + __s;
+ myValue = myValue / __base;
+ }
+ if (negative) {
+ __s = "-" + __s;
+ }
+ break;
+ }
}
return context._RETURN( new STString( __s ));
#else
@@ -4425,45 +4425,45 @@
static char lcDigits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
if (__isSmallInteger(base)) {
- char *digits;
- INT __base;
-
- if (self == __MKSMALLINT(0)) {
- RETURN (@global(ZeroString));
- }
- __base = __intVal(base);
- if (__base < 0) {
- __base = - __base;
- digits = lcDigits;
- } else {
- digits = ucDigits;
- }
-
- if ((__base < sizeof(ucDigits)) && (__base > 1)) {
- char buffer[64+5]; /* for 64bit machines, base 2, plus sign, plus 0-byte */
- char *cp;
- OBJ newString;
- int negative = 0;
- INT myValue = __intVal(self);
-
- if (myValue < 0) {
- negative = 1;
- myValue = -myValue;
- }
- cp = buffer + sizeof(buffer) - 1;
- *cp-- = '\0';
- for (; myValue != 0; cp--) {
- *cp = digits[myValue % __base];
- myValue /= __base;
- }
- if (negative) {
- *cp-- = '-';
- }
- newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
- if (newString != nil) {
- RETURN (newString);
- }
- }
+ char *digits;
+ INT __base;
+
+ if (self == __MKSMALLINT(0)) {
+ RETURN (@global(ZeroString));
+ }
+ __base = __intVal(base);
+ if (__base < 0) {
+ __base = - __base;
+ digits = lcDigits;
+ } else {
+ digits = ucDigits;
+ }
+
+ if ((__base < sizeof(ucDigits)) && (__base > 1)) {
+ char buffer[64+5]; /* for 64bit machines, base 2, plus sign, plus 0-byte */
+ char *cp;
+ OBJ newString;
+ int negative = 0;
+ INT myValue = __intVal(self);
+
+ if (myValue < 0) {
+ negative = 1;
+ myValue = -myValue;
+ }
+ cp = buffer + sizeof(buffer) - 1;
+ *cp-- = '\0';
+ for (; myValue != 0; cp--) {
+ *cp = digits[myValue % __base];
+ myValue /= __base;
+ }
+ if (negative) {
+ *cp-- = '-';
+ }
+ newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp));
+ if (newString != nil) {
+ RETURN (newString);
+ }
+ }
}
#endif /* not __SCHTEAM__ */
%}.
@@ -4545,23 +4545,23 @@
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: ;
#endif /* not __SCHTEAM__ */
@@ -4569,11 +4569,11 @@
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'
"
! !
@@ -4589,7 +4589,7 @@
absVal := self abs.
aNumber < 0 ifTrue:[
- ^ absVal negated
+ ^ absVal negated
].
aNumber == 0 ifTrue:[^ 0].
^ absVal
@@ -4661,33 +4661,33 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
{
- long myValue = self.longValue();
- long otherValue = aNumber.longValue();
- long sum = myValue + otherValue;
- return context._RETURN( STInteger._new(sum) );
+ long myValue = self.longValue();
+ long otherValue = aNumber.longValue();
+ long sum = myValue + otherValue;
+ return context._RETURN( STInteger._new(sum) );
}
/* NOT REACHED */
#else
if (__isSmallInteger(aNumber)) {
- INT sum;
-
- sum = __intVal(self) + __intVal(aNumber);
- if (!__ISVALIDINTEGER(sum)) {
- /* keep the sign */
- sum %= _MAX_INT;
- }
- RETURN ( __mkSmallInteger(sum));
+ INT sum;
+
+ sum = __intVal(self) + __intVal(aNumber);
+ if (!__ISVALIDINTEGER(sum)) {
+ /* keep the sign */
+ sum %= _MAX_INT;
+ }
+ RETURN ( __mkSmallInteger(sum));
}
#endif
%}.
self primitiveFailed
"
- 5 plus:-1
- 5 plus:1
- 1 plus:-5
- self maxVal plus:1
- self maxVal + 1
+ 5 plus:-1
+ 5 plus:1
+ 1 plus:-5
+ self maxVal plus:1
+ self maxVal + 1
"
!
@@ -4702,34 +4702,34 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
{
- long myValue = self.longValue();
- long otherValue = aNumber.longValue();
- long diference = myValue - otherValue;
- return context._RETURN( STInteger._new(diference) );
+ long myValue = self.longValue();
+ long otherValue = aNumber.longValue();
+ long diference = myValue - otherValue;
+ return context._RETURN( STInteger._new(diference) );
}
/* NOT REACHED */
#else
if (__isSmallInteger(aNumber)) {
- INT diff;
-
- diff = __intVal(self) - __intVal(aNumber);
- if (!__ISVALIDINTEGER(diff)) {
- /* keep the sign */
- diff %= _MAX_INT;
- }
- RETURN ( __mkSmallInteger(diff));
+ INT diff;
+
+ diff = __intVal(self) - __intVal(aNumber);
+ if (!__ISVALIDINTEGER(diff)) {
+ /* keep the sign */
+ diff %= _MAX_INT;
+ }
+ RETURN ( __mkSmallInteger(diff));
}
#endif
%}.
self primitiveFailed
"
- -1 subtract:5
- 5 subtract:1
- 1 subtract:-5
- self minVal subtract:1
- self minVal - 1
+ -1 subtract:5
+ 5 subtract:1
+ 1 subtract:-5
+ self minVal subtract:1
+ self minVal - 1
"
!
@@ -4744,10 +4744,10 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
{
- long myValue = self.longValue();
- long otherValue = aNumber.longValue();
- long product = myValue * otherValue;
- return context._RETURN( STInteger._new(product) );
+ long myValue = self.longValue();
+ long otherValue = aNumber.longValue();
+ long product = myValue * otherValue;
+ return context._RETURN( STInteger._new(product) );
}
/* NOT REACHED */
#else
@@ -4776,128 +4776,128 @@
# 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(__x86__)
- 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);
# undef LLMASK
# define LLMASK 0xC000000000000000LL
# 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__ && __x86__) */
# 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 */
}
#endif /* not __SCHTEAM__ */
@@ -4906,11 +4906,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
"
! !
@@ -4954,19 +4954,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));
}
#endif
%}.
@@ -5000,21 +5000,21 @@
INT bits, count;
if (__isSmallInteger(shiftCount)) {
- count = __intVal(shiftCount);
- if (count >= 32) {
- RETURN (__mkSmallInteger(0));
- }
-
- bits = __intVal(self);
- if (count > 0) {
- bits = bits << count;
- } else {
- bits = bits >> (-count);
- }
+ count = __intVal(shiftCount);
+ if (count >= 32) {
+ RETURN (__mkSmallInteger(0));
+ }
+
+ bits = __intVal(self);
+ if (count > 0) {
+ bits = bits << count;
+ } else {
+ bits = bits >> (-count);
+ }
# if __POINTER_SIZE__ == 8
- bits &= 0xFFFFFFFFL;
+ bits &= 0xFFFFFFFFL;
# endif
- RETURN (__MKINT(bits));
+ RETURN (__MKINT(bits));
}
#endif
%}.
@@ -5068,21 +5068,21 @@
INT count;
if (__isSmallInteger(shiftCount)) {
- count = __intVal(shiftCount);
- if (count >= 32) {
- RETURN (__mkSmallInteger(0));
- }
-
- bits = __intVal(self);
- if (count > 0) {
- bits = bits << count;
- } else {
- bits = bits >> (-count);
- }
+ count = __intVal(shiftCount);
+ if (count >= 32) {
+ RETURN (__mkSmallInteger(0));
+ }
+
+ bits = __intVal(self);
+ if (count > 0) {
+ bits = bits << count;
+ } else {
+ bits = bits >> (-count);
+ }
# if __POINTER_SIZE__ == 8
- bits &= 0xFFFFFFFFL;
+ bits &= 0xFFFFFFFFL;
# endif
- RETURN (__MKUINT(bits));
+ RETURN (__MKUINT(bits));
}
#endif
%}.
@@ -5110,37 +5110,37 @@
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
if (STObject.bothSmallInteger(min, max)) {
- long myVal = ((STInteger)self).longValue();
-
- if (myVal >= ((STInteger)min).longValue()) {
- if (myVal <= ((STInteger)max).longValue()) {
- return __c__._RETURN_true();
- }
- }
- return __c__._RETURN_false();
+ long myVal = ((STInteger)self).longValue();
+
+ if (myVal >= ((STInteger)min).longValue()) {
+ if (myVal <= ((STInteger)max).longValue()) {
+ return __c__._RETURN_true();
+ }
+ }
+ return __c__._RETURN_false();
}
#else /* not SCHTEAM */
if (__bothSmallInteger(min, max)) {
# if TAG_INT == 1
- // tag bit does not change the magnitude order
- if ((INT)self < (INT)(min)) {
- RETURN ( false );
- }
- if ((INT)self > (INT)(max)) {
- RETURN ( false );
- }
- RETURN ( true );
+ // tag bit does not change the magnitude order
+ if ((INT)self < (INT)(min)) {
+ RETURN ( false );
+ }
+ if ((INT)self > (INT)(max)) {
+ RETURN ( false );
+ }
+ RETURN ( true );
# else
- REGISTER INT selfVal;
-
- selfVal = __intVal(self);
- if (selfVal < __intVal(min)) {
- RETURN ( false );
- }
- if (selfVal > __intVal(max)) {
- RETURN ( false );
- }
- RETURN ( true );
+ REGISTER INT selfVal;
+
+ selfVal = __intVal(self);
+ if (selfVal < __intVal(min)) {
+ RETURN ( false );
+ }
+ if (selfVal > __intVal(max)) {
+ RETURN ( false );
+ }
+ RETURN ( true );
# endif
}
#endif /* not SCHTEAM */
@@ -5249,12 +5249,12 @@
22 nextPowerOf2
32 nextPowerOf2
- 16rFFFF nextPowerOf2 = 16r10000
- 16rFFFFFFFF nextPowerOf2 = 16r100000000
- 16r1FFFFFFFFFFFFFFF nextPowerOf2 = 16r2000000000000000
- 16r3FFFFFFFFFFFFFFF nextPowerOf2 = 16r4000000000000000
- 16r7FFFFFFFFFFFFFFF nextPowerOf2 = 16r8000000000000000
- 16rFFFFFFFFFFFFFFFF nextPowerOf2 = 16r10000000000000000
+ 16rFFFF nextPowerOf2 = 16r10000
+ 16rFFFFFFFF nextPowerOf2 = 16r100000000
+ 16r1FFFFFFFFFFFFFFF nextPowerOf2 = 16r2000000000000000
+ 16r3FFFFFFFFFFFFFFF nextPowerOf2 = 16r4000000000000000
+ 16r7FFFFFFFFFFFFFFF nextPowerOf2 = 16r8000000000000000
+ 16rFFFFFFFFFFFFFFFF nextPowerOf2 = 16r10000000000000000
10 factorial nextPowerOf2
20 factorial nextPowerOf2
100 factorial nextPowerOf2
@@ -5299,20 +5299,20 @@
^ 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:(16r3FFFFFFFFFFFFFFF parityOdd = 16r3FFFFFFFFFFFFFFF bitCount odd).
- self assert:(16r7FFFFFFFFFFFFFFF parityOdd = 16r7FFFFFFFFFFFFFFF bitCount odd).
- self assert:(16rFFFFFFFFFFFFFFFF parityOdd = 16rFFFFFFFFFFFFFFFF 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).
+ self assert:(16r3FFFFFFFFFFFFFFF parityOdd = 16r3FFFFFFFFFFFFFFF bitCount odd).
+ self assert:(16r7FFFFFFFFFFFFFFF parityOdd = 16r7FFFFFFFFFFFFFFF bitCount odd).
+ self assert:(16rFFFFFFFFFFFFFFFF parityOdd = 16rFFFFFFFFFFFFFFFF bitCount odd).
"
"Modified (comment): / 09-01-2012 / 19:55:37 / cg"