Friday, April 28, 2006

Defining new compiler intrinsics

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.

2 comments:

Anonymous said...

What makes something an intrinsic?

Slava Pestov said...

A word which has special behavior when compiled -- basically a primitive for which efficient inline assembly is providd.