--- a/SmallInteger.st Wed Mar 27 11:51:54 2002 +0100
+++ b/SmallInteger.st Thu Mar 28 11:50:28 2002 +0100
@@ -1291,7 +1291,8 @@
lowBit
"return the bitIndex of the lowest bit set. The returned bitIndex
- starts at 1 for the least significant bit. Returns -1 if no bit is set."
+ starts at 1 for the least significant bit.
+ Returns 0 if no bit is set."
%{ /* NOCONTEXT */
@@ -1299,88 +1300,86 @@
bits = __intVal(self);
if (bits == 0) {
- RETURN ( __MKSMALLINT(-1) );
+ RETURN ( __MKSMALLINT(0) );
}
#ifdef __BSF
/*
* so much for CISC CPUS:
* the following code is only marginally faster on a PIII-400
- * (but saves a few code-bytes, though)
+ * (and not at all faster on an Athlon...)
+ * but saves a few code-bytes, though.
*/
bits = __BSF(bits);
RETURN ( __MKSMALLINT(bits + 1) );
#else
- if ((bits & 0xFFFFFF) == 0) {
- mask = 0x1000000;
- index = 25;
- } else {
- if ((bits & 0xFFFF) == 0) {
- mask = 0x10000;
- index = 17;
- } else {
- if ((bits & 0xFF) == 0) {
- mask = 0x100;
- index = 9;
- } else {
- mask = 1;
- index = 1;
- }
- }
- }
+ index = 1;
# ifdef alpha64
- while (index != 63) {
-# else
- while (index != 31) {
+ if ((bits<<32) == 0) {
+ index += 32; bits >>= 32;
+ }
# endif
- if (bits & mask) {
- RETURN ( __MKSMALLINT(index) );
- }
- mask = mask << 1;
- index++;
+
+ if ((bits & 0xFFFF)==0) {
+ index += 16; bits >>= 16;
+ }
+ if ((bits & 0xFF)==0) {
+ index += 8; bits >>= 8;
+ }
+ if ((bits & 0xF)==0) {
+ index += 4; bits >>= 4;
}
- RETURN ( __MKSMALLINT(-1) );
+ if ((bits & 0x3)==0) {
+ index += 2; bits >>= 2;
+ }
+ if ((bits & 0x1)==0) {
+ index += 1;
+ }
#endif
+
+ RETURN ( __MKSMALLINT(index) );
%}
"
+ 0 lowBit
+ 2r0001 lowBit
+ 2r0010 lowBit
+ 2r0100 lowBit
+ 2r1000 lowBit
+
+ 2r000100 lowBit
+ 2r010010 lowBit
+ 2r100001 lowBit
+ 16r1000 lowBit
+ 16r1000000 lowBit
+ 16r1000000000000000 lowBit
+
Time millisecondsToRun:[
1000000 timesRepeat:[
2r1000 lowBit
]
- ]
- "
- "
+ ]
+
Time millisecondsToRun:[
1000000 timesRepeat:[
2r11110000000 lowBit
]
]
- "
- "
+
Time millisecondsToRun:[
1000000 timesRepeat:[
2r1000000000000 lowBit
]
]
- "
- "
+
Time millisecondsToRun:[
1000000 timesRepeat:[
2r1000000000000000000000000000 lowBit
]
]
"
- "
- 2r000100 lowBit
- 2r010010 lowBit
- 2r100001 lowBit
- 16r1000 lowBit
- 16r1000000 lowBit
- 0 lowBit
- "
!
setBit:anInteger
@@ -3405,5 +3404,5 @@
!SmallInteger class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.145 2002-02-26 10:48:26 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.146 2002-03-28 10:50:28 cg Exp $'
! !