The Inbox: Kernel-nice.1293.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Kernel-nice.1293.mcz

commits-2
Nicolas Cellier uploaded a new version of Kernel to project The Inbox:
http://source.squeak.org/inbox/Kernel-nice.1293.mcz

==================== Summary ====================

Name: Kernel-nice.1293
Author: nice
Time: 8 January 2020, 12:56:57.717854 am
UUID: 2a023bb6-8b85-41b9-bc59-fb247fc48658
Ancestors: Kernel-nice.1292

Connect the highBit primitive provided by new VM.
Since the primitive is jitted, it's about 3x faster than highBitOfPositiveReceiver.

[0 to: 1<<24 do: #highBit] bench.
 '7.66 per second. 131 milliseconds per run. 0 % GC time.'
[0 to: 1<<24 do: #highBitOfPositiveReceiver] bench.
 '2.59 per second. 386 milliseconds per run. 0 % GC time.'

It's even a bit faster than highBitOfByte.

[0 to: 255 do: #highBit] bench.
 '472,000 per second. 2.12 microseconds per run. 0 % GC time.'
[0 to: 255 do: #highBitOfByte] bench.
 '323,000 per second. 3.09 microseconds per run. 0 % GC time.'

Note: this has been tested on intel x86 and x64 architecture.
Please report the status on ARM (or mips).

=============== Diff against Kernel-nice.1292 ===============

Item was changed:
  ----- Method: SmallInteger>>highBit (in category 'bit manipulation') -----
  highBit
  "Answer the index of the high order bit of the receiver, or zero if the  
  receiver is zero. Raise an error if the receiver is negative, since  
  negative integers are defined to have an infinite number of leading 1's
  in 2's-complement arithmetic. Use >>highBitOfMagnitude if you want to
  get the highest bit of the magnitude."
+ <primitive: 575>
  self < 0 ifTrue: [^ self error: 'highBit is not defined for negative integers'].
  ^ self highBitOfPositiveReceiver!

Item was changed:
  ----- Method: SmallInteger>>highBitOfMagnitude (in category 'bit manipulation') -----
  highBitOfMagnitude
  "Answer the index of the high order bit of the receiver, or zero if the  
  receiver is zero. This method is used for negative SmallIntegers as well,  
  since Squeak's LargeIntegers are sign/magnitude."
 
+ <primitive: 575>
+ self < 0 ifTrue: [^self negated highBit].
- self < 0 ifTrue: [
- "Beware: do not use highBitOfPositiveReceiver
- because self negated is not necessarily a SmallInteger
- (see SmallInteger minVal)"
- ^self negated highBitOfMagnitude].
-
- "Implementation note: this method could be as well inlined here."
  ^self highBitOfPositiveReceiver!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Kernel-nice.1293.mcz

Levente Uzonyi
On Tue, 7 Jan 2020, [hidden email] wrote:

> Nicolas Cellier uploaded a new version of Kernel to project The Inbox:
> http://source.squeak.org/inbox/Kernel-nice.1293.mcz
>
> ==================== Summary ====================
>
> Name: Kernel-nice.1293
> Author: nice
> Time: 8 January 2020, 12:56:57.717854 am
> UUID: 2a023bb6-8b85-41b9-bc59-fb247fc48658
> Ancestors: Kernel-nice.1292
>
> Connect the highBit primitive provided by new VM.
> Since the primitive is jitted, it's about 3x faster than highBitOfPositiveReceiver.
>
> [0 to: 1<<24 do: #highBit] bench.
> '7.66 per second. 131 milliseconds per run. 0 % GC time.'
> [0 to: 1<<24 do: #highBitOfPositiveReceiver] bench.
> '2.59 per second. 386 milliseconds per run. 0 % GC time.'
>
> It's even a bit faster than highBitOfByte.
>
> [0 to: 255 do: #highBit] bench.
> '472,000 per second. 2.12 microseconds per run. 0 % GC time.'
> [0 to: 255 do: #highBitOfByte] bench.
> '323,000 per second. 3.09 microseconds per run. 0 % GC time.'

Actually, the difference is even greater because if you create a block,
the send will be properly jitted and you won't be measuring Symbol >>
#value: and Object >> #perform:. Subtracting the loop overhead, I measued
9.2x speedup for the first case, and 3.5x speedup for the second case.


Levente

>
> Note: this has been tested on intel x86 and x64 architecture.
> Please report the status on ARM (or mips).
>
> =============== Diff against Kernel-nice.1292 ===============
>
> Item was changed:
>  ----- Method: SmallInteger>>highBit (in category 'bit manipulation') -----
>  highBit
>   "Answer the index of the high order bit of the receiver, or zero if the
>   receiver is zero. Raise an error if the receiver is negative, since
>   negative integers are defined to have an infinite number of leading 1's
>   in 2's-complement arithmetic. Use >>highBitOfMagnitude if you want to
>   get the highest bit of the magnitude."
> + <primitive: 575>
>   self < 0 ifTrue: [^ self error: 'highBit is not defined for negative integers'].
>   ^ self highBitOfPositiveReceiver!
>
> Item was changed:
>  ----- Method: SmallInteger>>highBitOfMagnitude (in category 'bit manipulation') -----
>  highBitOfMagnitude
>   "Answer the index of the high order bit of the receiver, or zero if the
>   receiver is zero. This method is used for negative SmallIntegers as well,
>   since Squeak's LargeIntegers are sign/magnitude."
>
> + <primitive: 575>
> + self < 0 ifTrue: [^self negated highBit].
> - self < 0 ifTrue: [
> - "Beware: do not use highBitOfPositiveReceiver
> - because self negated is not necessarily a SmallInteger
> - (see SmallInteger minVal)"
> - ^self negated highBitOfMagnitude].
> -
> - "Implementation note: this method could be as well inlined here."
>   ^self highBitOfPositiveReceiver!