[gambit-list] bitwise operations

Bradley Lucier lucier at math.purdue.edu
Tue Nov 29 17:53:19 EST 2005


Marc:

There seems to be a disconnect between the documentation and the  
implementation of the following procedures in gambc40b15. Perhaps I  
should document more of the low-level details of the bignum  
operations so people could contribute faster implementation of some  
of the bitwise operations.

BTW, do you happen to have the implementation of the bitset  
operations (rather than bitwise operations, including destructive  
operations) I sent you in gambc40a4.tar.gz on December 16, 2000?  I  
can't seem to find it on my machine. ;-)

Brad

procedure: any-bits-set? n1 n2

     This procedure returns a boolean indicating if the bitwise and  
of n1 and n2 is different from zero or not. This procedure is  
implemented more efficiently than the naive definition:
      	

     (define (any-bits-set? n1 n2) (not (zero? (bitwise-and n1 n2))))

(define-prim (##any-bits-set? x y)
   (cond ((##not (macro-exact-int? x))
          (##fail-check-exact-integer 1 any-bits-set? x y))
         ((##not (macro-exact-int? y))
          (##fail-check-exact-integer 2 any-bits-set? x y))
         (else
          (##not (##eq? (##bitwise-and x y) 0)))))

procedure: all-bits-set? n1 n2

     This procedure returns a boolean indicating if the bitwise and  
of n1 and n2 is equal to n1 or not. This procedure is implemented  
more efficiently than the naive definition:
      	

     (define (all-bits-set? n1 n2) (= n1 (bitwise-and n1 n2)))


(define-prim (##all-bits-set? x y)
   (cond ((##not (macro-exact-int? x))
          (##fail-check-exact-integer 1 all-bits-set? x y))
         ((##not (macro-exact-int? y))
          (##fail-check-exact-integer 2 all-bits-set? x y))
         (else
          (##= x (##bitwise-and x y)))))





More information about the Gambit-list mailing list