mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Issue #189 - Reimplementation of bitwise-if
This commit is contained in:
parent
8749981f23
commit
8f4e0ccf75
1 changed files with 13 additions and 9 deletions
22
srfi/60.scm
22
srfi/60.scm
|
@ -139,15 +139,19 @@
|
||||||
|
|
||||||
(define bitwise-not lognot)
|
(define bitwise-not lognot)
|
||||||
|
|
||||||
(define-c bitwise-if
|
;;(define-c bitwise-if
|
||||||
"(void* data, int argc, closure _, object k,
|
;; "(void* data, int argc, closure _, object k,
|
||||||
object mask, object n0, object n1)"
|
;; object mask, object n0, object n1)"
|
||||||
"Cyc_check_fixnum(data, mask); // TODO: bignum support
|
;; "Cyc_check_fixnum(data, mask); // TODO: bignum support
|
||||||
Cyc_check_fixnum(data, n0);
|
;; Cyc_check_fixnum(data, n0);
|
||||||
Cyc_check_fixnum(data, n1);
|
;; Cyc_check_fixnum(data, n1);
|
||||||
int m = unbox_number(mask);
|
;; int m = unbox_number(mask);
|
||||||
int result = (m & ((int)unbox_number(n0))) | ((~m) & ((int)unbox_number(n1)));
|
;; int result = (m & ((int)unbox_number(n0))) | ((~m) & ((int)unbox_number(n1)));
|
||||||
return_closcall1(data, k, obj_int2obj(result));")
|
;; return_closcall1(data, k, obj_int2obj(result));")
|
||||||
|
|
||||||
|
(define (bitwise-if mask n0 n1)
|
||||||
|
(logior (logand mask n0)
|
||||||
|
(logand (lognot mask) n1)))
|
||||||
|
|
||||||
(define bitwise-merge bitwise-if)
|
(define bitwise-merge bitwise-if)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue