[gambit-list] newbie: bitwise and arithmetic runtime speed for u64
Bradley Lucier
lucier at purdue.edu
Sun Apr 26 17:31:41 EDT 2020
On 4/26/20 9:48 AM, Paolo wrote:
> Well I tried to do my best to fix most of the performance issues and I
> am now pretty happy with what I have come to, therefore I point you to
> my code in case you are looking for a fun "chess scheme" challenge.
Cool! It looks like a nice project.
I looked at your code a bit. I usually add the following declarations
when working with code that generally does not work with flonums:
(declare
(standard-bindings)
+ (extended-bindings)
+ (mostly-fixnum)
(not safe)
(block))
And, it seems that if you rename the "bitwise" functions then the
compiler doesn't inline checks for fixnum arguments and use the inlined
fixnum operations. I filed an issue:
https://github.com/gambit/gambit/issues/535
If you redefine u64-and, etc., as macros, like
@@ -214,16 +216,24 @@
; int "___return(__builtin_ffsl(___arg1) - 1);"))
; (define (u64-and . args-list) (fold u64c-and #xFFFFFFFFFFFFFFFF
args-list))
-(define u64-and bitwise-and)
+; (define u64-and bitwise-and)
+(define-macro (u64-and . rest)
+ `(bitwise-and , at rest))
; (define (u64-ior . args-list) (fold u64c-ior 0 args-list))
-(define u64-ior bitwise-ior)
+; (define u64-ior bitwise-ior)
+(define-macro (u64-ior . rest)
+ `(bitwise-ior , at rest))
; (define (u64-xor . args-list) (fold u64c-xor 0 args-list))
-(define u64-xor bitwise-xor)
+; (define u64-xor bitwise-xor)
+(define-macro (u64-xor . rest)
+ `(bitwise-xor , at rest))
; (define u64-not u64c-not)
-(define u64-not bitwise-not)
+; (define u64-not bitwise-not)
+(define-macro (u64-not . rest)
+ `(bitwise-not , at rest))
; (define u64-shift u64c-shift)
(define (u64-shift n i) (u64-and #xFFFFFFFFFFFFFFFF
(arithmetic-shift n i)))
@@ -232,10 +242,14 @@
(define (u64-mult a b) (u64-and #xFFFFFFFFFFFFFFFF (* a b)))
; (define bitwise-bit-count c-bitcount)
-(define bitwise-bit-count bit-count)
+; (define bitwise-bit-count bit-count)
+(define-macro (bitwise-bit-count . rest)
+ `(bit-count , at rest))
; (define bitscan-fwd c-bitscan-fwd)
-(define bitscan-fwd first-bit-set)
+; (define bitscan-fwd first-bit-set)
+(define-macro (bitscan-fwd . rest)
+ `(first-bit-set , at rest))
; (define reset-ls1b c-reset-ls1b)
(define (reset-ls1b bits) (u64-and bits (- bits 1)))
then you get a small but noticeable speedup.
Brad
More information about the Gambit-list
mailing list