authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-17 18:10:00-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-17 18:10:00-07:00
log0556a2ba53b8bbb1a60ff31d8dcdde78a8b16727
treec691076f8f43db00ba0c6e58afebb1300ea4093e
parent3efc229bbf8aaec9de54a702054b091bf890d56e

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.

45 files changed, 647 insertions(+), 850 deletions(-)

lib/compiler_rt/arm.zig+23-22
......@@ -2,40 +2,41 @@
22const std = @import("std");
33const builtin = @import("builtin");
44const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
78
89comptime {
910 if (!builtin.is_test) {
1011 if (arch.isARM() or arch.isThumb()) {
11 @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });
12 @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
13 @export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
12 @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = common.linkage });
13 @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = common.linkage });
14 @export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = common.linkage });
1415
15 @export(__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = linkage });
16 @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = linkage });
16 @export(__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = common.linkage });
17 @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = common.linkage });
1718
18 @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = linkage });
19 @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = linkage });
19 @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = common.linkage });
20 @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = common.linkage });
2021
21 @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = linkage });
22 @export(__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = linkage });
23 @export(__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = linkage });
22 @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = common.linkage });
23 @export(__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = common.linkage });
24 @export(__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = common.linkage });
2425
25 @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = linkage });
26 @export(__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = linkage });
27 @export(__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = linkage });
26 @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = common.linkage });
27 @export(__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = common.linkage });
28 @export(__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = common.linkage });
2829
29 @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = linkage });
30 @export(__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = linkage });
31 @export(__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = linkage });
30 @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = common.linkage });
31 @export(__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = common.linkage });
32 @export(__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = common.linkage });
3233
33 @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = linkage });
34 @export(__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = linkage });
35 @export(__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = linkage });
34 @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = common.linkage });
35 @export(__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = common.linkage });
36 @export(__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = common.linkage });
3637
3738 if (builtin.os.tag == .linux) {
38 @export(__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage });
39 @export(__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = common.linkage });
3940 }
4041 }
4142 }
lib/compiler_rt/aulldiv.zig+5-5
......@@ -2,19 +2,19 @@ const std = @import("std");
22const builtin = @import("builtin");
33const arch = builtin.cpu.arch;
44const abi = builtin.abi;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Strong;
6pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
78
89comptime {
910 if (arch == .i386 and abi == .msvc) {
1011 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
11 @export(_alldiv, .{ .name = "\x01__alldiv", .linkage = linkage });
12 @export(_aulldiv, .{ .name = "\x01__aulldiv", .linkage = linkage });
12 @export(_alldiv, .{ .name = "\x01__alldiv", .linkage = common.linkage });
13 @export(_aulldiv, .{ .name = "\x01__aulldiv", .linkage = common.linkage });
1314 }
1415}
1516
1617pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
17 @setRuntimeSafety(builtin.is_test);
1818 const s_a = a >> (64 - 1);
1919 const s_b = b >> (64 - 1);
2020
lib/compiler_rt/aullrem.zig+5-5
......@@ -2,19 +2,19 @@ const std = @import("std");
22const builtin = @import("builtin");
33const arch = builtin.cpu.arch;
44const abi = builtin.abi;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Strong;
6pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
78
89comptime {
910 if (arch == .i386 and abi == .msvc) {
1011 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
11 @export(_allrem, .{ .name = "\x01__allrem", .linkage = linkage });
12 @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = linkage });
12 @export(_allrem, .{ .name = "\x01__allrem", .linkage = common.linkage });
13 @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = common.linkage });
1314 }
1415}
1516
1617pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {
17 @setRuntimeSafety(builtin.is_test);
1818 const s_a = a >> (64 - 1);
1919 const s_b = b >> (64 - 1);
2020
lib/compiler_rt/bswap.zig+6-7
......@@ -1,13 +1,13 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
3const common = @import("common.zig");
4
5pub const panic = common.panic;
66
77comptime {
8 @export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = linkage });
9 @export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = linkage });
10 @export(__bswapti2, .{ .name = "__bswapti2", .linkage = linkage });
8 @export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = common.linkage });
9 @export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = common.linkage });
10 @export(__bswapti2, .{ .name = "__bswapti2", .linkage = common.linkage });
1111}
1212
1313// bswap - byteswap
......@@ -21,7 +21,6 @@ comptime {
2121// 00 00 00 ff << 3*8 (rightmost byte)
2222
2323inline fn bswapXi2(comptime T: type, a: T) T {
24 @setRuntimeSafety(builtin.is_test);
2524 switch (@bitSizeOf(T)) {
2625 32 => {
2726 // zig fmt: off
lib/compiler_rt/ceil.zig+15-23
......@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
1//! Ported from musl, which is MIT licensed.
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
66
77const std = @import("std");
88const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
1111const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
12const common = @import("common.zig");
13
14pub const panic = common.panic;
1415
1516comptime {
16 @export(__ceilh, .{ .name = "__ceilh", .linkage = linkage });
17 @export(ceilf, .{ .name = "ceilf", .linkage = linkage });
18 @export(ceil, .{ .name = "ceil", .linkage = linkage });
19 @export(__ceilx, .{ .name = "__ceilx", .linkage = linkage });
20 @export(ceilq, .{ .name = "ceilq", .linkage = linkage });
21 @export(ceill, .{ .name = "ceill", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(ceilf128, .{ .name = "ceilf128", .linkage = linkage });
26 }
27 }
17 @export(__ceilh, .{ .name = "__ceilh", .linkage = common.linkage });
18 @export(ceilf, .{ .name = "ceilf", .linkage = common.linkage });
19 @export(ceil, .{ .name = "ceil", .linkage = common.linkage });
20 @export(__ceilx, .{ .name = "__ceilx", .linkage = common.linkage });
21 const ceilq_sym_name = if (common.want_ppc_abi) "ceilf128" else "ceilq";
22 @export(ceilq, .{ .name = ceilq_sym_name, .linkage = common.linkage });
23 @export(ceill, .{ .name = "ceill", .linkage = common.linkage });
2824}
2925
3026pub fn __ceilh(x: f16) callconv(.C) f16 {
......@@ -130,10 +126,6 @@ pub fn ceilq(x: f128) callconv(.C) f128 {
130126 }
131127}
132128
133pub fn ceilf128(x: f128) callconv(.C) f128 {
134 return @call(.{ .modifier = .always_inline }, ceilq, .{x});
135}
136
137129pub fn ceill(x: c_longdouble) callconv(.C) c_longdouble {
138130 switch (@typeInfo(c_longdouble).Float.bits) {
139131 16 => return __ceilh(x),
lib/compiler_rt/cmp.zig+9-9
......@@ -1,16 +1,17 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
4const common = @import("common.zig");
5
6pub const panic = common.panic;
67
78comptime {
8 @export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = linkage });
9 @export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = linkage });
10 @export(__cmpti2, .{ .name = "__cmpti2", .linkage = linkage });
11 @export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = linkage });
12 @export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = linkage });
13 @export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = linkage });
9 @export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = common.linkage });
10 @export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = common.linkage });
11 @export(__cmpti2, .{ .name = "__cmpti2", .linkage = common.linkage });
12 @export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = common.linkage });
13 @export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = common.linkage });
14 @export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = common.linkage });
1415}
1516
1617// cmp - signed compare
......@@ -24,7 +25,6 @@ comptime {
2425// a > b => 2
2526
2627inline fn XcmpXi2(comptime T: type, a: T, b: T) i32 {
27 @setRuntimeSafety(builtin.is_test);
2828 var cmp1: i32 = 0;
2929 var cmp2: i32 = 0;
3030 if (a > b)
lib/compiler_rt/cos.zig+10-18
......@@ -3,26 +3,22 @@ const builtin = @import("builtin");
33const arch = builtin.cpu.arch;
44const math = std.math;
55const expect = std.testing.expect;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
6const common = @import("common.zig");
7
8pub const panic = common.panic;
89
910const trig = @import("trig.zig");
1011const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
1112const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
1213
1314comptime {
14 @export(__cosh, .{ .name = "__cosh", .linkage = linkage });
15 @export(cosf, .{ .name = "cosf", .linkage = linkage });
16 @export(cos, .{ .name = "cos", .linkage = linkage });
17 @export(__cosx, .{ .name = "__cosx", .linkage = linkage });
18 @export(cosq, .{ .name = "cosq", .linkage = linkage });
19 @export(cosl, .{ .name = "cosl", .linkage = linkage });
20
21 if (!builtin.is_test) {
22 if (arch.isPPC() or arch.isPPC64()) {
23 @export(cosf128, .{ .name = "cosf128", .linkage = linkage });
24 }
25 }
15 @export(__cosh, .{ .name = "__cosh", .linkage = common.linkage });
16 @export(cosf, .{ .name = "cosf", .linkage = common.linkage });
17 @export(cos, .{ .name = "cos", .linkage = common.linkage });
18 @export(__cosx, .{ .name = "__cosx", .linkage = common.linkage });
19 const cosq_sym_name = if (common.want_ppc_abi) "cosf128" else "cosq";
20 @export(cosq, .{ .name = cosq_sym_name, .linkage = common.linkage });
21 @export(cosl, .{ .name = "cosl", .linkage = common.linkage });
2622}
2723
2824pub fn __cosh(a: f16) callconv(.C) f16 {
......@@ -126,10 +122,6 @@ pub fn cosq(a: f128) callconv(.C) f128 {
126122 return cos(@floatCast(f64, a));
127123}
128124
129pub fn cosf128(a: f128) callconv(.C) f128 {
130 return @call(.{ .modifier = .always_inline }, cosq, .{a});
131}
132
133125pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {
134126 switch (@typeInfo(c_longdouble).Float.bits) {
135127 16 => return __cosh(x),
lib/compiler_rt/count0bits.zig+12-17
......@@ -1,19 +1,20 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
4const common = @import("common.zig");
5
6pub const panic = common.panic;
67
78comptime {
8 @export(__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });
9 @export(__clzdi2, .{ .name = "__clzdi2", .linkage = linkage });
10 @export(__clzti2, .{ .name = "__clzti2", .linkage = linkage });
11 @export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = linkage });
12 @export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = linkage });
13 @export(__ctzti2, .{ .name = "__ctzti2", .linkage = linkage });
14 @export(__ffssi2, .{ .name = "__ffssi2", .linkage = linkage });
15 @export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = linkage });
16 @export(__ffsti2, .{ .name = "__ffsti2", .linkage = linkage });
9 @export(__clzsi2, .{ .name = "__clzsi2", .linkage = common.linkage });
10 @export(__clzdi2, .{ .name = "__clzdi2", .linkage = common.linkage });
11 @export(__clzti2, .{ .name = "__clzti2", .linkage = common.linkage });
12 @export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = common.linkage });
13 @export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = common.linkage });
14 @export(__ctzti2, .{ .name = "__ctzti2", .linkage = common.linkage });
15 @export(__ffssi2, .{ .name = "__ffssi2", .linkage = common.linkage });
16 @export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = common.linkage });
17 @export(__ffsti2, .{ .name = "__ffsti2", .linkage = common.linkage });
1718}
1819
1920// clz - count leading zeroes
......@@ -30,8 +31,6 @@ comptime {
3031// - ffsXi2 for unoptimized little and big endian
3132
3233inline fn clzXi2(comptime T: type, a: T) i32 {
33 @setRuntimeSafety(builtin.is_test);
34
3534 var x = switch (@bitSizeOf(T)) {
3635 32 => @bitCast(u32, a),
3736 64 => @bitCast(u64, a),
......@@ -169,8 +168,6 @@ pub fn __clzti2(a: i128) callconv(.C) i32 {
169168}
170169
171170inline fn ctzXi2(comptime T: type, a: T) i32 {
172 @setRuntimeSafety(builtin.is_test);
173
174171 var x = switch (@bitSizeOf(T)) {
175172 32 => @bitCast(u32, a),
176173 64 => @bitCast(u64, a),
......@@ -206,8 +203,6 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 {
206203}
207204
208205inline fn ffsXi2(comptime T: type, a: T) i32 {
209 @setRuntimeSafety(builtin.is_test);
210
211206 var x = switch (@bitSizeOf(T)) {
212207 32 => @bitCast(u32, a),
213208 64 => @bitCast(u64, a),
lib/compiler_rt/divdf3.zig+17-17
......@@ -1,30 +1,35 @@
1// Ported from:
2//
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divdf3.c
1//! Ported from:
2//!
3//! https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divdf3.c
44
55const std = @import("std");
66const builtin = @import("builtin");
77const arch = builtin.cpu.arch;
88const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10
119const common = @import("common.zig");
10
1211const normalize = common.normalize;
1312const wideMultiply = common.wideMultiply;
13
1414pub const panic = common.panic;
1515
1616comptime {
17 @export(__divdf3, .{ .name = "__divdf3", .linkage = linkage });
18
19 if (!is_test) {
20 if (arch.isARM() or arch.isThumb()) {
21 @export(__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage });
22 }
17 if (common.want_aeabi) {
18 @export(__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = common.linkage });
19 } else {
20 @export(__divdf3, .{ .name = "__divdf3", .linkage = common.linkage });
2321 }
2422}
2523
2624pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
27 @setRuntimeSafety(builtin.is_test);
25 return div(a, b);
26}
27
28fn __aeabi_ddiv(a: f64, b: f64) callconv(.AAPCS) f64 {
29 return div(a, b);
30}
31
32inline fn div(a: f64, b: f64) f64 {
2833 const Z = std.meta.Int(.unsigned, 64);
2934 const SignedZ = std.meta.Int(.signed, 64);
3035
......@@ -220,11 +225,6 @@ pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
220225 }
221226}
222227
223pub fn __aeabi_ddiv(a: f64, b: f64) callconv(.AAPCS) f64 {
224 @setRuntimeSafety(false);
225 return @call(.{ .modifier = .always_inline }, __divdf3, .{ a, b });
226}
227
228228test {
229229 _ = @import("divdf3_test.zig");
230230}
lib/compiler_rt/divsf3.zig+16-17
......@@ -1,29 +1,33 @@
1// Ported from:
2//
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divsf3.c
1//! Ported from:
2//!
3//! https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divsf3.c
44
55const std = @import("std");
66const builtin = @import("builtin");
77const arch = builtin.cpu.arch;
8const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
108
119const common = @import("common.zig");
1210const normalize = common.normalize;
11
1312pub const panic = common.panic;
1413
1514comptime {
16 @export(__divsf3, .{ .name = "__divsf3", .linkage = linkage });
17
18 if (!is_test) {
19 if (arch.isARM() or arch.isThumb()) {
20 @export(__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage });
21 }
15 if (common.want_aeabi) {
16 @export(__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = common.linkage });
17 } else {
18 @export(__divsf3, .{ .name = "__divsf3", .linkage = common.linkage });
2219 }
2320}
2421
2522pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
26 @setRuntimeSafety(builtin.is_test);
23 return div(a, b);
24}
25
26fn __aeabi_fdiv(a: f32, b: f32) callconv(.AAPCS) f32 {
27 return div(a, b);
28}
29
30inline fn div(a: f32, b: f32) f32 {
2731 const Z = std.meta.Int(.unsigned, 32);
2832
2933 const significandBits = std.math.floatMantissaBits(f32);
......@@ -201,11 +205,6 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
201205 }
202206}
203207
204pub fn __aeabi_fdiv(a: f32, b: f32) callconv(.AAPCS) f32 {
205 @setRuntimeSafety(false);
206 return @call(.{ .modifier = .always_inline }, __divsf3, .{ a, b });
207}
208
209208test {
210209 _ = @import("divsf3_test.zig");
211210}
lib/compiler_rt/divti3.zig+16-16
......@@ -2,34 +2,42 @@ const std = @import("std");
22const builtin = @import("builtin");
33const udivmod = @import("udivmod.zig").udivmod;
44const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
88
99comptime {
1010 if (builtin.os.tag == .windows) {
1111 switch (arch) {
1212 .i386 => {
13 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
13 @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
1414 },
1515 .x86_64 => {
1616 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
1717 // that LLVM expects compiler-rt to have.
18 @export(__divti3_windows_x86_64, .{ .name = "__divti3", .linkage = linkage });
18 @export(__divti3_windows_x86_64, .{ .name = "__divti3", .linkage = common.linkage });
1919 },
2020 else => {},
2121 }
2222 if (arch.isAARCH64()) {
23 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
23 @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
2424 }
2525 } else {
26 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
26 @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
2727 }
2828}
2929
3030pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
31 @setRuntimeSafety(builtin.is_test);
31 return div(a, b);
32}
3233
34const v128 = @import("std").meta.Vector(2, u64);
35
36fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
37 return @bitCast(v128, div(@bitCast(i128, a), @bitCast(i128, b)));
38}
39
40inline fn div(a: i128, b: i128) i128 {
3341 const s_a = a >> (128 - 1);
3442 const s_b = b >> (128 - 1);
3543
......@@ -41,14 +49,6 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
4149 return (@bitCast(i128, r) ^ s) -% s;
4250}
4351
44const v128 = @import("std").meta.Vector(2, u64);
45pub fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
46 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __divti3, .{
47 @bitCast(i128, a),
48 @bitCast(i128, b),
49 }));
50}
51
5252test {
5353 _ = @import("divti3_test.zig");
5454}
lib/compiler_rt/divxf3.zig+2-4
......@@ -1,20 +1,18 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
64
75const common = @import("common.zig");
86const normalize = common.normalize;
97const wideMultiply = common.wideMultiply;
8
109pub const panic = common.panic;
1110
1211comptime {
13 @export(__divxf3, .{ .name = "__divxf3", .linkage = linkage });
12 @export(__divxf3, .{ .name = "__divxf3", .linkage = common.linkage });
1413}
1514
1615pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
17 @setRuntimeSafety(builtin.is_test);
1816 const T = f80;
1917 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
2018
lib/compiler_rt/emutls.zig+10-10
......@@ -1,25 +1,25 @@
1// __emutls_get_address specific builtin
2//
3// derived work from LLVM Compiler Infrastructure - release 8.0 (MIT)
4// https://github.com/llvm-mirror/compiler-rt/blob/release_80/lib/builtins/emutls.c
5//
1//! __emutls_get_address specific builtin
2//!
3//! derived work from LLVM Compiler Infrastructure - release 8.0 (MIT)
4//! https://github.com/llvm-mirror/compiler-rt/blob/release_80/lib/builtins/emutls.c
65
76const std = @import("std");
87const builtin = @import("builtin");
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10pub const panic = @import("common.zig").panic;
8const common = @import("common.zig");
119
1210const abort = std.os.abort;
1311const assert = std.debug.assert;
1412const expect = std.testing.expect;
1513
16// defined in C as:
17// typedef unsigned int gcc_word __attribute__((mode(word)));
14/// defined in C as:
15/// typedef unsigned int gcc_word __attribute__((mode(word)));
1816const gcc_word = usize;
1917
18pub const panic = common.panic;
19
2020comptime {
2121 if (builtin.link_libc and builtin.os.tag == .openbsd) {
22 @export(__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage });
22 @export(__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = common.linkage });
2323 }
2424}
2525
lib/compiler_rt/exp.zig+10-18
......@@ -9,22 +9,18 @@ const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
1111const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
12const common = @import("common.zig");
13
14pub const panic = common.panic;
1415
1516comptime {
16 @export(__exph, .{ .name = "__exph", .linkage = linkage });
17 @export(expf, .{ .name = "expf", .linkage = linkage });
18 @export(exp, .{ .name = "exp", .linkage = linkage });
19 @export(__expx, .{ .name = "__expx", .linkage = linkage });
20 @export(expq, .{ .name = "expq", .linkage = linkage });
21 @export(expl, .{ .name = "expl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(expf128, .{ .name = "expf128", .linkage = linkage });
26 }
27 }
17 @export(__exph, .{ .name = "__exph", .linkage = common.linkage });
18 @export(expf, .{ .name = "expf", .linkage = common.linkage });
19 @export(exp, .{ .name = "exp", .linkage = common.linkage });
20 @export(__expx, .{ .name = "__expx", .linkage = common.linkage });
21 const expq_sym_name = if (common.want_ppc_abi) "expf128" else "expq";
22 @export(expq, .{ .name = expq_sym_name, .linkage = common.linkage });
23 @export(expl, .{ .name = "expl", .linkage = common.linkage });
2824}
2925
3026pub fn __exph(a: f16) callconv(.C) f16 {
......@@ -201,10 +197,6 @@ pub fn expq(a: f128) callconv(.C) f128 {
201197 return exp(@floatCast(f64, a));
202198}
203199
204pub fn expf128(a: f128) callconv(.C) f128 {
205 return @call(.{ .modifier = .always_inline }, expq, .{a});
206}
207
208200pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {
209201 switch (@typeInfo(c_longdouble).Float.bits) {
210202 16 => return __exph(x),
lib/compiler_rt/exp2.zig+10-18
......@@ -9,22 +9,18 @@ const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
1111const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
12const common = @import("common.zig");
1413
15comptime {
16 @export(__exp2h, .{ .name = "__exp2h", .linkage = linkage });
17 @export(exp2f, .{ .name = "exp2f", .linkage = linkage });
18 @export(exp2, .{ .name = "exp2", .linkage = linkage });
19 @export(__exp2x, .{ .name = "__exp2x", .linkage = linkage });
20 @export(exp2q, .{ .name = "exp2q", .linkage = linkage });
21 @export(exp2l, .{ .name = "exp2l", .linkage = linkage });
14pub const panic = common.panic;
2215
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(exp2f128, .{ .name = "exp2f128", .linkage = linkage });
26 }
27 }
16comptime {
17 @export(__exp2h, .{ .name = "__exp2h", .linkage = common.linkage });
18 @export(exp2f, .{ .name = "exp2f", .linkage = common.linkage });
19 @export(exp2, .{ .name = "exp2", .linkage = common.linkage });
20 @export(__exp2x, .{ .name = "__exp2x", .linkage = common.linkage });
21 const exp2q_sym_name = if (common.want_ppc_abi) "exp2f128" else "exp2q";
22 @export(exp2q, .{ .name = exp2q_sym_name, .linkage = common.linkage });
23 @export(exp2l, .{ .name = "exp2l", .linkage = common.linkage });
2824}
2925
3026pub fn __exp2h(x: f16) callconv(.C) f16 {
......@@ -168,10 +164,6 @@ pub fn exp2q(x: f128) callconv(.C) f128 {
168164 return exp2(@floatCast(f64, x));
169165}
170166
171pub fn exp2f128(x: f128) callconv(.C) f128 {
172 return @call(.{ .modifier = .always_inline }, exp2q, .{x});
173}
174
175167pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {
176168 switch (@typeInfo(c_longdouble).Float.bits) {
177169 16 => return __exp2h(x),
lib/compiler_rt/fabs.zig+10-18
......@@ -1,22 +1,18 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const arch = builtin.cpu.arch;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
4const common = @import("common.zig");
5
6pub const panic = common.panic;
67
78comptime {
8 @export(__fabsh, .{ .name = "__fabsh", .linkage = linkage });
9 @export(fabsf, .{ .name = "fabsf", .linkage = linkage });
10 @export(fabs, .{ .name = "fabs", .linkage = linkage });
11 @export(__fabsx, .{ .name = "__fabsx", .linkage = linkage });
12 @export(fabsq, .{ .name = "fabsq", .linkage = linkage });
13 @export(fabsl, .{ .name = "fabsl", .linkage = linkage });
14
15 if (!builtin.is_test) {
16 if (arch.isPPC() or arch.isPPC64()) {
17 @export(fabsf128, .{ .name = "fabsf128", .linkage = linkage });
18 }
19 }
9 @export(__fabsh, .{ .name = "__fabsh", .linkage = common.linkage });
10 @export(fabsf, .{ .name = "fabsf", .linkage = common.linkage });
11 @export(fabs, .{ .name = "fabs", .linkage = common.linkage });
12 @export(__fabsx, .{ .name = "__fabsx", .linkage = common.linkage });
13 const fabsq_sym_name = if (common.want_ppc_abi) "fabsf128" else "fabsq";
14 @export(fabsq, .{ .name = fabsq_sym_name, .linkage = common.linkage });
15 @export(fabsl, .{ .name = "fabsl", .linkage = common.linkage });
2016}
2117
2218pub fn __fabsh(a: f16) callconv(.C) f16 {
......@@ -39,10 +35,6 @@ pub fn fabsq(a: f128) callconv(.C) f128 {
3935 return generic_fabs(a);
4036}
4137
42pub fn fabsf128(a: f128) callconv(.C) f128 {
43 return @call(.{ .modifier = .always_inline }, fabsq, .{a});
44}
45
4638pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {
4739 switch (@typeInfo(c_longdouble).Float.bits) {
4840 16 => return __fabsh(x),
lib/compiler_rt/floor.zig+15-23
......@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
1//! Ported from musl, which is licensed under the MIT license:
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
66
77const std = @import("std");
88const builtin = @import("builtin");
99const math = std.math;
1010const expect = std.testing.expect;
1111const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
12const common = @import("common.zig");
13
14pub const panic = common.panic;
1415
1516comptime {
16 @export(__floorh, .{ .name = "__floorh", .linkage = linkage });
17 @export(floorf, .{ .name = "floorf", .linkage = linkage });
18 @export(floor, .{ .name = "floor", .linkage = linkage });
19 @export(__floorx, .{ .name = "__floorx", .linkage = linkage });
20 @export(floorq, .{ .name = "floorq", .linkage = linkage });
21 @export(floorl, .{ .name = "floorl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(floorf128, .{ .name = "floorf128", .linkage = linkage });
26 }
27 }
17 @export(__floorh, .{ .name = "__floorh", .linkage = common.linkage });
18 @export(floorf, .{ .name = "floorf", .linkage = common.linkage });
19 @export(floor, .{ .name = "floor", .linkage = common.linkage });
20 @export(__floorx, .{ .name = "__floorx", .linkage = common.linkage });
21 const floorq_sym_name = if (common.want_ppc_abi) "floorf128" else "floorq";
22 @export(floorq, .{ .name = floorq_sym_name, .linkage = common.linkage });
23 @export(floorl, .{ .name = "floorl", .linkage = common.linkage });
2824}
2925
3026pub fn __floorh(x: f16) callconv(.C) f16 {
......@@ -160,10 +156,6 @@ pub fn floorq(x: f128) callconv(.C) f128 {
160156 }
161157}
162158
163pub fn floorf128(x: f128) callconv(.C) f128 {
164 return @call(.{ .modifier = .always_inline }, floorq, .{x});
165}
166
167159pub fn floorl(x: c_longdouble) callconv(.C) c_longdouble {
168160 switch (@typeInfo(c_longdouble).Float.bits) {
169161 16 => return __floorh(x),
lib/compiler_rt/fma.zig+16-24
......@@ -1,31 +1,27 @@
1// Ported from musl, which is MIT licensed:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/fmal.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/fmaf.c
6// https://git.musl-libc.org/cgit/musl/tree/src/math/fma.c
1//! Ported from musl, which is MIT licensed:
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/fmal.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/fmaf.c
6//! https://git.musl-libc.org/cgit/musl/tree/src/math/fma.c
77
88const std = @import("std");
99const builtin = @import("builtin");
1010const math = std.math;
1111const expect = std.testing.expect;
1212const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
14pub const panic = @import("common.zig").panic;
13const common = @import("common.zig");
14
15pub const panic = common.panic;
1516
1617comptime {
17 @export(__fmah, .{ .name = "__fmah", .linkage = linkage });
18 @export(fmaf, .{ .name = "fmaf", .linkage = linkage });
19 @export(fma, .{ .name = "fma", .linkage = linkage });
20 @export(__fmax, .{ .name = "__fmax", .linkage = linkage });
21 @export(fmaq, .{ .name = "fmaq", .linkage = linkage });
22 @export(fmal, .{ .name = "fmal", .linkage = linkage });
23
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(fmaf128, .{ .name = "fmaf128", .linkage = linkage });
27 }
28 }
18 @export(__fmah, .{ .name = "__fmah", .linkage = common.linkage });
19 @export(fmaf, .{ .name = "fmaf", .linkage = common.linkage });
20 @export(fma, .{ .name = "fma", .linkage = common.linkage });
21 @export(__fmax, .{ .name = "__fmax", .linkage = common.linkage });
22 const fmaq_sym_name = if (common.want_ppc_abi) "fmaf128" else "fmaq";
23 @export(fmaq, .{ .name = fmaq_sym_name, .linkage = common.linkage });
24 @export(fmal, .{ .name = "fmal", .linkage = common.linkage });
2925}
3026
3127pub 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 {
154150 }
155151}
156152
157pub fn fmaf128(x: f128, y: f128, z: f128) callconv(.C) f128 {
158 return @call(.{ .modifier = .always_inline }, fmaq, .{ x, y, z });
159}
160
161153pub fn fmal(x: c_longdouble, y: c_longdouble, z: c_longdouble) callconv(.C) c_longdouble {
162154 switch (@typeInfo(c_longdouble).Float.bits) {
163155 16 => return __fmah(x, y, z),
lib/compiler_rt/fmax.zig+10-18
......@@ -2,22 +2,18 @@ const std = @import("std");
22const builtin = @import("builtin");
33const math = std.math;
44const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
76
8comptime {
9 @export(__fmaxh, .{ .name = "__fmaxh", .linkage = linkage });
10 @export(fmaxf, .{ .name = "fmaxf", .linkage = linkage });
11 @export(fmax, .{ .name = "fmax", .linkage = linkage });
12 @export(__fmaxx, .{ .name = "__fmaxx", .linkage = linkage });
13 @export(fmaxq, .{ .name = "fmaxq", .linkage = linkage });
14 @export(fmaxl, .{ .name = "fmaxl", .linkage = linkage });
7pub const panic = common.panic;
158
16 if (!builtin.is_test) {
17 if (arch.isPPC() or arch.isPPC64()) {
18 @export(fmaxf128, .{ .name = "fmaxf128", .linkage = linkage });
19 }
20 }
9comptime {
10 @export(__fmaxh, .{ .name = "__fmaxh", .linkage = common.linkage });
11 @export(fmaxf, .{ .name = "fmaxf", .linkage = common.linkage });
12 @export(fmax, .{ .name = "fmax", .linkage = common.linkage });
13 @export(__fmaxx, .{ .name = "__fmaxx", .linkage = common.linkage });
14 const fmaxq_sym_name = if (common.want_ppc_abi) "fmaxf128" else "fmaxq";
15 @export(fmaxq, .{ .name = fmaxq_sym_name, .linkage = common.linkage });
16 @export(fmaxl, .{ .name = "fmaxl", .linkage = common.linkage });
2117}
2218
2319pub fn __fmaxh(x: f16, y: f16) callconv(.C) f16 {
......@@ -40,10 +36,6 @@ pub fn fmaxq(x: f128, y: f128) callconv(.C) f128 {
4036 return generic_fmax(f128, x, y);
4137}
4238
43pub fn fmaxf128(x: f128, y: f128) callconv(.C) f128 {
44 return @call(.{ .modifier = .always_inline }, fmaxq, .{ x, y });
45}
46
4739pub fn fmaxl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {
4840 switch (@typeInfo(c_longdouble).Float.bits) {
4941 16 => return __fmaxh(x, y),
lib/compiler_rt/fmin.zig+10-18
......@@ -2,22 +2,18 @@ const std = @import("std");
22const builtin = @import("builtin");
33const math = std.math;
44const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
76
8comptime {
9 @export(__fminh, .{ .name = "__fminh", .linkage = linkage });
10 @export(fminf, .{ .name = "fminf", .linkage = linkage });
11 @export(fmin, .{ .name = "fmin", .linkage = linkage });
12 @export(__fminx, .{ .name = "__fminx", .linkage = linkage });
13 @export(fminq, .{ .name = "fminq", .linkage = linkage });
14 @export(fminl, .{ .name = "fminl", .linkage = linkage });
7pub const panic = common.panic;
158
16 if (!builtin.is_test) {
17 if (arch.isPPC() or arch.isPPC64()) {
18 @export(fminf128, .{ .name = "fminf128", .linkage = linkage });
19 }
20 }
9comptime {
10 @export(__fminh, .{ .name = "__fminh", .linkage = common.linkage });
11 @export(fminf, .{ .name = "fminf", .linkage = common.linkage });
12 @export(fmin, .{ .name = "fmin", .linkage = common.linkage });
13 @export(__fminx, .{ .name = "__fminx", .linkage = common.linkage });
14 const fminq_sym_name = if (common.want_ppc_abi) "fminf128" else "fminq";
15 @export(fminq, .{ .name = fminq_sym_name, .linkage = common.linkage });
16 @export(fminl, .{ .name = "fminl", .linkage = common.linkage });
2117}
2218
2319pub fn __fminh(x: f16, y: f16) callconv(.C) f16 {
......@@ -40,10 +36,6 @@ pub fn fminq(x: f128, y: f128) callconv(.C) f128 {
4036 return generic_fmin(f128, x, y);
4137}
4238
43pub fn fminf128(x: f128, y: f128) callconv(.C) f128 {
44 return @call(.{ .modifier = .always_inline }, fminq, .{ x, y });
45}
46
4739pub fn fminl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {
4840 switch (@typeInfo(c_longdouble).Float.bits) {
4941 16 => return __fminh(x, y),
lib/compiler_rt/fmod.zig+8-23
......@@ -3,25 +3,19 @@ const std = @import("std");
33const math = std.math;
44const assert = std.debug.assert;
55const arch = builtin.cpu.arch;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7
86const common = @import("common.zig");
97const normalize = common.normalize;
8
109pub const panic = common.panic;
1110
1211comptime {
13 @export(__fmodh, .{ .name = "__fmodh", .linkage = linkage });
14 @export(fmodf, .{ .name = "fmodf", .linkage = linkage });
15 @export(fmod, .{ .name = "fmod", .linkage = linkage });
16 @export(__fmodx, .{ .name = "__fmodx", .linkage = linkage });
17 @export(fmodq, .{ .name = "fmodq", .linkage = linkage });
18 @export(fmodl, .{ .name = "fmodl", .linkage = linkage });
19
20 if (!builtin.is_test) {
21 if (arch.isPPC() or arch.isPPC64()) {
22 @export(fmodf128, .{ .name = "fmodf128", .linkage = linkage });
23 }
24 }
12 @export(__fmodh, .{ .name = "__fmodh", .linkage = common.linkage });
13 @export(fmodf, .{ .name = "fmodf", .linkage = common.linkage });
14 @export(fmod, .{ .name = "fmod", .linkage = common.linkage });
15 @export(__fmodx, .{ .name = "__fmodx", .linkage = common.linkage });
16 const fmodq_sym_name = if (common.want_ppc_abi) "fmodf128" else "fmodq";
17 @export(fmodq, .{ .name = fmodq_sym_name, .linkage = common.linkage });
18 @export(fmodl, .{ .name = "fmodl", .linkage = common.linkage });
2519}
2620
2721pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
......@@ -40,8 +34,6 @@ pub fn fmod(x: f64, y: f64) callconv(.C) f64 {
4034/// fmodx - floating modulo large, returns the remainder of division for f80 types
4135/// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits
4236pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
43 @setRuntimeSafety(builtin.is_test);
44
4537 const T = f80;
4638 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
4739
......@@ -140,7 +132,6 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
140132/// fmodq - floating modulo large, returns the remainder of division for f128 types
141133/// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits
142134pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
143 @setRuntimeSafety(builtin.is_test);
144135 var amod = a;
145136 var bmod = b;
146137 const aPtr_u64 = @ptrCast([*]u64, &amod);
......@@ -257,10 +248,6 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
257248 return amod;
258249}
259250
260pub fn fmodf128(a: f128, b: f128) callconv(.C) f128 {
261 return @call(.{ .modifier = .always_inline }, fmodq, .{ a, b });
262}
263
264251pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {
265252 switch (@typeInfo(c_longdouble).Float.bits) {
266253 16 => return __fmodh(a, b),
......@@ -273,8 +260,6 @@ pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {
273260}
274261
275262inline fn generic_fmod(comptime T: type, x: T, y: T) T {
276 @setRuntimeSafety(false);
277
278263 const bits = @typeInfo(T).Float.bits;
279264 const uint = std.meta.Int(.unsigned, bits);
280265 const log2uint = math.Log2Int(uint);
lib/compiler_rt/int.zig+36-53
......@@ -1,4 +1,5 @@
1// Builtin functions that operate on integer types
1//! Builtin functions that operate on integer types
2
23const builtin = @import("builtin");
34const std = @import("std");
45const testing = std.testing;
......@@ -6,44 +7,39 @@ const maxInt = std.math.maxInt;
67const minInt = std.math.minInt;
78const arch = builtin.cpu.arch;
89const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10pub const panic = @import("common.zig").panic;
11
10const common = @import("common.zig");
1211const udivmod = @import("udivmod.zig").udivmod;
1312
13pub const panic = common.panic;
14
1415comptime {
15 @export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });
16 @export(__mulsi3, .{ .name = "__mulsi3", .linkage = linkage });
17 @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });
18 @export(__divsi3, .{ .name = "__divsi3", .linkage = linkage });
19 @export(__divdi3, .{ .name = "__divdi3", .linkage = linkage });
20 @export(__udivsi3, .{ .name = "__udivsi3", .linkage = linkage });
21 @export(__udivdi3, .{ .name = "__udivdi3", .linkage = linkage });
22 @export(__modsi3, .{ .name = "__modsi3", .linkage = linkage });
23 @export(__moddi3, .{ .name = "__moddi3", .linkage = linkage });
24 @export(__umodsi3, .{ .name = "__umodsi3", .linkage = linkage });
25 @export(__umoddi3, .{ .name = "__umoddi3", .linkage = linkage });
26 @export(__divmodsi4, .{ .name = "__divmodsi4", .linkage = linkage });
27 @export(__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = linkage });
28
29 if (!is_test) {
30 if (arch.isARM() or arch.isThumb()) {
31 @export(__aeabi_idiv, .{ .name = "__aeabi_idiv", .linkage = linkage });
32 @export(__aeabi_uidiv, .{ .name = "__aeabi_uidiv", .linkage = linkage });
33 }
16 @export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = common.linkage });
17 @export(__mulsi3, .{ .name = "__mulsi3", .linkage = common.linkage });
18 @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = common.linkage });
19 if (common.want_aeabi) {
20 @export(__aeabi_idiv, .{ .name = "__aeabi_idiv", .linkage = common.linkage });
21 @export(__aeabi_uidiv, .{ .name = "__aeabi_uidiv", .linkage = common.linkage });
22 } else {
23 @export(__divsi3, .{ .name = "__divsi3", .linkage = common.linkage });
24 @export(__udivsi3, .{ .name = "__udivsi3", .linkage = common.linkage });
3425 }
26 @export(__divdi3, .{ .name = "__divdi3", .linkage = common.linkage });
27 @export(__udivdi3, .{ .name = "__udivdi3", .linkage = common.linkage });
28 @export(__modsi3, .{ .name = "__modsi3", .linkage = common.linkage });
29 @export(__moddi3, .{ .name = "__moddi3", .linkage = common.linkage });
30 @export(__umodsi3, .{ .name = "__umodsi3", .linkage = common.linkage });
31 @export(__umoddi3, .{ .name = "__umoddi3", .linkage = common.linkage });
32 @export(__divmodsi4, .{ .name = "__divmodsi4", .linkage = common.linkage });
33 @export(__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = common.linkage });
3534}
3635
3736pub fn __divmoddi4(a: i64, b: i64, rem: *i64) callconv(.C) i64 {
38 @setRuntimeSafety(builtin.is_test);
39
4037 const d = __divdi3(a, b);
4138 rem.* = a -% (d *% b);
4239 return d;
4340}
4441
4542pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {
46 @setRuntimeSafety(builtin.is_test);
4743 return udivmod(u64, a, b, maybe_rem);
4844}
4945
......@@ -52,8 +48,6 @@ test "test_udivmoddi4" {
5248}
5349
5450pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 {
55 @setRuntimeSafety(builtin.is_test);
56
5751 // Set aside the sign of the quotient.
5852 const sign = @bitCast(u64, (a ^ b) >> 63);
5953 // 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 {
9185}
9286
9387pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
94 @setRuntimeSafety(builtin.is_test);
95
9688 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
9789 const abs_a = (a ^ (a >> 63)) -% (a >> 63);
9890 const abs_b = (b ^ (b >> 63)) -% (b >> 63);
......@@ -131,13 +123,10 @@ fn test_one_moddi3(a: i64, b: i64, expected_r: i64) !void {
131123}
132124
133125pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
134 @setRuntimeSafety(builtin.is_test);
135126 return __udivmoddi4(a, b, null);
136127}
137128
138129pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {
139 @setRuntimeSafety(builtin.is_test);
140
141130 var r: u64 = undefined;
142131 _ = __udivmoddi4(a, b, &r);
143132 return r;
......@@ -157,8 +146,6 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) !void {
157146}
158147
159148pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
160 @setRuntimeSafety(builtin.is_test);
161
162149 const d = __divsi3(a, b);
163150 rem.* = a -% (d * b);
164151 return d;
......@@ -193,16 +180,20 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
193180}
194181
195182pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
196 @setRuntimeSafety(builtin.is_test);
197
198183 const d = __udivsi3(a, b);
199184 rem.* = @bitCast(u32, @bitCast(i32, a) -% (@bitCast(i32, d) * @bitCast(i32, b)));
200185 return d;
201186}
202187
203188pub fn __divsi3(n: i32, d: i32) callconv(.C) i32 {
204 @setRuntimeSafety(builtin.is_test);
189 return div_i32(n, d);
190}
191
192fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {
193 return div_i32(n, d);
194}
205195
196inline fn div_i32(n: i32, d: i32) i32 {
206197 // Set aside the sign of the quotient.
207198 const sign = @bitCast(u32, (n ^ d) >> 31);
208199 // 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 {
214205 return @bitCast(i32, (res ^ sign) -% sign);
215206}
216207
217pub fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {
218 return @call(.{ .modifier = .always_inline }, __divsi3, .{ n, d });
219}
220
221208test "test_divsi3" {
222209 const cases = [_][3]i32{
223210 [_]i32{ 0, 1, 0 },
......@@ -244,8 +231,14 @@ fn test_one_divsi3(a: i32, b: i32, expected_q: i32) !void {
244231}
245232
246233pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
247 @setRuntimeSafety(builtin.is_test);
234 return div_u32(n, d);
235}
236
237fn __aeabi_uidiv(n: u32, d: u32) callconv(.AAPCS) u32 {
238 return div_u32(n, d);
239}
248240
241inline fn div_u32(n: u32, d: u32) u32 {
249242 const n_uword_bits: c_uint = 32;
250243 // special cases
251244 if (d == 0) return 0; // ?!
......@@ -284,10 +277,6 @@ pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
284277 return q;
285278}
286279
287pub fn __aeabi_uidiv(n: u32, d: u32) callconv(.AAPCS) u32 {
288 return @call(.{ .modifier = .always_inline }, __udivsi3, .{ n, d });
289}
290
291280test "test_udivsi3" {
292281 const cases = [_][3]u32{
293282 [_]u32{ 0x00000000, 0x00000001, 0x00000000 },
......@@ -435,8 +424,6 @@ fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) !void {
435424}
436425
437426pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
438 @setRuntimeSafety(builtin.is_test);
439
440427 return n -% __divsi3(n, d) *% d;
441428}
442429
......@@ -466,8 +453,6 @@ fn test_one_modsi3(a: i32, b: i32, expected_r: i32) !void {
466453}
467454
468455pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
469 @setRuntimeSafety(builtin.is_test);
470
471456 return n -% __udivsi3(n, d) *% d;
472457}
473458
......@@ -618,8 +603,6 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) !void {
618603}
619604
620605pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
621 @setRuntimeSafety(builtin.is_test);
622
623606 var ua = @bitCast(u32, a);
624607 var ub = @bitCast(u32, b);
625608 var r: u32 = 0;
lib/compiler_rt/log.zig+15-23
......@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/lnf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c
1//! Ported from musl, which is licensed under the MIT license:
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/lnf.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c
66
77const std = @import("std");
88const builtin = @import("builtin");
99const math = std.math;
1010const testing = std.testing;
1111const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
12const common = @import("common.zig");
13
14pub const panic = common.panic;
1415
1516comptime {
16 @export(__logh, .{ .name = "__logh", .linkage = linkage });
17 @export(logf, .{ .name = "logf", .linkage = linkage });
18 @export(log, .{ .name = "log", .linkage = linkage });
19 @export(__logx, .{ .name = "__logx", .linkage = linkage });
20 @export(logq, .{ .name = "logq", .linkage = linkage });
21 @export(logl, .{ .name = "logl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(logf128, .{ .name = "logf128", .linkage = linkage });
26 }
27 }
17 @export(__logh, .{ .name = "__logh", .linkage = common.linkage });
18 @export(logf, .{ .name = "logf", .linkage = common.linkage });
19 @export(log, .{ .name = "log", .linkage = common.linkage });
20 @export(__logx, .{ .name = "__logx", .linkage = common.linkage });
21 const logq_sym_name = if (common.want_ppc_abi) "logf128" else "logq";
22 @export(logq, .{ .name = logq_sym_name, .linkage = common.linkage });
23 @export(logl, .{ .name = "logl", .linkage = common.linkage });
2824}
2925
3026pub fn __logh(a: f16) callconv(.C) f16 {
......@@ -150,10 +146,6 @@ pub fn logq(a: f128) callconv(.C) f128 {
150146 return log(@floatCast(f64, a));
151147}
152148
153pub fn logf128(a: f128) callconv(.C) f128 {
154 return @call(.{ .modifier = .always_inline }, logq, .{a});
155}
156
157149pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {
158150 switch (@typeInfo(c_longdouble).Float.bits) {
159151 16 => return __logh(x),
lib/compiler_rt/log10.zig+15-23
......@@ -1,8 +1,8 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/log10f.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c
1//! Ported from musl, which is licensed under the MIT license:
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/log10f.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c
66
77const std = @import("std");
88const builtin = @import("builtin");
......@@ -10,22 +10,18 @@ const math = std.math;
1010const testing = std.testing;
1111const maxInt = std.math.maxInt;
1212const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
14pub const panic = @import("common.zig").panic;
13const common = @import("common.zig");
14
15pub const panic = common.panic;
1516
1617comptime {
17 @export(__log10h, .{ .name = "__log10h", .linkage = linkage });
18 @export(log10f, .{ .name = "log10f", .linkage = linkage });
19 @export(log10, .{ .name = "log10", .linkage = linkage });
20 @export(__log10x, .{ .name = "__log10x", .linkage = linkage });
21 @export(log10q, .{ .name = "log10q", .linkage = linkage });
22 @export(log10l, .{ .name = "log10l", .linkage = linkage });
23
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(log10f128, .{ .name = "log10f128", .linkage = linkage });
27 }
28 }
18 @export(__log10h, .{ .name = "__log10h", .linkage = common.linkage });
19 @export(log10f, .{ .name = "log10f", .linkage = common.linkage });
20 @export(log10, .{ .name = "log10", .linkage = common.linkage });
21 @export(__log10x, .{ .name = "__log10x", .linkage = common.linkage });
22 const log10q_sym_name = if (common.want_ppc_abi) "log10f128" else "log10q";
23 @export(log10q, .{ .name = log10q_sym_name, .linkage = common.linkage });
24 @export(log10l, .{ .name = "log10l", .linkage = common.linkage });
2925}
3026
3127pub fn __log10h(a: f16) callconv(.C) f16 {
......@@ -178,10 +174,6 @@ pub fn log10q(a: f128) callconv(.C) f128 {
178174 return log10(@floatCast(f64, a));
179175}
180176
181pub fn log10f128(a: f128) callconv(.C) f128 {
182 return @call(.{ .modifier = .always_inline }, log10q, .{a});
183}
184
185177pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {
186178 switch (@typeInfo(c_longdouble).Float.bits) {
187179 16 => return __log10h(x),
lib/compiler_rt/log2.zig+15-23
......@@ -1,8 +1,8 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/log2f.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c
1//! Ported from musl, which is licensed under the MIT license:
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/log2f.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c
66
77const std = @import("std");
88const builtin = @import("builtin");
......@@ -10,22 +10,18 @@ const math = std.math;
1010const expect = std.testing.expect;
1111const maxInt = std.math.maxInt;
1212const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
14pub const panic = @import("common.zig").panic;
13const common = @import("common.zig");
14
15pub const panic = common.panic;
1516
1617comptime {
17 @export(__log2h, .{ .name = "__log2h", .linkage = linkage });
18 @export(log2f, .{ .name = "log2f", .linkage = linkage });
19 @export(log2, .{ .name = "log2", .linkage = linkage });
20 @export(__log2x, .{ .name = "__log2x", .linkage = linkage });
21 @export(log2q, .{ .name = "log2q", .linkage = linkage });
22 @export(log2l, .{ .name = "log2l", .linkage = linkage });
23
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(log2f128, .{ .name = "log2f128", .linkage = linkage });
27 }
28 }
18 @export(__log2h, .{ .name = "__log2h", .linkage = common.linkage });
19 @export(log2f, .{ .name = "log2f", .linkage = common.linkage });
20 @export(log2, .{ .name = "log2", .linkage = common.linkage });
21 @export(__log2x, .{ .name = "__log2x", .linkage = common.linkage });
22 const log2q_sym_name = if (common.want_ppc_abi) "log2f128" else "log2q";
23 @export(log2q, .{ .name = log2q_sym_name, .linkage = common.linkage });
24 @export(log2l, .{ .name = "log2l", .linkage = common.linkage });
2925}
3026
3127pub fn __log2h(a: f16) callconv(.C) f16 {
......@@ -170,10 +166,6 @@ pub fn log2q(a: f128) callconv(.C) f128 {
170166 return log2(@floatCast(f64, a));
171167}
172168
173pub fn log2f128(a: f128) callconv(.C) f128 {
174 return @call(.{ .modifier = .always_inline }, log2q, .{a});
175}
176
177169pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {
178170 switch (@typeInfo(c_longdouble).Float.bits) {
179171 16 => return __log2h(x),
lib/compiler_rt/modti3.zig+19-19
......@@ -1,39 +1,47 @@
1// Ported from:
2//
3// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c
1//! Ported from:
2//!
3//! https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c
44
55const std = @import("std");
66const builtin = @import("builtin");
77const udivmod = @import("udivmod.zig").udivmod;
88const arch = builtin.cpu.arch;
9const is_test = builtin.is_test;
10const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
11pub const panic = @import("common.zig").panic;
9const common = @import("common.zig");
10
11pub const panic = common.panic;
1212
1313comptime {
1414 if (builtin.os.tag == .windows) {
1515 switch (arch) {
1616 .i386 => {
17 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
17 @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
1818 },
1919 .x86_64 => {
2020 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
2121 // that LLVM expects compiler-rt to have.
22 @export(__modti3_windows_x86_64, .{ .name = "__modti3", .linkage = linkage });
22 @export(__modti3_windows_x86_64, .{ .name = "__modti3", .linkage = common.linkage });
2323 },
2424 else => {},
2525 }
2626 if (arch.isAARCH64()) {
27 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
27 @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
2828 }
2929 } else {
30 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
30 @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
3131 }
3232}
3333
3434pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
35 @setRuntimeSafety(builtin.is_test);
35 return mod(a, b);
36}
3637
38const v128 = @import("std").meta.Vector(2, u64);
39
40fn __modti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
41 return @bitCast(v128, mod(@bitCast(i128, a), @bitCast(i128, b)));
42}
43
44inline fn mod(a: i128, b: i128) i128 {
3745 const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 0
3846 const s_b = b >> (128 - 1); // s = b < 0 ? -1 : 0
3947
......@@ -45,14 +53,6 @@ pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
4553 return (@bitCast(i128, r) ^ s_a) -% s_a; // negate if s == -1
4654}
4755
48const v128 = @import("std").meta.Vector(2, u64);
49pub fn __modti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
50 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __modti3, .{
51 @bitCast(i128, a),
52 @bitCast(i128, b),
53 }));
54}
55
5656test {
5757 _ = @import("modti3_test.zig");
5858}
lib/compiler_rt/muldi3.zig+26-29
......@@ -1,23 +1,36 @@
1//! Ported from
2//! https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
3
14const std = @import("std");
25const builtin = @import("builtin");
36const native_endian = builtin.cpu.arch.endian();
4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
7const common = @import("common.zig");
88
9comptime {
10 @export(__muldi3, .{ .name = "__muldi3", .linkage = linkage });
9pub const panic = common.panic;
1110
12 if (!is_test) {
13 if (arch.isARM() or arch.isThumb()) {
14 @export(__aeabi_lmul, .{ .name = "__aeabi_lmul", .linkage = linkage });
15 }
11comptime {
12 if (common.want_aeabi) {
13 @export(__aeabi_lmul, .{ .name = "__aeabi_lmul", .linkage = common.linkage });
14 } else {
15 @export(__muldi3, .{ .name = "__muldi3", .linkage = common.linkage });
1616 }
1717}
1818
19// Ported from
20// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
19pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
20 return mul(a, b);
21}
22
23fn __aeabi_lmul(a: i64, b: i64) callconv(.AAPCS) i64 {
24 return mul(a, b);
25}
26
27inline fn mul(a: i64, b: i64) i64 {
28 const x = dwords{ .all = a };
29 const y = dwords{ .all = b };
30 var r = dwords{ .all = muldsi3(x.s.low, y.s.low) };
31 r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
32 return r.all;
33}
2134
2235const dwords = extern union {
2336 all: i64,
......@@ -33,13 +46,7 @@ const dwords = extern union {
3346 },
3447};
3548
36pub fn __aeabi_lmul(a: i64, b: i64) callconv(.AAPCS) i64 {
37 return @call(.{ .modifier = .always_inline }, __muldi3, .{ a, b });
38}
39
40pub fn __muldsi3(a: u32, b: u32) i64 {
41 @setRuntimeSafety(is_test);
42
49fn muldsi3(a: u32, b: u32) i64 {
4350 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
4451 const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;
4552
......@@ -59,16 +66,6 @@ pub fn __muldsi3(a: u32, b: u32) i64 {
5966 return r.all;
6067}
6168
62pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
63 @setRuntimeSafety(is_test);
64
65 const x = dwords{ .all = a };
66 const y = dwords{ .all = b };
67 var r = dwords{ .all = __muldsi3(x.s.low, y.s.low) };
68 r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
69 return r.all;
70}
71
7269test {
7370 _ = @import("muldi3_test.zig");
7471}
lib/compiler_rt/mulo.zig+6-8
......@@ -1,14 +1,14 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const math = std.math;
4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
4const common = @import("common.zig");
5
6pub const panic = common.panic;
77
88comptime {
9 @export(__mulosi4, .{ .name = "__mulosi4", .linkage = linkage });
10 @export(__mulodi4, .{ .name = "__mulodi4", .linkage = linkage });
11 @export(__muloti4, .{ .name = "__muloti4", .linkage = linkage });
9 @export(__mulosi4, .{ .name = "__mulosi4", .linkage = common.linkage });
10 @export(__mulodi4, .{ .name = "__mulodi4", .linkage = common.linkage });
11 @export(__muloti4, .{ .name = "__muloti4", .linkage = common.linkage });
1212}
1313
1414// mulo - multiplication overflow
......@@ -18,7 +18,6 @@ comptime {
1818// - muloXi4_genericFast for 2*bitsize <= usize
1919
2020inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
21 @setRuntimeSafety(builtin.is_test);
2221 overflow.* = 0;
2322 const min = math.minInt(ST);
2423 var res: ST = a *% b;
......@@ -33,7 +32,6 @@ inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int
3332}
3433
3534inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
36 @setRuntimeSafety(builtin.is_test);
3735 overflow.* = 0;
3836 const EST = switch (ST) {
3937 i32 => i64,
lib/compiler_rt/multi3.zig+21-20
......@@ -1,51 +1,52 @@
1//! Ported from git@github.com:llvm-project/llvm-project-20170507.git
2//! ae684fad6d34858c014c94da69c15e7774a633c3
3//! 2018-08-13
4
15const std = @import("std");
26const builtin = @import("builtin");
37const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;
58const native_endian = builtin.cpu.arch.endian();
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
9const common = @import("common.zig");
810
9// Ported from git@github.com:llvm-project/llvm-project-20170507.git
10// ae684fad6d34858c014c94da69c15e7774a633c3
11// 2018-08-13
11pub const panic = common.panic;
1212
1313comptime {
1414 if (builtin.os.tag == .windows) {
1515 switch (arch) {
1616 .i386 => {
17 @export(__multi3, .{ .name = "__multi3", .linkage = linkage });
17 @export(__multi3, .{ .name = "__multi3", .linkage = common.linkage });
1818 },
1919 .x86_64 => {
2020 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
2121 // that LLVM expects compiler-rt to have.
22 @export(__multi3_windows_x86_64, .{ .name = "__multi3", .linkage = linkage });
22 @export(__multi3_windows_x86_64, .{ .name = "__multi3", .linkage = common.linkage });
2323 },
2424 else => {},
2525 }
2626 } else {
27 @export(__multi3, .{ .name = "__multi3", .linkage = linkage });
27 @export(__multi3, .{ .name = "__multi3", .linkage = common.linkage });
2828 }
2929}
3030
3131pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
32 @setRuntimeSafety(is_test);
32 return mul(a, b);
33}
34
35const v128 = @Vector(2, u64);
36
37fn __multi3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
38 return @bitCast(v128, mul(@bitCast(i128, a), @bitCast(i128, b)));
39}
40
41inline fn mul(a: i128, b: i128) i128 {
3342 const x = twords{ .all = a };
3443 const y = twords{ .all = b };
35 var r = twords{ .all = __mulddi3(x.s.low, y.s.low) };
44 var r = twords{ .all = mulddi3(x.s.low, y.s.low) };
3645 r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
3746 return r.all;
3847}
3948
40const v128 = @Vector(2, u64);
41pub fn __multi3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
42 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __multi3, .{
43 @bitCast(i128, a),
44 @bitCast(i128, b),
45 }));
46}
47
48pub fn __mulddi3(a: u64, b: u64) i128 {
49fn mulddi3(a: u64, b: u64) i128 {
4950 const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;
5051 const lower_mask = ~@as(u64, 0) >> bits_in_dword_2;
5152 var r: twords = undefined;
lib/compiler_rt/negXf2.zig+16-21
......@@ -1,19 +1,16 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
3const common = @import("common.zig");
4
5pub const panic = common.panic;
76
87comptime {
9 @export(__negsf2, .{ .name = "__negsf2", .linkage = linkage });
10 @export(__negdf2, .{ .name = "__negdf2", .linkage = linkage });
11
12 if (!is_test) {
13 if (arch.isARM() or arch.isThumb()) {
14 @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = linkage });
15 @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = linkage });
16 }
8 if (common.want_aeabi) {
9 @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = common.linkage });
10 @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = common.linkage });
11 } else {
12 @export(__negsf2, .{ .name = "__negsf2", .linkage = common.linkage });
13 @export(__negdf2, .{ .name = "__negdf2", .linkage = common.linkage });
1714 }
1815}
1916
......@@ -21,21 +18,19 @@ pub fn __negsf2(a: f32) callconv(.C) f32 {
2118 return negXf2(f32, a);
2219}
2320
24pub fn __negdf2(a: f64) callconv(.C) f64 {
25 return negXf2(f64, a);
21fn __aeabi_fneg(a: f32) callconv(.AAPCS) f32 {
22 return negXf2(f32, a);
2623}
2724
28pub fn __aeabi_fneg(arg: f32) callconv(.AAPCS) f32 {
29 @setRuntimeSafety(false);
30 return @call(.{ .modifier = .always_inline }, __negsf2, .{arg});
25pub fn __negdf2(a: f64) callconv(.C) f64 {
26 return negXf2(f64, a);
3127}
3228
33pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {
34 @setRuntimeSafety(false);
35 return @call(.{ .modifier = .always_inline }, __negdf2, .{arg});
29fn __aeabi_dneg(a: f64) callconv(.AAPCS) f64 {
30 return negXf2(f64, a);
3631}
3732
38fn negXf2(comptime T: type, a: T) T {
33inline fn negXf2(comptime T: type, a: T) T {
3934 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
4035
4136 const significandBits = std.math.floatMantissaBits(T);
lib/compiler_rt/negXi2.zig+18-21
......@@ -1,28 +1,21 @@
1//! neg - negate (the number)
2//! - negXi2 for unoptimized little and big endian
3//! sfffffff = 2^31-1
4//! two's complement inverting bits and add 1 would result in -INT_MIN == 0
5//! => -INT_MIN = -2^31 forbidden
6//! * size optimized builds
7//! * machines that dont support carry operations
8
19const std = @import("std");
210const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__negsi2, .{ .name = "__negsi2", .linkage = linkage });
9 @export(__negdi2, .{ .name = "__negdi2", .linkage = linkage });
10 @export(__negti2, .{ .name = "__negti2", .linkage = linkage });
11}
11const common = @import("common.zig");
1212
13// neg - negate (the number)
14// - negXi2 for unoptimized little and big endian
13pub const panic = common.panic;
1514
16// sfffffff = 2^31-1
17// two's complement inverting bits and add 1 would result in -INT_MIN == 0
18// => -INT_MIN = -2^31 forbidden
19
20// * size optimized builds
21// * machines that dont support carry operations
22
23inline fn negXi2(comptime T: type, a: T) T {
24 @setRuntimeSafety(builtin.is_test);
25 return -a;
15comptime {
16 @export(__negsi2, .{ .name = "__negsi2", .linkage = common.linkage });
17 @export(__negdi2, .{ .name = "__negdi2", .linkage = common.linkage });
18 @export(__negti2, .{ .name = "__negti2", .linkage = common.linkage });
2619}
2720
2821pub fn __negsi2(a: i32) callconv(.C) i32 {
......@@ -37,6 +30,10 @@ pub fn __negti2(a: i128) callconv(.C) i128 {
3730 return negXi2(i128, a);
3831}
3932
33inline fn negXi2(comptime T: type, a: T) T {
34 return -a;
35}
36
4037test {
4138 _ = @import("negsi2_test.zig");
4239 _ = @import("negdi2_test.zig");
lib/compiler_rt/negv.zig+21-22
......@@ -1,19 +1,30 @@
1// negv - negate oVerflow
2// * @panic, if result can not be represented
3// - negvXi4_generic for unoptimized version
1//! negv - negate oVerflow
2//! * @panic, if result can not be represented
3//! - negvXi4_generic for unoptimized version
44const std = @import("std");
55const builtin = @import("builtin");
6const is_test = builtin.is_test;
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
8pub const panic = @import("common.zig").panic;
6const common = @import("common.zig");
7
8pub const panic = common.panic;
99
1010comptime {
11 @export(__negvsi2, .{ .name = "__negvsi2", .linkage = linkage });
12 @export(__negvdi2, .{ .name = "__negvdi2", .linkage = linkage });
13 @export(__negvti2, .{ .name = "__negvti2", .linkage = linkage });
11 @export(__negvsi2, .{ .name = "__negvsi2", .linkage = common.linkage });
12 @export(__negvdi2, .{ .name = "__negvdi2", .linkage = common.linkage });
13 @export(__negvti2, .{ .name = "__negvti2", .linkage = common.linkage });
14}
15
16pub fn __negvsi2(a: i32) callconv(.C) i32 {
17 return negvXi(i32, a);
18}
19
20pub fn __negvdi2(a: i64) callconv(.C) i64 {
21 return negvXi(i64, a);
22}
23
24pub fn __negvti2(a: i128) callconv(.C) i128 {
25 return negvXi(i128, a);
1426}
1527
16// assume -0 == 0 is gracefully handled by the hardware
1728inline fn negvXi(comptime ST: type, a: ST) ST {
1829 const UT = switch (ST) {
1930 i32 => u32,
......@@ -28,18 +39,6 @@ inline fn negvXi(comptime ST: type, a: ST) ST {
2839 return -a;
2940}
3041
31pub fn __negvsi2(a: i32) callconv(.C) i32 {
32 return negvXi(i32, a);
33}
34
35pub fn __negvdi2(a: i64) callconv(.C) i64 {
36 return negvXi(i64, a);
37}
38
39pub fn __negvti2(a: i128) callconv(.C) i128 {
40 return negvXi(i128, a);
41}
42
4342test {
4443 _ = @import("negvsi2_test.zig");
4544 _ = @import("negvdi2_test.zig");
lib/compiler_rt/parity.zig+20-22
......@@ -1,21 +1,31 @@
1//! parity - if number of bits set is even => 0, else => 1
2//! - pariytXi2_generic for big and little endian
3
14const std = @import("std");
25const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6const common = @import("common.zig");
7
8pub const panic = common.panic;
69
710comptime {
8 @export(__paritysi2, .{ .name = "__paritysi2", .linkage = linkage });
9 @export(__paritydi2, .{ .name = "__paritydi2", .linkage = linkage });
10 @export(__parityti2, .{ .name = "__parityti2", .linkage = linkage });
11 @export(__paritysi2, .{ .name = "__paritysi2", .linkage = common.linkage });
12 @export(__paritydi2, .{ .name = "__paritydi2", .linkage = common.linkage });
13 @export(__parityti2, .{ .name = "__parityti2", .linkage = common.linkage });
1114}
1215
13// parity - if number of bits set is even => 0, else => 1
14// - pariytXi2_generic for big and little endian
16pub fn __paritysi2(a: i32) callconv(.C) i32 {
17 return parityXi2(i32, a);
18}
1519
16inline fn parityXi2(comptime T: type, a: T) i32 {
17 @setRuntimeSafety(builtin.is_test);
20pub fn __paritydi2(a: i64) callconv(.C) i32 {
21 return parityXi2(i64, a);
22}
23
24pub fn __parityti2(a: i128) callconv(.C) i32 {
25 return parityXi2(i128, a);
26}
1827
28inline fn parityXi2(comptime T: type, a: T) i32 {
1929 var x = switch (@bitSizeOf(T)) {
2030 32 => @bitCast(u32, a),
2131 64 => @bitCast(u64, a),
......@@ -32,18 +42,6 @@ inline fn parityXi2(comptime T: type, a: T) i32 {
3242 return (@intCast(u16, 0x6996) >> @intCast(u4, x)) & 1; // optimization for >>2 and >>1
3343}
3444
35pub fn __paritysi2(a: i32) callconv(.C) i32 {
36 return parityXi2(i32, a);
37}
38
39pub fn __paritydi2(a: i64) callconv(.C) i32 {
40 return parityXi2(i64, a);
41}
42
43pub fn __parityti2(a: i128) callconv(.C) i32 {
44 return parityXi2(i128, a);
45}
46
4745test {
4846 _ = @import("paritysi2_test.zig");
4947 _ = @import("paritydi2_test.zig");
lib/compiler_rt/popcount.zig+24-26
......@@ -1,26 +1,36 @@
1//! popcount - population count
2//! counts the number of 1 bits
3//! SWAR-Popcount: count bits of duos, aggregate to nibbles, and bytes inside
4//! x-bit register in parallel to sum up all bytes
5//! SWAR-Masks and factors can be defined as 2-adic fractions
6//! TAOCP: Combinational Algorithms, Bitwise Tricks And Techniques,
7//! subsubsection "Working with the rightmost bits" and "Sideways addition".
8
19const builtin = @import("builtin");
210const std = @import("std");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
11const common = @import("common.zig");
12
13pub const panic = common.panic;
614
715comptime {
8 @export(__popcountsi2, .{ .name = "__popcountsi2", .linkage = linkage });
9 @export(__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });
10 @export(__popcountti2, .{ .name = "__popcountti2", .linkage = linkage });
16 @export(__popcountsi2, .{ .name = "__popcountsi2", .linkage = common.linkage });
17 @export(__popcountdi2, .{ .name = "__popcountdi2", .linkage = common.linkage });
18 @export(__popcountti2, .{ .name = "__popcountti2", .linkage = common.linkage });
19}
20
21pub fn __popcountsi2(a: i32) callconv(.C) i32 {
22 return popcountXi2(i32, a);
1123}
1224
13// popcount - population count
14// counts the number of 1 bits
25pub fn __popcountdi2(a: i64) callconv(.C) i32 {
26 return popcountXi2(i64, a);
27}
1528
16// SWAR-Popcount: count bits of duos, aggregate to nibbles, and bytes inside
17// x-bit register in parallel to sum up all bytes
18// SWAR-Masks and factors can be defined as 2-adic fractions
19// TAOCP: Combinational Algorithms, Bitwise Tricks And Techniques,
20// subsubsection "Working with the rightmost bits" and "Sideways addition".
29pub fn __popcountti2(a: i128) callconv(.C) i32 {
30 return popcountXi2(i128, a);
31}
2132
2233inline fn popcountXi2(comptime ST: type, a: ST) i32 {
23 @setRuntimeSafety(builtin.is_test);
2434 const UT = switch (ST) {
2535 i32 => u32,
2636 i64 => u64,
......@@ -39,18 +49,6 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
3949 return @intCast(i32, x);
4050}
4151
42pub fn __popcountsi2(a: i32) callconv(.C) i32 {
43 return popcountXi2(i32, a);
44}
45
46pub fn __popcountdi2(a: i64) callconv(.C) i32 {
47 return popcountXi2(i64, a);
48}
49
50pub fn __popcountti2(a: i128) callconv(.C) i32 {
51 return popcountXi2(i128, a);
52}
53
5452test {
5553 _ = @import("popcountsi2_test.zig");
5654 _ = @import("popcountdi2_test.zig");
lib/compiler_rt/round.zig+15-23
......@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
1//! Ported from musl, which is licensed under the MIT license:
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
66
77const std = @import("std");
88const builtin = @import("builtin");
99const math = std.math;
1010const expect = std.testing.expect;
1111const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
12const common = @import("common.zig");
13
14pub const panic = common.panic;
1415
1516comptime {
16 @export(__roundh, .{ .name = "__roundh", .linkage = linkage });
17 @export(roundf, .{ .name = "roundf", .linkage = linkage });
18 @export(round, .{ .name = "round", .linkage = linkage });
19 @export(__roundx, .{ .name = "__roundx", .linkage = linkage });
20 @export(roundq, .{ .name = "roundq", .linkage = linkage });
21 @export(roundl, .{ .name = "roundl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(roundf128, .{ .name = "roundf128", .linkage = linkage });
26 }
27 }
17 @export(__roundh, .{ .name = "__roundh", .linkage = common.linkage });
18 @export(roundf, .{ .name = "roundf", .linkage = common.linkage });
19 @export(round, .{ .name = "round", .linkage = common.linkage });
20 @export(__roundx, .{ .name = "__roundx", .linkage = common.linkage });
21 const roundq_sym_name = if (common.want_ppc_abi) "roundf128" else "roundq";
22 @export(roundq, .{ .name = roundq_sym_name, .linkage = common.linkage });
23 @export(roundl, .{ .name = "roundl", .linkage = common.linkage });
2824}
2925
3026pub fn __roundh(x: f16) callconv(.C) f16 {
......@@ -142,10 +138,6 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
142138 }
143139}
144140
145pub fn roundf128(x_: f128) callconv(.C) f128 {
146 return @call(.{ .modifier = .always_inline }, roundq, .{x_});
147}
148
149141pub fn roundl(x: c_longdouble) callconv(.C) c_longdouble {
150142 switch (@typeInfo(c_longdouble).Float.bits) {
151143 16 => return __roundh(x),
lib/compiler_rt/shift.zig+29-27
......@@ -2,25 +2,23 @@ const std = @import("std");
22const builtin = @import("builtin");
33const Log2Int = std.math.Log2Int;
44const native_endian = builtin.cpu.arch.endian();
5const arch = builtin.cpu.arch;
6const is_test = builtin.is_test;
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
8pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
98
109comptime {
11 @export(__ashldi3, .{ .name = "__ashldi3", .linkage = linkage });
12 @export(__ashlti3, .{ .name = "__ashlti3", .linkage = linkage });
13 @export(__ashrdi3, .{ .name = "__ashrdi3", .linkage = linkage });
14 @export(__ashrti3, .{ .name = "__ashrti3", .linkage = linkage });
15 @export(__lshrdi3, .{ .name = "__lshrdi3", .linkage = linkage });
16 @export(__lshrti3, .{ .name = "__lshrti3", .linkage = linkage });
17
18 if (!is_test) {
19 if (arch.isARM() or arch.isThumb()) {
20 @export(__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = linkage });
21 @export(__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = linkage });
22 @export(__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = linkage });
23 }
10 @export(__ashlti3, .{ .name = "__ashlti3", .linkage = common.linkage });
11 @export(__ashrti3, .{ .name = "__ashrti3", .linkage = common.linkage });
12 @export(__lshrti3, .{ .name = "__lshrti3", .linkage = common.linkage });
13
14 if (common.want_aeabi) {
15 @export(__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = common.linkage });
16 @export(__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = common.linkage });
17 @export(__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = common.linkage });
18 } else {
19 @export(__ashldi3, .{ .name = "__ashldi3", .linkage = common.linkage });
20 @export(__ashrdi3, .{ .name = "__ashrdi3", .linkage = common.linkage });
21 @export(__lshrdi3, .{ .name = "__lshrdi3", .linkage = common.linkage });
2422 }
2523}
2624
......@@ -115,30 +113,34 @@ inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
115113pub fn __ashldi3(a: i64, b: i32) callconv(.C) i64 {
116114 return ashlXi3(i64, a, b);
117115}
116fn __aeabi_llsl(a: i64, b: i32) callconv(.AAPCS) i64 {
117 return ashlXi3(i64, a, b);
118}
119
118120pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 {
119121 return ashlXi3(i128, a, b);
120122}
123
121124pub fn __ashrdi3(a: i64, b: i32) callconv(.C) i64 {
122125 return ashrXi3(i64, a, b);
123126}
127fn __aeabi_lasr(a: i64, b: i32) callconv(.AAPCS) i64 {
128 return ashrXi3(i64, a, b);
129}
130
124131pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 {
125132 return ashrXi3(i128, a, b);
126133}
134
127135pub fn __lshrdi3(a: i64, b: i32) callconv(.C) i64 {
128136 return lshrXi3(i64, a, b);
129137}
130pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
131 return lshrXi3(i128, a, b);
138fn __aeabi_llsr(a: i64, b: i32) callconv(.AAPCS) i64 {
139 return lshrXi3(i64, a, b);
132140}
133141
134pub fn __aeabi_llsl(a: i64, b: i32) callconv(.AAPCS) i64 {
135 return ashlXi3(i64, a, b);
136}
137pub fn __aeabi_lasr(a: i64, b: i32) callconv(.AAPCS) i64 {
138 return ashrXi3(i64, a, b);
139}
140pub fn __aeabi_llsr(a: i64, b: i32) callconv(.AAPCS) i64 {
141 return lshrXi3(i64, a, b);
142pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
143 return lshrXi3(i128, a, b);
142144}
143145
144146test {
lib/compiler_rt/sin.zig+15-23
......@@ -1,34 +1,30 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/sinf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c
1//! Ported from musl, which is licensed under the MIT license:
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/sinf.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c
66
77const std = @import("std");
88const builtin = @import("builtin");
99const arch = builtin.cpu.arch;
1010const math = std.math;
1111const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
12const common = @import("common.zig");
1413
1514const trig = @import("trig.zig");
1615const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
1716const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
1817
18pub const panic = common.panic;
19
1920comptime {
20 @export(__sinh, .{ .name = "__sinh", .linkage = linkage });
21 @export(sinf, .{ .name = "sinf", .linkage = linkage });
22 @export(sin, .{ .name = "sin", .linkage = linkage });
23 @export(__sinx, .{ .name = "__sinx", .linkage = linkage });
24 @export(sinq, .{ .name = "sinq", .linkage = linkage });
25 @export(sinl, .{ .name = "sinl", .linkage = linkage });
26
27 if (!builtin.is_test) {
28 if (arch.isPPC() or arch.isPPC64()) {
29 @export(sinf128, .{ .name = "sinf128", .linkage = linkage });
30 }
31 }
21 @export(__sinh, .{ .name = "__sinh", .linkage = common.linkage });
22 @export(sinf, .{ .name = "sinf", .linkage = common.linkage });
23 @export(sin, .{ .name = "sin", .linkage = common.linkage });
24 @export(__sinx, .{ .name = "__sinx", .linkage = common.linkage });
25 const sinq_sym_name = if (common.want_ppc_abi) "sinf128" else "sinq";
26 @export(sinq, .{ .name = sinq_sym_name, .linkage = common.linkage });
27 @export(sinl, .{ .name = "sinl", .linkage = common.linkage });
3228}
3329
3430pub fn __sinh(x: f16) callconv(.C) f16 {
......@@ -130,10 +126,6 @@ pub fn sinq(x: f128) callconv(.C) f128 {
130126 return sin(@floatCast(f64, x));
131127}
132128
133pub fn sinf128(x: f128) callconv(.C) f128 {
134 return @call(.{ .modifier = .always_inline }, sinq, .{x});
135}
136
137129pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {
138130 switch (@typeInfo(c_longdouble).Float.bits) {
139131 16 => return __sinh(x),
lib/compiler_rt/sincos.zig+10-18
......@@ -5,22 +5,18 @@ const math = std.math;
55const trig = @import("trig.zig");
66const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
77const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
8const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
9pub const panic = @import("common.zig").panic;
8const common = @import("common.zig");
109
11comptime {
12 @export(__sincosh, .{ .name = "__sincosh", .linkage = linkage });
13 @export(sincosf, .{ .name = "sincosf", .linkage = linkage });
14 @export(sincos, .{ .name = "sincos", .linkage = linkage });
15 @export(__sincosx, .{ .name = "__sincosx", .linkage = linkage });
16 @export(sincosq, .{ .name = "sincosq", .linkage = linkage });
17 @export(sincosl, .{ .name = "sincosl", .linkage = linkage });
10pub const panic = common.panic;
1811
19 if (!builtin.is_test) {
20 if (arch.isPPC() or arch.isPPC64()) {
21 @export(sincosf128, .{ .name = "sincosf128", .linkage = linkage });
22 }
23 }
12comptime {
13 @export(__sincosh, .{ .name = "__sincosh", .linkage = common.linkage });
14 @export(sincosf, .{ .name = "sincosf", .linkage = common.linkage });
15 @export(sincos, .{ .name = "sincos", .linkage = common.linkage });
16 @export(__sincosx, .{ .name = "__sincosx", .linkage = common.linkage });
17 const sincosq_sym_name = if (common.want_ppc_abi) "sincosf128" else "sincosq";
18 @export(sincosq, .{ .name = sincosq_sym_name, .linkage = common.linkage });
19 @export(sincosl, .{ .name = "sincosl", .linkage = common.linkage });
2420}
2521
2622pub 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 {
198194 r_cos.* = small_cos;
199195}
200196
201pub fn sincosf128(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {
202 return @call(.{ .modifier = .always_inline }, sincosq, .{ x, r_sin, r_cos });
203}
204
205197pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.C) void {
206198 switch (@typeInfo(c_longdouble).Float.bits) {
207199 16 => return __sincosh(x, r_sin, r_cos),
lib/compiler_rt/sqrt.zig+10-18
......@@ -2,22 +2,18 @@ const std = @import("std");
22const builtin = @import("builtin");
33const arch = builtin.cpu.arch;
44const math = std.math;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
78
89comptime {
9 @export(__sqrth, .{ .name = "__sqrth", .linkage = linkage });
10 @export(sqrtf, .{ .name = "sqrtf", .linkage = linkage });
11 @export(sqrt, .{ .name = "sqrt", .linkage = linkage });
12 @export(__sqrtx, .{ .name = "__sqrtx", .linkage = linkage });
13 @export(sqrtq, .{ .name = "sqrtq", .linkage = linkage });
14 @export(sqrtl, .{ .name = "sqrtl", .linkage = linkage });
15
16 if (!builtin.is_test) {
17 if (arch.isPPC() or arch.isPPC64()) {
18 @export(sqrtf128, .{ .name = "sqrtf128", .linkage = linkage });
19 }
20 }
10 @export(__sqrth, .{ .name = "__sqrth", .linkage = common.linkage });
11 @export(sqrtf, .{ .name = "sqrtf", .linkage = common.linkage });
12 @export(sqrt, .{ .name = "sqrt", .linkage = common.linkage });
13 @export(__sqrtx, .{ .name = "__sqrtx", .linkage = common.linkage });
14 const sqrtq_sym_name = if (common.want_ppc_abi) "sqrtf128" else "sqrtq";
15 @export(sqrtq, .{ .name = sqrtq_sym_name, .linkage = common.linkage });
16 @export(sqrtl, .{ .name = "sqrtl", .linkage = common.linkage });
2117}
2218
2319pub fn __sqrth(x: f16) callconv(.C) f16 {
......@@ -255,10 +251,6 @@ pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {
255251 }
256252}
257253
258pub fn sqrtf128(x: f128) callconv(.C) f128 {
259 return @call(.{ .modifier = .always_inline }, sqrtq, .{x});
260}
261
262254test "sqrtf" {
263255 const V = [_]f32{
264256 0.0,
lib/compiler_rt/subo.zig+20-21
......@@ -1,22 +1,31 @@
1//! subo - subtract overflow
2//! * return a-%b.
3//! * return if a-b overflows => 1 else => 0
4//! - suboXi4_generic as default
5
16const std = @import("std");
27const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
8const common = @import("common.zig");
9
10pub const panic = common.panic;
611
712comptime {
8 @export(__subosi4, .{ .name = "__subosi4", .linkage = linkage });
9 @export(__subodi4, .{ .name = "__subodi4", .linkage = linkage });
10 @export(__suboti4, .{ .name = "__suboti4", .linkage = linkage });
13 @export(__subosi4, .{ .name = "__subosi4", .linkage = common.linkage });
14 @export(__subodi4, .{ .name = "__subodi4", .linkage = common.linkage });
15 @export(__suboti4, .{ .name = "__suboti4", .linkage = common.linkage });
1116}
1217
13// subo - subtract overflow
14// * return a-%b.
15// * return if a-b overflows => 1 else => 0
16// - suboXi4_generic as default
18pub fn __subosi4(a: i32, b: i32, overflow: *c_int) callconv(.C) i32 {
19 return suboXi4_generic(i32, a, b, overflow);
20}
21pub fn __subodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
22 return suboXi4_generic(i64, a, b, overflow);
23}
24pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
25 return suboXi4_generic(i128, a, b, overflow);
26}
1727
1828inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
19 @setRuntimeSafety(builtin.is_test);
2029 overflow.* = 0;
2130 var sum: ST = a -% b;
2231 // 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
3140 return sum;
3241}
3342
34pub fn __subosi4(a: i32, b: i32, overflow: *c_int) callconv(.C) i32 {
35 return suboXi4_generic(i32, a, b, overflow);
36}
37pub fn __subodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
38 return suboXi4_generic(i64, a, b, overflow);
39}
40pub fn __suboti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
41 return suboXi4_generic(i128, a, b, overflow);
42}
43
4443test {
4544 _ = @import("subosi4_test.zig");
4645 _ = @import("subodi4_test.zig");
lib/compiler_rt/tan.zig+16-24
......@@ -1,9 +1,9 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/tanf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/tan.c
6// https://golang.org/src/math/tan.go
1//! Ported from musl, which is licensed under the MIT license:
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/tanf.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/tan.c
6//! https://golang.org/src/math/tan.go
77
88const std = @import("std");
99const builtin = @import("builtin");
......@@ -15,22 +15,18 @@ const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
1515const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
1616
1717const arch = builtin.cpu.arch;
18const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
19pub const panic = @import("common.zig").panic;
18const common = @import("common.zig");
19
20pub const panic = common.panic;
2021
2122comptime {
22 @export(__tanh, .{ .name = "__tanh", .linkage = linkage });
23 @export(tanf, .{ .name = "tanf", .linkage = linkage });
24 @export(tan, .{ .name = "tan", .linkage = linkage });
25 @export(__tanx, .{ .name = "__tanx", .linkage = linkage });
26 @export(tanq, .{ .name = "tanq", .linkage = linkage });
27 @export(tanl, .{ .name = "tanl", .linkage = linkage });
28
29 if (!builtin.is_test) {
30 if (arch.isPPC() or arch.isPPC64()) {
31 @export(tanf128, .{ .name = "tanf128", .linkage = linkage });
32 }
33 }
23 @export(__tanh, .{ .name = "__tanh", .linkage = common.linkage });
24 @export(tanf, .{ .name = "tanf", .linkage = common.linkage });
25 @export(tan, .{ .name = "tan", .linkage = common.linkage });
26 @export(__tanx, .{ .name = "__tanx", .linkage = common.linkage });
27 const tanq_sym_name = if (common.want_ppc_abi) "tanf128" else "tanq";
28 @export(tanq, .{ .name = tanq_sym_name, .linkage = common.linkage });
29 @export(tanl, .{ .name = "tanl", .linkage = common.linkage });
3430}
3531
3632pub fn __tanh(x: f16) callconv(.C) f16 {
......@@ -116,10 +112,6 @@ pub fn tanq(x: f128) callconv(.C) f128 {
116112 return tan(@floatCast(f64, x));
117113}
118114
119pub fn tanf128(x: f128) callconv(.C) f128 {
120 return @call(.{ .modifier = .always_inline }, tanq, .{x});
121}
122
123115pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {
124116 switch (@typeInfo(c_longdouble).Float.bits) {
125117 16 => return __tanh(x),
lib/compiler_rt/trunc.zig+16-24
......@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//
4// https://git.musl-libc.org/cgit/musl/tree/src/math/truncf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
1//! Ported from musl, which is MIT licensed.
2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//!
4//! https://git.musl-libc.org/cgit/musl/tree/src/math/truncf.c
5//! https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
66
77const std = @import("std");
88const builtin = @import("builtin");
9const arch = builtin.cpu.arch;
910const math = std.math;
1011const expect = std.testing.expect;
11const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
12const common = @import("common.zig");
13
14pub const panic = common.panic;
1415
1516comptime {
16 @export(__trunch, .{ .name = "__trunch", .linkage = linkage });
17 @export(truncf, .{ .name = "truncf", .linkage = linkage });
18 @export(trunc, .{ .name = "trunc", .linkage = linkage });
19 @export(__truncx, .{ .name = "__truncx", .linkage = linkage });
20 @export(truncq, .{ .name = "truncq", .linkage = linkage });
21 @export(truncl, .{ .name = "truncl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(truncf128, .{ .name = "truncf128", .linkage = linkage });
26 }
27 }
17 @export(__trunch, .{ .name = "__trunch", .linkage = common.linkage });
18 @export(truncf, .{ .name = "truncf", .linkage = common.linkage });
19 @export(trunc, .{ .name = "trunc", .linkage = common.linkage });
20 @export(__truncx, .{ .name = "__truncx", .linkage = common.linkage });
21 const truncq_sym_name = if (common.want_ppc_abi) "truncf128" else "truncq";
22 @export(truncq, .{ .name = truncq_sym_name, .linkage = common.linkage });
23 @export(truncl, .{ .name = "truncl", .linkage = common.linkage });
2824}
2925
3026pub fn __trunch(x: f16) callconv(.C) f16 {
......@@ -100,10 +96,6 @@ pub fn truncq(x: f128) callconv(.C) f128 {
10096 }
10197}
10298
103pub fn truncf128(x: f128) callconv(.C) f128 {
104 return @call(.{ .modifier = .always_inline }, truncq, .{x});
105}
106
10799pub fn truncl(x: c_longdouble) callconv(.C) c_longdouble {
108100 switch (@typeInfo(c_longdouble).Float.bits) {
109101 16 => return __trunch(x),
lib/compiler_rt/udivmodti4.zig+8-9
......@@ -2,36 +2,35 @@ const std = @import("std");
22const builtin = @import("builtin");
33const udivmod = @import("udivmod.zig").udivmod;
44const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
88
99comptime {
1010 if (builtin.os.tag == .windows) {
1111 switch (arch) {
1212 .i386 => {
13 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
13 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = common.linkage });
1414 },
1515 .x86_64 => {
1616 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
1717 // that LLVM expects compiler-rt to have.
18 @export(__udivmodti4_windows_x86_64, .{ .name = "__udivmodti4", .linkage = linkage });
18 @export(__udivmodti4_windows_x86_64, .{ .name = "__udivmodti4", .linkage = common.linkage });
1919 },
2020 else => {},
2121 }
2222 } else {
23 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
23 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = common.linkage });
2424 }
2525}
2626
2727pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {
28 @setRuntimeSafety(builtin.is_test);
2928 return udivmod(u128, a, b, maybe_rem);
3029}
3130
3231const v128 = std.meta.Vector(2, u64);
33pub fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {
34 @setRuntimeSafety(builtin.is_test);
32
33fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {
3534 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));
3635}
3736
lib/compiler_rt/udivti3.zig+9-10
......@@ -2,38 +2,37 @@ const std = @import("std");
22const builtin = @import("builtin");
33const udivmod = @import("udivmod.zig").udivmod;
44const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
88
99comptime {
1010 if (builtin.os.tag == .windows) {
1111 switch (arch) {
1212 .i386 => {
13 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
13 @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
1414 },
1515 .x86_64 => {
1616 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
1717 // that LLVM expects compiler-rt to have.
18 @export(__udivti3_windows_x86_64, .{ .name = "__udivti3", .linkage = linkage });
18 @export(__udivti3_windows_x86_64, .{ .name = "__udivti3", .linkage = common.linkage });
1919 },
2020 else => {},
2121 }
2222 if (arch.isAARCH64()) {
23 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
23 @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
2424 }
2525 } else {
26 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
26 @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
2727 }
2828}
2929
3030pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {
31 @setRuntimeSafety(builtin.is_test);
3231 return udivmod(u128, a, b, null);
3332}
3433
3534const v128 = std.meta.Vector(2, u64);
36pub fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
37 @setRuntimeSafety(builtin.is_test);
35
36fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
3837 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), null));
3938}
lib/compiler_rt/umodti3.zig+12-13
......@@ -2,42 +2,41 @@ const std = @import("std");
22const builtin = @import("builtin");
33const udivmod = @import("udivmod.zig").udivmod;
44const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
5const common = @import("common.zig");
6
7pub const panic = common.panic;
88
99comptime {
1010 if (builtin.os.tag == .windows) {
1111 switch (arch) {
1212 .i386 => {
13 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
13 @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
1414 },
1515 .x86_64 => {
1616 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
1717 // that LLVM expects compiler-rt to have.
18 @export(__umodti3_windows_x86_64, .{ .name = "__umodti3", .linkage = linkage });
18 @export(__umodti3_windows_x86_64, .{ .name = "__umodti3", .linkage = common.linkage });
1919 },
2020 else => {},
2121 }
2222 if (arch.isAARCH64()) {
23 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
23 @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
2424 }
2525 } else {
26 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
26 @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
2727 }
2828}
2929
3030pub fn __umodti3(a: u128, b: u128) callconv(.C) u128 {
31 @setRuntimeSafety(builtin.is_test);
3231 var r: u128 = undefined;
3332 _ = udivmod(u128, a, b, &r);
3433 return r;
3534}
3635
3736const v128 = std.meta.Vector(2, u64);
38pub fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
39 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __umodti3, .{
40 @bitCast(u128, a),
41 @bitCast(u128, b),
42 }));
37
38fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
39 var r: u128 = undefined;
40 _ = udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), &r);
41 return @bitCast(v128, r);
4342}