Skip to content

proposal: cmd/compile: intrinsicify user defined assembly functions #17373

Closed
@minux

Description

@minux

I'd like the compiler to intrinsicify user defined assembly functions.

here is a simple sketch of the user interface:
we introduce CLOBBER pseudo instruction to describe that after
certain instruction, certain registers are clobbered.

When the user defines such an assembly function in a package:
TEXT ·Clz(SB), NOSPLIT, $0-4
MOVW 0(FP), R0 // compiler recognizes this as input read
CLZ R0, R1 // the new instruction template
CLOBBER [R2-R3, R11] // as an example of CLOBBER, so that compiler know to spill those registers before using this instruction template
MOVW R1, 4(FP) // compiler recognizes this as output write
RET

The user effectively tells the compiler a new rule to expand call
to Clz function with a custom instruction CLZ.

If we ignore the possibility of doing register allocation for the new
instruction template, I think instrinsicify such assembly functions
with the current SSA backend is within reach.

Of course, this has implications on safety, but if the user is already
using assembly, then that shouldn't be a big concern.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions