--- a/SmallInteger.st Sun May 15 08:38:43 2016 +0100
+++ b/SmallInteger.st Tue May 17 10:05:14 2016 +0100
@@ -46,8 +46,8 @@
"
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.
@@ -62,12 +62,12 @@
with an instance variable holding the value.
[author:]
- Claus Gittinger
+ Claus Gittinger
[see also:]
- Number
- Float Fraction FixedPoint
- LargeInteger
+ Number
+ Float Fraction FixedPoint
+ LargeInteger
"
! !
@@ -297,14 +297,14 @@
: "%0" ((unsigned long)(myValue)),
"dmi" ((unsigned long)(otherValue)));
# else
-# if defined (__GNUC__) && defined(__i386__)
+# if defined (__GNUC__) && defined(__x86__)
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__)
+# if defined(__win32__) && defined(__BORLANDC__)
asm {
mov eax, myValue
mov edx, otherValue
@@ -374,8 +374,8 @@
productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
# endif
}
-# endif /* ! WIN32 */
-# endif /* ! (__GNUC__ && __i386__) */
+# endif /* ! __win32__ */
+# endif /* ! (__GNUC__ && __x86__) */
# endif /* ! (__GNUC__ && __mc68k__) */
if (productHi == 0) {
@@ -1406,9 +1406,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__
@@ -1417,80 +1417,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 ?
!
@@ -1546,38 +1546,38 @@
!
highBit
- "return the bitIndex of the highest bit set.
+ "return the bitIndex of the highest bit set.
The returned bitIndex starts at 1 for the least significant bit.
Returns 0 if no bit is set."
%{ /* 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
@@ -1586,7 +1586,7 @@
bits = __intVal(self);
if (bits == 0) {
- RETURN ( __mkSmallInteger(0) );
+ RETURN ( __mkSmallInteger(0) );
}
# ifdef __BSR
@@ -1602,23 +1602,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 */
@@ -1636,38 +1636,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
+ ]
]
"
@@ -2166,7 +2166,7 @@
# if __POINTER_SIZE__ == 8
v &= 0xFFFFFFFF;
-# if defined(__x86_64__) && defined(__GNUC__) && !defined(__clang__)
+# if defined(__x86_64__) && defined(__GNUC__) && !defined(__CLANG__)
# define HAVE_BSWAP
asm("movq %1, %%rax \n\
@@ -2623,21 +2623,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
@@ -2645,27 +2645,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 */
%}.
@@ -4776,14 +4776,14 @@
: "%0" ((unsigned long)(myValue)),
"dmi" ((unsigned long)(otherValue)));
# else
-# if defined (__GNUC__) && defined(__i386__)
+# if defined (__GNUC__) && defined(__x86__)
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__)
+# if defined(__win32__) && defined(__BORLANDC__)
asm {
mov eax, myValue
mov edx, otherValue
@@ -4853,8 +4853,8 @@
productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH);
# endif
}
-# endif /* ! WIN32 */
-# endif /* ! (__GNUC__ && __i386__) */
+# endif /* ! __win32__ */
+# endif /* ! (__GNUC__ && __x86__) */
# endif /* ! (__GNUC__ && __mc68k__) */
if (negative < 0) {