mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-04 03:36:34 +02:00
Fixing integer-length to use inline C
This commit is contained in:
parent
c13f37e3b5
commit
a024126f7b
1 changed files with 11 additions and 3 deletions
14
srfi/60.scm
14
srfi/60.scm
|
@ -108,11 +108,19 @@
|
||||||
|
|
||||||
(define bit-count logcount)
|
(define bit-count logcount)
|
||||||
|
|
||||||
(define (integer-length x)
|
(define-c integer-length
|
||||||
(exact (ceiling (log (+ x 1) 2))))
|
"(void* data, int argc, closure _, object k, object x)"
|
||||||
|
"Cyc_check_int(data, x);
|
||||||
|
int input = (int)unbox_number(x);
|
||||||
|
int res = 0;
|
||||||
|
while (input) {
|
||||||
|
res++;
|
||||||
|
input >>= 1;
|
||||||
|
};
|
||||||
|
return_closcall1(data, k, obj_int2obj(res));")
|
||||||
|
|
||||||
(define (log2-binary-factors n)
|
(define (log2-binary-factors n)
|
||||||
(- (integer-length (logand n (- n))) 1))
|
(- (integer-length (raw-logand n (- n))) 1))
|
||||||
|
|
||||||
(define first-set-bit log2-binary-factors)
|
(define first-set-bit log2-binary-factors)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue