SmallInteger.st
changeset 4955 a294a8a19434
parent 4954 af47cd256ddf
child 4967 ce7e7852115f
equal deleted inserted replaced
4954:af47cd256ddf 4955:a294a8a19434
  1006      * the following code is not faster on a PIII-400
  1006      * the following code is not faster on a PIII-400
  1007      * (but saves a few code-bytes, though)
  1007      * (but saves a few code-bytes, though)
  1008      */
  1008      */
  1009     bits = __BSR(bits);
  1009     bits = __BSR(bits);
  1010     RETURN ( __MKSMALLINT(bits + 1) );
  1010     RETURN ( __MKSMALLINT(bits + 1) );
  1011 #endif
  1011 #else
  1012 
  1012 
  1013 #ifdef alpha64
  1013 # ifdef alpha64
  1014     INDEX0 = 0;
  1014     INDEX0 = 0;
  1015     if (bits & 0xFFFFFFFF00000000L) {
  1015     if (bits & 0xFFFFFFFF00000000L) {
  1016         INDEX0 = 32;
  1016         INDEX0 = 32;
  1017         bits = bits >> 32;
  1017         bits = bits >> 32;
  1018     }
  1018     }
  1019 #else
  1019 # else
  1020 # define INDEX0 0
  1020 #  define INDEX0 0
  1021 #endif
  1021 # endif
  1022 
  1022 
  1023     /*
  1023     /*
  1024      * a binary search ...
  1024      * a binary search ...
  1025      */
  1025      */
  1026     if ((bits & 0xFFFF0000) == 0) {
  1026     if ((bits & 0xFFFF0000) == 0) {
  1130                     RETURN (__MKSMALLINT(INDEX0+17) );        /* 0x00010000 */
  1130                     RETURN (__MKSMALLINT(INDEX0+17) );        /* 0x00010000 */
  1131                 }
  1131                 }
  1132             }
  1132             }
  1133         }
  1133         }
  1134     }
  1134     }
       
  1135 #endif
  1135 %}
  1136 %}
  1136     "
  1137     "
  1137      ((0 to:64) collect:[:s | 1 bitShift:s])
  1138      ((0 to:64) collect:[:s | 1 bitShift:s])
  1138         collect:[:n | n highBit]         
  1139         collect:[:n | n highBit]         
  1139 
  1140 
  1199      * the following code is only marginally faster on a PIII-400
  1200      * the following code is only marginally faster on a PIII-400
  1200      * (but saves a few code-bytes, though)
  1201      * (but saves a few code-bytes, though)
  1201      */
  1202      */
  1202     bits = __BSF(bits);
  1203     bits = __BSF(bits);
  1203     RETURN ( __MKSMALLINT(bits + 1) );
  1204     RETURN ( __MKSMALLINT(bits + 1) );
  1204 #endif
  1205 #else
  1205 
  1206 
  1206     if ((bits & 0xFFFFFF) == 0) {
  1207     if ((bits & 0xFFFFFF) == 0) {
  1207         mask = 0x1000000;
  1208         mask = 0x1000000;
  1208         index = 25;
  1209         index = 25;
  1209     } else {
  1210     } else {
  1219                 index = 1;
  1220                 index = 1;
  1220             }
  1221             }
  1221         }
  1222         }
  1222     }
  1223     }
  1223 
  1224 
  1224 #ifdef alpha64
  1225 # ifdef alpha64
  1225     while (index != 63) {
  1226     while (index != 63) {
  1226 #else
  1227 # else
  1227     while (index != 31) {
  1228     while (index != 31) {
  1228 #endif
  1229 # endif
  1229         if (bits & mask) {
  1230         if (bits & mask) {
  1230             RETURN ( __MKSMALLINT(index) );
  1231             RETURN ( __MKSMALLINT(index) );
  1231         }
  1232         }
  1232         mask = mask << 1;
  1233         mask = mask << 1;
  1233         index++;
  1234         index++;
  1234     }
  1235     }
  1235     RETURN ( __MKSMALLINT(-1) );
  1236     RETURN ( __MKSMALLINT(-1) );
       
  1237 #endif
  1236 %}
  1238 %}
  1237 
  1239 
  1238     "
  1240     "
  1239      Time millisecondsToRun:[
  1241      Time millisecondsToRun:[
  1240         1000000 timesRepeat:[
  1242         1000000 timesRepeat:[
  3110 ! !
  3112 ! !
  3111 
  3113 
  3112 !SmallInteger class methodsFor:'documentation'!
  3114 !SmallInteger class methodsFor:'documentation'!
  3113 
  3115 
  3114 version
  3116 version
  3115     ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.123 1999-10-26 23:33:14 cg Exp $'
  3117     ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.124 1999-10-26 23:34:03 cg Exp $'
  3116 ! !
  3118 ! !