Added bitwise-xor.

This commit is contained in:
Abdulaziz Ghuloum 2008-05-18 03:21:05 -07:00
parent de4276124b
commit da7cedfe64
5 changed files with 25 additions and 22 deletions

Binary file not shown.

View File

@ -590,20 +590,37 @@
(define binary-bitwise-xor
(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
[(fixnum? x)
(cond
[(fixnum? y) ($fxlogxor x y)]
[(bignum? y)
(foreign-call "ikrt_fxbnlogxor" x y)]
[(bignum? y) (fxbn x y)]
[else
(die 'bitwise-xor "not an exact integer" y)])]
[(bignum? x)
(cond
[(fixnum? y)
(foreign-call "ikrt_fxbnlogxor" y x)]
[(bignum? y)
(foreign-call "ikrt_bnbnlogxor" x y)]
[(fixnum? y) (fxbn y x)]
[(bignum? y) (bnbn x y)]
[else
(die 'bitwise-xor "not an exact integer" y)])]
[else (die 'bitwise-xor "not an exact integer" x)])))

View File

@ -1 +1 @@
1479
1480

View File

@ -74,7 +74,7 @@
(define (test-other-cases)
(test-case bitwise-and)
(test-case bitwise-ior)
;(test-case bitwise-xor)
(test-case bitwise-xor)
)

View File

@ -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
copy_bits_shifting_right(mp_limb_t* src, mp_limb_t* dst, int n, int m){
mp_limb_t carry = src[0] >> m;