首页 > 解决方案 > How to access the new x86 bit-manipulation instructions from Common Lisp?

问题描述

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).

标签: bit-manipulationcommon-lispbitwise-operatorssbcl

解决方案


我认为要真正添加对它的支持,您需要修改编译器本身。这可能涉及添加一个新的 VOP(参见 sbcl 源代码中的 vop.lisp)定义一个编译到它的新函数(可能在 sb-ext 包中)并将其连接起来。我实际上无法告诉您如何做到这一点,我对此的理解只是肤浅的。

另一种可能更可移植的方法是创建一个 C 库,其中包含在汇编中使用新原语的函数,然后将其包装在 CFFI 绑定中。


推荐阅读