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 @@...@@ -2,40 +2,41 @@
2const std = @import("std");2const std = @import("std");
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5const common = @import("common.zig");
6pub const panic = @import("common.zig").panic;6
7pub const panic = common.panic;
78
8comptime {9comptime {
9 if (!builtin.is_test) {10 if (!builtin.is_test) {
10 if (arch.isARM() or arch.isThumb()) {11 if (arch.isARM() or arch.isThumb()) {
11 @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });12 @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = common.linkage });
12 @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });13 @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = common.linkage });
13 @export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = 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_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = common.linkage });
16 @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = linkage });17 @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = common.linkage });
1718
18 @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = linkage });19 @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = common.linkage });
19 @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = linkage });20 @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = common.linkage });
2021
21 @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = linkage });22 @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = common.linkage });
22 @export(__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = linkage });23 @export(__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = common.linkage });
23 @export(__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = linkage });24 @export(__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = common.linkage });
2425
25 @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = linkage });26 @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = common.linkage });
26 @export(__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = linkage });27 @export(__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = common.linkage });
27 @export(__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = linkage });28 @export(__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = common.linkage });
2829
29 @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = linkage });30 @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = common.linkage });
30 @export(__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = linkage });31 @export(__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = common.linkage });
31 @export(__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = linkage });32 @export(__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = common.linkage });
3233
33 @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = linkage });34 @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = common.linkage });
34 @export(__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = linkage });35 @export(__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = common.linkage });
35 @export(__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = linkage });36 @export(__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = common.linkage });
3637
37 if (builtin.os.tag == .linux) {38 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 });
39 }40 }
40 }41 }
41 }42 }
lib/compiler_rt/aulldiv.zig+5-5
...@@ -2,19 +2,19 @@ const std = @import("std");...@@ -2,19 +2,19 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const abi = builtin.abi;4const abi = builtin.abi;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Strong;5const common = @import("common.zig");
6pub const panic = @import("common.zig").panic;6
7pub const panic = common.panic;
78
8comptime {9comptime {
9 if (arch == .i386 and abi == .msvc) {10 if (arch == .i386 and abi == .msvc) {
10 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins11 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
11 @export(_alldiv, .{ .name = "\x01__alldiv", .linkage = linkage });12 @export(_alldiv, .{ .name = "\x01__alldiv", .linkage = common.linkage });
12 @export(_aulldiv, .{ .name = "\x01__aulldiv", .linkage = linkage });13 @export(_aulldiv, .{ .name = "\x01__aulldiv", .linkage = common.linkage });
13 }14 }
14}15}
1516
16pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {17pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
17 @setRuntimeSafety(builtin.is_test);
18 const s_a = a >> (64 - 1);18 const s_a = a >> (64 - 1);
19 const s_b = b >> (64 - 1);19 const s_b = b >> (64 - 1);
2020
lib/compiler_rt/aullrem.zig+5-5
...@@ -2,19 +2,19 @@ const std = @import("std");...@@ -2,19 +2,19 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const abi = builtin.abi;4const abi = builtin.abi;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Strong;5const common = @import("common.zig");
6pub const panic = @import("common.zig").panic;6
7pub const panic = common.panic;
78
8comptime {9comptime {
9 if (arch == .i386 and abi == .msvc) {10 if (arch == .i386 and abi == .msvc) {
10 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins11 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
11 @export(_allrem, .{ .name = "\x01__allrem", .linkage = linkage });12 @export(_allrem, .{ .name = "\x01__allrem", .linkage = common.linkage });
12 @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = linkage });13 @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = common.linkage });
13 }14 }
14}15}
1516
16pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {17pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {
17 @setRuntimeSafety(builtin.is_test);
18 const s_a = a >> (64 - 1);18 const s_a = a >> (64 - 1);
19 const s_b = b >> (64 - 1);19 const s_b = b >> (64 - 1);
2020
lib/compiler_rt/bswap.zig+6-7
...@@ -1,13 +1,13 @@...@@ -1,13 +1,13 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;3const common = @import("common.zig");
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;4
5pub const panic = @import("common.zig").panic;5pub const panic = common.panic;
66
7comptime {7comptime {
8 @export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = linkage });8 @export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = common.linkage });
9 @export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = linkage });9 @export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = common.linkage });
10 @export(__bswapti2, .{ .name = "__bswapti2", .linkage = linkage });10 @export(__bswapti2, .{ .name = "__bswapti2", .linkage = common.linkage });
11}11}
1212
13// bswap - byteswap13// bswap - byteswap
...@@ -21,7 +21,6 @@ comptime {...@@ -21,7 +21,6 @@ comptime {
21// 00 00 00 ff << 3*8 (rightmost byte)21// 00 00 00 ff << 3*8 (rightmost byte)
2222
23inline fn bswapXi2(comptime T: type, a: T) T {23inline fn bswapXi2(comptime T: type, a: T) T {
24 @setRuntimeSafety(builtin.is_test);
25 switch (@bitSizeOf(T)) {24 switch (@bitSizeOf(T)) {
26 32 => {25 32 => {
27 // zig fmt: off26 // zig fmt: off
lib/compiler_rt/ceil.zig+15-23
...@@ -1,30 +1,26 @@...@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is MIT licensed.
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
9const arch = builtin.cpu.arch;9const arch = builtin.cpu.arch;
10const math = std.math;10const math = std.math;
11const expect = std.testing.expect;11const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;12const common = @import("common.zig");
13pub const panic = @import("common.zig").panic;13
14pub const panic = common.panic;
1415
15comptime {16comptime {
16 @export(__ceilh, .{ .name = "__ceilh", .linkage = linkage });17 @export(__ceilh, .{ .name = "__ceilh", .linkage = common.linkage });
17 @export(ceilf, .{ .name = "ceilf", .linkage = linkage });18 @export(ceilf, .{ .name = "ceilf", .linkage = common.linkage });
18 @export(ceil, .{ .name = "ceil", .linkage = linkage });19 @export(ceil, .{ .name = "ceil", .linkage = common.linkage });
19 @export(__ceilx, .{ .name = "__ceilx", .linkage = linkage });20 @export(__ceilx, .{ .name = "__ceilx", .linkage = common.linkage });
20 @export(ceilq, .{ .name = "ceilq", .linkage = linkage });21 const ceilq_sym_name = if (common.want_ppc_abi) "ceilf128" else "ceilq";
21 @export(ceill, .{ .name = "ceill", .linkage = linkage });22 @export(ceilq, .{ .name = ceilq_sym_name, .linkage = common.linkage });
2223 @export(ceill, .{ .name = "ceill", .linkage = common.linkage });
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(ceilf128, .{ .name = "ceilf128", .linkage = linkage });
26 }
27 }
28}24}
2925
30pub fn __ceilh(x: f16) callconv(.C) f16 {26pub fn __ceilh(x: f16) callconv(.C) f16 {
...@@ -130,10 +126,6 @@ pub fn ceilq(x: f128) callconv(.C) f128 {...@@ -130,10 +126,6 @@ pub fn ceilq(x: f128) callconv(.C) f128 {
130 }126 }
131}127}
132128
133pub fn ceilf128(x: f128) callconv(.C) f128 {
134 return @call(.{ .modifier = .always_inline }, ceilq, .{x});
135}
136
137pub fn ceill(x: c_longdouble) callconv(.C) c_longdouble {129pub fn ceill(x: c_longdouble) callconv(.C) c_longdouble {
138 switch (@typeInfo(c_longdouble).Float.bits) {130 switch (@typeInfo(c_longdouble).Float.bits) {
139 16 => return __ceilh(x),131 16 => return __ceilh(x),
lib/compiler_rt/cmp.zig+9-9
...@@ -1,16 +1,17 @@...@@ -1,16 +1,17 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;4const common = @import("common.zig");
5pub const panic = @import("common.zig").panic;5
6pub const panic = common.panic;
67
7comptime {8comptime {
8 @export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = linkage });9 @export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = common.linkage });
9 @export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = linkage });10 @export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = common.linkage });
10 @export(__cmpti2, .{ .name = "__cmpti2", .linkage = linkage });11 @export(__cmpti2, .{ .name = "__cmpti2", .linkage = common.linkage });
11 @export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = linkage });12 @export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = common.linkage });
12 @export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = linkage });13 @export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = common.linkage });
13 @export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = linkage });14 @export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = common.linkage });
14}15}
1516
16// cmp - signed compare17// cmp - signed compare
...@@ -24,7 +25,6 @@ comptime {...@@ -24,7 +25,6 @@ comptime {
24// a > b => 225// a > b => 2
2526
26inline fn XcmpXi2(comptime T: type, a: T, b: T) i32 {27inline fn XcmpXi2(comptime T: type, a: T, b: T) i32 {
27 @setRuntimeSafety(builtin.is_test);
28 var cmp1: i32 = 0;28 var cmp1: i32 = 0;
29 var cmp2: i32 = 0;29 var cmp2: i32 = 0;
30 if (a > b)30 if (a > b)
lib/compiler_rt/cos.zig+10-18
...@@ -3,26 +3,22 @@ const builtin = @import("builtin");...@@ -3,26 +3,22 @@ const builtin = @import("builtin");
3const arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const math = std.math;4const math = std.math;
5const expect = std.testing.expect;5const expect = std.testing.expect;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;6const common = @import("common.zig");
7pub const panic = @import("common.zig").panic;7
8pub const panic = common.panic;
89
9const trig = @import("trig.zig");10const trig = @import("trig.zig");
10const rem_pio2 = @import("rem_pio2.zig").rem_pio2;11const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
11const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;12const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
1213
13comptime {14comptime {
14 @export(__cosh, .{ .name = "__cosh", .linkage = linkage });15 @export(__cosh, .{ .name = "__cosh", .linkage = common.linkage });
15 @export(cosf, .{ .name = "cosf", .linkage = linkage });16 @export(cosf, .{ .name = "cosf", .linkage = common.linkage });
16 @export(cos, .{ .name = "cos", .linkage = linkage });17 @export(cos, .{ .name = "cos", .linkage = common.linkage });
17 @export(__cosx, .{ .name = "__cosx", .linkage = linkage });18 @export(__cosx, .{ .name = "__cosx", .linkage = common.linkage });
18 @export(cosq, .{ .name = "cosq", .linkage = linkage });19 const cosq_sym_name = if (common.want_ppc_abi) "cosf128" else "cosq";
19 @export(cosl, .{ .name = "cosl", .linkage = linkage });20 @export(cosq, .{ .name = cosq_sym_name, .linkage = common.linkage });
2021 @export(cosl, .{ .name = "cosl", .linkage = common.linkage });
21 if (!builtin.is_test) {
22 if (arch.isPPC() or arch.isPPC64()) {
23 @export(cosf128, .{ .name = "cosf128", .linkage = linkage });
24 }
25 }
26}22}
2723
28pub fn __cosh(a: f16) callconv(.C) f16 {24pub fn __cosh(a: f16) callconv(.C) f16 {
...@@ -126,10 +122,6 @@ pub fn cosq(a: f128) callconv(.C) f128 {...@@ -126,10 +122,6 @@ pub fn cosq(a: f128) callconv(.C) f128 {
126 return cos(@floatCast(f64, a));122 return cos(@floatCast(f64, a));
127}123}
128124
129pub fn cosf128(a: f128) callconv(.C) f128 {
130 return @call(.{ .modifier = .always_inline }, cosq, .{a});
131}
132
133pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {125pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {
134 switch (@typeInfo(c_longdouble).Float.bits) {126 switch (@typeInfo(c_longdouble).Float.bits) {
135 16 => return __cosh(x),127 16 => return __cosh(x),
lib/compiler_rt/count0bits.zig+12-17
...@@ -1,19 +1,20 @@...@@ -1,19 +1,20 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;4const common = @import("common.zig");
5pub const panic = @import("common.zig").panic;5
6pub const panic = common.panic;
67
7comptime {8comptime {
8 @export(__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });9 @export(__clzsi2, .{ .name = "__clzsi2", .linkage = common.linkage });
9 @export(__clzdi2, .{ .name = "__clzdi2", .linkage = linkage });10 @export(__clzdi2, .{ .name = "__clzdi2", .linkage = common.linkage });
10 @export(__clzti2, .{ .name = "__clzti2", .linkage = linkage });11 @export(__clzti2, .{ .name = "__clzti2", .linkage = common.linkage });
11 @export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = linkage });12 @export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = common.linkage });
12 @export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = linkage });13 @export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = common.linkage });
13 @export(__ctzti2, .{ .name = "__ctzti2", .linkage = linkage });14 @export(__ctzti2, .{ .name = "__ctzti2", .linkage = common.linkage });
14 @export(__ffssi2, .{ .name = "__ffssi2", .linkage = linkage });15 @export(__ffssi2, .{ .name = "__ffssi2", .linkage = common.linkage });
15 @export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = linkage });16 @export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = common.linkage });
16 @export(__ffsti2, .{ .name = "__ffsti2", .linkage = linkage });17 @export(__ffsti2, .{ .name = "__ffsti2", .linkage = common.linkage });
17}18}
1819
19// clz - count leading zeroes20// clz - count leading zeroes
...@@ -30,8 +31,6 @@ comptime {...@@ -30,8 +31,6 @@ comptime {
30// - ffsXi2 for unoptimized little and big endian31// - ffsXi2 for unoptimized little and big endian
3132
32inline fn clzXi2(comptime T: type, a: T) i32 {33inline fn clzXi2(comptime T: type, a: T) i32 {
33 @setRuntimeSafety(builtin.is_test);
34
35 var x = switch (@bitSizeOf(T)) {34 var x = switch (@bitSizeOf(T)) {
36 32 => @bitCast(u32, a),35 32 => @bitCast(u32, a),
37 64 => @bitCast(u64, a),36 64 => @bitCast(u64, a),
...@@ -169,8 +168,6 @@ pub fn __clzti2(a: i128) callconv(.C) i32 {...@@ -169,8 +168,6 @@ pub fn __clzti2(a: i128) callconv(.C) i32 {
169}168}
170169
171inline fn ctzXi2(comptime T: type, a: T) i32 {170inline fn ctzXi2(comptime T: type, a: T) i32 {
172 @setRuntimeSafety(builtin.is_test);
173
174 var x = switch (@bitSizeOf(T)) {171 var x = switch (@bitSizeOf(T)) {
175 32 => @bitCast(u32, a),172 32 => @bitCast(u32, a),
176 64 => @bitCast(u64, a),173 64 => @bitCast(u64, a),
...@@ -206,8 +203,6 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 {...@@ -206,8 +203,6 @@ pub fn __ctzti2(a: i128) callconv(.C) i32 {
206}203}
207204
208inline fn ffsXi2(comptime T: type, a: T) i32 {205inline fn ffsXi2(comptime T: type, a: T) i32 {
209 @setRuntimeSafety(builtin.is_test);
210
211 var x = switch (@bitSizeOf(T)) {206 var x = switch (@bitSizeOf(T)) {
212 32 => @bitCast(u32, a),207 32 => @bitCast(u32, a),
213 64 => @bitCast(u64, a),208 64 => @bitCast(u64, a),
lib/compiler_rt/divdf3.zig+17-17
...@@ -1,30 +1,35 @@...@@ -1,30 +1,35 @@
1// Ported from:1//! Ported from:
2//2//!
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divdf3.c3//! https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divdf3.c
44
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const arch = builtin.cpu.arch;7const arch = builtin.cpu.arch;
8const is_test = builtin.is_test;8const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10
11const common = @import("common.zig");9const common = @import("common.zig");
10
12const normalize = common.normalize;11const normalize = common.normalize;
13const wideMultiply = common.wideMultiply;12const wideMultiply = common.wideMultiply;
13
14pub const panic = common.panic;14pub const panic = common.panic;
1515
16comptime {16comptime {
17 @export(__divdf3, .{ .name = "__divdf3", .linkage = linkage });17 if (common.want_aeabi) {
1818 @export(__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = common.linkage });
19 if (!is_test) {19 } else {
20 if (arch.isARM() or arch.isThumb()) {20 @export(__divdf3, .{ .name = "__divdf3", .linkage = common.linkage });
21 @export(__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage });
22 }
23 }21 }
24}22}
2523
26pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {24pub 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 {
28 const Z = std.meta.Int(.unsigned, 64);33 const Z = std.meta.Int(.unsigned, 64);
29 const SignedZ = std.meta.Int(.signed, 64);34 const SignedZ = std.meta.Int(.signed, 64);
3035
...@@ -220,11 +225,6 @@ pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {...@@ -220,11 +225,6 @@ pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
220 }225 }
221}226}
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
228test {228test {
229 _ = @import("divdf3_test.zig");229 _ = @import("divdf3_test.zig");
230}230}
lib/compiler_rt/divsf3.zig+16-17
...@@ -1,29 +1,33 @@...@@ -1,29 +1,33 @@
1// Ported from:1//! Ported from:
2//2//!
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divsf3.c3//! https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divsf3.c
44
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const arch = builtin.cpu.arch;7const arch = builtin.cpu.arch;
8const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
108
11const common = @import("common.zig");9const common = @import("common.zig");
12const normalize = common.normalize;10const normalize = common.normalize;
11
13pub const panic = common.panic;12pub const panic = common.panic;
1413
15comptime {14comptime {
16 @export(__divsf3, .{ .name = "__divsf3", .linkage = linkage });15 if (common.want_aeabi) {
1716 @export(__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = common.linkage });
18 if (!is_test) {17 } else {
19 if (arch.isARM() or arch.isThumb()) {18 @export(__divsf3, .{ .name = "__divsf3", .linkage = common.linkage });
20 @export(__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage });
21 }
22 }19 }
23}20}
2421
25pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {22pub 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 {
27 const Z = std.meta.Int(.unsigned, 32);31 const Z = std.meta.Int(.unsigned, 32);
2832
29 const significandBits = std.math.floatMantissaBits(f32);33 const significandBits = std.math.floatMantissaBits(f32);
...@@ -201,11 +205,6 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {...@@ -201,11 +205,6 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
201 }205 }
202}206}
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
209test {208test {
210 _ = @import("divsf3_test.zig");209 _ = @import("divsf3_test.zig");
211}210}
lib/compiler_rt/divti3.zig+16-16
...@@ -2,34 +2,42 @@ const std = @import("std");...@@ -2,34 +2,42 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const udivmod = @import("udivmod.zig").udivmod;3const udivmod = @import("udivmod.zig").udivmod;
4const arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;5const common = @import("common.zig");
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;6
7pub const panic = @import("common.zig").panic;7pub const panic = common.panic;
88
9comptime {9comptime {
10 if (builtin.os.tag == .windows) {10 if (builtin.os.tag == .windows) {
11 switch (arch) {11 switch (arch) {
12 .i386 => {12 .i386 => {
13 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });13 @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
14 },14 },
15 .x86_64 => {15 .x86_64 => {
16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
17 // that LLVM expects compiler-rt to have.17 // 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 });
19 },19 },
20 else => {},20 else => {},
21 }21 }
22 if (arch.isAARCH64()) {22 if (arch.isAARCH64()) {
23 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });23 @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
24 }24 }
25 } else {25 } else {
26 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });26 @export(__divti3, .{ .name = "__divti3", .linkage = common.linkage });
27 }27 }
28}28}
2929
30pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {30pub 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 {
33 const s_a = a >> (128 - 1);41 const s_a = a >> (128 - 1);
34 const s_b = b >> (128 - 1);42 const s_b = b >> (128 - 1);
3543
...@@ -41,14 +49,6 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {...@@ -41,14 +49,6 @@ pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
41 return (@bitCast(i128, r) ^ s) -% s;49 return (@bitCast(i128, r) ^ s) -% s;
42}50}
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
52test {52test {
53 _ = @import("divti3_test.zig");53 _ = @import("divti3_test.zig");
54}54}
lib/compiler_rt/divxf3.zig+2-4
...@@ -1,20 +1,18 @@...@@ -1,20 +1,18 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
64
7const common = @import("common.zig");5const common = @import("common.zig");
8const normalize = common.normalize;6const normalize = common.normalize;
9const wideMultiply = common.wideMultiply;7const wideMultiply = common.wideMultiply;
8
10pub const panic = common.panic;9pub const panic = common.panic;
1110
12comptime {11comptime {
13 @export(__divxf3, .{ .name = "__divxf3", .linkage = linkage });12 @export(__divxf3, .{ .name = "__divxf3", .linkage = common.linkage });
14}13}
1514
16pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {15pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
17 @setRuntimeSafety(builtin.is_test);
18 const T = f80;16 const T = f80;
19 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));17 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
2018
lib/compiler_rt/emutls.zig+10-10
...@@ -1,25 +1,25 @@...@@ -1,25 +1,25 @@
1// __emutls_get_address specific builtin1//! __emutls_get_address specific builtin
2//2//!
3// derived work from LLVM Compiler Infrastructure - release 8.0 (MIT)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.c4//! https://github.com/llvm-mirror/compiler-rt/blob/release_80/lib/builtins/emutls.c
5//
65
7const std = @import("std");6const std = @import("std");
8const builtin = @import("builtin");7const builtin = @import("builtin");
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;8const common = @import("common.zig");
10pub const panic = @import("common.zig").panic;
119
12const abort = std.os.abort;10const abort = std.os.abort;
13const assert = std.debug.assert;11const assert = std.debug.assert;
14const expect = std.testing.expect;12const expect = std.testing.expect;
1513
16// defined in C as:14/// defined in C as:
17// typedef unsigned int gcc_word __attribute__((mode(word)));15/// typedef unsigned int gcc_word __attribute__((mode(word)));
18const gcc_word = usize;16const gcc_word = usize;
1917
18pub const panic = common.panic;
19
20comptime {20comptime {
21 if (builtin.link_libc and builtin.os.tag == .openbsd) {21 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 });
23 }23 }
24}24}
2525
lib/compiler_rt/exp.zig+10-18
...@@ -9,22 +9,18 @@ const builtin = @import("builtin");...@@ -9,22 +9,18 @@ const builtin = @import("builtin");
9const arch = builtin.cpu.arch;9const arch = builtin.cpu.arch;
10const math = std.math;10const math = std.math;
11const expect = std.testing.expect;11const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;12const common = @import("common.zig");
13pub const panic = @import("common.zig").panic;13
14pub const panic = common.panic;
1415
15comptime {16comptime {
16 @export(__exph, .{ .name = "__exph", .linkage = linkage });17 @export(__exph, .{ .name = "__exph", .linkage = common.linkage });
17 @export(expf, .{ .name = "expf", .linkage = linkage });18 @export(expf, .{ .name = "expf", .linkage = common.linkage });
18 @export(exp, .{ .name = "exp", .linkage = linkage });19 @export(exp, .{ .name = "exp", .linkage = common.linkage });
19 @export(__expx, .{ .name = "__expx", .linkage = linkage });20 @export(__expx, .{ .name = "__expx", .linkage = common.linkage });
20 @export(expq, .{ .name = "expq", .linkage = linkage });21 const expq_sym_name = if (common.want_ppc_abi) "expf128" else "expq";
21 @export(expl, .{ .name = "expl", .linkage = linkage });22 @export(expq, .{ .name = expq_sym_name, .linkage = common.linkage });
2223 @export(expl, .{ .name = "expl", .linkage = common.linkage });
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(expf128, .{ .name = "expf128", .linkage = linkage });
26 }
27 }
28}24}
2925
30pub fn __exph(a: f16) callconv(.C) f16 {26pub fn __exph(a: f16) callconv(.C) f16 {
...@@ -201,10 +197,6 @@ pub fn expq(a: f128) callconv(.C) f128 {...@@ -201,10 +197,6 @@ pub fn expq(a: f128) callconv(.C) f128 {
201 return exp(@floatCast(f64, a));197 return exp(@floatCast(f64, a));
202}198}
203199
204pub fn expf128(a: f128) callconv(.C) f128 {
205 return @call(.{ .modifier = .always_inline }, expq, .{a});
206}
207
208pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {200pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {
209 switch (@typeInfo(c_longdouble).Float.bits) {201 switch (@typeInfo(c_longdouble).Float.bits) {
210 16 => return __exph(x),202 16 => return __exph(x),
lib/compiler_rt/exp2.zig+10-18
...@@ -9,22 +9,18 @@ const builtin = @import("builtin");...@@ -9,22 +9,18 @@ const builtin = @import("builtin");
9const arch = builtin.cpu.arch;9const arch = builtin.cpu.arch;
10const math = std.math;10const math = std.math;
11const expect = std.testing.expect;11const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;12const common = @import("common.zig");
13pub const panic = @import("common.zig").panic;
1413
15comptime {14pub const panic = common.panic;
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 });
2215
23 if (!builtin.is_test) {16comptime {
24 if (arch.isPPC() or arch.isPPC64()) {17 @export(__exp2h, .{ .name = "__exp2h", .linkage = common.linkage });
25 @export(exp2f128, .{ .name = "exp2f128", .linkage = linkage });18 @export(exp2f, .{ .name = "exp2f", .linkage = common.linkage });
26 }19 @export(exp2, .{ .name = "exp2", .linkage = common.linkage });
27 }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 });
28}24}
2925
30pub fn __exp2h(x: f16) callconv(.C) f16 {26pub fn __exp2h(x: f16) callconv(.C) f16 {
...@@ -168,10 +164,6 @@ pub fn exp2q(x: f128) callconv(.C) f128 {...@@ -168,10 +164,6 @@ pub fn exp2q(x: f128) callconv(.C) f128 {
168 return exp2(@floatCast(f64, x));164 return exp2(@floatCast(f64, x));
169}165}
170166
171pub fn exp2f128(x: f128) callconv(.C) f128 {
172 return @call(.{ .modifier = .always_inline }, exp2q, .{x});
173}
174
175pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {167pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {
176 switch (@typeInfo(c_longdouble).Float.bits) {168 switch (@typeInfo(c_longdouble).Float.bits) {
177 16 => return __exp2h(x),169 16 => return __exp2h(x),
lib/compiler_rt/fabs.zig+10-18
...@@ -1,22 +1,18 @@...@@ -1,22 +1,18 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;4const common = @import("common.zig");
5pub const panic = @import("common.zig").panic;5
6pub const panic = common.panic;
67
7comptime {8comptime {
8 @export(__fabsh, .{ .name = "__fabsh", .linkage = linkage });9 @export(__fabsh, .{ .name = "__fabsh", .linkage = common.linkage });
9 @export(fabsf, .{ .name = "fabsf", .linkage = linkage });10 @export(fabsf, .{ .name = "fabsf", .linkage = common.linkage });
10 @export(fabs, .{ .name = "fabs", .linkage = linkage });11 @export(fabs, .{ .name = "fabs", .linkage = common.linkage });
11 @export(__fabsx, .{ .name = "__fabsx", .linkage = linkage });12 @export(__fabsx, .{ .name = "__fabsx", .linkage = common.linkage });
12 @export(fabsq, .{ .name = "fabsq", .linkage = linkage });13 const fabsq_sym_name = if (common.want_ppc_abi) "fabsf128" else "fabsq";
13 @export(fabsl, .{ .name = "fabsl", .linkage = linkage });14 @export(fabsq, .{ .name = fabsq_sym_name, .linkage = common.linkage });
1415 @export(fabsl, .{ .name = "fabsl", .linkage = common.linkage });
15 if (!builtin.is_test) {
16 if (arch.isPPC() or arch.isPPC64()) {
17 @export(fabsf128, .{ .name = "fabsf128", .linkage = linkage });
18 }
19 }
20}16}
2117
22pub fn __fabsh(a: f16) callconv(.C) f16 {18pub fn __fabsh(a: f16) callconv(.C) f16 {
...@@ -39,10 +35,6 @@ pub fn fabsq(a: f128) callconv(.C) f128 {...@@ -39,10 +35,6 @@ pub fn fabsq(a: f128) callconv(.C) f128 {
39 return generic_fabs(a);35 return generic_fabs(a);
40}36}
4137
42pub fn fabsf128(a: f128) callconv(.C) f128 {
43 return @call(.{ .modifier = .always_inline }, fabsq, .{a});
44}
45
46pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {38pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {
47 switch (@typeInfo(c_longdouble).Float.bits) {39 switch (@typeInfo(c_longdouble).Float.bits) {
48 16 => return __fabsh(x),40 16 => return __fabsh(x),
lib/compiler_rt/floor.zig+15-23
...@@ -1,30 +1,26 @@...@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/floorf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
9const math = std.math;9const math = std.math;
10const expect = std.testing.expect;10const expect = std.testing.expect;
11const arch = builtin.cpu.arch;11const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;12const common = @import("common.zig");
13pub const panic = @import("common.zig").panic;13
14pub const panic = common.panic;
1415
15comptime {16comptime {
16 @export(__floorh, .{ .name = "__floorh", .linkage = linkage });17 @export(__floorh, .{ .name = "__floorh", .linkage = common.linkage });
17 @export(floorf, .{ .name = "floorf", .linkage = linkage });18 @export(floorf, .{ .name = "floorf", .linkage = common.linkage });
18 @export(floor, .{ .name = "floor", .linkage = linkage });19 @export(floor, .{ .name = "floor", .linkage = common.linkage });
19 @export(__floorx, .{ .name = "__floorx", .linkage = linkage });20 @export(__floorx, .{ .name = "__floorx", .linkage = common.linkage });
20 @export(floorq, .{ .name = "floorq", .linkage = linkage });21 const floorq_sym_name = if (common.want_ppc_abi) "floorf128" else "floorq";
21 @export(floorl, .{ .name = "floorl", .linkage = linkage });22 @export(floorq, .{ .name = floorq_sym_name, .linkage = common.linkage });
2223 @export(floorl, .{ .name = "floorl", .linkage = common.linkage });
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(floorf128, .{ .name = "floorf128", .linkage = linkage });
26 }
27 }
28}24}
2925
30pub fn __floorh(x: f16) callconv(.C) f16 {26pub fn __floorh(x: f16) callconv(.C) f16 {
...@@ -160,10 +156,6 @@ pub fn floorq(x: f128) callconv(.C) f128 {...@@ -160,10 +156,6 @@ pub fn floorq(x: f128) callconv(.C) f128 {
160 }156 }
161}157}
162158
163pub fn floorf128(x: f128) callconv(.C) f128 {
164 return @call(.{ .modifier = .always_inline }, floorq, .{x});
165}
166
167pub fn floorl(x: c_longdouble) callconv(.C) c_longdouble {159pub fn floorl(x: c_longdouble) callconv(.C) c_longdouble {
168 switch (@typeInfo(c_longdouble).Float.bits) {160 switch (@typeInfo(c_longdouble).Float.bits) {
169 16 => return __floorh(x),161 16 => return __floorh(x),
lib/compiler_rt/fma.zig+16-24
...@@ -1,31 +1,27 @@...@@ -1,31 +1,27 @@
1// Ported from musl, which is MIT licensed:1//! Ported from musl, which is MIT licensed:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/fmal.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/fmal.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/fmaf.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/fmaf.c
6// https://git.musl-libc.org/cgit/musl/tree/src/math/fma.c6//! https://git.musl-libc.org/cgit/musl/tree/src/math/fma.c
77
8const std = @import("std");8const std = @import("std");
9const builtin = @import("builtin");9const builtin = @import("builtin");
10const math = std.math;10const math = std.math;
11const expect = std.testing.expect;11const expect = std.testing.expect;
12const arch = builtin.cpu.arch;12const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;13const common = @import("common.zig");
14pub const panic = @import("common.zig").panic;14
15pub const panic = common.panic;
1516
16comptime {17comptime {
17 @export(__fmah, .{ .name = "__fmah", .linkage = linkage });18 @export(__fmah, .{ .name = "__fmah", .linkage = common.linkage });
18 @export(fmaf, .{ .name = "fmaf", .linkage = linkage });19 @export(fmaf, .{ .name = "fmaf", .linkage = common.linkage });
19 @export(fma, .{ .name = "fma", .linkage = linkage });20 @export(fma, .{ .name = "fma", .linkage = common.linkage });
20 @export(__fmax, .{ .name = "__fmax", .linkage = linkage });21 @export(__fmax, .{ .name = "__fmax", .linkage = common.linkage });
21 @export(fmaq, .{ .name = "fmaq", .linkage = linkage });22 const fmaq_sym_name = if (common.want_ppc_abi) "fmaf128" else "fmaq";
22 @export(fmal, .{ .name = "fmal", .linkage = linkage });23 @export(fmaq, .{ .name = fmaq_sym_name, .linkage = common.linkage });
2324 @export(fmal, .{ .name = "fmal", .linkage = common.linkage });
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(fmaf128, .{ .name = "fmaf128", .linkage = linkage });
27 }
28 }
29}25}
3026
31pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 {27pub 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 {...@@ -154,10 +150,6 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 {
154 }150 }
155}151}
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
161pub fn fmal(x: c_longdouble, y: c_longdouble, z: c_longdouble) callconv(.C) c_longdouble {153pub fn fmal(x: c_longdouble, y: c_longdouble, z: c_longdouble) callconv(.C) c_longdouble {
162 switch (@typeInfo(c_longdouble).Float.bits) {154 switch (@typeInfo(c_longdouble).Float.bits) {
163 16 => return __fmah(x, y, z),155 16 => return __fmah(x, y, z),
lib/compiler_rt/fmax.zig+10-18
...@@ -2,22 +2,18 @@ const std = @import("std");...@@ -2,22 +2,18 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const math = std.math;3const math = std.math;
4const arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5const common = @import("common.zig");
6pub const panic = @import("common.zig").panic;
76
8comptime {7pub const panic = common.panic;
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 });
158
16 if (!builtin.is_test) {9comptime {
17 if (arch.isPPC() or arch.isPPC64()) {10 @export(__fmaxh, .{ .name = "__fmaxh", .linkage = common.linkage });
18 @export(fmaxf128, .{ .name = "fmaxf128", .linkage = linkage });11 @export(fmaxf, .{ .name = "fmaxf", .linkage = common.linkage });
19 }12 @export(fmax, .{ .name = "fmax", .linkage = common.linkage });
20 }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 });
21}17}
2218
23pub fn __fmaxh(x: f16, y: f16) callconv(.C) f16 {19pub fn __fmaxh(x: f16, y: f16) callconv(.C) f16 {
...@@ -40,10 +36,6 @@ pub fn fmaxq(x: f128, y: f128) callconv(.C) f128 {...@@ -40,10 +36,6 @@ pub fn fmaxq(x: f128, y: f128) callconv(.C) f128 {
40 return generic_fmax(f128, x, y);36 return generic_fmax(f128, x, y);
41}37}
4238
43pub fn fmaxf128(x: f128, y: f128) callconv(.C) f128 {
44 return @call(.{ .modifier = .always_inline }, fmaxq, .{ x, y });
45}
46
47pub fn fmaxl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {39pub fn fmaxl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {
48 switch (@typeInfo(c_longdouble).Float.bits) {40 switch (@typeInfo(c_longdouble).Float.bits) {
49 16 => return __fmaxh(x, y),41 16 => return __fmaxh(x, y),
lib/compiler_rt/fmin.zig+10-18
...@@ -2,22 +2,18 @@ const std = @import("std");...@@ -2,22 +2,18 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const math = std.math;3const math = std.math;
4const arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5const common = @import("common.zig");
6pub const panic = @import("common.zig").panic;
76
8comptime {7pub const panic = common.panic;
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 });
158
16 if (!builtin.is_test) {9comptime {
17 if (arch.isPPC() or arch.isPPC64()) {10 @export(__fminh, .{ .name = "__fminh", .linkage = common.linkage });
18 @export(fminf128, .{ .name = "fminf128", .linkage = linkage });11 @export(fminf, .{ .name = "fminf", .linkage = common.linkage });
19 }12 @export(fmin, .{ .name = "fmin", .linkage = common.linkage });
20 }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 });
21}17}
2218
23pub fn __fminh(x: f16, y: f16) callconv(.C) f16 {19pub fn __fminh(x: f16, y: f16) callconv(.C) f16 {
...@@ -40,10 +36,6 @@ pub fn fminq(x: f128, y: f128) callconv(.C) f128 {...@@ -40,10 +36,6 @@ pub fn fminq(x: f128, y: f128) callconv(.C) f128 {
40 return generic_fmin(f128, x, y);36 return generic_fmin(f128, x, y);
41}37}
4238
43pub fn fminf128(x: f128, y: f128) callconv(.C) f128 {
44 return @call(.{ .modifier = .always_inline }, fminq, .{ x, y });
45}
46
47pub fn fminl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {39pub fn fminl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {
48 switch (@typeInfo(c_longdouble).Float.bits) {40 switch (@typeInfo(c_longdouble).Float.bits) {
49 16 => return __fminh(x, y),41 16 => return __fminh(x, y),
lib/compiler_rt/fmod.zig+8-23
...@@ -3,25 +3,19 @@ const std = @import("std");...@@ -3,25 +3,19 @@ const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const arch = builtin.cpu.arch;5const arch = builtin.cpu.arch;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7
8const common = @import("common.zig");6const common = @import("common.zig");
9const normalize = common.normalize;7const normalize = common.normalize;
8
10pub const panic = common.panic;9pub const panic = common.panic;
1110
12comptime {11comptime {
13 @export(__fmodh, .{ .name = "__fmodh", .linkage = linkage });12 @export(__fmodh, .{ .name = "__fmodh", .linkage = common.linkage });
14 @export(fmodf, .{ .name = "fmodf", .linkage = linkage });13 @export(fmodf, .{ .name = "fmodf", .linkage = common.linkage });
15 @export(fmod, .{ .name = "fmod", .linkage = linkage });14 @export(fmod, .{ .name = "fmod", .linkage = common.linkage });
16 @export(__fmodx, .{ .name = "__fmodx", .linkage = linkage });15 @export(__fmodx, .{ .name = "__fmodx", .linkage = common.linkage });
17 @export(fmodq, .{ .name = "fmodq", .linkage = linkage });16 const fmodq_sym_name = if (common.want_ppc_abi) "fmodf128" else "fmodq";
18 @export(fmodl, .{ .name = "fmodl", .linkage = linkage });17 @export(fmodq, .{ .name = fmodq_sym_name, .linkage = common.linkage });
1918 @export(fmodl, .{ .name = "fmodl", .linkage = common.linkage });
20 if (!builtin.is_test) {
21 if (arch.isPPC() or arch.isPPC64()) {
22 @export(fmodf128, .{ .name = "fmodf128", .linkage = linkage });
23 }
24 }
25}19}
2620
27pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {21pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
...@@ -40,8 +34,6 @@ pub fn fmod(x: f64, y: f64) callconv(.C) f64 {...@@ -40,8 +34,6 @@ pub fn fmod(x: f64, y: f64) callconv(.C) f64 {
40/// fmodx - floating modulo large, returns the remainder of division for f80 types34/// fmodx - floating modulo large, returns the remainder of division for f80 types
41/// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits35/// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits
42pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {36pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
43 @setRuntimeSafety(builtin.is_test);
44
45 const T = f80;37 const T = f80;
46 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));38 const Z = std.meta.Int(.unsigned, @bitSizeOf(T));
4739
...@@ -140,7 +132,6 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {...@@ -140,7 +132,6 @@ pub fn __fmodx(a: f80, b: f80) callconv(.C) f80 {
140/// fmodq - floating modulo large, returns the remainder of division for f128 types132/// fmodq - floating modulo large, returns the remainder of division for f128 types
141/// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits133/// Logic and flow heavily inspired by MUSL fmodl for 113 mantissa digits
142pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {134pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
143 @setRuntimeSafety(builtin.is_test);
144 var amod = a;135 var amod = a;
145 var bmod = b;136 var bmod = b;
146 const aPtr_u64 = @ptrCast([*]u64, &amod);137 const aPtr_u64 = @ptrCast([*]u64, &amod);
...@@ -257,10 +248,6 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {...@@ -257,10 +248,6 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
257 return amod;248 return amod;
258}249}
259250
260pub fn fmodf128(a: f128, b: f128) callconv(.C) f128 {
261 return @call(.{ .modifier = .always_inline }, fmodq, .{ a, b });
262}
263
264pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {251pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {
265 switch (@typeInfo(c_longdouble).Float.bits) {252 switch (@typeInfo(c_longdouble).Float.bits) {
266 16 => return __fmodh(a, b),253 16 => return __fmodh(a, b),
...@@ -273,8 +260,6 @@ pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {...@@ -273,8 +260,6 @@ pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {
273}260}
274261
275inline fn generic_fmod(comptime T: type, x: T, y: T) T {262inline fn generic_fmod(comptime T: type, x: T, y: T) T {
276 @setRuntimeSafety(false);
277
278 const bits = @typeInfo(T).Float.bits;263 const bits = @typeInfo(T).Float.bits;
279 const uint = std.meta.Int(.unsigned, bits);264 const uint = std.meta.Int(.unsigned, bits);
280 const log2uint = math.Log2Int(uint);265 const log2uint = math.Log2Int(uint);
lib/compiler_rt/int.zig+36-53
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1// Builtin functions that operate on integer types1//! Builtin functions that operate on integer types
2
2const builtin = @import("builtin");3const builtin = @import("builtin");
3const std = @import("std");4const std = @import("std");
4const testing = std.testing;5const testing = std.testing;
...@@ -6,44 +7,39 @@ const maxInt = std.math.maxInt;...@@ -6,44 +7,39 @@ const maxInt = std.math.maxInt;
6const minInt = std.math.minInt;7const minInt = std.math.minInt;
7const arch = builtin.cpu.arch;8const arch = builtin.cpu.arch;
8const is_test = builtin.is_test;9const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;10const common = @import("common.zig");
10pub const panic = @import("common.zig").panic;
11
12const udivmod = @import("udivmod.zig").udivmod;11const udivmod = @import("udivmod.zig").udivmod;
1312
13pub const panic = common.panic;
14
14comptime {15comptime {
15 @export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });16 @export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = common.linkage });
16 @export(__mulsi3, .{ .name = "__mulsi3", .linkage = linkage });17 @export(__mulsi3, .{ .name = "__mulsi3", .linkage = common.linkage });
17 @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });18 @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = common.linkage });
18 @export(__divsi3, .{ .name = "__divsi3", .linkage = linkage });19 if (common.want_aeabi) {
19 @export(__divdi3, .{ .name = "__divdi3", .linkage = linkage });20 @export(__aeabi_idiv, .{ .name = "__aeabi_idiv", .linkage = common.linkage });
20 @export(__udivsi3, .{ .name = "__udivsi3", .linkage = linkage });21 @export(__aeabi_uidiv, .{ .name = "__aeabi_uidiv", .linkage = common.linkage });
21 @export(__udivdi3, .{ .name = "__udivdi3", .linkage = linkage });22 } else {
22 @export(__modsi3, .{ .name = "__modsi3", .linkage = linkage });23 @export(__divsi3, .{ .name = "__divsi3", .linkage = common.linkage });
23 @export(__moddi3, .{ .name = "__moddi3", .linkage = linkage });24 @export(__udivsi3, .{ .name = "__udivsi3", .linkage = common.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 }
34 }25 }
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 });
35}34}
3635
37pub fn __divmoddi4(a: i64, b: i64, rem: *i64) callconv(.C) i64 {36pub fn __divmoddi4(a: i64, b: i64, rem: *i64) callconv(.C) i64 {
38 @setRuntimeSafety(builtin.is_test);
39
40 const d = __divdi3(a, b);37 const d = __divdi3(a, b);
41 rem.* = a -% (d *% b);38 rem.* = a -% (d *% b);
42 return d;39 return d;
43}40}
4441
45pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {42pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {
46 @setRuntimeSafety(builtin.is_test);
47 return udivmod(u64, a, b, maybe_rem);43 return udivmod(u64, a, b, maybe_rem);
48}44}
4945
...@@ -52,8 +48,6 @@ test "test_udivmoddi4" {...@@ -52,8 +48,6 @@ test "test_udivmoddi4" {
52}48}
5349
54pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 {50pub fn __divdi3(a: i64, b: i64) callconv(.C) i64 {
55 @setRuntimeSafety(builtin.is_test);
56
57 // Set aside the sign of the quotient.51 // Set aside the sign of the quotient.
58 const sign = @bitCast(u64, (a ^ b) >> 63);52 const sign = @bitCast(u64, (a ^ b) >> 63);
59 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).53 // 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 {...@@ -91,8 +85,6 @@ fn test_one_divdi3(a: i64, b: i64, expected_q: i64) !void {
91}85}
9286
93pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {87pub fn __moddi3(a: i64, b: i64) callconv(.C) i64 {
94 @setRuntimeSafety(builtin.is_test);
95
96 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).88 // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
97 const abs_a = (a ^ (a >> 63)) -% (a >> 63);89 const abs_a = (a ^ (a >> 63)) -% (a >> 63);
98 const abs_b = (b ^ (b >> 63)) -% (b >> 63);90 const abs_b = (b ^ (b >> 63)) -% (b >> 63);
...@@ -131,13 +123,10 @@ fn test_one_moddi3(a: i64, b: i64, expected_r: i64) !void {...@@ -131,13 +123,10 @@ fn test_one_moddi3(a: i64, b: i64, expected_r: i64) !void {
131}123}
132124
133pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {125pub fn __udivdi3(a: u64, b: u64) callconv(.C) u64 {
134 @setRuntimeSafety(builtin.is_test);
135 return __udivmoddi4(a, b, null);126 return __udivmoddi4(a, b, null);
136}127}
137128
138pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {129pub fn __umoddi3(a: u64, b: u64) callconv(.C) u64 {
139 @setRuntimeSafety(builtin.is_test);
140
141 var r: u64 = undefined;130 var r: u64 = undefined;
142 _ = __udivmoddi4(a, b, &r);131 _ = __udivmoddi4(a, b, &r);
143 return r;132 return r;
...@@ -157,8 +146,6 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) !void {...@@ -157,8 +146,6 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) !void {
157}146}
158147
159pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {148pub fn __divmodsi4(a: i32, b: i32, rem: *i32) callconv(.C) i32 {
160 @setRuntimeSafety(builtin.is_test);
161
162 const d = __divsi3(a, b);149 const d = __divsi3(a, b);
163 rem.* = a -% (d * b);150 rem.* = a -% (d * b);
164 return d;151 return d;
...@@ -193,16 +180,20 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {...@@ -193,16 +180,20 @@ fn test_one_divmodsi4(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
193}180}
194181
195pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {182pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
196 @setRuntimeSafety(builtin.is_test);
197
198 const d = __udivsi3(a, b);183 const d = __udivsi3(a, b);
199 rem.* = @bitCast(u32, @bitCast(i32, a) -% (@bitCast(i32, d) * @bitCast(i32, b)));184 rem.* = @bitCast(u32, @bitCast(i32, a) -% (@bitCast(i32, d) * @bitCast(i32, b)));
200 return d;185 return d;
201}186}
202187
203pub fn __divsi3(n: i32, d: i32) callconv(.C) i32 {188pub 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 {
206 // Set aside the sign of the quotient.197 // Set aside the sign of the quotient.
207 const sign = @bitCast(u32, (n ^ d) >> 31);198 const sign = @bitCast(u32, (n ^ d) >> 31);
208 // Take absolute value of a and b via abs(x) = (x^(x >> 31)) - (x >> 31).199 // 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 {...@@ -214,10 +205,6 @@ pub fn __divsi3(n: i32, d: i32) callconv(.C) i32 {
214 return @bitCast(i32, (res ^ sign) -% sign);205 return @bitCast(i32, (res ^ sign) -% sign);
215}206}
216207
217pub fn __aeabi_idiv(n: i32, d: i32) callconv(.AAPCS) i32 {
218 return @call(.{ .modifier = .always_inline }, __divsi3, .{ n, d });
219}
220
221test "test_divsi3" {208test "test_divsi3" {
222 const cases = [_][3]i32{209 const cases = [_][3]i32{
223 [_]i32{ 0, 1, 0 },210 [_]i32{ 0, 1, 0 },
...@@ -244,8 +231,14 @@ fn test_one_divsi3(a: i32, b: i32, expected_q: i32) !void {...@@ -244,8 +231,14 @@ fn test_one_divsi3(a: i32, b: i32, expected_q: i32) !void {
244}231}
245232
246pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {233pub 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 {
249 const n_uword_bits: c_uint = 32;242 const n_uword_bits: c_uint = 32;
250 // special cases243 // special cases
251 if (d == 0) return 0; // ?!244 if (d == 0) return 0; // ?!
...@@ -284,10 +277,6 @@ pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {...@@ -284,10 +277,6 @@ pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
284 return q;277 return q;
285}278}
286279
287pub fn __aeabi_uidiv(n: u32, d: u32) callconv(.AAPCS) u32 {
288 return @call(.{ .modifier = .always_inline }, __udivsi3, .{ n, d });
289}
290
291test "test_udivsi3" {280test "test_udivsi3" {
292 const cases = [_][3]u32{281 const cases = [_][3]u32{
293 [_]u32{ 0x00000000, 0x00000001, 0x00000000 },282 [_]u32{ 0x00000000, 0x00000001, 0x00000000 },
...@@ -435,8 +424,6 @@ fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) !void {...@@ -435,8 +424,6 @@ fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) !void {
435}424}
436425
437pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {426pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
438 @setRuntimeSafety(builtin.is_test);
439
440 return n -% __divsi3(n, d) *% d;427 return n -% __divsi3(n, d) *% d;
441}428}
442429
...@@ -466,8 +453,6 @@ fn test_one_modsi3(a: i32, b: i32, expected_r: i32) !void {...@@ -466,8 +453,6 @@ fn test_one_modsi3(a: i32, b: i32, expected_r: i32) !void {
466}453}
467454
468pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {455pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
469 @setRuntimeSafety(builtin.is_test);
470
471 return n -% __udivsi3(n, d) *% d;456 return n -% __udivsi3(n, d) *% d;
472}457}
473458
...@@ -618,8 +603,6 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) !void {...@@ -618,8 +603,6 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) !void {
618}603}
619604
620pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {605pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
621 @setRuntimeSafety(builtin.is_test);
622
623 var ua = @bitCast(u32, a);606 var ua = @bitCast(u32, a);
624 var ub = @bitCast(u32, b);607 var ub = @bitCast(u32, b);
625 var r: u32 = 0;608 var r: u32 = 0;
lib/compiler_rt/log.zig+15-23
...@@ -1,30 +1,26 @@...@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/lnf.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/lnf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
9const math = std.math;9const math = std.math;
10const testing = std.testing;10const testing = std.testing;
11const arch = builtin.cpu.arch;11const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;12const common = @import("common.zig");
13pub const panic = @import("common.zig").panic;13
14pub const panic = common.panic;
1415
15comptime {16comptime {
16 @export(__logh, .{ .name = "__logh", .linkage = linkage });17 @export(__logh, .{ .name = "__logh", .linkage = common.linkage });
17 @export(logf, .{ .name = "logf", .linkage = linkage });18 @export(logf, .{ .name = "logf", .linkage = common.linkage });
18 @export(log, .{ .name = "log", .linkage = linkage });19 @export(log, .{ .name = "log", .linkage = common.linkage });
19 @export(__logx, .{ .name = "__logx", .linkage = linkage });20 @export(__logx, .{ .name = "__logx", .linkage = common.linkage });
20 @export(logq, .{ .name = "logq", .linkage = linkage });21 const logq_sym_name = if (common.want_ppc_abi) "logf128" else "logq";
21 @export(logl, .{ .name = "logl", .linkage = linkage });22 @export(logq, .{ .name = logq_sym_name, .linkage = common.linkage });
2223 @export(logl, .{ .name = "logl", .linkage = common.linkage });
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(logf128, .{ .name = "logf128", .linkage = linkage });
26 }
27 }
28}24}
2925
30pub fn __logh(a: f16) callconv(.C) f16 {26pub fn __logh(a: f16) callconv(.C) f16 {
...@@ -150,10 +146,6 @@ pub fn logq(a: f128) callconv(.C) f128 {...@@ -150,10 +146,6 @@ pub fn logq(a: f128) callconv(.C) f128 {
150 return log(@floatCast(f64, a));146 return log(@floatCast(f64, a));
151}147}
152148
153pub fn logf128(a: f128) callconv(.C) f128 {
154 return @call(.{ .modifier = .always_inline }, logq, .{a});
155}
156
157pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {149pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {
158 switch (@typeInfo(c_longdouble).Float.bits) {150 switch (@typeInfo(c_longdouble).Float.bits) {
159 16 => return __logh(x),151 16 => return __logh(x),
lib/compiler_rt/log10.zig+15-23
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/log10f.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/log10f.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
...@@ -10,22 +10,18 @@ const math = std.math;...@@ -10,22 +10,18 @@ const math = std.math;
10const testing = std.testing;10const testing = std.testing;
11const maxInt = std.math.maxInt;11const maxInt = std.math.maxInt;
12const arch = builtin.cpu.arch;12const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;13const common = @import("common.zig");
14pub const panic = @import("common.zig").panic;14
15pub const panic = common.panic;
1516
16comptime {17comptime {
17 @export(__log10h, .{ .name = "__log10h", .linkage = linkage });18 @export(__log10h, .{ .name = "__log10h", .linkage = common.linkage });
18 @export(log10f, .{ .name = "log10f", .linkage = linkage });19 @export(log10f, .{ .name = "log10f", .linkage = common.linkage });
19 @export(log10, .{ .name = "log10", .linkage = linkage });20 @export(log10, .{ .name = "log10", .linkage = common.linkage });
20 @export(__log10x, .{ .name = "__log10x", .linkage = linkage });21 @export(__log10x, .{ .name = "__log10x", .linkage = common.linkage });
21 @export(log10q, .{ .name = "log10q", .linkage = linkage });22 const log10q_sym_name = if (common.want_ppc_abi) "log10f128" else "log10q";
22 @export(log10l, .{ .name = "log10l", .linkage = linkage });23 @export(log10q, .{ .name = log10q_sym_name, .linkage = common.linkage });
2324 @export(log10l, .{ .name = "log10l", .linkage = common.linkage });
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(log10f128, .{ .name = "log10f128", .linkage = linkage });
27 }
28 }
29}25}
3026
31pub fn __log10h(a: f16) callconv(.C) f16 {27pub fn __log10h(a: f16) callconv(.C) f16 {
...@@ -178,10 +174,6 @@ pub fn log10q(a: f128) callconv(.C) f128 {...@@ -178,10 +174,6 @@ pub fn log10q(a: f128) callconv(.C) f128 {
178 return log10(@floatCast(f64, a));174 return log10(@floatCast(f64, a));
179}175}
180176
181pub fn log10f128(a: f128) callconv(.C) f128 {
182 return @call(.{ .modifier = .always_inline }, log10q, .{a});
183}
184
185pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {177pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {
186 switch (@typeInfo(c_longdouble).Float.bits) {178 switch (@typeInfo(c_longdouble).Float.bits) {
187 16 => return __log10h(x),179 16 => return __log10h(x),
lib/compiler_rt/log2.zig+15-23
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/log2f.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/log2f.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
...@@ -10,22 +10,18 @@ const math = std.math;...@@ -10,22 +10,18 @@ const math = std.math;
10const expect = std.testing.expect;10const expect = std.testing.expect;
11const maxInt = std.math.maxInt;11const maxInt = std.math.maxInt;
12const arch = builtin.cpu.arch;12const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;13const common = @import("common.zig");
14pub const panic = @import("common.zig").panic;14
15pub const panic = common.panic;
1516
16comptime {17comptime {
17 @export(__log2h, .{ .name = "__log2h", .linkage = linkage });18 @export(__log2h, .{ .name = "__log2h", .linkage = common.linkage });
18 @export(log2f, .{ .name = "log2f", .linkage = linkage });19 @export(log2f, .{ .name = "log2f", .linkage = common.linkage });
19 @export(log2, .{ .name = "log2", .linkage = linkage });20 @export(log2, .{ .name = "log2", .linkage = common.linkage });
20 @export(__log2x, .{ .name = "__log2x", .linkage = linkage });21 @export(__log2x, .{ .name = "__log2x", .linkage = common.linkage });
21 @export(log2q, .{ .name = "log2q", .linkage = linkage });22 const log2q_sym_name = if (common.want_ppc_abi) "log2f128" else "log2q";
22 @export(log2l, .{ .name = "log2l", .linkage = linkage });23 @export(log2q, .{ .name = log2q_sym_name, .linkage = common.linkage });
2324 @export(log2l, .{ .name = "log2l", .linkage = common.linkage });
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(log2f128, .{ .name = "log2f128", .linkage = linkage });
27 }
28 }
29}25}
3026
31pub fn __log2h(a: f16) callconv(.C) f16 {27pub fn __log2h(a: f16) callconv(.C) f16 {
...@@ -170,10 +166,6 @@ pub fn log2q(a: f128) callconv(.C) f128 {...@@ -170,10 +166,6 @@ pub fn log2q(a: f128) callconv(.C) f128 {
170 return log2(@floatCast(f64, a));166 return log2(@floatCast(f64, a));
171}167}
172168
173pub fn log2f128(a: f128) callconv(.C) f128 {
174 return @call(.{ .modifier = .always_inline }, log2q, .{a});
175}
176
177pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {169pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {
178 switch (@typeInfo(c_longdouble).Float.bits) {170 switch (@typeInfo(c_longdouble).Float.bits) {
179 16 => return __log2h(x),171 16 => return __log2h(x),
lib/compiler_rt/modti3.zig+19-19
...@@ -1,39 +1,47 @@...@@ -1,39 +1,47 @@
1// Ported from:1//! Ported from:
2//2//!
3// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c3//! https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c
44
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const udivmod = @import("udivmod.zig").udivmod;7const udivmod = @import("udivmod.zig").udivmod;
8const arch = builtin.cpu.arch;8const arch = builtin.cpu.arch;
9const is_test = builtin.is_test;9const common = @import("common.zig");
10const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;10
11pub const panic = @import("common.zig").panic;11pub const panic = common.panic;
1212
13comptime {13comptime {
14 if (builtin.os.tag == .windows) {14 if (builtin.os.tag == .windows) {
15 switch (arch) {15 switch (arch) {
16 .i386 => {16 .i386 => {
17 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });17 @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
18 },18 },
19 .x86_64 => {19 .x86_64 => {
20 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI20 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
21 // that LLVM expects compiler-rt to have.21 // 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 });
23 },23 },
24 else => {},24 else => {},
25 }25 }
26 if (arch.isAARCH64()) {26 if (arch.isAARCH64()) {
27 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });27 @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
28 }28 }
29 } else {29 } else {
30 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });30 @export(__modti3, .{ .name = "__modti3", .linkage = common.linkage });
31 }31 }
32}32}
3333
34pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {34pub 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 {
37 const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 045 const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 0
38 const s_b = b >> (128 - 1); // s = b < 0 ? -1 : 046 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 {...@@ -45,14 +53,6 @@ pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
45 return (@bitCast(i128, r) ^ s_a) -% s_a; // negate if s == -153 return (@bitCast(i128, r) ^ s_a) -% s_a; // negate if s == -1
46}54}
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
56test {56test {
57 _ = @import("modti3_test.zig");57 _ = @import("modti3_test.zig");
58}58}
lib/compiler_rt/muldi3.zig+26-29
...@@ -1,23 +1,36 @@...@@ -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
1const std = @import("std");4const std = @import("std");
2const builtin = @import("builtin");5const builtin = @import("builtin");
3const native_endian = builtin.cpu.arch.endian();6const native_endian = builtin.cpu.arch.endian();
4const arch = builtin.cpu.arch;7const common = @import("common.zig");
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;
88
9comptime {9pub const panic = common.panic;
10 @export(__muldi3, .{ .name = "__muldi3", .linkage = linkage });
1110
12 if (!is_test) {11comptime {
13 if (arch.isARM() or arch.isThumb()) {12 if (common.want_aeabi) {
14 @export(__aeabi_lmul, .{ .name = "__aeabi_lmul", .linkage = linkage });13 @export(__aeabi_lmul, .{ .name = "__aeabi_lmul", .linkage = common.linkage });
15 }14 } else {
15 @export(__muldi3, .{ .name = "__muldi3", .linkage = common.linkage });
16 }16 }
17}17}
1818
19// Ported from19pub fn __muldi3(a: i64, b: i64) callconv(.C) i64 {
20// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c20 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
22const dwords = extern union {35const dwords = extern union {
23 all: i64,36 all: i64,
...@@ -33,13 +46,7 @@ const dwords = extern union {...@@ -33,13 +46,7 @@ const dwords = extern union {
33 },46 },
34};47};
3548
36pub fn __aeabi_lmul(a: i64, b: i64) callconv(.AAPCS) i64 {49fn muldsi3(a: u32, b: u32) 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
43 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;50 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
44 const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;51 const lower_mask = (~@as(u32, 0)) >> bits_in_word_2;
4552
...@@ -59,16 +66,6 @@ pub fn __muldsi3(a: u32, b: u32) i64 {...@@ -59,16 +66,6 @@ pub fn __muldsi3(a: u32, b: u32) i64 {
59 return r.all;66 return r.all;
60}67}
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
72test {69test {
73 _ = @import("muldi3_test.zig");70 _ = @import("muldi3_test.zig");
74}71}
lib/compiler_rt/mulo.zig+6-8
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const math = std.math;3const math = std.math;
4const is_test = builtin.is_test;4const common = @import("common.zig");
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5
6pub const panic = @import("common.zig").panic;6pub const panic = common.panic;
77
8comptime {8comptime {
9 @export(__mulosi4, .{ .name = "__mulosi4", .linkage = linkage });9 @export(__mulosi4, .{ .name = "__mulosi4", .linkage = common.linkage });
10 @export(__mulodi4, .{ .name = "__mulodi4", .linkage = linkage });10 @export(__mulodi4, .{ .name = "__mulodi4", .linkage = common.linkage });
11 @export(__muloti4, .{ .name = "__muloti4", .linkage = linkage });11 @export(__muloti4, .{ .name = "__muloti4", .linkage = common.linkage });
12}12}
1313
14// mulo - multiplication overflow14// mulo - multiplication overflow
...@@ -18,7 +18,6 @@ comptime {...@@ -18,7 +18,6 @@ comptime {
18// - muloXi4_genericFast for 2*bitsize <= usize18// - muloXi4_genericFast for 2*bitsize <= usize
1919
20inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {20inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
21 @setRuntimeSafety(builtin.is_test);
22 overflow.* = 0;21 overflow.* = 0;
23 const min = math.minInt(ST);22 const min = math.minInt(ST);
24 var res: ST = a *% b;23 var res: ST = a *% b;
...@@ -33,7 +32,6 @@ inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int...@@ -33,7 +32,6 @@ inline fn muloXi4_genericSmall(comptime ST: type, a: ST, b: ST, overflow: *c_int
33}32}
3433
35inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {34inline fn muloXi4_genericFast(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
36 @setRuntimeSafety(builtin.is_test);
37 overflow.* = 0;35 overflow.* = 0;
38 const EST = switch (ST) {36 const EST = switch (ST) {
39 i32 => i64,37 i32 => i64,
lib/compiler_rt/multi3.zig+21-20
...@@ -1,51 +1,52 @@...@@ -1,51 +1,52 @@
1//! Ported from git@github.com:llvm-project/llvm-project-20170507.git
2//! ae684fad6d34858c014c94da69c15e7774a633c3
3//! 2018-08-13
4
1const std = @import("std");5const std = @import("std");
2const builtin = @import("builtin");6const builtin = @import("builtin");
3const arch = builtin.cpu.arch;7const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;
5const native_endian = builtin.cpu.arch.endian();8const native_endian = builtin.cpu.arch.endian();
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;9const common = @import("common.zig");
7pub const panic = @import("common.zig").panic;
810
9// Ported from git@github.com:llvm-project/llvm-project-20170507.git11pub const panic = common.panic;
10// ae684fad6d34858c014c94da69c15e7774a633c3
11// 2018-08-13
1212
13comptime {13comptime {
14 if (builtin.os.tag == .windows) {14 if (builtin.os.tag == .windows) {
15 switch (arch) {15 switch (arch) {
16 .i386 => {16 .i386 => {
17 @export(__multi3, .{ .name = "__multi3", .linkage = linkage });17 @export(__multi3, .{ .name = "__multi3", .linkage = common.linkage });
18 },18 },
19 .x86_64 => {19 .x86_64 => {
20 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI20 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
21 // that LLVM expects compiler-rt to have.21 // 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 });
23 },23 },
24 else => {},24 else => {},
25 }25 }
26 } else {26 } else {
27 @export(__multi3, .{ .name = "__multi3", .linkage = linkage });27 @export(__multi3, .{ .name = "__multi3", .linkage = common.linkage });
28 }28 }
29}29}
3030
31pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {31pub 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 {
33 const x = twords{ .all = a };42 const x = twords{ .all = a };
34 const y = twords{ .all = b };43 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) };
36 r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;45 r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
37 return r.all;46 return r.all;
38}47}
3948
40const v128 = @Vector(2, u64);49fn mulddi3(a: u64, b: u64) i128 {
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 {
49 const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;50 const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;
50 const lower_mask = ~@as(u64, 0) >> bits_in_dword_2;51 const lower_mask = ~@as(u64, 0) >> bits_in_dword_2;
51 var r: twords = undefined;52 var r: twords = undefined;
lib/compiler_rt/negXf2.zig+16-21
...@@ -1,19 +1,16 @@...@@ -1,19 +1,16 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;3const common = @import("common.zig");
4const is_test = builtin.is_test;4
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5pub const panic = common.panic;
6pub const panic = @import("common.zig").panic;
76
8comptime {7comptime {
9 @export(__negsf2, .{ .name = "__negsf2", .linkage = linkage });8 if (common.want_aeabi) {
10 @export(__negdf2, .{ .name = "__negdf2", .linkage = linkage });9 @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = common.linkage });
1110 @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = common.linkage });
12 if (!is_test) {11 } else {
13 if (arch.isARM() or arch.isThumb()) {12 @export(__negsf2, .{ .name = "__negsf2", .linkage = common.linkage });
14 @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = linkage });13 @export(__negdf2, .{ .name = "__negdf2", .linkage = common.linkage });
15 @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = linkage });
16 }
17 }14 }
18}15}
1916
...@@ -21,21 +18,19 @@ pub fn __negsf2(a: f32) callconv(.C) f32 {...@@ -21,21 +18,19 @@ pub fn __negsf2(a: f32) callconv(.C) f32 {
21 return negXf2(f32, a);18 return negXf2(f32, a);
22}19}
2320
24pub fn __negdf2(a: f64) callconv(.C) f64 {21fn __aeabi_fneg(a: f32) callconv(.AAPCS) f32 {
25 return negXf2(f64, a);22 return negXf2(f32, a);
26}23}
2724
28pub fn __aeabi_fneg(arg: f32) callconv(.AAPCS) f32 {25pub fn __negdf2(a: f64) callconv(.C) f64 {
29 @setRuntimeSafety(false);26 return negXf2(f64, a);
30 return @call(.{ .modifier = .always_inline }, __negsf2, .{arg});
31}27}
3228
33pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {29fn __aeabi_dneg(a: f64) callconv(.AAPCS) f64 {
34 @setRuntimeSafety(false);30 return negXf2(f64, a);
35 return @call(.{ .modifier = .always_inline }, __negdf2, .{arg});
36}31}
3732
38fn negXf2(comptime T: type, a: T) T {33inline fn negXf2(comptime T: type, a: T) T {
39 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);34 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
4035
41 const significandBits = std.math.floatMantissaBits(T);36 const significandBits = std.math.floatMantissaBits(T);
lib/compiler_rt/negXi2.zig+18-21
...@@ -1,28 +1,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
1const std = @import("std");9const std = @import("std");
2const builtin = @import("builtin");10const builtin = @import("builtin");
3const is_test = builtin.is_test;11const common = @import("common.zig");
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}
1212
13// neg - negate (the number)13pub const panic = common.panic;
14// - negXi2 for unoptimized little and big endian
1514
16// sfffffff = 2^31-115comptime {
17// two's complement inverting bits and add 1 would result in -INT_MIN == 016 @export(__negsi2, .{ .name = "__negsi2", .linkage = common.linkage });
18// => -INT_MIN = -2^31 forbidden17 @export(__negdi2, .{ .name = "__negdi2", .linkage = common.linkage });
1918 @export(__negti2, .{ .name = "__negti2", .linkage = common.linkage });
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;
26}19}
2720
28pub fn __negsi2(a: i32) callconv(.C) i32 {21pub fn __negsi2(a: i32) callconv(.C) i32 {
...@@ -37,6 +30,10 @@ pub fn __negti2(a: i128) callconv(.C) i128 {...@@ -37,6 +30,10 @@ pub fn __negti2(a: i128) callconv(.C) i128 {
37 return negXi2(i128, a);30 return negXi2(i128, a);
38}31}
3932
33inline fn negXi2(comptime T: type, a: T) T {
34 return -a;
35}
36
40test {37test {
41 _ = @import("negsi2_test.zig");38 _ = @import("negsi2_test.zig");
42 _ = @import("negdi2_test.zig");39 _ = @import("negdi2_test.zig");
lib/compiler_rt/negv.zig+21-22
...@@ -1,19 +1,30 @@...@@ -1,19 +1,30 @@
1// negv - negate oVerflow1//! negv - negate oVerflow
2// * @panic, if result can not be represented2//! * @panic, if result can not be represented
3// - negvXi4_generic for unoptimized version3//! - negvXi4_generic for unoptimized version
4const std = @import("std");4const std = @import("std");
5const builtin = @import("builtin");5const builtin = @import("builtin");
6const is_test = builtin.is_test;6const common = @import("common.zig");
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;7
8pub const panic = @import("common.zig").panic;8pub const panic = common.panic;
99
10comptime {10comptime {
11 @export(__negvsi2, .{ .name = "__negvsi2", .linkage = linkage });11 @export(__negvsi2, .{ .name = "__negvsi2", .linkage = common.linkage });
12 @export(__negvdi2, .{ .name = "__negvdi2", .linkage = linkage });12 @export(__negvdi2, .{ .name = "__negvdi2", .linkage = common.linkage });
13 @export(__negvti2, .{ .name = "__negvti2", .linkage = 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);
14}26}
1527
16// assume -0 == 0 is gracefully handled by the hardware
17inline fn negvXi(comptime ST: type, a: ST) ST {28inline fn negvXi(comptime ST: type, a: ST) ST {
18 const UT = switch (ST) {29 const UT = switch (ST) {
19 i32 => u32,30 i32 => u32,
...@@ -28,18 +39,6 @@ inline fn negvXi(comptime ST: type, a: ST) ST {...@@ -28,18 +39,6 @@ inline fn negvXi(comptime ST: type, a: ST) ST {
28 return -a;39 return -a;
29}40}
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
43test {42test {
44 _ = @import("negvsi2_test.zig");43 _ = @import("negvsi2_test.zig");
45 _ = @import("negvdi2_test.zig");44 _ = @import("negvdi2_test.zig");
lib/compiler_rt/parity.zig+20-22
...@@ -1,21 +1,31 @@...@@ -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
1const std = @import("std");4const std = @import("std");
2const builtin = @import("builtin");5const builtin = @import("builtin");
3const is_test = builtin.is_test;6const common = @import("common.zig");
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;7
5pub const panic = @import("common.zig").panic;8pub const panic = common.panic;
69
7comptime {10comptime {
8 @export(__paritysi2, .{ .name = "__paritysi2", .linkage = linkage });11 @export(__paritysi2, .{ .name = "__paritysi2", .linkage = common.linkage });
9 @export(__paritydi2, .{ .name = "__paritydi2", .linkage = linkage });12 @export(__paritydi2, .{ .name = "__paritydi2", .linkage = common.linkage });
10 @export(__parityti2, .{ .name = "__parityti2", .linkage = linkage });13 @export(__parityti2, .{ .name = "__parityti2", .linkage = common.linkage });
11}14}
1215
13// parity - if number of bits set is even => 0, else => 116pub fn __paritysi2(a: i32) callconv(.C) i32 {
14// - pariytXi2_generic for big and little endian17 return parityXi2(i32, a);
18}
1519
16inline fn parityXi2(comptime T: type, a: T) i32 {20pub fn __paritydi2(a: i64) callconv(.C) i32 {
17 @setRuntimeSafety(builtin.is_test);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 {
19 var x = switch (@bitSizeOf(T)) {29 var x = switch (@bitSizeOf(T)) {
20 32 => @bitCast(u32, a),30 32 => @bitCast(u32, a),
21 64 => @bitCast(u64, a),31 64 => @bitCast(u64, a),
...@@ -32,18 +42,6 @@ inline fn parityXi2(comptime T: type, a: T) i32 {...@@ -32,18 +42,6 @@ inline fn parityXi2(comptime T: type, a: T) i32 {
32 return (@intCast(u16, 0x6996) >> @intCast(u4, x)) & 1; // optimization for >>2 and >>142 return (@intCast(u16, 0x6996) >> @intCast(u4, x)) & 1; // optimization for >>2 and >>1
33}43}
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
47test {45test {
48 _ = @import("paritysi2_test.zig");46 _ = @import("paritysi2_test.zig");
49 _ = @import("paritydi2_test.zig");47 _ = @import("paritydi2_test.zig");
lib/compiler_rt/popcount.zig+24-26
...@@ -1,26 +1,36 @@...@@ -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
1const builtin = @import("builtin");9const builtin = @import("builtin");
2const std = @import("std");10const std = @import("std");
3const is_test = builtin.is_test;11const common = @import("common.zig");
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;12
5pub const panic = @import("common.zig").panic;13pub const panic = common.panic;
614
7comptime {15comptime {
8 @export(__popcountsi2, .{ .name = "__popcountsi2", .linkage = linkage });16 @export(__popcountsi2, .{ .name = "__popcountsi2", .linkage = common.linkage });
9 @export(__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });17 @export(__popcountdi2, .{ .name = "__popcountdi2", .linkage = common.linkage });
10 @export(__popcountti2, .{ .name = "__popcountti2", .linkage = linkage });18 @export(__popcountti2, .{ .name = "__popcountti2", .linkage = common.linkage });
19}
20
21pub fn __popcountsi2(a: i32) callconv(.C) i32 {
22 return popcountXi2(i32, a);
11}23}
1224
13// popcount - population count25pub fn __popcountdi2(a: i64) callconv(.C) i32 {
14// counts the number of 1 bits26 return popcountXi2(i64, a);
27}
1528
16// SWAR-Popcount: count bits of duos, aggregate to nibbles, and bytes inside29pub fn __popcountti2(a: i128) callconv(.C) i32 {
17// x-bit register in parallel to sum up all bytes30 return popcountXi2(i128, a);
18// SWAR-Masks and factors can be defined as 2-adic fractions31}
19// TAOCP: Combinational Algorithms, Bitwise Tricks And Techniques,
20// subsubsection "Working with the rightmost bits" and "Sideways addition".
2132
22inline fn popcountXi2(comptime ST: type, a: ST) i32 {33inline fn popcountXi2(comptime ST: type, a: ST) i32 {
23 @setRuntimeSafety(builtin.is_test);
24 const UT = switch (ST) {34 const UT = switch (ST) {
25 i32 => u32,35 i32 => u32,
26 i64 => u64,36 i64 => u64,
...@@ -39,18 +49,6 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {...@@ -39,18 +49,6 @@ inline fn popcountXi2(comptime ST: type, a: ST) i32 {
39 return @intCast(i32, x);49 return @intCast(i32, x);
40}50}
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
54test {52test {
55 _ = @import("popcountsi2_test.zig");53 _ = @import("popcountsi2_test.zig");
56 _ = @import("popcountdi2_test.zig");54 _ = @import("popcountdi2_test.zig");
lib/compiler_rt/round.zig+15-23
...@@ -1,30 +1,26 @@...@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/roundf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
9const math = std.math;9const math = std.math;
10const expect = std.testing.expect;10const expect = std.testing.expect;
11const arch = builtin.cpu.arch;11const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;12const common = @import("common.zig");
13pub const panic = @import("common.zig").panic;13
14pub const panic = common.panic;
1415
15comptime {16comptime {
16 @export(__roundh, .{ .name = "__roundh", .linkage = linkage });17 @export(__roundh, .{ .name = "__roundh", .linkage = common.linkage });
17 @export(roundf, .{ .name = "roundf", .linkage = linkage });18 @export(roundf, .{ .name = "roundf", .linkage = common.linkage });
18 @export(round, .{ .name = "round", .linkage = linkage });19 @export(round, .{ .name = "round", .linkage = common.linkage });
19 @export(__roundx, .{ .name = "__roundx", .linkage = linkage });20 @export(__roundx, .{ .name = "__roundx", .linkage = common.linkage });
20 @export(roundq, .{ .name = "roundq", .linkage = linkage });21 const roundq_sym_name = if (common.want_ppc_abi) "roundf128" else "roundq";
21 @export(roundl, .{ .name = "roundl", .linkage = linkage });22 @export(roundq, .{ .name = roundq_sym_name, .linkage = common.linkage });
2223 @export(roundl, .{ .name = "roundl", .linkage = common.linkage });
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(roundf128, .{ .name = "roundf128", .linkage = linkage });
26 }
27 }
28}24}
2925
30pub fn __roundh(x: f16) callconv(.C) f16 {26pub fn __roundh(x: f16) callconv(.C) f16 {
...@@ -142,10 +138,6 @@ pub fn roundq(x_: f128) callconv(.C) f128 {...@@ -142,10 +138,6 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
142 }138 }
143}139}
144140
145pub fn roundf128(x_: f128) callconv(.C) f128 {
146 return @call(.{ .modifier = .always_inline }, roundq, .{x_});
147}
148
149pub fn roundl(x: c_longdouble) callconv(.C) c_longdouble {141pub fn roundl(x: c_longdouble) callconv(.C) c_longdouble {
150 switch (@typeInfo(c_longdouble).Float.bits) {142 switch (@typeInfo(c_longdouble).Float.bits) {
151 16 => return __roundh(x),143 16 => return __roundh(x),
lib/compiler_rt/shift.zig+29-27
...@@ -2,25 +2,23 @@ const std = @import("std");...@@ -2,25 +2,23 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const Log2Int = std.math.Log2Int;3const Log2Int = std.math.Log2Int;
4const native_endian = builtin.cpu.arch.endian();4const native_endian = builtin.cpu.arch.endian();
5const arch = builtin.cpu.arch;5const common = @import("common.zig");
6const is_test = builtin.is_test;6
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;7pub const panic = common.panic;
8pub const panic = @import("common.zig").panic;
98
10comptime {9comptime {
11 @export(__ashldi3, .{ .name = "__ashldi3", .linkage = linkage });10 @export(__ashlti3, .{ .name = "__ashlti3", .linkage = common.linkage });
12 @export(__ashlti3, .{ .name = "__ashlti3", .linkage = linkage });11 @export(__ashrti3, .{ .name = "__ashrti3", .linkage = common.linkage });
13 @export(__ashrdi3, .{ .name = "__ashrdi3", .linkage = linkage });12 @export(__lshrti3, .{ .name = "__lshrti3", .linkage = common.linkage });
14 @export(__ashrti3, .{ .name = "__ashrti3", .linkage = linkage });13
15 @export(__lshrdi3, .{ .name = "__lshrdi3", .linkage = linkage });14 if (common.want_aeabi) {
16 @export(__lshrti3, .{ .name = "__lshrti3", .linkage = linkage });15 @export(__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = common.linkage });
1716 @export(__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = common.linkage });
18 if (!is_test) {17 @export(__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = common.linkage });
19 if (arch.isARM() or arch.isThumb()) {18 } else {
20 @export(__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = linkage });19 @export(__ashldi3, .{ .name = "__ashldi3", .linkage = common.linkage });
21 @export(__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = linkage });20 @export(__ashrdi3, .{ .name = "__ashrdi3", .linkage = common.linkage });
22 @export(__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = linkage });21 @export(__lshrdi3, .{ .name = "__lshrdi3", .linkage = common.linkage });
23 }
24 }22 }
25}23}
2624
...@@ -115,30 +113,34 @@ inline fn lshrXi3(comptime T: type, a: T, b: i32) T {...@@ -115,30 +113,34 @@ inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
115pub fn __ashldi3(a: i64, b: i32) callconv(.C) i64 {113pub fn __ashldi3(a: i64, b: i32) callconv(.C) i64 {
116 return ashlXi3(i64, a, b);114 return ashlXi3(i64, a, b);
117}115}
116fn __aeabi_llsl(a: i64, b: i32) callconv(.AAPCS) i64 {
117 return ashlXi3(i64, a, b);
118}
119
118pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 {120pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 {
119 return ashlXi3(i128, a, b);121 return ashlXi3(i128, a, b);
120}122}
123
121pub fn __ashrdi3(a: i64, b: i32) callconv(.C) i64 {124pub fn __ashrdi3(a: i64, b: i32) callconv(.C) i64 {
122 return ashrXi3(i64, a, b);125 return ashrXi3(i64, a, b);
123}126}
127fn __aeabi_lasr(a: i64, b: i32) callconv(.AAPCS) i64 {
128 return ashrXi3(i64, a, b);
129}
130
124pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 {131pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 {
125 return ashrXi3(i128, a, b);132 return ashrXi3(i128, a, b);
126}133}
134
127pub fn __lshrdi3(a: i64, b: i32) callconv(.C) i64 {135pub fn __lshrdi3(a: i64, b: i32) callconv(.C) i64 {
128 return lshrXi3(i64, a, b);136 return lshrXi3(i64, a, b);
129}137}
130pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {138fn __aeabi_llsr(a: i64, b: i32) callconv(.AAPCS) i64 {
131 return lshrXi3(i128, a, b);139 return lshrXi3(i64, a, b);
132}140}
133141
134pub fn __aeabi_llsl(a: i64, b: i32) callconv(.AAPCS) i64 {142pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
135 return ashlXi3(i64, a, b);143 return lshrXi3(i128, 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);
142}144}
143145
144test {146test {
lib/compiler_rt/sin.zig+15-23
...@@ -1,34 +1,30 @@...@@ -1,34 +1,30 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/sinf.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/sinf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
9const arch = builtin.cpu.arch;9const arch = builtin.cpu.arch;
10const math = std.math;10const math = std.math;
11const expect = std.testing.expect;11const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;12const common = @import("common.zig");
13pub const panic = @import("common.zig").panic;
1413
15const trig = @import("trig.zig");14const trig = @import("trig.zig");
16const rem_pio2 = @import("rem_pio2.zig").rem_pio2;15const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
17const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;16const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
1817
18pub const panic = common.panic;
19
19comptime {20comptime {
20 @export(__sinh, .{ .name = "__sinh", .linkage = linkage });21 @export(__sinh, .{ .name = "__sinh", .linkage = common.linkage });
21 @export(sinf, .{ .name = "sinf", .linkage = linkage });22 @export(sinf, .{ .name = "sinf", .linkage = common.linkage });
22 @export(sin, .{ .name = "sin", .linkage = linkage });23 @export(sin, .{ .name = "sin", .linkage = common.linkage });
23 @export(__sinx, .{ .name = "__sinx", .linkage = linkage });24 @export(__sinx, .{ .name = "__sinx", .linkage = common.linkage });
24 @export(sinq, .{ .name = "sinq", .linkage = linkage });25 const sinq_sym_name = if (common.want_ppc_abi) "sinf128" else "sinq";
25 @export(sinl, .{ .name = "sinl", .linkage = linkage });26 @export(sinq, .{ .name = sinq_sym_name, .linkage = common.linkage });
2627 @export(sinl, .{ .name = "sinl", .linkage = common.linkage });
27 if (!builtin.is_test) {
28 if (arch.isPPC() or arch.isPPC64()) {
29 @export(sinf128, .{ .name = "sinf128", .linkage = linkage });
30 }
31 }
32}28}
3329
34pub fn __sinh(x: f16) callconv(.C) f16 {30pub fn __sinh(x: f16) callconv(.C) f16 {
...@@ -130,10 +126,6 @@ pub fn sinq(x: f128) callconv(.C) f128 {...@@ -130,10 +126,6 @@ pub fn sinq(x: f128) callconv(.C) f128 {
130 return sin(@floatCast(f64, x));126 return sin(@floatCast(f64, x));
131}127}
132128
133pub fn sinf128(x: f128) callconv(.C) f128 {
134 return @call(.{ .modifier = .always_inline }, sinq, .{x});
135}
136
137pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {129pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {
138 switch (@typeInfo(c_longdouble).Float.bits) {130 switch (@typeInfo(c_longdouble).Float.bits) {
139 16 => return __sinh(x),131 16 => return __sinh(x),
lib/compiler_rt/sincos.zig+10-18
...@@ -5,22 +5,18 @@ const math = std.math;...@@ -5,22 +5,18 @@ const math = std.math;
5const trig = @import("trig.zig");5const trig = @import("trig.zig");
6const rem_pio2 = @import("rem_pio2.zig").rem_pio2;6const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
7const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;7const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
8const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;8const common = @import("common.zig");
9pub const panic = @import("common.zig").panic;
109
11comptime {10pub const panic = common.panic;
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 });
1811
19 if (!builtin.is_test) {12comptime {
20 if (arch.isPPC() or arch.isPPC64()) {13 @export(__sincosh, .{ .name = "__sincosh", .linkage = common.linkage });
21 @export(sincosf128, .{ .name = "sincosf128", .linkage = linkage });14 @export(sincosf, .{ .name = "sincosf", .linkage = common.linkage });
22 }15 @export(sincos, .{ .name = "sincos", .linkage = common.linkage });
23 }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 });
24}20}
2521
26pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.C) void {22pub 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 {...@@ -198,10 +194,6 @@ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {
198 r_cos.* = small_cos;194 r_cos.* = small_cos;
199}195}
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
205pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.C) void {197pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.C) void {
206 switch (@typeInfo(c_longdouble).Float.bits) {198 switch (@typeInfo(c_longdouble).Float.bits) {
207 16 => return __sincosh(x, r_sin, r_cos),199 16 => return __sincosh(x, r_sin, r_cos),
lib/compiler_rt/sqrt.zig+10-18
...@@ -2,22 +2,18 @@ const std = @import("std");...@@ -2,22 +2,18 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const math = std.math;4const math = std.math;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5const common = @import("common.zig");
6pub const panic = @import("common.zig").panic;6
7pub const panic = common.panic;
78
8comptime {9comptime {
9 @export(__sqrth, .{ .name = "__sqrth", .linkage = linkage });10 @export(__sqrth, .{ .name = "__sqrth", .linkage = common.linkage });
10 @export(sqrtf, .{ .name = "sqrtf", .linkage = linkage });11 @export(sqrtf, .{ .name = "sqrtf", .linkage = common.linkage });
11 @export(sqrt, .{ .name = "sqrt", .linkage = linkage });12 @export(sqrt, .{ .name = "sqrt", .linkage = common.linkage });
12 @export(__sqrtx, .{ .name = "__sqrtx", .linkage = linkage });13 @export(__sqrtx, .{ .name = "__sqrtx", .linkage = common.linkage });
13 @export(sqrtq, .{ .name = "sqrtq", .linkage = linkage });14 const sqrtq_sym_name = if (common.want_ppc_abi) "sqrtf128" else "sqrtq";
14 @export(sqrtl, .{ .name = "sqrtl", .linkage = linkage });15 @export(sqrtq, .{ .name = sqrtq_sym_name, .linkage = common.linkage });
1516 @export(sqrtl, .{ .name = "sqrtl", .linkage = common.linkage });
16 if (!builtin.is_test) {
17 if (arch.isPPC() or arch.isPPC64()) {
18 @export(sqrtf128, .{ .name = "sqrtf128", .linkage = linkage });
19 }
20 }
21}17}
2218
23pub fn __sqrth(x: f16) callconv(.C) f16 {19pub fn __sqrth(x: f16) callconv(.C) f16 {
...@@ -255,10 +251,6 @@ pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {...@@ -255,10 +251,6 @@ pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {
255 }251 }
256}252}
257253
258pub fn sqrtf128(x: f128) callconv(.C) f128 {
259 return @call(.{ .modifier = .always_inline }, sqrtq, .{x});
260}
261
262test "sqrtf" {254test "sqrtf" {
263 const V = [_]f32{255 const V = [_]f32{
264 0.0,256 0.0,
lib/compiler_rt/subo.zig+20-21
...@@ -1,22 +1,31 @@...@@ -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
1const std = @import("std");6const std = @import("std");
2const builtin = @import("builtin");7const builtin = @import("builtin");
3const is_test = builtin.is_test;8const common = @import("common.zig");
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;9
5pub const panic = @import("common.zig").panic;10pub const panic = common.panic;
611
7comptime {12comptime {
8 @export(__subosi4, .{ .name = "__subosi4", .linkage = linkage });13 @export(__subosi4, .{ .name = "__subosi4", .linkage = common.linkage });
9 @export(__subodi4, .{ .name = "__subodi4", .linkage = linkage });14 @export(__subodi4, .{ .name = "__subodi4", .linkage = common.linkage });
10 @export(__suboti4, .{ .name = "__suboti4", .linkage = linkage });15 @export(__suboti4, .{ .name = "__suboti4", .linkage = common.linkage });
11}16}
1217
13// subo - subtract overflow18pub fn __subosi4(a: i32, b: i32, overflow: *c_int) callconv(.C) i32 {
14// * return a-%b.19 return suboXi4_generic(i32, a, b, overflow);
15// * return if a-b overflows => 1 else => 020}
16// - suboXi4_generic as default21pub 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
18inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {28inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST {
19 @setRuntimeSafety(builtin.is_test);
20 overflow.* = 0;29 overflow.* = 0;
21 var sum: ST = a -% b;30 var sum: ST = a -% b;
22 // Hackers Delight: section Overflow Detection, subsection Signed Add/Subtract31 // 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...@@ -31,16 +40,6 @@ inline fn suboXi4_generic(comptime ST: type, a: ST, b: ST, overflow: *c_int) ST
31 return sum;40 return sum;
32}41}
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
44test {43test {
45 _ = @import("subosi4_test.zig");44 _ = @import("subosi4_test.zig");
46 _ = @import("subodi4_test.zig");45 _ = @import("subodi4_test.zig");
lib/compiler_rt/tan.zig+16-24
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is licensed under the MIT license:
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/tanf.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/tanf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/tan.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/tan.c
6// https://golang.org/src/math/tan.go6//! https://golang.org/src/math/tan.go
77
8const std = @import("std");8const std = @import("std");
9const builtin = @import("builtin");9const builtin = @import("builtin");
...@@ -15,22 +15,18 @@ const rem_pio2 = @import("rem_pio2.zig").rem_pio2;...@@ -15,22 +15,18 @@ const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
15const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;15const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
1616
17const arch = builtin.cpu.arch;17const arch = builtin.cpu.arch;
18const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;18const common = @import("common.zig");
19pub const panic = @import("common.zig").panic;19
20pub const panic = common.panic;
2021
21comptime {22comptime {
22 @export(__tanh, .{ .name = "__tanh", .linkage = linkage });23 @export(__tanh, .{ .name = "__tanh", .linkage = common.linkage });
23 @export(tanf, .{ .name = "tanf", .linkage = linkage });24 @export(tanf, .{ .name = "tanf", .linkage = common.linkage });
24 @export(tan, .{ .name = "tan", .linkage = linkage });25 @export(tan, .{ .name = "tan", .linkage = common.linkage });
25 @export(__tanx, .{ .name = "__tanx", .linkage = linkage });26 @export(__tanx, .{ .name = "__tanx", .linkage = common.linkage });
26 @export(tanq, .{ .name = "tanq", .linkage = linkage });27 const tanq_sym_name = if (common.want_ppc_abi) "tanf128" else "tanq";
27 @export(tanl, .{ .name = "tanl", .linkage = linkage });28 @export(tanq, .{ .name = tanq_sym_name, .linkage = common.linkage });
2829 @export(tanl, .{ .name = "tanl", .linkage = common.linkage });
29 if (!builtin.is_test) {
30 if (arch.isPPC() or arch.isPPC64()) {
31 @export(tanf128, .{ .name = "tanf128", .linkage = linkage });
32 }
33 }
34}30}
3531
36pub fn __tanh(x: f16) callconv(.C) f16 {32pub fn __tanh(x: f16) callconv(.C) f16 {
...@@ -116,10 +112,6 @@ pub fn tanq(x: f128) callconv(.C) f128 {...@@ -116,10 +112,6 @@ pub fn tanq(x: f128) callconv(.C) f128 {
116 return tan(@floatCast(f64, x));112 return tan(@floatCast(f64, x));
117}113}
118114
119pub fn tanf128(x: f128) callconv(.C) f128 {
120 return @call(.{ .modifier = .always_inline }, tanq, .{x});
121}
122
123pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {115pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {
124 switch (@typeInfo(c_longdouble).Float.bits) {116 switch (@typeInfo(c_longdouble).Float.bits) {
125 16 => return __tanh(x),117 16 => return __tanh(x),
lib/compiler_rt/trunc.zig+16-24
...@@ -1,30 +1,26 @@...@@ -1,30 +1,26 @@
1// Ported from musl, which is licensed under the MIT license:1//! Ported from musl, which is MIT licensed.
2// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT2//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3//3//!
4// https://git.musl-libc.org/cgit/musl/tree/src/math/truncf.c4//! https://git.musl-libc.org/cgit/musl/tree/src/math/truncf.c
5// https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c5//! https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
9const arch = builtin.cpu.arch;
9const math = std.math;10const math = std.math;
10const expect = std.testing.expect;11const expect = std.testing.expect;
11const arch = builtin.cpu.arch;12const common = @import("common.zig");
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;13
13pub const panic = @import("common.zig").panic;14pub const panic = common.panic;
1415
15comptime {16comptime {
16 @export(__trunch, .{ .name = "__trunch", .linkage = linkage });17 @export(__trunch, .{ .name = "__trunch", .linkage = common.linkage });
17 @export(truncf, .{ .name = "truncf", .linkage = linkage });18 @export(truncf, .{ .name = "truncf", .linkage = common.linkage });
18 @export(trunc, .{ .name = "trunc", .linkage = linkage });19 @export(trunc, .{ .name = "trunc", .linkage = common.linkage });
19 @export(__truncx, .{ .name = "__truncx", .linkage = linkage });20 @export(__truncx, .{ .name = "__truncx", .linkage = common.linkage });
20 @export(truncq, .{ .name = "truncq", .linkage = linkage });21 const truncq_sym_name = if (common.want_ppc_abi) "truncf128" else "truncq";
21 @export(truncl, .{ .name = "truncl", .linkage = linkage });22 @export(truncq, .{ .name = truncq_sym_name, .linkage = common.linkage });
2223 @export(truncl, .{ .name = "truncl", .linkage = common.linkage });
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(truncf128, .{ .name = "truncf128", .linkage = linkage });
26 }
27 }
28}24}
2925
30pub fn __trunch(x: f16) callconv(.C) f16 {26pub fn __trunch(x: f16) callconv(.C) f16 {
...@@ -100,10 +96,6 @@ pub fn truncq(x: f128) callconv(.C) f128 {...@@ -100,10 +96,6 @@ pub fn truncq(x: f128) callconv(.C) f128 {
100 }96 }
101}97}
10298
103pub fn truncf128(x: f128) callconv(.C) f128 {
104 return @call(.{ .modifier = .always_inline }, truncq, .{x});
105}
106
107pub fn truncl(x: c_longdouble) callconv(.C) c_longdouble {99pub fn truncl(x: c_longdouble) callconv(.C) c_longdouble {
108 switch (@typeInfo(c_longdouble).Float.bits) {100 switch (@typeInfo(c_longdouble).Float.bits) {
109 16 => return __trunch(x),101 16 => return __trunch(x),
lib/compiler_rt/udivmodti4.zig+8-9
...@@ -2,36 +2,35 @@ const std = @import("std");...@@ -2,36 +2,35 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const udivmod = @import("udivmod.zig").udivmod;3const udivmod = @import("udivmod.zig").udivmod;
4const arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;5const common = @import("common.zig");
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;6
7pub const panic = @import("common.zig").panic;7pub const panic = common.panic;
88
9comptime {9comptime {
10 if (builtin.os.tag == .windows) {10 if (builtin.os.tag == .windows) {
11 switch (arch) {11 switch (arch) {
12 .i386 => {12 .i386 => {
13 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });13 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = common.linkage });
14 },14 },
15 .x86_64 => {15 .x86_64 => {
16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
17 // that LLVM expects compiler-rt to have.17 // 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 });
19 },19 },
20 else => {},20 else => {},
21 }21 }
22 } else {22 } else {
23 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });23 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = common.linkage });
24 }24 }
25}25}
2626
27pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {27pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {
28 @setRuntimeSafety(builtin.is_test);
29 return udivmod(u128, a, b, maybe_rem);28 return udivmod(u128, a, b, maybe_rem);
30}29}
3130
32const v128 = std.meta.Vector(2, u64);31const v128 = std.meta.Vector(2, u64);
33pub fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {32
34 @setRuntimeSafety(builtin.is_test);33fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {
35 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));34 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));
36}35}
3736
lib/compiler_rt/udivti3.zig+9-10
...@@ -2,38 +2,37 @@ const std = @import("std");...@@ -2,38 +2,37 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const udivmod = @import("udivmod.zig").udivmod;3const udivmod = @import("udivmod.zig").udivmod;
4const arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;5const common = @import("common.zig");
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;6
7pub const panic = @import("common.zig").panic;7pub const panic = common.panic;
88
9comptime {9comptime {
10 if (builtin.os.tag == .windows) {10 if (builtin.os.tag == .windows) {
11 switch (arch) {11 switch (arch) {
12 .i386 => {12 .i386 => {
13 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });13 @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
14 },14 },
15 .x86_64 => {15 .x86_64 => {
16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
17 // that LLVM expects compiler-rt to have.17 // 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 });
19 },19 },
20 else => {},20 else => {},
21 }21 }
22 if (arch.isAARCH64()) {22 if (arch.isAARCH64()) {
23 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });23 @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
24 }24 }
25 } else {25 } else {
26 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });26 @export(__udivti3, .{ .name = "__udivti3", .linkage = common.linkage });
27 }27 }
28}28}
2929
30pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {30pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {
31 @setRuntimeSafety(builtin.is_test);
32 return udivmod(u128, a, b, null);31 return udivmod(u128, a, b, null);
33}32}
3433
35const v128 = std.meta.Vector(2, u64);34const v128 = std.meta.Vector(2, u64);
36pub fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {35
37 @setRuntimeSafety(builtin.is_test);36fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
38 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), null));37 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), null));
39}38}
lib/compiler_rt/umodti3.zig+12-13
...@@ -2,42 +2,41 @@ const std = @import("std");...@@ -2,42 +2,41 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const udivmod = @import("udivmod.zig").udivmod;3const udivmod = @import("udivmod.zig").udivmod;
4const arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;5const common = @import("common.zig");
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;6
7pub const panic = @import("common.zig").panic;7pub const panic = common.panic;
88
9comptime {9comptime {
10 if (builtin.os.tag == .windows) {10 if (builtin.os.tag == .windows) {
11 switch (arch) {11 switch (arch) {
12 .i386 => {12 .i386 => {
13 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });13 @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
14 },14 },
15 .x86_64 => {15 .x86_64 => {
16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
17 // that LLVM expects compiler-rt to have.17 // 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 });
19 },19 },
20 else => {},20 else => {},
21 }21 }
22 if (arch.isAARCH64()) {22 if (arch.isAARCH64()) {
23 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });23 @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
24 }24 }
25 } else {25 } else {
26 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });26 @export(__umodti3, .{ .name = "__umodti3", .linkage = common.linkage });
27 }27 }
28}28}
2929
30pub fn __umodti3(a: u128, b: u128) callconv(.C) u128 {30pub fn __umodti3(a: u128, b: u128) callconv(.C) u128 {
31 @setRuntimeSafety(builtin.is_test);
32 var r: u128 = undefined;31 var r: u128 = undefined;
33 _ = udivmod(u128, a, b, &r);32 _ = udivmod(u128, a, b, &r);
34 return r;33 return r;
35}34}
3635
37const v128 = std.meta.Vector(2, u64);36const v128 = std.meta.Vector(2, u64);
38pub fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {37
39 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __umodti3, .{38fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
40 @bitCast(u128, a),39 var r: u128 = undefined;
41 @bitCast(u128, b),40 _ = udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), &r);
42 }));41 return @bitCast(v128, r);
43}42}