Commit 0556a2ba53

Andrew Kelley <andrew@ziglang.org>
2022-06-18 03:10:00
compiler-rt: finish cleanups
Finishes cleanups that I started in other commits in this branch. * Use common.linkage for all exports instead of redoing the logic in each file. * Remove pointless `@setRuntimeSafety` calls. * Avoid redundantly exporting multiple versions of functions. For example, if PPC wants `ceilf128` then don't also export `ceilq`; similarly if ARM wants `__aeabi_ddiv` then don't also export `__divdf3`. * Use `inline` for helper functions instead of making inline calls at callsites.
1 parent 3efc229
lib/compiler_rt/arm.zig
@@ -2,40 +2,41 @@
 const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
     if (!builtin.is_test) {
         if (arch.isARM() or arch.isThumb()) {
-            @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });
-            @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
-            @export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
+            @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = common.linkage });
+            @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = common.linkage });
+            @export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = common.linkage });
 
-            @export(__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = linkage });
-            @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = linkage });
+            @export(__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = common.linkage });
+            @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = common.linkage });
 
-            @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = linkage });
-            @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = linkage });
+            @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = common.linkage });
+            @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = common.linkage });
 
-            @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = linkage });
-            @export(__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = linkage });
-            @export(__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = linkage });
+            @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = common.linkage });
+            @export(__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = common.linkage });
+            @export(__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = common.linkage });
 
-            @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = linkage });
-            @export(__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = linkage });
-            @export(__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = linkage });
+            @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = common.linkage });
+            @export(__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = common.linkage });
+            @export(__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = common.linkage });
 
-            @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = linkage });
-            @export(__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = linkage });
-            @export(__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = linkage });
+            @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = common.linkage });
+            @export(__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = common.linkage });
+            @export(__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = common.linkage });
 
-            @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = linkage });
-            @export(__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = linkage });
-            @export(__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = linkage });
+            @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = common.linkage });
+            @export(__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = common.linkage });
+            @export(__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = common.linkage });
 
             if (builtin.os.tag == .linux) {
-                @export(__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage });
+                @export(__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = common.linkage });
             }
         }
     }
lib/compiler_rt/aulldiv.zig
@@ -2,19 +2,19 @@ const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const abi = builtin.abi;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Strong;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
     if (arch == .i386 and abi == .msvc) {
         // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
-        @export(_alldiv, .{ .name = "\x01__alldiv", .linkage = linkage });
-        @export(_aulldiv, .{ .name = "\x01__aulldiv", .linkage = linkage });
+        @export(_alldiv, .{ .name = "\x01__alldiv", .linkage = common.linkage });
+        @export(_aulldiv, .{ .name = "\x01__aulldiv", .linkage = common.linkage });
     }
 }
 
 pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
-    @setRuntimeSafety(builtin.is_test);
     const s_a = a >> (64 - 1);
     const s_b = b >> (64 - 1);
 
lib/compiler_rt/aullrem.zig
@@ -2,19 +2,19 @@ const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const abi = builtin.abi;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Strong;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
     if (arch == .i386 and abi == .msvc) {
         // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
-        @export(_allrem, .{ .name = "\x01__allrem", .linkage = linkage });
-        @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = linkage });
+        @export(_allrem, .{ .name = "\x01__allrem", .linkage = common.linkage });
+        @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = common.linkage });
     }
 }
 
 pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {
-    @setRuntimeSafety(builtin.is_test);
     const s_a = a >> (64 - 1);
     const s_b = b >> (64 - 1);
 
lib/compiler_rt/bswap.zig
@@ -1,13 +1,13 @@
 const std = @import("std");
 const builtin = @import("builtin");
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = linkage });
-    @export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = linkage });
-    @export(__bswapti2, .{ .name = "__bswapti2", .linkage = linkage });
+    @export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = common.linkage });
+    @export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = common.linkage });
+    @export(__bswapti2, .{ .name = "__bswapti2", .linkage = common.linkage });
 }
 
 // bswap - byteswap
@@ -21,7 +21,6 @@ comptime {
 // 00 00 00 ff << 3*8 (rightmost byte)
 
 inline fn bswapXi2(comptime T: type, a: T) T {
-    @setRuntimeSafety(builtin.is_test);
     switch (@bitSizeOf(T)) {
         32 => {
             // zig fmt: off
lib/compiler_rt/ceil.zig
@@ -1,30 +1,26 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
+//! Ported from musl, which is MIT licensed.
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const math = std.math;
 const expect = std.testing.expect;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__ceilh, .{ .name = "__ceilh", .linkage = linkage });
-    @export(ceilf, .{ .name = "ceilf", .linkage = linkage });
-    @export(ceil, .{ .name = "ceil", .linkage = linkage });
-    @export(__ceilx, .{ .name = "__ceilx", .linkage = linkage });
-    @export(ceilq, .{ .name = "ceilq", .linkage = linkage });
-    @export(ceill, .{ .name = "ceill", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(ceilf128, .{ .name = "ceilf128", .linkage = linkage });
-        }
-    }
+    @export(__ceilh, .{ .name = "__ceilh", .linkage = common.linkage });
+    @export(ceilf, .{ .name = "ceilf", .linkage = common.linkage });
+    @export(ceil, .{ .name = "ceil", .linkage = common.linkage });
+    @export(__ceilx, .{ .name = "__ceilx", .linkage = common.linkage });
+    const ceilq_sym_name = if (common.want_ppc_abi) "ceilf128" else "ceilq";
+    @export(ceilq, .{ .name = ceilq_sym_name, .linkage = common.linkage });
+    @export(ceill, .{ .name = "ceill", .linkage = common.linkage });
 }
 
 pub fn __ceilh(x: f16) callconv(.C) f16 {
@@ -130,10 +126,6 @@ pub fn ceilq(x: f128) callconv(.C) f128 {
     }
 }
 
-pub fn ceilf128(x: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, ceilq, .{x});
-}
-
 pub fn ceill(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __ceilh(x),
lib/compiler_rt/cmp.zig
@@ -1,16 +1,17 @@
 const std = @import("std");
 const builtin = @import("builtin");
 const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = linkage });
-    @export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = linkage });
-    @export(__cmpti2, .{ .name = "__cmpti2", .linkage = linkage });
-    @export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = linkage });
-    @export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = linkage });
-    @export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = linkage });
+    @export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = common.linkage });
+    @export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = common.linkage });
+    @export(__cmpti2, .{ .name = "__cmpti2", .linkage = common.linkage });
+    @export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = common.linkage });
+    @export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = common.linkage });
+    @export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = common.linkage });
 }
 
 // cmp - signed compare
@@ -24,7 +25,6 @@ comptime {
 // a >  b => 2
 
 inline fn XcmpXi2(comptime T: type, a: T, b: T) i32 {
-    @setRuntimeSafety(builtin.is_test);
     var cmp1: i32 = 0;
     var cmp2: i32 = 0;
     if (a > b)
lib/compiler_rt/cos.zig
@@ -3,26 +3,22 @@ const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const math = std.math;
 const expect = std.testing.expect;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 const trig = @import("trig.zig");
 const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
 const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
 
 comptime {
-    @export(__cosh, .{ .name = "__cosh", .linkage = linkage });
-    @export(cosf, .{ .name = "cosf", .linkage = linkage });
-    @export(cos, .{ .name = "cos", .linkage = linkage });
-    @export(__cosx, .{ .name = "__cosx", .linkage = linkage });
-    @export(cosq, .{ .name = "cosq", .linkage = linkage });
-    @export(cosl, .{ .name = "cosl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(cosf128, .{ .name = "cosf128", .linkage = linkage });
-        }
-    }
+    @export(__cosh, .{ .name = "__cosh", .linkage = common.linkage });
+    @export(cosf, .{ .name = "cosf", .linkage = common.linkage });
+    @export(cos, .{ .name = "cos", .linkage = common.linkage });
+    @export(__cosx, .{ .name = "__cosx", .linkage = common.linkage });
+    const cosq_sym_name = if (common.want_ppc_abi) "cosf128" else "cosq";
+    @export(cosq, .{ .name = cosq_sym_name, .linkage = common.linkage });
+    @export(cosl, .{ .name = "cosl", .linkage = common.linkage });
 }
 
 pub fn __cosh(a: f16) callconv(.C) f16 {
@@ -126,10 +122,6 @@ pub fn cosq(a: f128) callconv(.C) f128 {
     return cos(@floatCast(f64, a));
 }
 
-pub fn cosf128(a: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, cosq, .{a});
-}
-
 pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __cosh(x),
lib/compiler_rt/count0bits.zig
@@ -1,19 +1,20 @@
 const std = @import("std");
 const builtin = @import("builtin");
 const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });
-    @export(__clzdi2, .{ .name = "__clzdi2", .linkage = linkage });
-    @export(__clzti2, .{ .name = "__clzti2", .linkage = linkage });
-    @export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = linkage });
-    @export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = linkage });
-    @export(__ctzti2, .{ .name = "__ctzti2", .linkage = linkage });
-    @export(__ffssi2, .{ .name = "__ffssi2", .linkage = linkage });
-    @export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = linkage });
-    @export(__ffsti2, .{ .name = "__ffsti2", .linkage = linkage });
+    @export(__clzsi2, .{ .name = "__clzsi2", .linkage = common.linkage });
+    @export(__clzdi2, .{ .name = "__clzdi2", .linkage = common.linkage });
+    @export(__clzti2, .{ .name = "__clzti2", .linkage = common.linkage });
+    @export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = common.linkage });
+    @export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = common.linkage });
+    @export(__ctzti2, .{ .name = "__ctzti2", .linkage = common.linkage });
+    @export(__ffssi2, .{ .name = "__ffssi2", .linkage = common.linkage });
+    @export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = common.linkage });
+    @export(__ffsti2, .{ .name = "__ffsti2", .linkage = common.linkage });
 }
 
 // clz - count leading zeroes
@@ -30,8 +31,6 @@ comptime {
 // - ffsXi2 for unoptimized little and big endian
 
 inline fn clzXi2(comptime T: type, a: T) i32 {
-    @setRuntimeSafety(builtin.is_test);
-
     var x = switch (@bitSizeOf(T)) {
         32 => @bitCast(u32, a),
         64 => @bitCast(u64, a),
@@ -169,8 +168,6 @@ pub fn __clzti2(a: i128) callconv(.C) i32 {
 }
 
 inline fn ctzXi2(comptime T: type, a: T) i32 {
-    @setRuntimeSafety(builtin.is_test);
-
     var x = switch (@bitSizeOf(T)) {
         32 => @bitCast(u32, a),
         64 => @bitCast(u64, a),
@@ -206,8 +203,6 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 {
 }
 
 inline fn ffsXi2(comptime T: type, a: T) i32 {
-    @setRuntimeSafety(builtin.is_test);
-
     var x = switch (@bitSizeOf(T)) {
         32 => @bitCast(u32, a),
         64 => @bitCast(u64, a),
lib/compiler_rt/divdf3.zig
@@ -1,30 +1,35 @@
-// Ported from:
-//
-// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divdf3.c
+//! Ported from:
+//!
+//! https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divdf3.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-
 const common = @import("common.zig");
+
 const normalize = common.normalize;
 const wideMultiply = common.wideMultiply;
+
 pub const panic = common.panic;
 
 comptime {
-    @export(__divdf3, .{ .name = "__divdf3", .linkage = linkage });
-
-    if (!is_test) {
-        if (arch.isARM() or arch.isThumb()) {
-            @export(__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage });
-        }
+    if (common.want_aeabi) {
+        @export(__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = common.linkage });
+    } else {
+        @export(__divdf3, .{ .name = "__divdf3", .linkage = common.linkage });
     }
 }
 
 pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
-    @setRuntimeSafety(builtin.is_test);
+    return div(a, b);
+}
+
+fn __aeabi_ddiv(a: f64, b: f64) callconv(.AAPCS) f64 {
+    return div(a, b);
+}
+
+inline fn div(a: f64, b: f64) f64 {
     const Z = std.meta.Int(.unsigned, 64);
     const SignedZ = std.meta.Int(.signed, 64);
 
@@ -220,11 +225,6 @@ pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
     }
 }
 
-pub fn __aeabi_ddiv(a: f64, b: f64) callconv(.AAPCS) f64 {
-    @setRuntimeSafety(false);
-    return @call(.{ .modifier = .always_inline }, __divdf3, .{ a, b });
-}
-
 test {
     _ = @import("divdf3_test.zig");
 }
lib/compiler_rt/divsf3.zig
@@ -1,29 +1,33 @@
-// Ported from:
-//
-// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divsf3.c
+//! Ported from:
+//!
+//! https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divsf3.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
 
 const common = @import("common.zig");
 const normalize = common.normalize;
+
 pub const panic = common.panic;
 
 comptime {
-    @export(__divsf3, .{ .name = "__divsf3", .linkage = linkage });
-
-    if (!is_test) {
-        if (arch.isARM() or arch.isThumb()) {
-            @export(__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage });
-        }
+    if (common.want_aeabi) {
+        @export(__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = common.linkage });
+    } else {
+        @export(__divsf3, .{ .name = "__divsf3", .linkage = common.linkage });
     }
 }
 
 pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
-    @setRuntimeSafety(builtin.is_test);
+    return div(a, b);
+}
+
+fn __aeabi_fdiv(a: f32, b: f32) callconv(.AAPCS) f32 {
+    return div(a, b);
+}
+
+inline fn div(a: f32, b: f32) f32 {
     const Z = std.meta.Int(.unsigned, 32);
 
     const significandBits = std.math.floatMantissaBits(f32);
@@ -201,11 +205,6 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
     }
 }
 
-pub fn __aeabi_fdiv(a: f32, b: f32) callconv(.AAPCS) f32 {
-    @setRuntimeSafety(false);
-    return @call(.{ .modifier = .always_inline }, __divsf3, .{ a, b });
-}
-
 test {
     _ = @import("divsf3_test.zig");
 }
lib/compiler_rt/divti3.zig
@@ -2,34 +2,42 @@ const std = @import("std");
 const builtin = @import("builtin");
 const udivmod = @import("udivmod.zig").udivmod;
 const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
     if (builtin.os.tag == .windows) {
         switch (arch) {
             .i386 => {
-                @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
+                @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
             },
             .x86_64 => {
                 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
                 // that LLVM expects compiler-rt to have.
-                @export(__divti3_windows_x86_64, .{ .name = "__divti3", .linkage = linkage });
+                @export(__divti3_windows_x86_64, .{ .name = "__divti3", .linkage = common.linkage });
             },
             else => {},
         }
         if (arch.isAARCH64()) {
-            @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
+            @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
         }
     } else {
-        @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
+        @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
     }
 }
 
 pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
-    @setRuntimeSafety(builtin.is_test);
+    return div(a, b);
+}
 
+const v128 = @import("std").meta.Vector(2, u64);
+
+fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
+    return @bitCast(v128, div(@bitCast(i128, a), @bitCast(i128, b)));
+}
+
+inline fn div(a: i128, b: i128) i128 {
     const s_a = a >> (128 - 1);
     const s_b = b >> (128 - 1);
 
@@ -41,14 +49,6 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
     return (@bitCast(i128, r) ^ s) -% s;
 }
 
-const v128 = @import("std").meta.Vector(2, u64);
-pub fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
-    return @bitCast(v128, @call(.{ .modifier = .always_inline }, __divti3, .{
-        @bitCast(i128, a),
-        @bitCast(i128, b),
-    }));
-}
-
 test {
     _ = @import("divti3_test.zig");
 }
lib/compiler_rt/divxf3.zig
@@ -1,20 +1,18 @@
 const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
 
 const common = @import("common.zig");
 const normalize = common.normalize;
 const wideMultiply = common.wideMultiply;
+
 pub const panic = common.panic;
 
 comptime {
-    @export(__divxf3, .{ .name = "__divxf3", .linkage = linkage });
+    @export(__divxf3, .{ .name = "__divxf3", .linkage = common.linkage });
 }
 
 pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
-    @setRuntimeSafety(builtin.is_test);
     const T = f80;
     const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
 
lib/compiler_rt/emutls.zig
@@ -1,25 +1,25 @@
-// __emutls_get_address specific builtin
-//
-// derived work from LLVM Compiler Infrastructure - release 8.0 (MIT)
-// https://github.com/llvm-mirror/compiler-rt/blob/release_80/lib/builtins/emutls.c
-//
+//! __emutls_get_address specific builtin
+//!
+//! derived work from LLVM Compiler Infrastructure - release 8.0 (MIT)
+//! https://github.com/llvm-mirror/compiler-rt/blob/release_80/lib/builtins/emutls.c
 
 const std = @import("std");
 const builtin = @import("builtin");
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
 
 const abort = std.os.abort;
 const assert = std.debug.assert;
 const expect = std.testing.expect;
 
-// defined in C as:
-// typedef unsigned int gcc_word __attribute__((mode(word)));
+/// defined in C as:
+/// typedef unsigned int gcc_word __attribute__((mode(word)));
 const gcc_word = usize;
 
+pub const panic = common.panic;
+
 comptime {
     if (builtin.link_libc and builtin.os.tag == .openbsd) {
-        @export(__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage });
+        @export(__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = common.linkage });
     }
 }
 
lib/compiler_rt/exp.zig
@@ -9,22 +9,18 @@ const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const math = std.math;
 const expect = std.testing.expect;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__exph, .{ .name = "__exph", .linkage = linkage });
-    @export(expf, .{ .name = "expf", .linkage = linkage });
-    @export(exp, .{ .name = "exp", .linkage = linkage });
-    @export(__expx, .{ .name = "__expx", .linkage = linkage });
-    @export(expq, .{ .name = "expq", .linkage = linkage });
-    @export(expl, .{ .name = "expl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(expf128, .{ .name = "expf128", .linkage = linkage });
-        }
-    }
+    @export(__exph, .{ .name = "__exph", .linkage = common.linkage });
+    @export(expf, .{ .name = "expf", .linkage = common.linkage });
+    @export(exp, .{ .name = "exp", .linkage = common.linkage });
+    @export(__expx, .{ .name = "__expx", .linkage = common.linkage });
+    const expq_sym_name = if (common.want_ppc_abi) "expf128" else "expq";
+    @export(expq, .{ .name = expq_sym_name, .linkage = common.linkage });
+    @export(expl, .{ .name = "expl", .linkage = common.linkage });
 }
 
 pub fn __exph(a: f16) callconv(.C) f16 {
@@ -201,10 +197,6 @@ pub fn expq(a: f128) callconv(.C) f128 {
     return exp(@floatCast(f64, a));
 }
 
-pub fn expf128(a: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, expq, .{a});
-}
-
 pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __exph(x),
lib/compiler_rt/exp2.zig
@@ -9,22 +9,18 @@ const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const math = std.math;
 const expect = std.testing.expect;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
 
-comptime {
-    @export(__exp2h, .{ .name = "__exp2h", .linkage = linkage });
-    @export(exp2f, .{ .name = "exp2f", .linkage = linkage });
-    @export(exp2, .{ .name = "exp2", .linkage = linkage });
-    @export(__exp2x, .{ .name = "__exp2x", .linkage = linkage });
-    @export(exp2q, .{ .name = "exp2q", .linkage = linkage });
-    @export(exp2l, .{ .name = "exp2l", .linkage = linkage });
+pub const panic = common.panic;
 
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(exp2f128, .{ .name = "exp2f128", .linkage = linkage });
-        }
-    }
+comptime {
+    @export(__exp2h, .{ .name = "__exp2h", .linkage = common.linkage });
+    @export(exp2f, .{ .name = "exp2f", .linkage = common.linkage });
+    @export(exp2, .{ .name = "exp2", .linkage = common.linkage });
+    @export(__exp2x, .{ .name = "__exp2x", .linkage = common.linkage });
+    const exp2q_sym_name = if (common.want_ppc_abi) "exp2f128" else "exp2q";
+    @export(exp2q, .{ .name = exp2q_sym_name, .linkage = common.linkage });
+    @export(exp2l, .{ .name = "exp2l", .linkage = common.linkage });
 }
 
 pub fn __exp2h(x: f16) callconv(.C) f16 {
@@ -168,10 +164,6 @@ pub fn exp2q(x: f128) callconv(.C) f128 {
     return exp2(@floatCast(f64, x));
 }
 
-pub fn exp2f128(x: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, exp2q, .{x});
-}
-
 pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __exp2h(x),
lib/compiler_rt/fabs.zig
@@ -1,22 +1,18 @@
 const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__fabsh, .{ .name = "__fabsh", .linkage = linkage });
-    @export(fabsf, .{ .name = "fabsf", .linkage = linkage });
-    @export(fabs, .{ .name = "fabs", .linkage = linkage });
-    @export(__fabsx, .{ .name = "__fabsx", .linkage = linkage });
-    @export(fabsq, .{ .name = "fabsq", .linkage = linkage });
-    @export(fabsl, .{ .name = "fabsl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(fabsf128, .{ .name = "fabsf128", .linkage = linkage });
-        }
-    }
+    @export(__fabsh, .{ .name = "__fabsh", .linkage = common.linkage });
+    @export(fabsf, .{ .name = "fabsf", .linkage = common.linkage });
+    @export(fabs, .{ .name = "fabs", .linkage = common.linkage });
+    @export(__fabsx, .{ .name = "__fabsx", .linkage = common.linkage });
+    const fabsq_sym_name = if (common.want_ppc_abi) "fabsf128" else "fabsq";
+    @export(fabsq, .{ .name = fabsq_sym_name, .linkage = common.linkage });
+    @export(fabsl, .{ .name = "fabsl", .linkage = common.linkage });
 }
 
 pub fn __fabsh(a: f16) callconv(.C) f16 {
@@ -39,10 +35,6 @@ pub fn fabsq(a: f128) callconv(.C) f128 {
     return generic_fabs(a);
 }
 
-pub fn fabsf128(a: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, fabsq, .{a});
-}
-
 pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __fabsh(x),
lib/compiler_rt/floor.zig
@@ -1,30 +1,26 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
+//! Ported from musl, which is licensed under the MIT license:
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const math = std.math;
 const expect = std.testing.expect;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__floorh, .{ .name = "__floorh", .linkage = linkage });
-    @export(floorf, .{ .name = "floorf", .linkage = linkage });
-    @export(floor, .{ .name = "floor", .linkage = linkage });
-    @export(__floorx, .{ .name = "__floorx", .linkage = linkage });
-    @export(floorq, .{ .name = "floorq", .linkage = linkage });
-    @export(floorl, .{ .name = "floorl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(floorf128, .{ .name = "floorf128", .linkage = linkage });
-        }
-    }
+    @export(__floorh, .{ .name = "__floorh", .linkage = common.linkage });
+    @export(floorf, .{ .name = "floorf", .linkage = common.linkage });
+    @export(floor, .{ .name = "floor", .linkage = common.linkage });
+    @export(__floorx, .{ .name = "__floorx", .linkage = common.linkage });
+    const floorq_sym_name = if (common.want_ppc_abi) "floorf128" else "floorq";
+    @export(floorq, .{ .name = floorq_sym_name, .linkage = common.linkage });
+    @export(floorl, .{ .name = "floorl", .linkage = common.linkage });
 }
 
 pub fn __floorh(x: f16) callconv(.C) f16 {
@@ -160,10 +156,6 @@ pub fn floorq(x: f128) callconv(.C) f128 {
     }
 }
 
-pub fn floorf128(x: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, floorq, .{x});
-}
-
 pub fn floorl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __floorh(x),
lib/compiler_rt/fma.zig
@@ -1,31 +1,27 @@
-// Ported from musl, which is MIT licensed:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/fmal.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/fmaf.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/fma.c
+//! Ported from musl, which is MIT licensed:
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/fmal.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/fmaf.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/fma.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const math = std.math;
 const expect = std.testing.expect;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__fmah, .{ .name = "__fmah", .linkage = linkage });
-    @export(fmaf, .{ .name = "fmaf", .linkage = linkage });
-    @export(fma, .{ .name = "fma", .linkage = linkage });
-    @export(__fmax, .{ .name = "__fmax", .linkage = linkage });
-    @export(fmaq, .{ .name = "fmaq", .linkage = linkage });
-    @export(fmal, .{ .name = "fmal", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(fmaf128, .{ .name = "fmaf128", .linkage = linkage });
-        }
-    }
+    @export(__fmah, .{ .name = "__fmah", .linkage = common.linkage });
+    @export(fmaf, .{ .name = "fmaf", .linkage = common.linkage });
+    @export(fma, .{ .name = "fma", .linkage = common.linkage });
+    @export(__fmax, .{ .name = "__fmax", .linkage = common.linkage });
+    const fmaq_sym_name = if (common.want_ppc_abi) "fmaf128" else "fmaq";
+    @export(fmaq, .{ .name = fmaq_sym_name, .linkage = common.linkage });
+    @export(fmal, .{ .name = "fmal", .linkage = common.linkage });
 }
 
 pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 {
@@ -154,10 +150,6 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 {
     }
 }
 
-pub fn fmaf128(x: f128, y: f128, z: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, fmaq, .{ x, y, z });
-}
-
 pub fn fmal(x: c_longdouble, y: c_longdouble, z: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __fmah(x, y, z),
lib/compiler_rt/fmax.zig
@@ -2,22 +2,18 @@ const std = @import("std");
 const builtin = @import("builtin");
 const math = std.math;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
 
-comptime {
-    @export(__fmaxh, .{ .name = "__fmaxh", .linkage = linkage });
-    @export(fmaxf, .{ .name = "fmaxf", .linkage = linkage });
-    @export(fmax, .{ .name = "fmax", .linkage = linkage });
-    @export(__fmaxx, .{ .name = "__fmaxx", .linkage = linkage });
-    @export(fmaxq, .{ .name = "fmaxq", .linkage = linkage });
-    @export(fmaxl, .{ .name = "fmaxl", .linkage = linkage });
+pub const panic = common.panic;
 
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(fmaxf128, .{ .name = "fmaxf128", .linkage = linkage });
-        }
-    }
+comptime {
+    @export(__fmaxh, .{ .name = "__fmaxh", .linkage = common.linkage });
+    @export(fmaxf, .{ .name = "fmaxf", .linkage = common.linkage });
+    @export(fmax, .{ .name = "fmax", .linkage = common.linkage });
+    @export(__fmaxx, .{ .name = "__fmaxx", .linkage = common.linkage });
+    const fmaxq_sym_name = if (common.want_ppc_abi) "fmaxf128" else "fmaxq";
+    @export(fmaxq, .{ .name = fmaxq_sym_name, .linkage = common.linkage });
+    @export(fmaxl, .{ .name = "fmaxl", .linkage = common.linkage });
 }
 
 pub fn __fmaxh(x: f16, y: f16) callconv(.C) f16 {
@@ -40,10 +36,6 @@ pub fn fmaxq(x: f128, y: f128) callconv(.C) f128 {
     return generic_fmax(f128, x, y);
 }
 
-pub fn fmaxf128(x: f128, y: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, fmaxq, .{ x, y });
-}
-
 pub fn fmaxl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __fmaxh(x, y),
lib/compiler_rt/fmin.zig
@@ -2,22 +2,18 @@ const std = @import("std");
 const builtin = @import("builtin");
 const math = std.math;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
 
-comptime {
-    @export(__fminh, .{ .name = "__fminh", .linkage = linkage });
-    @export(fminf, .{ .name = "fminf", .linkage = linkage });
-    @export(fmin, .{ .name = "fmin", .linkage = linkage });
-    @export(__fminx, .{ .name = "__fminx", .linkage = linkage });
-    @export(fminq, .{ .name = "fminq", .linkage = linkage });
-    @export(fminl, .{ .name = "fminl", .linkage = linkage });
+pub const panic = common.panic;
 
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(fminf128, .{ .name = "fminf128", .linkage = linkage });
-        }
-    }
+comptime {
+    @export(__fminh, .{ .name = "__fminh", .linkage = common.linkage });
+    @export(fminf, .{ .name = "fminf", .linkage = common.linkage });
+    @export(fmin, .{ .name = "fmin", .linkage = common.linkage });
+    @export(__fminx, .{ .name = "__fminx", .linkage = common.linkage });
+    const fminq_sym_name = if (common.want_ppc_abi) "fminf128" else "fminq";
+    @export(fminq, .{ .name = fminq_sym_name, .linkage = common.linkage });
+    @export(fminl, .{ .name = "fminl", .linkage = common.linkage });
 }
 
 pub fn __fminh(x: f16, y: f16) callconv(.C) f16 {
@@ -40,10 +36,6 @@ pub fn fminq(x: f128, y: f128) callconv(.C) f128 {
     return generic_fmin(f128, x, y);
 }
 
-pub fn fminf128(x: f128, y: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, fminq, .{ x, y });
-}
-
 pub fn fminl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __fminh(x, y),
lib/compiler_rt/fmod.zig
@@ -3,25 +3,19 @@ const std = @import("std");
 const math = std.math;
 const assert = std.debug.assert;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-
 const common = @import("common.zig");
 const normalize = common.normalize;
+
 pub const panic = common.panic;
 
 comptime {
-    @export(__fmodh, .{ .name = "__fmodh", .linkage = linkage });
-    @export(fmodf, .{ .name = "fmodf", .linkage = linkage });
-    @export(fmod, .{ .name = "fmod", .linkage = linkage });
-    @export(__fmodx, .{ .name = "__fmodx", .linkage = linkage });
-    @export(fmodq, .{ .name = "fmodq", .linkage = linkage });
-    @export(fmodl, .{ .name = "fmodl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(fmodf128, .{ .name = "fmodf128", .linkage = linkage });
-        }
-    }
+    @export(__fmodh, .{ .name = "__fmodh", .linkage = common.linkage });
+    @export(fmodf, .{ .name = "fmodf", .linkage = common.linkage });
+    @export(fmod, .{ .name = "fmod", .linkage = common.linkage });
+    @export(__fmodx, .{ .name = "__fmodx", .linkage = common.linkage });
+    const fmodq_sym_name = if (common.want_ppc_abi) "fmodf128" else "fmodq";
+    @export(fmodq, .{ .name = fmodq_sym_name, .linkage = common.linkage });
+    @export(fmodl, .{ .name = "fmodl", .linkage = common.linkage });
 }
 
 pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
@@ -40,8 +34,6 @@ pub fn fmod(x: f64, y: f64) callconv(.C) f64 {
 /// fmodx - floating modulo large, returns the remainder of division for f80 types
 /// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits
 pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
-    @setRuntimeSafety(builtin.is_test);
-
     const T = f80;
     const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
 
@@ -140,7 +132,6 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
 /// fmodq - floating modulo large, returns the remainder of division for f128 types
 /// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits
 pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
-    @setRuntimeSafety(builtin.is_test);
     var amod = a;
     var bmod = b;
     const aPtr_u64 = @ptrCast([*]u64, &amod);
@@ -257,10 +248,6 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
     return amod;
 }
 
-pub fn fmodf128(a: f128, b: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, fmodq, .{ a, b });
-}
-
 pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __fmodh(a, b),
@@ -273,8 +260,6 @@ pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {
 }
 
 inline fn generic_fmod(comptime T: type, x: T, y: T) T {
-    @setRuntimeSafety(false);
-
     const bits = @typeInfo(T).Float.bits;
     const uint = std.meta.Int(.unsigned, bits);
     const log2uint = math.Log2Int(uint);
lib/compiler_rt/int.zig
@@ -1,4 +1,5 @@
-// Builtin functions that operate on integer types
+//! Builtin functions that operate on integer types
+
 const builtin = @import("builtin");
 const std = @import("std");
 const testing = std.testing;
@@ -6,44 +7,39 @@ const maxInt = std.math.maxInt;
 const minInt = std.math.minInt;
 const arch = builtin.cpu.arch;
 const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
-
+const common = @import("common.zig");
 const udivmod = @import("udivmod.zig").udivmod;
 
+pub const panic = common.panic;
+
 comptime {
-    @export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });
-    @export(__mulsi3, .{ .name = "__mulsi3", .linkage = linkage });
-    @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });
-    @export(__divsi3, .{ .name = "__divsi3", .linkage = linkage });
-    @export(__divdi3, .{ .name = "__divdi3", .linkage = linkage });
-    @export(__udivsi3, .{ .name = "__udivsi3", .linkage = linkage });
-    @export(__udivdi3, .{ .name = "__udivdi3", .linkage = linkage });
-    @export(__modsi3, .{ .name = "__modsi3", .linkage = linkage });
-    @export(__moddi3, .{ .name = "__moddi3", .linkage = linkage });
-    @export(__umodsi3, .{ .name = "__umodsi3", .linkage = linkage });
-    @export(__umoddi3, .{ .name = "__umoddi3", .linkage = linkage });
-    @export(__divmodsi4, .{ .name = "__divmodsi4", .linkage = linkage });
-    @export(__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = linkage });
-
-    if (!is_test) {
-        if (arch.isARM() or arch.isThumb()) {
-            @export(__aeabi_idiv, .{ .name = "__aeabi_idiv", .linkage = linkage });
-            @export(__aeabi_uidiv, .{ .name = "__aeabi_uidiv", .linkage = linkage });
-        }
+    @export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = common.linkage });
+    @export(__mulsi3, .{ .name = "__mulsi3", .linkage = common.linkage });
+    @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = common.linkage });
+    if (common.want_aeabi) {
+        @export(__aeabi_idiv, .{ .name = "__aeabi_idiv", .linkage = common.linkage });
+        @export(__aeabi_uidiv, .{ .name = "__aeabi_uidiv", .linkage = common.linkage });
+    } else {
+        @export(__divsi3, .{ .name = "__divsi3", .linkage = common.linkage });
+        @export(__udivsi3, .{ .name = "__udivsi3", .linkage = common.linkage });
     }
+    @export(__divdi3, .{ .name = "__divdi3", .linkage = common.linkage });
+    @export(__udivdi3, .{ .name = "__udivdi3", .linkage = common.linkage });
+    @export(__modsi3, .{ .name = "__modsi3", .linkage = common.linkage });
+    @export(__moddi3, .{ .name = "__moddi3", .linkage = common.linkage });
+    @export(__umodsi3, .{ .name = "__umodsi3", .linkage = common.linkage });
+    @export(__umoddi3, .{ .name = "__umoddi3", .linkage = common.linkage });
+    @export(__divmodsi4, .{ .name = "__divmodsi4", .linkage = common.linkage });
+    @export(__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = common.linkage });
 }
 
 pub fn __divmoddi4(a: i64, b: i64, rem: *i64) callconv(.C) i64 {
-    @setRuntimeSafety(builtin.is_test);
-
     const d = __divdi3(a, b);
     rem.* = a -% (d *% b);
     return d;
 }
 
 pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {
-    @setRuntimeSafety(builtin.is_test);
     return udivmod(u64, a, b, maybe_rem);
 }
 
@@ -52,8 +48,6 @@ test "test_udivmoddi4" {
 }
 
 pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 {
-    @setRuntimeSafety(builtin.is_test);
-
     // Set aside the sign of the quotient.
     const sign = @bitCast(u64, (a ^ b) >> 63);
     // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
@@ -91,8 +85,6 @@ fn test_one_divdi3(a: i64, b: i64, expected_q: i64) !void {
 }
 
 pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
-    @setRuntimeSafety(builtin.is_test);
-
     // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
     const abs_a = (a ^ (a >> 63)) -% (a >> 63);
     const abs_b = (b ^ (b >> 63)) -% (b >> 63);
@@ -131,13 +123,10 @@ fn test_one_moddi3(a: i64, b: i64, expected_r: i64) !void {
 }
 
 pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
-    @setRuntimeSafety(builtin.is_test);
     return __udivmoddi4(a, b, null);
 }
 
 pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {
-    @setRuntimeSafety(builtin.is_test);
-
     var r: u64 = undefined;
     _ = __udivmoddi4(a, b, &r);
     return r;
@@ -157,8 +146,6 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) !void {
 }
 
 pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
-    @setRuntimeSafety(builtin.is_test);
-
     const d = __divsi3(a, b);
     rem.* = a -% (d * b);
     return d;
@@ -193,16 +180,20 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
 }
 
 pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
-    @setRuntimeSafety(builtin.is_test);
-
     const d = __udivsi3(a, b);
     rem.* = @bitCast(u32, @bitCast(i32, a) -% (@bitCast(i32, d) * @bitCast(i32, b)));
     return d;
 }
 
 pub fn __divsi3(n: i32, d: i32) callconv(.C) i32 {
-    @setRuntimeSafety(builtin.is_test);
+    return div_i32(n, d);
+}
+
+fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {
+    return div_i32(n, d);
+}
 
+inline fn div_i32(n: i32, d: i32) i32 {
     // Set aside the sign of the quotient.
     const sign = @bitCast(u32, (n ^ d) >> 31);
     // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).
@@ -214,10 +205,6 @@ pub fn __divsi3(n: i32, d: i32) callconv(.C) i32 {
     return @bitCast(i32, (res ^ sign) -% sign);
 }
 
-pub fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {
-    return @call(.{ .modifier = .always_inline }, __divsi3, .{ n, d });
-}
-
 test "test_divsi3" {
     const cases = [_][3]i32{
         [_]i32{ 0, 1, 0 },
@@ -244,8 +231,14 @@ fn test_one_divsi3(a: i32, b: i32, expected_q: i32) !void {
 }
 
 pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
-    @setRuntimeSafety(builtin.is_test);
+    return div_u32(n, d);
+}
+
+fn __aeabi_uidiv(n: u32, d: u32) callconv(.AAPCS) u32 {
+    return div_u32(n, d);
+}
 
+inline fn div_u32(n: u32, d: u32) u32 {
     const n_uword_bits: c_uint = 32;
     // special cases
     if (d == 0) return 0; // ?!
@@ -284,10 +277,6 @@ pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
     return q;
 }
 
-pub fn __aeabi_uidiv(n: u32, d: u32) callconv(.AAPCS) u32 {
-    return @call(.{ .modifier = .always_inline }, __udivsi3, .{ n, d });
-}
-
 test "test_udivsi3" {
     const cases = [_][3]u32{
         [_]u32{ 0x00000000, 0x00000001, 0x00000000 },
@@ -435,8 +424,6 @@ fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) !void {
 }
 
 pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
-    @setRuntimeSafety(builtin.is_test);
-
     return n -% __divsi3(n, d) *% d;
 }
 
@@ -466,8 +453,6 @@ fn test_one_modsi3(a: i32, b: i32, expected_r: i32) !void {
 }
 
 pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
-    @setRuntimeSafety(builtin.is_test);
-
     return n -% __udivsi3(n, d) *% d;
 }
 
@@ -618,8 +603,6 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) !void {
 }
 
 pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
-    @setRuntimeSafety(builtin.is_test);
-
     var ua = @bitCast(u32, a);
     var ub = @bitCast(u32, b);
     var r: u32 = 0;
lib/compiler_rt/log.zig
@@ -1,30 +1,26 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/lnf.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c
+//! Ported from musl, which is licensed under the MIT license:
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/lnf.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const math = std.math;
 const testing = std.testing;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__logh, .{ .name = "__logh", .linkage = linkage });
-    @export(logf, .{ .name = "logf", .linkage = linkage });
-    @export(log, .{ .name = "log", .linkage = linkage });
-    @export(__logx, .{ .name = "__logx", .linkage = linkage });
-    @export(logq, .{ .name = "logq", .linkage = linkage });
-    @export(logl, .{ .name = "logl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(logf128, .{ .name = "logf128", .linkage = linkage });
-        }
-    }
+    @export(__logh, .{ .name = "__logh", .linkage = common.linkage });
+    @export(logf, .{ .name = "logf", .linkage = common.linkage });
+    @export(log, .{ .name = "log", .linkage = common.linkage });
+    @export(__logx, .{ .name = "__logx", .linkage = common.linkage });
+    const logq_sym_name = if (common.want_ppc_abi) "logf128" else "logq";
+    @export(logq, .{ .name = logq_sym_name, .linkage = common.linkage });
+    @export(logl, .{ .name = "logl", .linkage = common.linkage });
 }
 
 pub fn __logh(a: f16) callconv(.C) f16 {
@@ -150,10 +146,6 @@ pub fn logq(a: f128) callconv(.C) f128 {
     return log(@floatCast(f64, a));
 }
 
-pub fn logf128(a: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, logq, .{a});
-}
-
 pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __logh(x),
lib/compiler_rt/log10.zig
@@ -1,8 +1,8 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/log10f.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c
+//! Ported from musl, which is licensed under the MIT license:
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/log10f.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c
 
 const std = @import("std");
 const builtin = @import("builtin");
@@ -10,22 +10,18 @@ const math = std.math;
 const testing = std.testing;
 const maxInt = std.math.maxInt;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__log10h, .{ .name = "__log10h", .linkage = linkage });
-    @export(log10f, .{ .name = "log10f", .linkage = linkage });
-    @export(log10, .{ .name = "log10", .linkage = linkage });
-    @export(__log10x, .{ .name = "__log10x", .linkage = linkage });
-    @export(log10q, .{ .name = "log10q", .linkage = linkage });
-    @export(log10l, .{ .name = "log10l", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(log10f128, .{ .name = "log10f128", .linkage = linkage });
-        }
-    }
+    @export(__log10h, .{ .name = "__log10h", .linkage = common.linkage });
+    @export(log10f, .{ .name = "log10f", .linkage = common.linkage });
+    @export(log10, .{ .name = "log10", .linkage = common.linkage });
+    @export(__log10x, .{ .name = "__log10x", .linkage = common.linkage });
+    const log10q_sym_name = if (common.want_ppc_abi) "log10f128" else "log10q";
+    @export(log10q, .{ .name = log10q_sym_name, .linkage = common.linkage });
+    @export(log10l, .{ .name = "log10l", .linkage = common.linkage });
 }
 
 pub fn __log10h(a: f16) callconv(.C) f16 {
@@ -178,10 +174,6 @@ pub fn log10q(a: f128) callconv(.C) f128 {
     return log10(@floatCast(f64, a));
 }
 
-pub fn log10f128(a: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, log10q, .{a});
-}
-
 pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __log10h(x),
lib/compiler_rt/log2.zig
@@ -1,8 +1,8 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/log2f.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c
+//! Ported from musl, which is licensed under the MIT license:
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/log2f.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c
 
 const std = @import("std");
 const builtin = @import("builtin");
@@ -10,22 +10,18 @@ const math = std.math;
 const expect = std.testing.expect;
 const maxInt = std.math.maxInt;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__log2h, .{ .name = "__log2h", .linkage = linkage });
-    @export(log2f, .{ .name = "log2f", .linkage = linkage });
-    @export(log2, .{ .name = "log2", .linkage = linkage });
-    @export(__log2x, .{ .name = "__log2x", .linkage = linkage });
-    @export(log2q, .{ .name = "log2q", .linkage = linkage });
-    @export(log2l, .{ .name = "log2l", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(log2f128, .{ .name = "log2f128", .linkage = linkage });
-        }
-    }
+    @export(__log2h, .{ .name = "__log2h", .linkage = common.linkage });
+    @export(log2f, .{ .name = "log2f", .linkage = common.linkage });
+    @export(log2, .{ .name = "log2", .linkage = common.linkage });
+    @export(__log2x, .{ .name = "__log2x", .linkage = common.linkage });
+    const log2q_sym_name = if (common.want_ppc_abi) "log2f128" else "log2q";
+    @export(log2q, .{ .name = log2q_sym_name, .linkage = common.linkage });
+    @export(log2l, .{ .name = "log2l", .linkage = common.linkage });
 }
 
 pub fn __log2h(a: f16) callconv(.C) f16 {
@@ -170,10 +166,6 @@ pub fn log2q(a: f128) callconv(.C) f128 {
     return log2(@floatCast(f64, a));
 }
 
-pub fn log2f128(a: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, log2q, .{a});
-}
-
 pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __log2h(x),
lib/compiler_rt/modti3.zig
@@ -1,39 +1,47 @@
-// Ported from:
-//
-// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c
+//! Ported from:
+//!
+//! https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const udivmod = @import("udivmod.zig").udivmod;
 const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
     if (builtin.os.tag == .windows) {
         switch (arch) {
             .i386 => {
-                @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
+                @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
             },
             .x86_64 => {
                 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
                 // that LLVM expects compiler-rt to have.
-                @export(__modti3_windows_x86_64, .{ .name = "__modti3", .linkage = linkage });
+                @export(__modti3_windows_x86_64, .{ .name = "__modti3", .linkage = common.linkage });
             },
             else => {},
         }
         if (arch.isAARCH64()) {
-            @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
+            @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
         }
     } else {
-        @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
+        @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
     }
 }
 
 pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
-    @setRuntimeSafety(builtin.is_test);
+    return mod(a, b);
+}
 
+const v128 = @import("std").meta.Vector(2, u64);
+
+fn __modti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
+    return @bitCast(v128, mod(@bitCast(i128, a), @bitCast(i128, b)));
+}
+
+inline fn mod(a: i128, b: i128) i128 {
     const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 0
     const s_b = b >> (128 - 1); // s = b < 0 ? -1 : 0
 
@@ -45,14 +53,6 @@ pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
     return (@bitCast(i128, r) ^ s_a) -% s_a; // negate if s == -1
 }
 
-const v128 = @import("std").meta.Vector(2, u64);
-pub fn __modti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
-    return @bitCast(v128, @call(.{ .modifier = .always_inline }, __modti3, .{
-        @bitCast(i128, a),
-        @bitCast(i128, b),
-    }));
-}
-
 test {
     _ = @import("modti3_test.zig");
 }
lib/compiler_rt/muldi3.zig
@@ -1,23 +1,36 @@
+//! Ported from
+//! https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
+
 const std = @import("std");
 const builtin = @import("builtin");
 const native_endian = builtin.cpu.arch.endian();
-const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
 
-comptime {
-    @export(__muldi3, .{ .name = "__muldi3", .linkage = linkage });
+pub const panic = common.panic;
 
-    if (!is_test) {
-        if (arch.isARM() or arch.isThumb()) {
-            @export(__aeabi_lmul, .{ .name = "__aeabi_lmul", .linkage = linkage });
-        }
+comptime {
+    if (common.want_aeabi) {
+        @export(__aeabi_lmul, .{ .name = "__aeabi_lmul", .linkage = common.linkage });
+    } else {
+        @export(__muldi3, .{ .name = "__muldi3", .linkage = common.linkage });
     }
 }
 
-// Ported from
-// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
+pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
+    return mul(a, b);
+}
+
+fn __aeabi_lmul(a: i64, b: i64) callconv(.AAPCS) i64 {
+    return mul(a, b);
+}
+
+inline fn mul(a: i64, b: i64) i64 {
+    const x = dwords{ .all = a };
+    const y = dwords{ .all = b };
+    var r = dwords{ .all = muldsi3(x.s.low, y.s.low) };
+    r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
+    return r.all;
+}
 
 const dwords = extern union {
     all: i64,
@@ -33,13 +46,7 @@ const dwords = extern union {
     },
 };
 
-pub fn __aeabi_lmul(a: i64, b: i64) callconv(.AAPCS) i64 {
-    return @call(.{ .modifier = .always_inline }, __muldi3, .{ a, b });
-}
-
-pub fn __muldsi3(a: u32, b: u32) i64 {
-    @setRuntimeSafety(is_test);
-
+fn muldsi3(a: u32, b: u32) i64 {
     const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
     const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;
 
@@ -59,16 +66,6 @@ pub fn __muldsi3(a: u32, b: u32) i64 {
     return r.all;
 }
 
-pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
-    @setRuntimeSafety(is_test);
-
-    const x = dwords{ .all = a };
-    const y = dwords{ .all = b };
-    var r = dwords{ .all = __muldsi3(x.s.low, y.s.low) };
-    r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
-    return r.all;
-}
-
 test {
     _ = @import("muldi3_test.zig");
 }
lib/compiler_rt/mulo.zig
@@ -1,14 +1,14 @@
 const std = @import("std");
 const builtin = @import("builtin");
 const math = std.math;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__mulosi4, .{ .name = "__mulosi4", .linkage = linkage });
-    @export(__mulodi4, .{ .name = "__mulodi4", .linkage = linkage });
-    @export(__muloti4, .{ .name = "__muloti4", .linkage = linkage });
+    @export(__mulosi4, .{ .name = "__mulosi4", .linkage = common.linkage });
+    @export(__mulodi4, .{ .name = "__mulodi4", .linkage = common.linkage });
+    @export(__muloti4, .{ .name = "__muloti4", .linkage = common.linkage });
 }
 
 // mulo - multiplication overflow
@@ -18,7 +18,6 @@ comptime {
 // - muloXi4_genericFast for 2*bitsize <= usize
 
 inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
-    @setRuntimeSafety(builtin.is_test);
     overflow.* = 0;
     const min = math.minInt(ST);
     var res: ST = a *% b;
@@ -33,7 +32,6 @@ inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int
 }
 
 inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
-    @setRuntimeSafety(builtin.is_test);
     overflow.* = 0;
     const EST = switch (ST) {
         i32 => i64,
lib/compiler_rt/multi3.zig
@@ -1,51 +1,52 @@
+//! Ported from git@github.com:llvm-project/llvm-project-20170507.git
+//! ae684fad6d34858c014c94da69c15e7774a633c3
+//! 2018-08-13
+
 const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
 const native_endian = builtin.cpu.arch.endian();
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
 
-// Ported from git@github.com:llvm-project/llvm-project-20170507.git
-// ae684fad6d34858c014c94da69c15e7774a633c3
-// 2018-08-13
+pub const panic = common.panic;
 
 comptime {
     if (builtin.os.tag == .windows) {
         switch (arch) {
             .i386 => {
-                @export(__multi3, .{ .name = "__multi3", .linkage = linkage });
+                @export(__multi3, .{ .name = "__multi3", .linkage = common.linkage });
             },
             .x86_64 => {
                 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
                 // that LLVM expects compiler-rt to have.
-                @export(__multi3_windows_x86_64, .{ .name = "__multi3", .linkage = linkage });
+                @export(__multi3_windows_x86_64, .{ .name = "__multi3", .linkage = common.linkage });
             },
             else => {},
         }
     } else {
-        @export(__multi3, .{ .name = "__multi3", .linkage = linkage });
+        @export(__multi3, .{ .name = "__multi3", .linkage = common.linkage });
     }
 }
 
 pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
-    @setRuntimeSafety(is_test);
+    return mul(a, b);
+}
+
+const v128 = @Vector(2, u64);
+
+fn __multi3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
+    return @bitCast(v128, mul(@bitCast(i128, a), @bitCast(i128, b)));
+}
+
+inline fn mul(a: i128, b: i128) i128 {
     const x = twords{ .all = a };
     const y = twords{ .all = b };
-    var r = twords{ .all = __mulddi3(x.s.low, y.s.low) };
+    var r = twords{ .all = mulddi3(x.s.low, y.s.low) };
     r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
     return r.all;
 }
 
-const v128 = @Vector(2, u64);
-pub fn __multi3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
-    return @bitCast(v128, @call(.{ .modifier = .always_inline }, __multi3, .{
-        @bitCast(i128, a),
-        @bitCast(i128, b),
-    }));
-}
-
-pub fn __mulddi3(a: u64, b: u64) i128 {
+fn mulddi3(a: u64, b: u64) i128 {
     const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;
     const lower_mask = ~@as(u64, 0) >> bits_in_dword_2;
     var r: twords = undefined;
lib/compiler_rt/negv.zig
@@ -1,19 +1,30 @@
-// negv - negate oVerflow
-// * @panic, if result can not be represented
-// - negvXi4_generic for unoptimized version
+//! negv - negate oVerflow
+//! * @panic, if result can not be represented
+//! - negvXi4_generic for unoptimized version
 const std = @import("std");
 const builtin = @import("builtin");
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__negvsi2, .{ .name = "__negvsi2", .linkage = linkage });
-    @export(__negvdi2, .{ .name = "__negvdi2", .linkage = linkage });
-    @export(__negvti2, .{ .name = "__negvti2", .linkage = linkage });
+    @export(__negvsi2, .{ .name = "__negvsi2", .linkage = common.linkage });
+    @export(__negvdi2, .{ .name = "__negvdi2", .linkage = common.linkage });
+    @export(__negvti2, .{ .name = "__negvti2", .linkage = common.linkage });
+}
+
+pub fn __negvsi2(a: i32) callconv(.C) i32 {
+    return negvXi(i32, a);
+}
+
+pub fn __negvdi2(a: i64) callconv(.C) i64 {
+    return negvXi(i64, a);
+}
+
+pub fn __negvti2(a: i128) callconv(.C) i128 {
+    return negvXi(i128, a);
 }
 
-// assume -0 == 0 is gracefully handled by the hardware
 inline fn negvXi(comptime ST: type, a: ST) ST {
     const UT = switch (ST) {
         i32 => u32,
@@ -28,18 +39,6 @@ inline fn negvXi(comptime ST: type, a: ST) ST {
     return -a;
 }
 
-pub fn __negvsi2(a: i32) callconv(.C) i32 {
-    return negvXi(i32, a);
-}
-
-pub fn __negvdi2(a: i64) callconv(.C) i64 {
-    return negvXi(i64, a);
-}
-
-pub fn __negvti2(a: i128) callconv(.C) i128 {
-    return negvXi(i128, a);
-}
-
 test {
     _ = @import("negvsi2_test.zig");
     _ = @import("negvdi2_test.zig");
lib/compiler_rt/negXf2.zig
@@ -1,19 +1,16 @@
 const std = @import("std");
 const builtin = @import("builtin");
-const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__negsf2, .{ .name = "__negsf2", .linkage = linkage });
-    @export(__negdf2, .{ .name = "__negdf2", .linkage = linkage });
-
-    if (!is_test) {
-        if (arch.isARM() or arch.isThumb()) {
-            @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = linkage });
-            @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = linkage });
-        }
+    if (common.want_aeabi) {
+        @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = common.linkage });
+        @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = common.linkage });
+    } else {
+        @export(__negsf2, .{ .name = "__negsf2", .linkage = common.linkage });
+        @export(__negdf2, .{ .name = "__negdf2", .linkage = common.linkage });
     }
 }
 
@@ -21,21 +18,19 @@ pub fn __negsf2(a: f32) callconv(.C) f32 {
     return negXf2(f32, a);
 }
 
-pub fn __negdf2(a: f64) callconv(.C) f64 {
-    return negXf2(f64, a);
+fn __aeabi_fneg(a: f32) callconv(.AAPCS) f32 {
+    return negXf2(f32, a);
 }
 
-pub fn __aeabi_fneg(arg: f32) callconv(.AAPCS) f32 {
-    @setRuntimeSafety(false);
-    return @call(.{ .modifier = .always_inline }, __negsf2, .{arg});
+pub fn __negdf2(a: f64) callconv(.C) f64 {
+    return negXf2(f64, a);
 }
 
-pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {
-    @setRuntimeSafety(false);
-    return @call(.{ .modifier = .always_inline }, __negdf2, .{arg});
+fn __aeabi_dneg(a: f64) callconv(.AAPCS) f64 {
+    return negXf2(f64, a);
 }
 
-fn negXf2(comptime T: type, a: T) T {
+inline fn negXf2(comptime T: type, a: T) T {
     const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
 
     const significandBits = std.math.floatMantissaBits(T);
lib/compiler_rt/negXi2.zig
@@ -1,28 +1,21 @@
+//! neg - negate (the number)
+//! - negXi2 for unoptimized little and big endian
+//! sfffffff = 2^31-1
+//! two's complement inverting bits and add 1 would result in -INT_MIN == 0
+//! => -INT_MIN = -2^31 forbidden
+//! * size optimized builds
+//! * machines that dont support carry operations
+
 const std = @import("std");
 const builtin = @import("builtin");
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
-
-comptime {
-    @export(__negsi2, .{ .name = "__negsi2", .linkage = linkage });
-    @export(__negdi2, .{ .name = "__negdi2", .linkage = linkage });
-    @export(__negti2, .{ .name = "__negti2", .linkage = linkage });
-}
+const common = @import("common.zig");
 
-// neg - negate (the number)
-// - negXi2 for unoptimized little and big endian
+pub const panic = common.panic;
 
-// sfffffff = 2^31-1
-// two's complement inverting bits and add 1 would result in -INT_MIN == 0
-// => -INT_MIN = -2^31 forbidden
-
-// * size optimized builds
-// * machines that dont support carry operations
-
-inline fn negXi2(comptime T: type, a: T) T {
-    @setRuntimeSafety(builtin.is_test);
-    return -a;
+comptime {
+    @export(__negsi2, .{ .name = "__negsi2", .linkage = common.linkage });
+    @export(__negdi2, .{ .name = "__negdi2", .linkage = common.linkage });
+    @export(__negti2, .{ .name = "__negti2", .linkage = common.linkage });
 }
 
 pub fn __negsi2(a: i32) callconv(.C) i32 {
@@ -37,6 +30,10 @@ pub fn __negti2(a: i128) callconv(.C) i128 {
     return negXi2(i128, a);
 }
 
+inline fn negXi2(comptime T: type, a: T) T {
+    return -a;
+}
+
 test {
     _ = @import("negsi2_test.zig");
     _ = @import("negdi2_test.zig");
lib/compiler_rt/parity.zig
@@ -1,21 +1,31 @@
+//! parity - if number of bits set is even => 0, else => 1
+//! - pariytXi2_generic for big and little endian
+
 const std = @import("std");
 const builtin = @import("builtin");
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__paritysi2, .{ .name = "__paritysi2", .linkage = linkage });
-    @export(__paritydi2, .{ .name = "__paritydi2", .linkage = linkage });
-    @export(__parityti2, .{ .name = "__parityti2", .linkage = linkage });
+    @export(__paritysi2, .{ .name = "__paritysi2", .linkage = common.linkage });
+    @export(__paritydi2, .{ .name = "__paritydi2", .linkage = common.linkage });
+    @export(__parityti2, .{ .name = "__parityti2", .linkage = common.linkage });
 }
 
-// parity - if number of bits set is even => 0, else => 1
-// - pariytXi2_generic for big and little endian
+pub fn __paritysi2(a: i32) callconv(.C) i32 {
+    return parityXi2(i32, a);
+}
 
-inline fn parityXi2(comptime T: type, a: T) i32 {
-    @setRuntimeSafety(builtin.is_test);
+pub fn __paritydi2(a: i64) callconv(.C) i32 {
+    return parityXi2(i64, a);
+}
+
+pub fn __parityti2(a: i128) callconv(.C) i32 {
+    return parityXi2(i128, a);
+}
 
+inline fn parityXi2(comptime T: type, a: T) i32 {
     var x = switch (@bitSizeOf(T)) {
         32 => @bitCast(u32, a),
         64 => @bitCast(u64, a),
@@ -32,18 +42,6 @@ inline fn parityXi2(comptime T: type, a: T) i32 {
     return (@intCast(u16, 0x6996) >> @intCast(u4, x)) & 1; // optimization for >>2 and >>1
 }
 
-pub fn __paritysi2(a: i32) callconv(.C) i32 {
-    return parityXi2(i32, a);
-}
-
-pub fn __paritydi2(a: i64) callconv(.C) i32 {
-    return parityXi2(i64, a);
-}
-
-pub fn __parityti2(a: i128) callconv(.C) i32 {
-    return parityXi2(i128, a);
-}
-
 test {
     _ = @import("paritysi2_test.zig");
     _ = @import("paritydi2_test.zig");
lib/compiler_rt/popcount.zig
@@ -1,26 +1,36 @@
+//! popcount - population count
+//! counts the number of 1 bits
+//! SWAR-Popcount: count bits of duos, aggregate to nibbles, and bytes inside
+//!   x-bit register in parallel to sum up all bytes
+//!   SWAR-Masks and factors can be defined as 2-adic fractions
+//! TAOCP: Combinational Algorithms, Bitwise Tricks And Techniques,
+//!   subsubsection "Working with the rightmost bits" and "Sideways addition".
+
 const builtin = @import("builtin");
 const std = @import("std");
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__popcountsi2, .{ .name = "__popcountsi2", .linkage = linkage });
-    @export(__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });
-    @export(__popcountti2, .{ .name = "__popcountti2", .linkage = linkage });
+    @export(__popcountsi2, .{ .name = "__popcountsi2", .linkage = common.linkage });
+    @export(__popcountdi2, .{ .name = "__popcountdi2", .linkage = common.linkage });
+    @export(__popcountti2, .{ .name = "__popcountti2", .linkage = common.linkage });
+}
+
+pub fn __popcountsi2(a: i32) callconv(.C) i32 {
+    return popcountXi2(i32, a);
 }
 
-// popcount - population count
-// counts the number of 1 bits
+pub fn __popcountdi2(a: i64) callconv(.C) i32 {
+    return popcountXi2(i64, a);
+}
 
-// SWAR-Popcount: count bits of duos, aggregate to nibbles, and bytes inside
-//   x-bit register in parallel to sum up all bytes
-//   SWAR-Masks and factors can be defined as 2-adic fractions
-// TAOCP: Combinational Algorithms, Bitwise Tricks And Techniques,
-//   subsubsection "Working with the rightmost bits" and "Sideways addition".
+pub fn __popcountti2(a: i128) callconv(.C) i32 {
+    return popcountXi2(i128, a);
+}
 
 inline fn popcountXi2(comptime ST: type, a: ST) i32 {
-    @setRuntimeSafety(builtin.is_test);
     const UT = switch (ST) {
         i32 => u32,
         i64 => u64,
@@ -39,18 +49,6 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
     return @intCast(i32, x);
 }
 
-pub fn __popcountsi2(a: i32) callconv(.C) i32 {
-    return popcountXi2(i32, a);
-}
-
-pub fn __popcountdi2(a: i64) callconv(.C) i32 {
-    return popcountXi2(i64, a);
-}
-
-pub fn __popcountti2(a: i128) callconv(.C) i32 {
-    return popcountXi2(i128, a);
-}
-
 test {
     _ = @import("popcountsi2_test.zig");
     _ = @import("popcountdi2_test.zig");
lib/compiler_rt/round.zig
@@ -1,30 +1,26 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
+//! Ported from musl, which is licensed under the MIT license:
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const math = std.math;
 const expect = std.testing.expect;
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__roundh, .{ .name = "__roundh", .linkage = linkage });
-    @export(roundf, .{ .name = "roundf", .linkage = linkage });
-    @export(round, .{ .name = "round", .linkage = linkage });
-    @export(__roundx, .{ .name = "__roundx", .linkage = linkage });
-    @export(roundq, .{ .name = "roundq", .linkage = linkage });
-    @export(roundl, .{ .name = "roundl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(roundf128, .{ .name = "roundf128", .linkage = linkage });
-        }
-    }
+    @export(__roundh, .{ .name = "__roundh", .linkage = common.linkage });
+    @export(roundf, .{ .name = "roundf", .linkage = common.linkage });
+    @export(round, .{ .name = "round", .linkage = common.linkage });
+    @export(__roundx, .{ .name = "__roundx", .linkage = common.linkage });
+    const roundq_sym_name = if (common.want_ppc_abi) "roundf128" else "roundq";
+    @export(roundq, .{ .name = roundq_sym_name, .linkage = common.linkage });
+    @export(roundl, .{ .name = "roundl", .linkage = common.linkage });
 }
 
 pub fn __roundh(x: f16) callconv(.C) f16 {
@@ -142,10 +138,6 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
     }
 }
 
-pub fn roundf128(x_: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, roundq, .{x_});
-}
-
 pub fn roundl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __roundh(x),
lib/compiler_rt/shift.zig
@@ -2,25 +2,23 @@ const std = @import("std");
 const builtin = @import("builtin");
 const Log2Int = std.math.Log2Int;
 const native_endian = builtin.cpu.arch.endian();
-const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__ashldi3, .{ .name = "__ashldi3", .linkage = linkage });
-    @export(__ashlti3, .{ .name = "__ashlti3", .linkage = linkage });
-    @export(__ashrdi3, .{ .name = "__ashrdi3", .linkage = linkage });
-    @export(__ashrti3, .{ .name = "__ashrti3", .linkage = linkage });
-    @export(__lshrdi3, .{ .name = "__lshrdi3", .linkage = linkage });
-    @export(__lshrti3, .{ .name = "__lshrti3", .linkage = linkage });
-
-    if (!is_test) {
-        if (arch.isARM() or arch.isThumb()) {
-            @export(__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = linkage });
-            @export(__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = linkage });
-            @export(__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = linkage });
-        }
+    @export(__ashlti3, .{ .name = "__ashlti3", .linkage = common.linkage });
+    @export(__ashrti3, .{ .name = "__ashrti3", .linkage = common.linkage });
+    @export(__lshrti3, .{ .name = "__lshrti3", .linkage = common.linkage });
+
+    if (common.want_aeabi) {
+        @export(__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = common.linkage });
+        @export(__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = common.linkage });
+        @export(__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = common.linkage });
+    } else {
+        @export(__ashldi3, .{ .name = "__ashldi3", .linkage = common.linkage });
+        @export(__ashrdi3, .{ .name = "__ashrdi3", .linkage = common.linkage });
+        @export(__lshrdi3, .{ .name = "__lshrdi3", .linkage = common.linkage });
     }
 }
 
@@ -115,30 +113,34 @@ inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
 pub fn __ashldi3(a: i64, b: i32) callconv(.C) i64 {
     return ashlXi3(i64, a, b);
 }
+fn __aeabi_llsl(a: i64, b: i32) callconv(.AAPCS) i64 {
+    return ashlXi3(i64, a, b);
+}
+
 pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 {
     return ashlXi3(i128, a, b);
 }
+
 pub fn __ashrdi3(a: i64, b: i32) callconv(.C) i64 {
     return ashrXi3(i64, a, b);
 }
+fn __aeabi_lasr(a: i64, b: i32) callconv(.AAPCS) i64 {
+    return ashrXi3(i64, a, b);
+}
+
 pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 {
     return ashrXi3(i128, a, b);
 }
+
 pub fn __lshrdi3(a: i64, b: i32) callconv(.C) i64 {
     return lshrXi3(i64, a, b);
 }
-pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
-    return lshrXi3(i128, a, b);
+fn __aeabi_llsr(a: i64, b: i32) callconv(.AAPCS) i64 {
+    return lshrXi3(i64, a, b);
 }
 
-pub fn __aeabi_llsl(a: i64, b: i32) callconv(.AAPCS) i64 {
-    return ashlXi3(i64, a, b);
-}
-pub fn __aeabi_lasr(a: i64, b: i32) callconv(.AAPCS) i64 {
-    return ashrXi3(i64, a, b);
-}
-pub fn __aeabi_llsr(a: i64, b: i32) callconv(.AAPCS) i64 {
-    return lshrXi3(i64, a, b);
+pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
+    return lshrXi3(i128, a, b);
 }
 
 test {
lib/compiler_rt/sin.zig
@@ -1,34 +1,30 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/sinf.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c
+//! Ported from musl, which is licensed under the MIT license:
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/sinf.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c
 
 const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const math = std.math;
 const expect = std.testing.expect;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
 
 const trig = @import("trig.zig");
 const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
 const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
 
+pub const panic = common.panic;
+
 comptime {
-    @export(__sinh, .{ .name = "__sinh", .linkage = linkage });
-    @export(sinf, .{ .name = "sinf", .linkage = linkage });
-    @export(sin, .{ .name = "sin", .linkage = linkage });
-    @export(__sinx, .{ .name = "__sinx", .linkage = linkage });
-    @export(sinq, .{ .name = "sinq", .linkage = linkage });
-    @export(sinl, .{ .name = "sinl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(sinf128, .{ .name = "sinf128", .linkage = linkage });
-        }
-    }
+    @export(__sinh, .{ .name = "__sinh", .linkage = common.linkage });
+    @export(sinf, .{ .name = "sinf", .linkage = common.linkage });
+    @export(sin, .{ .name = "sin", .linkage = common.linkage });
+    @export(__sinx, .{ .name = "__sinx", .linkage = common.linkage });
+    const sinq_sym_name = if (common.want_ppc_abi) "sinf128" else "sinq";
+    @export(sinq, .{ .name = sinq_sym_name, .linkage = common.linkage });
+    @export(sinl, .{ .name = "sinl", .linkage = common.linkage });
 }
 
 pub fn __sinh(x: f16) callconv(.C) f16 {
@@ -130,10 +126,6 @@ pub fn sinq(x: f128) callconv(.C) f128 {
     return sin(@floatCast(f64, x));
 }
 
-pub fn sinf128(x: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, sinq, .{x});
-}
-
 pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __sinh(x),
lib/compiler_rt/sincos.zig
@@ -5,22 +5,18 @@ const math = std.math;
 const trig = @import("trig.zig");
 const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
 const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
 
-comptime {
-    @export(__sincosh, .{ .name = "__sincosh", .linkage = linkage });
-    @export(sincosf, .{ .name = "sincosf", .linkage = linkage });
-    @export(sincos, .{ .name = "sincos", .linkage = linkage });
-    @export(__sincosx, .{ .name = "__sincosx", .linkage = linkage });
-    @export(sincosq, .{ .name = "sincosq", .linkage = linkage });
-    @export(sincosl, .{ .name = "sincosl", .linkage = linkage });
+pub const panic = common.panic;
 
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(sincosf128, .{ .name = "sincosf128", .linkage = linkage });
-        }
-    }
+comptime {
+    @export(__sincosh, .{ .name = "__sincosh", .linkage = common.linkage });
+    @export(sincosf, .{ .name = "sincosf", .linkage = common.linkage });
+    @export(sincos, .{ .name = "sincos", .linkage = common.linkage });
+    @export(__sincosx, .{ .name = "__sincosx", .linkage = common.linkage });
+    const sincosq_sym_name = if (common.want_ppc_abi) "sincosf128" else "sincosq";
+    @export(sincosq, .{ .name = sincosq_sym_name, .linkage = common.linkage });
+    @export(sincosl, .{ .name = "sincosl", .linkage = common.linkage });
 }
 
 pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.C) void {
@@ -198,10 +194,6 @@ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {
     r_cos.* = small_cos;
 }
 
-pub fn sincosf128(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {
-    return @call(.{ .modifier = .always_inline }, sincosq, .{ x, r_sin, r_cos });
-}
-
 pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.C) void {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __sincosh(x, r_sin, r_cos),
lib/compiler_rt/sqrt.zig
@@ -2,22 +2,18 @@ const std = @import("std");
 const builtin = @import("builtin");
 const arch = builtin.cpu.arch;
 const math = std.math;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__sqrth, .{ .name = "__sqrth", .linkage = linkage });
-    @export(sqrtf, .{ .name = "sqrtf", .linkage = linkage });
-    @export(sqrt, .{ .name = "sqrt", .linkage = linkage });
-    @export(__sqrtx, .{ .name = "__sqrtx", .linkage = linkage });
-    @export(sqrtq, .{ .name = "sqrtq", .linkage = linkage });
-    @export(sqrtl, .{ .name = "sqrtl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(sqrtf128, .{ .name = "sqrtf128", .linkage = linkage });
-        }
-    }
+    @export(__sqrth, .{ .name = "__sqrth", .linkage = common.linkage });
+    @export(sqrtf, .{ .name = "sqrtf", .linkage = common.linkage });
+    @export(sqrt, .{ .name = "sqrt", .linkage = common.linkage });
+    @export(__sqrtx, .{ .name = "__sqrtx", .linkage = common.linkage });
+    const sqrtq_sym_name = if (common.want_ppc_abi) "sqrtf128" else "sqrtq";
+    @export(sqrtq, .{ .name = sqrtq_sym_name, .linkage = common.linkage });
+    @export(sqrtl, .{ .name = "sqrtl", .linkage = common.linkage });
 }
 
 pub fn __sqrth(x: f16) callconv(.C) f16 {
@@ -255,10 +251,6 @@ pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {
     }
 }
 
-pub fn sqrtf128(x: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, sqrtq, .{x});
-}
-
 test "sqrtf" {
     const V = [_]f32{
         0.0,
lib/compiler_rt/subo.zig
@@ -1,22 +1,31 @@
+//! subo - subtract overflow
+//! * return a-%b.
+//! * return if a-b overflows => 1 else => 0
+//! - suboXi4_generic as default
+
 const std = @import("std");
 const builtin = @import("builtin");
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__subosi4, .{ .name = "__subosi4", .linkage = linkage });
-    @export(__subodi4, .{ .name = "__subodi4", .linkage = linkage });
-    @export(__suboti4, .{ .name = "__suboti4", .linkage = linkage });
+    @export(__subosi4, .{ .name = "__subosi4", .linkage = common.linkage });
+    @export(__subodi4, .{ .name = "__subodi4", .linkage = common.linkage });
+    @export(__suboti4, .{ .name = "__suboti4", .linkage = common.linkage });
 }
 
-// subo - subtract overflow
-// * return a-%b.
-// * return if a-b overflows => 1 else => 0
-// - suboXi4_generic as default
+pub fn __subosi4(a: i32, b: i32, overflow: *c_int) callconv(.C) i32 {
+    return suboXi4_generic(i32, a, b, overflow);
+}
+pub fn __subodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
+    return suboXi4_generic(i64, a, b, overflow);
+}
+pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
+    return suboXi4_generic(i128, a, b, overflow);
+}
 
 inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
-    @setRuntimeSafety(builtin.is_test);
     overflow.* = 0;
     var sum: ST = a -% b;
     // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract
@@ -31,16 +40,6 @@ inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST
     return sum;
 }
 
-pub fn __subosi4(a: i32, b: i32, overflow: *c_int) callconv(.C) i32 {
-    return suboXi4_generic(i32, a, b, overflow);
-}
-pub fn __subodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
-    return suboXi4_generic(i64, a, b, overflow);
-}
-pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
-    return suboXi4_generic(i128, a, b, overflow);
-}
-
 test {
     _ = @import("subosi4_test.zig");
     _ = @import("subodi4_test.zig");
lib/compiler_rt/tan.zig
@@ -1,9 +1,9 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/tanf.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/tan.c
-// https://golang.org/src/math/tan.go
+//! Ported from musl, which is licensed under the MIT license:
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/tanf.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/tan.c
+//! https://golang.org/src/math/tan.go
 
 const std = @import("std");
 const builtin = @import("builtin");
@@ -15,22 +15,18 @@ const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
 const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
 
 const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__tanh, .{ .name = "__tanh", .linkage = linkage });
-    @export(tanf, .{ .name = "tanf", .linkage = linkage });
-    @export(tan, .{ .name = "tan", .linkage = linkage });
-    @export(__tanx, .{ .name = "__tanx", .linkage = linkage });
-    @export(tanq, .{ .name = "tanq", .linkage = linkage });
-    @export(tanl, .{ .name = "tanl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(tanf128, .{ .name = "tanf128", .linkage = linkage });
-        }
-    }
+    @export(__tanh, .{ .name = "__tanh", .linkage = common.linkage });
+    @export(tanf, .{ .name = "tanf", .linkage = common.linkage });
+    @export(tan, .{ .name = "tan", .linkage = common.linkage });
+    @export(__tanx, .{ .name = "__tanx", .linkage = common.linkage });
+    const tanq_sym_name = if (common.want_ppc_abi) "tanf128" else "tanq";
+    @export(tanq, .{ .name = tanq_sym_name, .linkage = common.linkage });
+    @export(tanl, .{ .name = "tanl", .linkage = common.linkage });
 }
 
 pub fn __tanh(x: f16) callconv(.C) f16 {
@@ -116,10 +112,6 @@ pub fn tanq(x: f128) callconv(.C) f128 {
     return tan(@floatCast(f64, x));
 }
 
-pub fn tanf128(x: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, tanq, .{x});
-}
-
 pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __tanh(x),
lib/compiler_rt/trunc.zig
@@ -1,30 +1,26 @@
-// Ported from musl, which is licensed under the MIT license:
-// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
-//
-// https://git.musl-libc.org/cgit/musl/tree/src/math/truncf.c
-// https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
+//! Ported from musl, which is MIT licensed.
+//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
+//!
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/truncf.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
 
 const std = @import("std");
 const builtin = @import("builtin");
+const arch = builtin.cpu.arch;
 const math = std.math;
 const expect = std.testing.expect;
-const arch = builtin.cpu.arch;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
-    @export(__trunch, .{ .name = "__trunch", .linkage = linkage });
-    @export(truncf, .{ .name = "truncf", .linkage = linkage });
-    @export(trunc, .{ .name = "trunc", .linkage = linkage });
-    @export(__truncx, .{ .name = "__truncx", .linkage = linkage });
-    @export(truncq, .{ .name = "truncq", .linkage = linkage });
-    @export(truncl, .{ .name = "truncl", .linkage = linkage });
-
-    if (!builtin.is_test) {
-        if (arch.isPPC() or arch.isPPC64()) {
-            @export(truncf128, .{ .name = "truncf128", .linkage = linkage });
-        }
-    }
+    @export(__trunch, .{ .name = "__trunch", .linkage = common.linkage });
+    @export(truncf, .{ .name = "truncf", .linkage = common.linkage });
+    @export(trunc, .{ .name = "trunc", .linkage = common.linkage });
+    @export(__truncx, .{ .name = "__truncx", .linkage = common.linkage });
+    const truncq_sym_name = if (common.want_ppc_abi) "truncf128" else "truncq";
+    @export(truncq, .{ .name = truncq_sym_name, .linkage = common.linkage });
+    @export(truncl, .{ .name = "truncl", .linkage = common.linkage });
 }
 
 pub fn __trunch(x: f16) callconv(.C) f16 {
@@ -100,10 +96,6 @@ pub fn truncq(x: f128) callconv(.C) f128 {
     }
 }
 
-pub fn truncf128(x: f128) callconv(.C) f128 {
-    return @call(.{ .modifier = .always_inline }, truncq, .{x});
-}
-
 pub fn truncl(x: c_longdouble) callconv(.C) c_longdouble {
     switch (@typeInfo(c_longdouble).Float.bits) {
         16 => return __trunch(x),
lib/compiler_rt/udivmodti4.zig
@@ -2,36 +2,35 @@ const std = @import("std");
 const builtin = @import("builtin");
 const udivmod = @import("udivmod.zig").udivmod;
 const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
     if (builtin.os.tag == .windows) {
         switch (arch) {
             .i386 => {
-                @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
+                @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = common.linkage });
             },
             .x86_64 => {
                 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
                 // that LLVM expects compiler-rt to have.
-                @export(__udivmodti4_windows_x86_64, .{ .name = "__udivmodti4", .linkage = linkage });
+                @export(__udivmodti4_windows_x86_64, .{ .name = "__udivmodti4", .linkage = common.linkage });
             },
             else => {},
         }
     } else {
-        @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
+        @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = common.linkage });
     }
 }
 
 pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {
-    @setRuntimeSafety(builtin.is_test);
     return udivmod(u128, a, b, maybe_rem);
 }
 
 const v128 = std.meta.Vector(2, u64);
-pub fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {
-    @setRuntimeSafety(builtin.is_test);
+
+fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {
     return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));
 }
 
lib/compiler_rt/udivti3.zig
@@ -2,38 +2,37 @@ const std = @import("std");
 const builtin = @import("builtin");
 const udivmod = @import("udivmod.zig").udivmod;
 const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
     if (builtin.os.tag == .windows) {
         switch (arch) {
             .i386 => {
-                @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
+                @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
             },
             .x86_64 => {
                 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
                 // that LLVM expects compiler-rt to have.
-                @export(__udivti3_windows_x86_64, .{ .name = "__udivti3", .linkage = linkage });
+                @export(__udivti3_windows_x86_64, .{ .name = "__udivti3", .linkage = common.linkage });
             },
             else => {},
         }
         if (arch.isAARCH64()) {
-            @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
+            @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
         }
     } else {
-        @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
+        @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
     }
 }
 
 pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {
-    @setRuntimeSafety(builtin.is_test);
     return udivmod(u128, a, b, null);
 }
 
 const v128 = std.meta.Vector(2, u64);
-pub fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
-    @setRuntimeSafety(builtin.is_test);
+
+fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
     return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), null));
 }
lib/compiler_rt/umodti3.zig
@@ -2,42 +2,41 @@ const std = @import("std");
 const builtin = @import("builtin");
 const udivmod = @import("udivmod.zig").udivmod;
 const arch = builtin.cpu.arch;
-const is_test = builtin.is_test;
-const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
-pub const panic = @import("common.zig").panic;
+const common = @import("common.zig");
+
+pub const panic = common.panic;
 
 comptime {
     if (builtin.os.tag == .windows) {
         switch (arch) {
             .i386 => {
-                @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
+                @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
             },
             .x86_64 => {
                 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
                 // that LLVM expects compiler-rt to have.
-                @export(__umodti3_windows_x86_64, .{ .name = "__umodti3", .linkage = linkage });
+                @export(__umodti3_windows_x86_64, .{ .name = "__umodti3", .linkage = common.linkage });
             },
             else => {},
         }
         if (arch.isAARCH64()) {
-            @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
+            @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
         }
     } else {
-        @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
+        @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
     }
 }
 
 pub fn __umodti3(a: u128, b: u128) callconv(.C) u128 {
-    @setRuntimeSafety(builtin.is_test);
     var r: u128 = undefined;
     _ = udivmod(u128, a, b, &r);
     return r;
 }
 
 const v128 = std.meta.Vector(2, u64);
-pub fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
-    return @bitCast(v128, @call(.{ .modifier = .always_inline }, __umodti3, .{
-        @bitCast(u128, a),
-        @bitCast(u128, b),
-    }));
+
+fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
+    var r: u128 = undefined;
+    _ = udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), &r);
+    return @bitCast(v128, r);
 }