1 unstable release
0.1.0 | Aug 9, 2024 |
---|
#65 in #instructions
106 downloads per month
Used in static-keys
9KB
109 lines
clear-cache
A native implementation of __builtin___clear_cache
without dependency of GCC/Clang.
From GCC documentation:
This function is used to flush the processor’s instruction cache for the region of memory between begin inclusive and end exclusive. Some targets require that the instruction cache be flushed, after modifying memory containing code, in order to obtain deterministic behavior.
If the target does not require instruction cache flushes,
__builtin___clear_cache
has no effect. Otherwise either instructions are emitted in-line to clear the instruction cache or a call to the__clear_cache
function in libgcc is made.
From LLVM documentation:
The
llvm.clear_cache
intrinsic ensures visibility of modifications in the specified range to the execution unit of the processor. On targets with non-unified instruction and data cache, the implementation flushes the instruction cache.On platforms with coherent instruction and data caches (e.g. x86), this intrinsic is a nop. On platforms with non-coherent instruction and data cache (e.g. ARM, MIPS), the intrinsic is lowered either to appropriate instructions or a system call, if cache flushing requires special privileges.
The default behavior is to emit a call to
__clear_cache
from the run time library.This intrinsic does not empty the instruction pipeline. Modifications of the current function are outside the scope of the intrinsic.
Current implementation is taken from LLVM's implementation
Current CI-tested platforms:
-
Linux
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl
i686-unknown-linux-gnu
aarch64-unknown-linux-gnu
riscv64gc-unknown-linux-gnu
loongarch64-unknown-linux-gnu
-
macOS
aarch64-apple-darwin
-
Windows
x86_64-pc-windows-msvc
i686-pc-windows-msvc
Dependencies
~0–35MB
~526K SLoC