authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-31 10:48:48-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-31 10:48:48-04:00
log0e372ccff511a9e286949328037d87af64e31875
treee3afe2b2dca825295dc842f2f1d6804886c8fa79
parente9c49f423d981dc5f4826f284226f312d51b33cc
signaturelock-open Commit is signed but in an unrecognized format.

clean up the duplicate export logic for __clear_cache


2 files changed, 27 insertions(+), 27 deletions(-)

lib/std/special/compiler_rt.zig+3-18
......@@ -17,27 +17,12 @@ comptime {
1717 .linkage = linkage,
1818 }),
1919
20 .aarch64,
21 .aarch64_be,
22 .aarch64_32,
23 .riscv32,
24 .riscv64,
25 => @export(@import("compiler_rt/clear_cache.zig").clear_cache, .{
26 .name = "__clear_cache",
27 .linkage = linkage,
28 }),
29
30 .arm, .armeb, .thumb, .thumbeb => switch (builtin.os.tag) {
31 .linux => @export(@import("compiler_rt/clear_cache.zig").clear_cache, .{
32 .name = "__clear_cache",
33 .linkage = linkage,
34 }),
35 else => {},
36 },
37
3820 else => {},
3921 }
4022
23 // __clear_cache manages its own logic about whether to be exported or not.
24 _ = @import("compiler_rt/clear_cache.zig").clear_cache;
25
4126 @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage });
4227 @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage });
4328 @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage });
lib/std/special/compiler_rt/clear_cache.zig+24-9
......@@ -45,9 +45,11 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
4545 if (x86) {
4646 // Intel processors have a unified instruction and data cache
4747 // so there is nothing to do
48 exportIt();
4849 } else if (os == .windows and (arm32 or arm64)) {
49 @compileError("TODO");
50 // TODO
5051 // FlushInstructionCache(GetCurrentProcess(), start, end - start);
52 // exportIt();
5153 } else if (arm32 and !apple) {
5254 switch (os) {
5355 .freebsd, .netbsd => {
......@@ -57,23 +59,28 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
5759 };
5860 const result = sysarch(ARM_SYNC_ICACHE, @ptrToInt(&arg));
5961 std.debug.assert(result == 0);
62 exportIt();
6063 },
6164 .linux => {
6265 const result = std.os.linux.syscall3(.cacheflush, start, end, 0);
6366 std.debug.assert(result == 0);
67 exportIt();
6468 },
65 else => @compileError("TODO"),
69 else => {},
6670 }
6771 } else if (os == .linux and mips) {
6872 const flags = 3; // ICACHE | DCACHE
69 const result = std.os.linux.syscall3(std.os.linux.SYS_cacheflush, start, end - start, flags);
73 const result = std.os.linux.syscall3(.cacheflush, start, end - start, flags);
7074 std.debug.assert(result == 0);
75 exportIt();
7176 } else if (mips and os == .openbsd) {
72 @compileError("TODO");
77 // TODO
7378 //cacheflush(start, (uintptr_t)end - (uintptr_t)start, BCACHE);
79 // exportIt();
7480 } else if (os == .linux and riscv) {
75 const result = std.os.linux.syscall3(std.os.linux.SYS_riscv_flush_icache, start, end - start, 0);
81 const result = std.os.linux.syscall3(.riscv_flush_icache, start, end - start, 0);
7682 std.debug.assert(result == 0);
83 exportIt();
7784 } else if (arm64 and !apple) {
7885 // Get Cache Type Info.
7986 // TODO memoize this?
......@@ -112,8 +119,9 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
112119 }
113120 }
114121 asm volatile ("isb sy");
122 exportIt();
115123 } else if (powerpc64) {
116 @compileError("TODO");
124 // TODO
117125 //const size_t line_size = 32;
118126 //const size_t len = (uintptr_t)end - (uintptr_t)start;
119127 //
......@@ -128,8 +136,9 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
128136 //for (uintptr_t line = start_line; line < end_line; line += line_size)
129137 // __asm__ volatile("icbi 0, %0" : : "r"(line));
130138 //__asm__ volatile("isync");
139 // exportIt();
131140 } else if (sparc) {
132 @compileError("TODO");
141 // TODO
133142 //const size_t dword_size = 8;
134143 //const size_t len = (uintptr_t)end - (uintptr_t)start;
135144 //
......@@ -139,14 +148,20 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
139148 //
140149 //for (uintptr_t dword = start_dword; dword < end_dword; dword += dword_size)
141150 // __asm__ volatile("flush %0" : : "r"(dword));
151 // exportIt();
142152 } else if (apple) {
143153 // On Darwin, sys_icache_invalidate() provides this functionality
144154 sys_icache_invalidate(start, end - start);
145 } else {
146 @compileError("no __clear_cache implementation available for this target");
155 exportIt();
147156 }
148157}
149158
159const linkage = if (std.builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak;
160
161inline fn exportIt() void {
162 @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage });
163}
164
150165// Darwin-only
151166extern fn sys_icache_invalidate(start: usize, len: usize) void;
152167// BSD-only