Added bitwise-xor.
This commit is contained in:
parent
de4276124b
commit
da7cedfe64
Binary file not shown.
|
@ -590,20 +590,37 @@
|
||||||
|
|
||||||
(define binary-bitwise-xor
|
(define binary-bitwise-xor
|
||||||
(lambda (x y)
|
(lambda (x y)
|
||||||
|
(define (fxbn x y)
|
||||||
|
(let ([y0 (bitwise-and y (greatest-fixnum))]
|
||||||
|
[y1 (bitwise-arithmetic-shift-right y (- (fixnum-width) 1))])
|
||||||
|
(bitwise-ior
|
||||||
|
($fxlogand ($fxlogxor x y0) (greatest-fixnum))
|
||||||
|
(bitwise-arithmetic-shift-left
|
||||||
|
(bitwise-arithmetic-shift-right
|
||||||
|
(if ($fx>= x 0) y (bitwise-not y))
|
||||||
|
(- (fixnum-width) 1))
|
||||||
|
(- (fixnum-width) 1)))))
|
||||||
|
(define (bnbn x y)
|
||||||
|
(let ([x0 (bitwise-and x (greatest-fixnum))]
|
||||||
|
[x1 (bitwise-arithmetic-shift-right x (- (fixnum-width) 1))]
|
||||||
|
[y0 (bitwise-and y (greatest-fixnum))]
|
||||||
|
[y1 (bitwise-arithmetic-shift-right y (- (fixnum-width) 1))])
|
||||||
|
(bitwise-ior
|
||||||
|
($fxlogand ($fxlogxor x0 y0) (greatest-fixnum))
|
||||||
|
(bitwise-arithmetic-shift-left
|
||||||
|
(binary-bitwise-xor x1 y1)
|
||||||
|
(- (fixnum-width) 1)))))
|
||||||
(cond
|
(cond
|
||||||
[(fixnum? x)
|
[(fixnum? x)
|
||||||
(cond
|
(cond
|
||||||
[(fixnum? y) ($fxlogxor x y)]
|
[(fixnum? y) ($fxlogxor x y)]
|
||||||
[(bignum? y)
|
[(bignum? y) (fxbn x y)]
|
||||||
(foreign-call "ikrt_fxbnlogxor" x y)]
|
|
||||||
[else
|
[else
|
||||||
(die 'bitwise-xor "not an exact integer" y)])]
|
(die 'bitwise-xor "not an exact integer" y)])]
|
||||||
[(bignum? x)
|
[(bignum? x)
|
||||||
(cond
|
(cond
|
||||||
[(fixnum? y)
|
[(fixnum? y) (fxbn y x)]
|
||||||
(foreign-call "ikrt_fxbnlogxor" y x)]
|
[(bignum? y) (bnbn x y)]
|
||||||
[(bignum? y)
|
|
||||||
(foreign-call "ikrt_bnbnlogxor" x y)]
|
|
||||||
[else
|
[else
|
||||||
(die 'bitwise-xor "not an exact integer" y)])]
|
(die 'bitwise-xor "not an exact integer" y)])]
|
||||||
[else (die 'bitwise-xor "not an exact integer" x)])))
|
[else (die 'bitwise-xor "not an exact integer" x)])))
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1479
|
1480
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
(define (test-other-cases)
|
(define (test-other-cases)
|
||||||
(test-case bitwise-and)
|
(test-case bitwise-and)
|
||||||
(test-case bitwise-ior)
|
(test-case bitwise-ior)
|
||||||
;(test-case bitwise-xor)
|
(test-case bitwise-xor)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1476,20 +1476,6 @@ ikrt_bnbnlogor(ikptr x, ikptr y, ikpcb* pcb){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ikptr
|
|
||||||
ikrt_fxbnlogxor(ikptr x, ikptr y, ikpcb* pcb){
|
|
||||||
fprintf(stderr, "ikrt_fxbnlogxor\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ikptr
|
|
||||||
ikrt_bnbnlogxor(ikptr x, ikptr y, ikpcb* pcb){
|
|
||||||
fprintf(stderr, "ikrt_bnbnlogxor\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
copy_bits_shifting_right(mp_limb_t* src, mp_limb_t* dst, int n, int m){
|
copy_bits_shifting_right(mp_limb_t* src, mp_limb_t* dst, int n, int m){
|
||||||
mp_limb_t carry = src[0] >> m;
|
mp_limb_t carry = src[0] >> m;
|
||||||
|
|
Loading…
Reference in New Issue