Skip to content

Commit 0b9f9b8

Browse files
authored
Merge pull request #46 from BeMg/prefetch-builtin
Locality for prefetch built-in proposal
2 parents 56d7e63 + d37ece8 commit 0b9f9b8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

riscv-c-api.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,25 @@ enum {
400400
| `__RISCV_NTLH_INNERMOST_SHARED` | `ntl.s1` |
401401
| `__RISCV_NTLH_ALL` | `ntl.all` |
402402
403+
### Prefetch Intrinsics
404+
405+
The Zicbop extension provides the prefetch instruction to allow users to optimize data access patterns by providing hints to the hardware regarding future data accesses. It is supported through a compiler-defined built-in function with three arguments that specify its behavior.
406+
407+
```
408+
void __builtin_prefetch(const void *addr, int rw, int locality)
409+
```
410+
411+
The locality for the built-in `__builtin_prefetch` function in RISC-V can be achieved using the Non-Temporal Locality Hints (Zihintntl) extension. When a Non-Temporal Locality (NTL) Hints instruction is applied to prefetch instruction, a cache line should be prefetched into a cache level that is higher than the level specified by the NTL.
412+
413+
The following table presents the mapping from the `__builtin_prefetch` function to the corresponding assembly instructions assuming the presence of the Zihintntl and Zicbop extensions.
414+
415+
| Prefetch function | Assembly |
416+
| ----------------------------------------------- | ---------------------------- |
417+
| `__builtin_prefetch(ptr, 0, 0 /* locality */);` | `ntl.all + prefetch.r (ptr)` |
418+
| `__builtin_prefetch(ptr, 0, 1 /* locality */);` | `ntl.pall + prefetch.r (ptr)`|
419+
| `__builtin_prefetch(ptr, 0, 2 /* locality */);` | `ntl.p1 + prefetch.r (ptr)` |
420+
| `__builtin_prefetch(ptr, 0, 3 /* locality */);` | `prefetch.r (ptr)` |
421+
403422
### Scalar Bit Manipulation Extension Intrinsics
404423
405424
In order to access the RISC-V scalar bit manipulation intrinsics, it is
@@ -501,6 +520,7 @@ Sign extension of 32-bit values on RV64 is not reflected in the interface.
501520
| `uint32_t __riscv_sm4ed(uint32_t rs1, uint32_t rs2, const int bs);` | `sm4ed` | Zksed | `bs`=[0..3] |
502521
| `uint32_t __riscv_sm4ks(uint32_t rs1, uint32_t rs2, const int bs);` | `sm4ks` | Zksed | `bs`=[0..3] |
503522
523+
504524
## Constraints on Operands of Inline Assembly Statements
505525
506526
This section lists operand constraints that can be used with inline assembly

0 commit comments

Comments
 (0)