I want to use the new bit manipulation instructions available in the latest Intel and AMD chips, in particular the "Parallel Bits Extract" PEXT
instruction (see here and here). How can I access these instructions from within Common Lisp? (specifically SBCL).
Ideally, I would like to access these instructions through a library that detects whether the CPU provides them and, if it doesn't, it emulates them in software. Compilers for other languages provide such functions (e.g., GCC provides the function _pext_u32
; see here).
I think that to actually add support for it, you need to modify the compiler itself. This might involve something like adding a new VOP (see vop.lisp in the sbcl sources) defining a new function that compiles to it (maybe in the sb-ext package) and wiring it up. I can't actually tell you how to do that, my understanding of that is only superficial.
The other way, which might be more portable, is to create a C library containing functions that use the new primitive in assembly, then to wrap it in a CFFI binding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With