Factor Language Blog

Defining new compiler intrinsics

Friday, April 28, 2006

Although the code is not all in darcs yet, you can now define new compiler intrinsics in a very direct way. For example, here is how fixnum-bitand is defined on PowerPC:

\ fixnum-bitand [
    "x" operand "y" operand "x" operand AND
] H{
    { +input { { f "x" } { f "y" } } }
    { +output { "x" } }
} define-intrinsic

This overrides the fixnum-bitand primitive in compiled code; instead of a call to the runtime function being compiled, it instead generates an AND instruction by calling the assembler word ‘AND’ with some arguments.
I think this is very neat and clean. I wonder if anybody find a use for this feature outside of the compiler core.