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
Copy file name to clipboardExpand all lines: riscv-c-api.md
+41-2Lines changed: 41 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -172,5 +172,44 @@ For example:
172
172
173
173
## Intrinsic Functions
174
174
175
-
Do we really have none of these? I can't figure out
176
-
`gcc/gcc/config/riscv/riscv-builtins.c`...
175
+
Intrinsic functions (or intrinsics or built-ins) are expanded into instruction sequences by compilers.
176
+
They typically provide access to functionality that is otherwise not synthesizable by compilers.
177
+
Some intrinsics expand to different code sequences depending on the available instructions from the enabled ISA extensions.
178
+
179
+
Compilers typically come with their own architecture-independent intrinsics (e.g. synchronization primitives, byte-swap, etc.).
180
+
The RISC-V compiler backend can define additional target-specific intrinsics.
181
+
Providing functionality via architecture-independent intrinsics is the preferred method, as it improves code portability.
182
+
183
+
Some intrinsics are only available if a particular header file is included.
184
+
RISC-V header files that enable intrinsics require the prefix `riscv_` (e.g. `riscv_vector.h` or `riscv_crypto.h`).
185
+
186
+
RISC-V specific intrinsics use the common prefix "__riscv_" to avoid namespace collisions.
187
+
188
+
The intrinsic name describes the functional behaviour of the function.
189
+
In case the functionality can be expressed with a single instruction, the instruction's name (any '.' replaced by '_') is the preferred choice.
190
+
Note, that intrinsics that are restricted to RISC-V vendor extensions need to include the vendor prefix (as documented in the RISC-V toolchain conventions).
191
+
192
+
If intrinsics are available for multiple data types, then function overloading is preferred over multiple type-specific functions.
193
+
If an intrinsic function is has parameters or return values that reference registers with XLEN bits, then the data type `long` should be used.
194
+
In case a function is only available for one data type and this type cannot be derived from the function's name, then the type should be appended to the function name, delimited by a '_' character.
195
+
Typical type postfixes are "32" (32-bit), "i32" (signed 32-bit), "i8m4" (vector register group consisting of 4 signed 8-bit vector registers).
196
+
197
+
RISC-V intrinsics follow the following naming rule:
198
+
199
+
```
200
+
INTRINSIC ::= PREFIX NAME [ '_' TYPE ]
201
+
PREFIX ::= "__riscv_"
202
+
NAME ::= Name of the intrinsic function.
203
+
TYPE ::= Optional type postfix.
204
+
```
205
+
206
+
RISC-V intrinsics examples:
207
+
208
+
```
209
+
type __riscv_orc_b (type rs); // orc.b rd, rs
210
+
211
+
long __riscv_clmul (long a, long b); // clmul rd, rs1, rs2
212
+
213
+
#include <riscv_vector.h> // make RISC-V vector intrinsics available
0 commit comments