SmallInteger.st
changeset 4954 af47cd256ddf
parent 4953 b021f07215b2
child 4955 a294a8a19434
equal deleted inserted replaced
4953:b021f07215b2 4954:af47cd256ddf
   997 
   997 
   998     bits = __intVal(self);
   998     bits = __intVal(self);
   999     if (bits == 0) {
   999     if (bits == 0) {
  1000         RETURN ( __MKSMALLINT(-1) );
  1000         RETURN ( __MKSMALLINT(-1) );
  1001     }
  1001     }
       
  1002 
       
  1003 #ifdef __BSR
       
  1004     /*
       
  1005      * so much for CISC CPUS:
       
  1006      * the following code is not faster on a PIII-400
       
  1007      * (but saves a few code-bytes, though)
       
  1008      */
       
  1009     bits = __BSR(bits);
       
  1010     RETURN ( __MKSMALLINT(bits + 1) );
       
  1011 #endif
  1002 
  1012 
  1003 #ifdef alpha64
  1013 #ifdef alpha64
  1004     INDEX0 = 0;
  1014     INDEX0 = 0;
  1005     if (bits & 0xFFFFFFFF00000000L) {
  1015     if (bits & 0xFFFFFFFF00000000L) {
  1006         INDEX0 = 32;
  1016         INDEX0 = 32;
  1126     "
  1136     "
  1127      ((0 to:64) collect:[:s | 1 bitShift:s])
  1137      ((0 to:64) collect:[:s | 1 bitShift:s])
  1128         collect:[:n | n highBit]         
  1138         collect:[:n | n highBit]         
  1129 
  1139 
  1130      (((0 to:64) collect:[:s | 1 bitShift:s])
  1140      (((0 to:64) collect:[:s | 1 bitShift:s])
  1131         collect:[:n | n highBit]) = (1 to:65)   
  1141         collect:[:n | n highBit]) = (1 to:65)     
       
  1142     "
       
  1143 
       
  1144     "
       
  1145      Time millisecondsToRun:[
       
  1146         1000000 timesRepeat:[
       
  1147             2r1 highBit
       
  1148         ]
       
  1149      ]   
       
  1150     "
       
  1151     "
       
  1152      Time millisecondsToRun:[
       
  1153         1000000 timesRepeat:[
       
  1154             2r1111 highBit
       
  1155         ]
       
  1156      ]  
       
  1157     "
       
  1158     "
       
  1159      Time millisecondsToRun:[
       
  1160         1000000 timesRepeat:[
       
  1161             2r11111111111111 highBit
       
  1162         ]
       
  1163      ]   
       
  1164     "
       
  1165     "
       
  1166      Time millisecondsToRun:[
       
  1167         1000000 timesRepeat:[
       
  1168             2r11111111111111111111111111 highBit     
       
  1169         ]
       
  1170      ]   
  1132     "
  1171     "
  1133 
  1172 
  1134     "
  1173     "
  1135      2r000100 highBit      
  1174      2r000100 highBit      
  1136      2r010100 highBit      
  1175      2r010100 highBit      
  1137      2r000001 highBit      
  1176      2r000001 highBit      
  1138      0 highBit             
  1177      0 highBit             
  1139      SmallInteger maxVal highBit
  1178      SmallInteger maxVal highBit 
  1140     "
  1179     "
  1141 
  1180 
  1142 !
  1181 !
  1143 
  1182 
  1144 lowBit
  1183 lowBit
  1149 
  1188 
  1150     INT mask, index, bits;
  1189     INT mask, index, bits;
  1151 
  1190 
  1152     bits = __intVal(self);
  1191     bits = __intVal(self);
  1153     if (bits == 0) {
  1192     if (bits == 0) {
  1154 	RETURN ( __MKSMALLINT(-1) );
  1193         RETURN ( __MKSMALLINT(-1) );
  1155     }
  1194     }
       
  1195 
       
  1196 #ifdef __BSF
       
  1197     /*
       
  1198      * so much for CISC CPUS:
       
  1199      * the following code is only marginally faster on a PIII-400
       
  1200      * (but saves a few code-bytes, though)
       
  1201      */
       
  1202     bits = __BSF(bits);
       
  1203     RETURN ( __MKSMALLINT(bits + 1) );
       
  1204 #endif
  1156 
  1205 
  1157     if ((bits & 0xFFFFFF) == 0) {
  1206     if ((bits & 0xFFFFFF) == 0) {
  1158 	mask = 0x1000000;
  1207         mask = 0x1000000;
  1159 	index = 25;
  1208         index = 25;
  1160     } else {
  1209     } else {
  1161 	if ((bits & 0xFFFF) == 0) {
  1210         if ((bits & 0xFFFF) == 0) {
  1162 	    mask = 0x10000;
  1211             mask = 0x10000;
  1163 	    index = 17;
  1212             index = 17;
  1164 	} else {
  1213         } else {
  1165 	    if ((bits & 0xFF) == 0) {
  1214             if ((bits & 0xFF) == 0) {
  1166 		mask = 0x100;
  1215                 mask = 0x100;
  1167 		index = 9;
  1216                 index = 9;
  1168 	    } else {
  1217             } else {
  1169 		mask = 1;
  1218                 mask = 1;
  1170 		index = 1;
  1219                 index = 1;
  1171 	    }
  1220             }
  1172 	}
  1221         }
  1173     }
  1222     }
  1174 
  1223 
  1175 #ifdef alpha64
  1224 #ifdef alpha64
  1176     while (index != 63) {
  1225     while (index != 63) {
  1177 #else
  1226 #else
  1178     while (index != 31) {
  1227     while (index != 31) {
  1179 #endif
  1228 #endif
  1180 	if (bits & mask) {
  1229         if (bits & mask) {
  1181 	    RETURN ( __MKSMALLINT(index) );
  1230             RETURN ( __MKSMALLINT(index) );
  1182 	}
  1231         }
  1183 	mask = mask << 1;
  1232         mask = mask << 1;
  1184 	index++;
  1233         index++;
  1185     }
  1234     }
  1186     RETURN ( __MKSMALLINT(-1) );
  1235     RETURN ( __MKSMALLINT(-1) );
  1187 %}
  1236 %}
       
  1237 
       
  1238     "
       
  1239      Time millisecondsToRun:[
       
  1240         1000000 timesRepeat:[
       
  1241             2r1000 lowBit
       
  1242         ]
       
  1243      ]  
       
  1244     "
       
  1245     "
       
  1246      Time millisecondsToRun:[
       
  1247         1000000 timesRepeat:[
       
  1248             2r11110000000 lowBit
       
  1249         ]
       
  1250      ] 
       
  1251     "
       
  1252     "
       
  1253      Time millisecondsToRun:[
       
  1254         1000000 timesRepeat:[
       
  1255             2r1000000000000 lowBit
       
  1256         ]
       
  1257      ]  
       
  1258     "
       
  1259     "
       
  1260      Time millisecondsToRun:[
       
  1261         1000000 timesRepeat:[
       
  1262             2r1000000000000000000000000000 lowBit     
       
  1263         ]
       
  1264      ]  
       
  1265     "
  1188     "
  1266     "
  1189      2r000100 lowBit
  1267      2r000100 lowBit
  1190      2r010010 lowBit
  1268      2r010010 lowBit
  1191      2r100001 lowBit
  1269      2r100001 lowBit
  1192      16r1000 lowBit 
  1270      16r1000 lowBit 
  3032 ! !
  3110 ! !
  3033 
  3111 
  3034 !SmallInteger class methodsFor:'documentation'!
  3112 !SmallInteger class methodsFor:'documentation'!
  3035 
  3113 
  3036 version
  3114 version
  3037     ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.122 1999-10-26 22:09:59 cg Exp $'
  3115     ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.123 1999-10-26 23:33:14 cg Exp $'
  3038 ! !
  3116 ! !