Mantis - Squeak
Viewing Issue Advanced Details
7113 Kernel minor N/A 07-07-08 23:57 04-18-10 21:59
nicolas cellier  
nicolas cellier  
normal  
closed 3.10  
fixed  
none    
none trunk  
0007113: [ENH] Speed-up SmallInteger highBit and lowBit
Currently, algorithms are supposed to be fast for a one-byte-long and not optimized for a longer one.

I claim both cases can be speed up for highBit.
Provided code hereafter shows a gain between 30% and 40% for highBit.
I used a log: 2 power descent 16r10000 16r100 16r10
then finish with a 16 bytes array.
First test is a whileTrue: to handle future case of 64bits

For lowBit, I kept it fast for byte and suboptimal for longer.
I used a table of 16 bytes.
Speed-up ranges from 0% to 66%

{
[100000 timesRepeat: [123456798 highBit]] timeToRun.
[100000 timesRepeat: [122 highBit]] timeToRun.
[100000 timesRepeat: [12 highBit]] timeToRun.
[100000 timesRepeat: [3950591 lowBit]] timeToRun.
[100000 timesRepeat: [3950592 lowBit]] timeToRun.
[100000 timesRepeat: [8 lowBit]] timeToRun.
[100000 timesRepeat: [(-1073741824) lowBit]] timeToRun.
}

OLD-> #(289 188 184 90 242 177 3763)
NEW-> #(203 136 117 90 147 89 2769)
 SmallInteger-highBit-lowBit-SpeedUp-M7113-nice.1.cs [^] (1,759 bytes) 07-08-08 00:28
 SmallInteger-highBit-lowBit-Test-M7113-nice.1.cs [^] (1,508 bytes) 07-08-08 00:28
 SmallInteger-highBit-lowBit-Test-M7113-nice.2.cs [^] (1,489 bytes) 07-08-08 00:49

Notes
(0012349)
nicolas cellier   
07-08-08 00:50   
Uploaded a second test file in order to separate issue 0007114 (highBitOfMagnitude)
(0012350)
nicolas cellier   
07-08-08 00:54   
"fix begin"
Installer mantis bug: 7113 fix:'SmallInteger-highBit-lowBit-SpeedUp-M7113-nice.1.cs'.
"fix test"
Installer mantis bug: 7113 fix:'SmallInteger-highBit-lowBit-Test-M7113-nice.2.cs'.
"fix end"
(0013407)
nicolas cellier   
11-27-09 19:27   
fixed in http://source.squeak.org/trunk/Kernel-nice.306.mcz [^]
The version in trunk cache results for last 8 bits, not just last 4 bits as in 'SmallInteger-highBit-lowBit-Test-M7113-nice.2.cs'