2

The Common Lisp standard includes bit arrays and logical operations on them, such as bit-ior, bit-and,...

What the standard does not seem to offer is logical shifting of bit arrays. Of course, this could be done manually with a simple loop and sbit, but that would not be very efficient.

Looking into the sbcl source code (vm-tran.lisp), on how the other logical bit operations are implemented, the next possible way to implement it would be to mimicri the techniques, used there.

Last not least, there also seems to be a simd instruction, which allows simultaneous shifting (with carry) of 64 bit unsigned integers. This would either call for some vop hackery or to factor the problem out into a foreign library.

So, right now, I am at a cross roads, either trying to implement the function bit-logical-shift within common lisp, or to write myself a shared library and use it via ffi. Which, of course would also open a small can of worms (would need to use simple-finalizer and trivial-garbage for the opaque pointer to the self-made bit arrays...)

I cannot believe, that I am the first, facing this problem and maybe someone here can share their experience, how they solved it.

8
  • I think the expectation was that if you need to do this you would use integers rather than bit arrays. There's no standard shifting operation for any kind of array. Commented Feb 24 at 17:09
  • Some use cases could be solved with displaced arrays. Commented Feb 24 at 17:46
  • @Barmar I need this to test for bit patterns - think 5 in a row (gomoku) on a 19x19 board. The operation is then always (= pattern (bit-and pattern board)), where pattern is the 5 horizontal/vertical/diagonal bits shifted to each possible position. Commented Feb 24 at 18:57
  • Couldn't you use the bitwise operations on integers? Commented Feb 24 at 19:00
  • I found a bit-smasher library that has lshift and rshift functions for bit vectors that might be useful to you. Commented Feb 24 at 19:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.