Created
June 2, 2016 21:09
-
-
Save alex-eg/506210590736a4c23e87035a07692a3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defconstant +debruijn64+ #x22fdd63cc95386d) | |
| (defvar *bit-table* | |
| (let ((a (make-array 64 :element-type '(unsigned-byte 8)))) | |
| (loop for i from 0 below 64 do | |
| (setf (aref a (ash (logand #xFFFFFFFFFFFFFFFF | |
| (ash +debruijn64+ i)) -58)) i)) | |
| a)) | |
| (defun ctz (x) | |
| (declare (type (unsigned-byte 64) x)) | |
| (aref *bit-table* (ash (logand #xFFFFFFFFFFFFFFFF | |
| (* +debruijn64+ (logand x (- x)))) -58))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment