Skip to content

Commit 6d54f20

Browse files
authored
loongarch: add __clear_cache builtin implementation (#21008)
1 parent 5415142 commit 6d54f20

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/compiler_rt/clear_cache.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
2828
.aarch64, .aarch64_be => true,
2929
else => false,
3030
};
31+
const loongarch64 = switch (arch) {
32+
.loongarch64 => true,
33+
else => false,
34+
};
3135
const mips = switch (arch) {
3236
.mips, .mipsel, .mips64, .mips64el => true,
3337
else => false,
@@ -159,6 +163,12 @@ fn clear_cache(start: usize, end: usize) callconv(.C) void {
159163
// On Darwin, sys_icache_invalidate() provides this functionality
160164
sys_icache_invalidate(start, end - start);
161165
exportIt();
166+
} else if (os == .linux and loongarch64) {
167+
// See: https://github.com/llvm/llvm-project/blob/cf54cae26b65fc3201eff7200ffb9b0c9e8f9a13/compiler-rt/lib/builtins/clear_cache.c#L94-L95
168+
asm volatile (
169+
\\ ibar 0
170+
);
171+
exportIt();
162172
}
163173
}
164174

0 commit comments

Comments
 (0)