authorgravatar for yangxudong@ymatrix.cnYANG Xudong <yangxudong@ymatrix.cn> 2024-08-10 16:24:01+08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-10 01:24:01-07:00
log6d54f20c4713c564cfe65a84683b10b445a7d34c
treeacd149fa0d5090f73bd4722f5d47006f900ec4c8
parent54151428e5236a0612fe36837ed5a6c1e28aec7a
signaturebadge-check Signed by PGP key B5690EEEBB952194

loongarch: add __clear_cache builtin implementation (#21008)


1 files changed, 10 insertions(+), 0 deletions(-)

lib/compiler_rt/clear_cache.zig+10
......@@ -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