You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch implements the C frontend support for APEX custom instructions
via the #pragma intrinsic directive. This allows users to bind existing
C function declarations to APEX custom instruction opcodes at compile time.
Syntax:
#pragma intrinsic(fn_name, "mnemonic", opcode, "format"...)
Where:
- fn_name: Previously declared C function to register as intrinsic
- mnemonic: Assembly instruction name (normalized to lowercase)
- opcode: Instruction opcode (0-255 for XD, 0-63 for XS, 0-31 for XI/XC)
- format: One or more of "XD", "XS", "XI", "XC", or "side_effect"
The pragma parser validates identifier syntax, looks up the function
declaration via lookup_name, extracts format flags from the pragma
arguments, and delegates to arcv_apex_register_builtin for actual
registration.
Format classes:
- XD: Default register-register format (up to 3 registers, 8-bit opcode)
- XS: Two-operand with 8-bit signed immediate (6-bit opcode)
- XI: One-operand with 12-bit signed immediate (5-bit opcode)
- XC: Accumulator format where destination is also source0 (5-bit opcode)
- side_effect: Marks instruction as volatile to prevent optimization
If no format is specified, the compiler infers it from the opcode value
and function signature (see arcv_apex_infer_format in the middle-end
patch).
Example:
int custom_add (int a, int b);
#pragma intrinsic(custom_add, "myadd", 42, "XD")
gcc/ChangeLog:
* config/riscv/riscv-c.cc (arcv_apex_lookup_function): New helper to
lookup function declarations.
(arcv_apex_valid_identifier_p): New helper to validate identifiers.
(arcv_apex_pragma_intrinsic): New function to handle #pragma intrinsic.
(riscv_check_builtin_call): Add APEX builtin call validation.
(riscv_resolve_overloaded_builtin): Add APEX builtin resolution.
(riscv_register_pragmas): Register #pragma intrinsic handler.
* config/riscv/riscv-protos.h (arcv_apex_register_builtin): Declare.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/apex/apex.exp: New test.
* gcc.target/riscv/apex/arcv-apex-err1.c: New test.
* gcc.target/riscv/apex/arcv-apex-err10.c: New test.
* gcc.target/riscv/apex/arcv-apex-err11.c: New test.
* gcc.target/riscv/apex/arcv-apex-err12.c: New test.
* gcc.target/riscv/apex/arcv-apex-err13.c: New test.
* gcc.target/riscv/apex/arcv-apex-err14.c: New test.
* gcc.target/riscv/apex/arcv-apex-err15.c: New test.
* gcc.target/riscv/apex/arcv-apex-err16-rpx.c: New test.
* gcc.target/riscv/apex/arcv-apex-err16.c: New test.
* gcc.target/riscv/apex/arcv-apex-err17-rpx.c: New test.
* gcc.target/riscv/apex/arcv-apex-err17.c: New test.
* gcc.target/riscv/apex/arcv-apex-err18.c: New test.
* gcc.target/riscv/apex/arcv-apex-err19.c: New test.
* gcc.target/riscv/apex/arcv-apex-err2.c: New test.
* gcc.target/riscv/apex/arcv-apex-err20.c: New test.
* gcc.target/riscv/apex/arcv-apex-err3.c: New test.
* gcc.target/riscv/apex/arcv-apex-err4.c: New test.
* gcc.target/riscv/apex/arcv-apex-err5.c: New test.
* gcc.target/riscv/apex/arcv-apex-err6.c: New test.
* gcc.target/riscv/apex/arcv-apex-err7.c: New test.
* gcc.target/riscv/apex/arcv-apex-err8.c: New test.
* gcc.target/riscv/apex/arcv-apex-err9.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-err1_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-err1_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-err2_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-err2_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-err3_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-err3_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-err4_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-err4_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test1_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test1_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test2_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test2_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test3_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test3_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test4_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test4_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test5_0.c: New test.
* gcc.target/riscv/apex/arcv-apex-lto-test5_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-test1.c: New test.
* gcc.target/riscv/apex/arcv-apex-test2.c: New test.
* gcc.target/riscv/apex/arcv-apex-test3.c: New test.
* gcc.target/riscv/apex/arcv-apex-test4.c: New test.
* gcc.target/riscv/apex/arcv-apex-test5.c: New test.
* gcc.target/riscv/apex/arcv-apex-test6.c: New test.
* gcc.target/riscv/apex/arcv-apex-test7.c: New test.
* gcc.target/riscv/apex/arcv-apex-test8.c: New test.
* gcc.target/riscv/apex/arcv-apex-test9.c: New test.
* gcc.target/riscv/apex/arcv-apex-test_XC_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-test_XD_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-test_XI_1.c: New test.
* gcc.target/riscv/apex/arcv-apex-test_XS_1.c: New test.
Signed-off-by: Luis Silva <luiss@synopsys.com>
#pragma intrinsic (foo, FOP, 10, "XC") /* { dg-error "pragma intrinsic: APEX function 'foo' must return the same type as the first parameter for the 'XC' format class" } */
#pragma intrinsic (foo, FOP, 10, "XS") /* { dg-error "pragma intrinsic: APEX function 'foo' must have 2 scalar parameter\\(s\\) for the 'XS' format class" } */
8
+
#pragma intrinsic (bar0, bar0, 11, "XS") /* { dg-error "pragma intrinsic: APEX function 'bar0' must have 2 scalar parameter\\(s\\) for the 'XS' format class" } */
9
+
#pragma intrinsic (bar3, bar3, 12, "XS") /* { dg-warning "pragma intrinsic: Associated function can have no more than 2 parameters" } */
0 commit comments