authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-18 23:37:13+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-19 00:12:25+01:00
log6b056d1fb93bba68c03bda5039994d4df338ef13
treea55fe4549eb562f3bb9e66e1c0a6878120af7482
parent7d94e712f125e10f234338e800953aa4837206ef

Nuke some repeated code


5 files changed, 227 insertions(+), 379 deletions(-)

lib/std/special/compiler_rt.zig+26-26
...@@ -16,42 +16,42 @@ comptime {...@@ -16,42 +16,42 @@ comptime {
16 else => {},16 else => {},
17 }17 }
1818
19 @export(@import("compiler_rt/comparesf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage });19 @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage });
20 @export(@import("compiler_rt/comparedf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage });20 @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage });
21 @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage });21 @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage });
2222
23 @export(@import("compiler_rt/comparesf2.zig").__gesf2, .{ .name = "__gesf2", .linkage = linkage });23 @export(@import("compiler_rt/compareXf2.zig").__gesf2, .{ .name = "__gesf2", .linkage = linkage });
24 @export(@import("compiler_rt/comparedf2.zig").__gedf2, .{ .name = "__gedf2", .linkage = linkage });24 @export(@import("compiler_rt/compareXf2.zig").__gedf2, .{ .name = "__gedf2", .linkage = linkage });
25 @export(@import("compiler_rt/comparetf2.zig").__getf2, .{ .name = "__getf2", .linkage = linkage });25 @export(@import("compiler_rt/compareXf2.zig").__getf2, .{ .name = "__getf2", .linkage = linkage });
2626
27 if (!is_test) {27 if (!is_test) {
28 @export(@import("compiler_rt/comparesf2.zig").__lesf2, .{ .name = "__cmpsf2", .linkage = linkage });28 @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__cmpsf2", .linkage = linkage });
29 @export(@import("compiler_rt/comparedf2.zig").__ledf2, .{ .name = "__cmpdf2", .linkage = linkage });29 @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__cmpdf2", .linkage = linkage });
30 @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__cmptf2", .linkage = linkage });30 @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__cmptf2", .linkage = linkage });
3131
32 @export(@import("compiler_rt/comparesf2.zig").__eqsf2, .{ .name = "__eqsf2", .linkage = linkage });32 @export(@import("compiler_rt/compareXf2.zig").__eqsf2, .{ .name = "__eqsf2", .linkage = linkage });
33 @export(@import("compiler_rt/comparedf2.zig").__eqdf2, .{ .name = "__eqdf2", .linkage = linkage });33 @export(@import("compiler_rt/compareXf2.zig").__eqdf2, .{ .name = "__eqdf2", .linkage = linkage });
34 @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__eqtf2", .linkage = linkage });34 @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__eqtf2", .linkage = linkage });
3535
36 @export(@import("compiler_rt/comparesf2.zig").__ltsf2, .{ .name = "__ltsf2", .linkage = linkage });36 @export(@import("compiler_rt/compareXf2.zig").__ltsf2, .{ .name = "__ltsf2", .linkage = linkage });
37 @export(@import("compiler_rt/comparedf2.zig").__ltdf2, .{ .name = "__ltdf2", .linkage = linkage });37 @export(@import("compiler_rt/compareXf2.zig").__ltdf2, .{ .name = "__ltdf2", .linkage = linkage });
38 @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__lttf2", .linkage = linkage });38 @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__lttf2", .linkage = linkage });
3939
40 @export(@import("compiler_rt/comparesf2.zig").__nesf2, .{ .name = "__nesf2", .linkage = linkage });40 @export(@import("compiler_rt/compareXf2.zig").__nesf2, .{ .name = "__nesf2", .linkage = linkage });
41 @export(@import("compiler_rt/comparedf2.zig").__nedf2, .{ .name = "__nedf2", .linkage = linkage });41 @export(@import("compiler_rt/compareXf2.zig").__nedf2, .{ .name = "__nedf2", .linkage = linkage });
42 @export(@import("compiler_rt/comparetf2.zig").__letf2, .{ .name = "__netf2", .linkage = linkage });42 @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__netf2", .linkage = linkage });
4343
44 @export(@import("compiler_rt/comparesf2.zig").__gtsf2, .{ .name = "__gtsf2", .linkage = linkage });44 @export(@import("compiler_rt/compareXf2.zig").__gtsf2, .{ .name = "__gtsf2", .linkage = linkage });
45 @export(@import("compiler_rt/comparedf2.zig").__gtdf2, .{ .name = "__gtdf2", .linkage = linkage });45 @export(@import("compiler_rt/compareXf2.zig").__gtdf2, .{ .name = "__gtdf2", .linkage = linkage });
46 @export(@import("compiler_rt/comparetf2.zig").__getf2, .{ .name = "__gttf2", .linkage = linkage });46 @export(@import("compiler_rt/compareXf2.zig").__getf2, .{ .name = "__gttf2", .linkage = linkage });
4747
48 @export(@import("compiler_rt/extendXfYf2.zig").__extendhfsf2, .{ .name = "__gnu_h2f_ieee", .linkage = linkage });48 @export(@import("compiler_rt/extendXfYf2.zig").__extendhfsf2, .{ .name = "__gnu_h2f_ieee", .linkage = linkage });
49 @export(@import("compiler_rt/truncXfYf2.zig").__truncsfhf2, .{ .name = "__gnu_f2h_ieee", .linkage = linkage });49 @export(@import("compiler_rt/truncXfYf2.zig").__truncsfhf2, .{ .name = "__gnu_f2h_ieee", .linkage = linkage });
50 }50 }
5151
52 @export(@import("compiler_rt/comparesf2.zig").__unordsf2, .{ .name = "__unordsf2", .linkage = linkage });52 @export(@import("compiler_rt/compareXf2.zig").__unordsf2, .{ .name = "__unordsf2", .linkage = linkage });
53 @export(@import("compiler_rt/comparedf2.zig").__unorddf2, .{ .name = "__unorddf2", .linkage = linkage });53 @export(@import("compiler_rt/compareXf2.zig").__unorddf2, .{ .name = "__unorddf2", .linkage = linkage });
54 @export(@import("compiler_rt/comparetf2.zig").__unordtf2, .{ .name = "__unordtf2", .linkage = linkage });54 @export(@import("compiler_rt/compareXf2.zig").__unordtf2, .{ .name = "__unordtf2", .linkage = linkage });
5555
56 @export(@import("compiler_rt/addXf3.zig").__addsf3, .{ .name = "__addsf3", .linkage = linkage });56 @export(@import("compiler_rt/addXf3.zig").__addsf3, .{ .name = "__addsf3", .linkage = linkage });
57 @export(@import("compiler_rt/addXf3.zig").__adddf3, .{ .name = "__adddf3", .linkage = linkage });57 @export(@import("compiler_rt/addXf3.zig").__adddf3, .{ .name = "__adddf3", .linkage = linkage });
...@@ -231,14 +231,14 @@ comptime {...@@ -231,14 +231,14 @@ comptime {
231 @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage });231 @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage });
232 @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage });232 @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage });
233 @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage });233 @export(@import("compiler_rt/arm/aeabi_fcmp.zig").__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage });
234 @export(@import("compiler_rt/comparesf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage });234 @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage });
235235
236 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage });236 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage });
237 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage });237 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage });
238 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage });238 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage });
239 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage });239 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage });
240 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage });240 @export(@import("compiler_rt/arm/aeabi_dcmp.zig").__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage });
241 @export(@import("compiler_rt/comparedf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });241 @export(@import("compiler_rt/compareXf2.zig").__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });
242 }242 }
243 if (builtin.os == .windows) {243 if (builtin.os == .windows) {
244 // Default stack-probe functions emitted by LLVM244 // Default stack-probe functions emitted by LLVM
lib/std/special/compiler_rt/compareXf2.zig created+201
...@@ -0,0 +1,201 @@
1// Ported from:
2//
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparesf2.c
4
5const std = @import("std");
6const builtin = @import("builtin");
7
8const LE = extern enum(i32) {
9 Less = -1,
10 Equal = 0,
11 Greater = 1,
12 Unordered = 1,
13};
14
15const GE = extern enum(i32) {
16 Less = -1,
17 Equal = 0,
18 Greater = 1,
19 Unordered = -1,
20};
21
22pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
23 @setRuntimeSafety(builtin.is_test);
24
25 const srep_t = @IntType(true, T.bit_count);
26 const rep_t = @IntType(false, T.bit_count);
27
28 const significandBits = std.math.floatMantissaBits(T);
29 const exponentBits = std.math.floatExponentBits(T);
30 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
31 const absMask = signBit - 1;
32 const infRep = @bitCast(rep_t, std.math.inf(T));
33
34 const aInt = @bitCast(srep_t, a);
35 const bInt = @bitCast(srep_t, b);
36 const aAbs = @bitCast(rep_t, aInt) & absMask;
37 const bAbs = @bitCast(rep_t, bInt) & absMask;
38
39 // If either a or b is NaN, they are unordered.
40 if (aAbs > infRep or bAbs > infRep) return .Unordered;
41
42 // If a and b are both zeros, they are equal.
43 if ((aAbs | bAbs) == 0) return .Equal;
44
45 // If at least one of a and b is positive, we get the same result comparing
46 // a and b as signed integers as we would with a fp_ting-point compare.
47 if ((aInt & bInt) >= 0) {
48 if (aInt < bInt) {
49 return .Less;
50 } else if (aInt == bInt) {
51 return .Equal;
52 } else return .Greater;
53 }
54
55 // Otherwise, both are negative, so we need to flip the sense of the
56 // comparison to get the correct result. (This assumes a twos- or ones-
57 // complement integer representation; if integers are represented in a
58 // sign-magnitude representation, then this flip is incorrect).
59 else {
60 if (aInt > bInt) {
61 return .Less;
62 } else if (aInt == bInt) {
63 return .Equal;
64 } else return .Greater;
65 }
66}
67
68pub fn unordcmp(comptime T: type, a: T, b: T) i32 {
69 @setRuntimeSafety(builtin.is_test);
70
71 const rep_t = @IntType(false, T.bit_count);
72
73 const significandBits = std.math.floatMantissaBits(T);
74 const exponentBits = std.math.floatExponentBits(T);
75 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
76 const absMask = signBit - 1;
77 const infRep = @bitCast(rep_t, std.math.inf(T));
78
79 const aAbs: rep_t = @bitCast(rep_t, a) & absMask;
80 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;
81
82 return @boolToInt(aAbs > infRep or bAbs > infRep);
83}
84
85// Comparison between f32
86
87pub fn __lesf2(a: f32, b: f32) callconv(.C) i32 {
88 @setRuntimeSafety(builtin.is_test);
89 return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f32, LE, a, b }));
90}
91
92pub fn __gesf2(a: f32, b: f32) callconv(.C) i32 {
93 @setRuntimeSafety(builtin.is_test);
94 return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f32, GE, a, b }));
95}
96
97pub fn __eqsf2(a: f32, b: f32) callconv(.C) i32 {
98 return __lesf2(a, b);
99}
100
101pub fn __ltsf2(a: f32, b: f32) callconv(.C) i32 {
102 return __lesf2(a, b);
103}
104
105pub fn __nesf2(a: f32, b: f32) callconv(.C) i32 {
106 return __lesf2(a, b);
107}
108
109pub fn __gtsf2(a: f32, b: f32) callconv(.C) i32 {
110 return __gesf2(a, b);
111}
112
113// Comparison between f64
114
115pub fn __ledf2(a: f64, b: f64) callconv(.C) i32 {
116 @setRuntimeSafety(builtin.is_test);
117 return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f64, LE, a, b }));
118}
119
120pub fn __gedf2(a: f64, b: f64) callconv(.C) i32 {
121 @setRuntimeSafety(builtin.is_test);
122 return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f64, GE, a, b }));
123}
124
125pub fn __eqdf2(a: f64, b: f64) callconv(.C) i32 {
126 return __ledf2(a, b);
127}
128
129pub fn __ltdf2(a: f64, b: f64) callconv(.C) i32 {
130 return __ledf2(a, b);
131}
132
133pub fn __nedf2(a: f64, b: f64) callconv(.C) i32 {
134 return __ledf2(a, b);
135}
136
137pub fn __gtdf2(a: f64, b: f64) callconv(.C) i32 {
138 return __gedf2(a, b);
139}
140
141// Comparison between f128
142
143pub fn __letf2(a: f128, b: f128) callconv(.C) i32 {
144 @setRuntimeSafety(builtin.is_test);
145 return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f128, LE, a, b }));
146}
147
148pub fn __getf2(a: f128, b: f128) callconv(.C) i32 {
149 @setRuntimeSafety(builtin.is_test);
150 return @bitCast(i32, @call(.{ .modifier = .always_inline }, cmp, .{ f128, GE, a, b }));
151}
152
153pub fn __eqtf2(a: f128, b: f128) callconv(.C) i32 {
154 return __letf2(a, b);
155}
156
157pub fn __lttf2(a: f128, b: f128) callconv(.C) i32 {
158 return __letf2(a, b);
159}
160
161pub fn __netf2(a: f128, b: f128) callconv(.C) i32 {
162 return __letf2(a, b);
163}
164
165pub fn __gttf2(a: f128, b: f128) callconv(.C) i32 {
166 return __getf2(a, b);
167}
168
169// Unordered comparison between f32/f64/f128
170
171pub fn __unordsf2(a: f32, b: f32) callconv(.C) i32 {
172 @setRuntimeSafety(builtin.is_test);
173 return @call(.{ .modifier = .always_inline }, unordcmp, .{ f32, a, b });
174}
175
176pub fn __unorddf2(a: f64, b: f64) callconv(.C) i32 {
177 @setRuntimeSafety(builtin.is_test);
178 return @call(.{ .modifier = .always_inline }, unordcmp, .{ f64, a, b });
179}
180
181pub fn __unordtf2(a: f128, b: f128) callconv(.C) i32 {
182 @setRuntimeSafety(builtin.is_test);
183 return @call(.{ .modifier = .always_inline }, unordcmp, .{ f128, a, b });
184}
185
186pub fn __aeabi_fcmpun(a: f32, b: f32) callconv(.AAPCS) i32 {
187 @setRuntimeSafety(false);
188 return @call(.{ .modifier = .always_inline }, __unordsf2, .{ a, b });
189}
190
191pub fn __aeabi_dcmpun(a: f64, b: f64) callconv(.AAPCS) i32 {
192 @setRuntimeSafety(false);
193 return @call(.{ .modifier = .always_inline }, __unorddf2, .{ a, b });
194}
195
196test "comparesf2" {
197 _ = @import("comparesf2_test.zig");
198}
199test "comparedf2" {
200 _ = @import("comparedf2_test.zig");
201}
lib/std/special/compiler_rt/comparedf2.zig deleted-127
...@@ -1,127 +0,0 @@
1// Ported from:
2//
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparedf2.c
4
5const std = @import("std");
6const builtin = @import("builtin");
7const is_test = builtin.is_test;
8
9const fp_t = f64;
10const rep_t = u64;
11const srep_t = i64;
12
13const typeWidth = rep_t.bit_count;
14const significandBits = std.math.floatMantissaBits(fp_t);
15const exponentBits = std.math.floatExponentBits(fp_t);
16const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
17const absMask = signBit - 1;
18const implicitBit = @as(rep_t, 1) << significandBits;
19const significandMask = implicitBit - 1;
20const exponentMask = absMask ^ significandMask;
21const infRep = @bitCast(rep_t, std.math.inf(fp_t));
22
23// TODO https://github.com/ziglang/zig/issues/641
24// and then make the return types of some of these functions the enum instead of c_int
25const LE_LESS = @as(c_int, -1);
26const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = @as(c_int, 1);
29
30pub fn __ledf2(a: fp_t, b: fp_t) callconv(.C) c_int {
31 @setRuntimeSafety(is_test);
32 const aInt: srep_t = @bitCast(srep_t, a);
33 const bInt: srep_t = @bitCast(srep_t, b);
34 const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask;
35 const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask;
36
37 // If either a or b is NaN, they are unordered.
38 if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED;
39
40 // If a and b are both zeros, they are equal.
41 if ((aAbs | bAbs) == 0) return LE_EQUAL;
42
43 // If at least one of a and b is positive, we get the same result comparing
44 // a and b as signed integers as we would with a fp_ting-point compare.
45 if ((aInt & bInt) >= 0) {
46 if (aInt < bInt) {
47 return LE_LESS;
48 } else if (aInt == bInt) {
49 return LE_EQUAL;
50 } else return LE_GREATER;
51 }
52
53 // Otherwise, both are negative, so we need to flip the sense of the
54 // comparison to get the correct result. (This assumes a twos- or ones-
55 // complement integer representation; if integers are represented in a
56 // sign-magnitude representation, then this flip is incorrect).
57 else {
58 if (aInt > bInt) {
59 return LE_LESS;
60 } else if (aInt == bInt) {
61 return LE_EQUAL;
62 } else return LE_GREATER;
63 }
64}
65
66// TODO https://github.com/ziglang/zig/issues/641
67// and then make the return types of some of these functions the enum instead of c_int
68const GE_LESS = @as(c_int, -1);
69const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
72
73pub fn __gedf2(a: fp_t, b: fp_t) callconv(.C) c_int {
74 @setRuntimeSafety(is_test);
75 const aInt: srep_t = @bitCast(srep_t, a);
76 const bInt: srep_t = @bitCast(srep_t, b);
77 const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask;
78 const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask;
79
80 if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED;
81 if ((aAbs | bAbs) == 0) return GE_EQUAL;
82 if ((aInt & bInt) >= 0) {
83 if (aInt < bInt) {
84 return GE_LESS;
85 } else if (aInt == bInt) {
86 return GE_EQUAL;
87 } else return GE_GREATER;
88 } else {
89 if (aInt > bInt) {
90 return GE_LESS;
91 } else if (aInt == bInt) {
92 return GE_EQUAL;
93 } else return GE_GREATER;
94 }
95}
96
97pub fn __unorddf2(a: fp_t, b: fp_t) callconv(.C) c_int {
98 @setRuntimeSafety(is_test);
99 const aAbs: rep_t = @bitCast(rep_t, a) & absMask;
100 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;
101 return @boolToInt(aAbs > infRep or bAbs > infRep);
102}
103
104pub fn __eqdf2(a: fp_t, b: fp_t) callconv(.C) c_int {
105 return __ledf2(a, b);
106}
107
108pub fn __ltdf2(a: fp_t, b: fp_t) callconv(.C) c_int {
109 return __ledf2(a, b);
110}
111
112pub fn __nedf2(a: fp_t, b: fp_t) callconv(.C) c_int {
113 return __ledf2(a, b);
114}
115
116pub fn __gtdf2(a: fp_t, b: fp_t) callconv(.C) c_int {
117 return __gedf2(a, b);
118}
119
120pub fn __aeabi_dcmpun(a: fp_t, b: fp_t) callconv(.AAPCS) c_int {
121 @setRuntimeSafety(false);
122 return @call(.{ .modifier = .always_inline }, __unorddf2, .{ a, b });
123}
124
125test "import comparedf2" {
126 _ = @import("comparedf2_test.zig");
127}
lib/std/special/compiler_rt/comparesf2.zig deleted-127
...@@ -1,127 +0,0 @@
1// Ported from:
2//
3// https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/comparesf2.c
4
5const std = @import("std");
6const builtin = @import("builtin");
7const is_test = builtin.is_test;
8
9const fp_t = f32;
10const rep_t = u32;
11const srep_t = i32;
12
13const typeWidth = rep_t.bit_count;
14const significandBits = std.math.floatMantissaBits(fp_t);
15const exponentBits = std.math.floatExponentBits(fp_t);
16const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
17const absMask = signBit - 1;
18const implicitBit = @as(rep_t, 1) << significandBits;
19const significandMask = implicitBit - 1;
20const exponentMask = absMask ^ significandMask;
21const infRep = @bitCast(rep_t, std.math.inf(fp_t));
22
23// TODO https://github.com/ziglang/zig/issues/641
24// and then make the return types of some of these functions the enum instead of c_int
25const LE_LESS = @as(c_int, -1);
26const LE_EQUAL = @as(c_int, 0);
27const LE_GREATER = @as(c_int, 1);
28const LE_UNORDERED = @as(c_int, 1);
29
30pub fn __lesf2(a: fp_t, b: fp_t) callconv(.C) c_int {
31 @setRuntimeSafety(is_test);
32 const aInt: srep_t = @bitCast(srep_t, a);
33 const bInt: srep_t = @bitCast(srep_t, b);
34 const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask;
35 const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask;
36
37 // If either a or b is NaN, they are unordered.
38 if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED;
39
40 // If a and b are both zeros, they are equal.
41 if ((aAbs | bAbs) == 0) return LE_EQUAL;
42
43 // If at least one of a and b is positive, we get the same result comparing
44 // a and b as signed integers as we would with a fp_ting-point compare.
45 if ((aInt & bInt) >= 0) {
46 if (aInt < bInt) {
47 return LE_LESS;
48 } else if (aInt == bInt) {
49 return LE_EQUAL;
50 } else return LE_GREATER;
51 }
52
53 // Otherwise, both are negative, so we need to flip the sense of the
54 // comparison to get the correct result. (This assumes a twos- or ones-
55 // complement integer representation; if integers are represented in a
56 // sign-magnitude representation, then this flip is incorrect).
57 else {
58 if (aInt > bInt) {
59 return LE_LESS;
60 } else if (aInt == bInt) {
61 return LE_EQUAL;
62 } else return LE_GREATER;
63 }
64}
65
66// TODO https://github.com/ziglang/zig/issues/641
67// and then make the return types of some of these functions the enum instead of c_int
68const GE_LESS = @as(c_int, -1);
69const GE_EQUAL = @as(c_int, 0);
70const GE_GREATER = @as(c_int, 1);
71const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
72
73pub fn __gesf2(a: fp_t, b: fp_t) callconv(.C) c_int {
74 @setRuntimeSafety(is_test);
75 const aInt: srep_t = @bitCast(srep_t, a);
76 const bInt: srep_t = @bitCast(srep_t, b);
77 const aAbs: rep_t = @bitCast(rep_t, aInt) & absMask;
78 const bAbs: rep_t = @bitCast(rep_t, bInt) & absMask;
79
80 if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED;
81 if ((aAbs | bAbs) == 0) return GE_EQUAL;
82 if ((aInt & bInt) >= 0) {
83 if (aInt < bInt) {
84 return GE_LESS;
85 } else if (aInt == bInt) {
86 return GE_EQUAL;
87 } else return GE_GREATER;
88 } else {
89 if (aInt > bInt) {
90 return GE_LESS;
91 } else if (aInt == bInt) {
92 return GE_EQUAL;
93 } else return GE_GREATER;
94 }
95}
96
97pub fn __unordsf2(a: fp_t, b: fp_t) callconv(.C) c_int {
98 @setRuntimeSafety(is_test);
99 const aAbs: rep_t = @bitCast(rep_t, a) & absMask;
100 const bAbs: rep_t = @bitCast(rep_t, b) & absMask;
101 return @boolToInt(aAbs > infRep or bAbs > infRep);
102}
103
104pub fn __eqsf2(a: fp_t, b: fp_t) callconv(.C) c_int {
105 return __lesf2(a, b);
106}
107
108pub fn __ltsf2(a: fp_t, b: fp_t) callconv(.C) c_int {
109 return __lesf2(a, b);
110}
111
112pub fn __nesf2(a: fp_t, b: fp_t) callconv(.C) c_int {
113 return __lesf2(a, b);
114}
115
116pub fn __gtsf2(a: fp_t, b: fp_t) callconv(.C) c_int {
117 return __gesf2(a, b);
118}
119
120pub fn __aeabi_fcmpun(a: fp_t, b: fp_t) callconv(.AAPCS) c_int {
121 @setRuntimeSafety(false);
122 return @call(.{ .modifier = .always_inline }, __unordsf2, .{ a, b });
123}
124
125test "import comparesf2" {
126 _ = @import("comparesf2_test.zig");
127}
lib/std/special/compiler_rt/comparetf2.zig deleted-99
...@@ -1,99 +0,0 @@
1// TODO https://github.com/ziglang/zig/issues/641
2// and then make the return types of some of these functions the enum instead of c_int
3const LE_LESS = @as(c_int, -1);
4const LE_EQUAL = @as(c_int, 0);
5const LE_GREATER = @as(c_int, 1);
6const LE_UNORDERED = @as(c_int, 1);
7
8const rep_t = u128;
9const srep_t = i128;
10
11const typeWidth = rep_t.bit_count;
12const significandBits = 112;
13const exponentBits = (typeWidth - significandBits - 1);
14const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
15const absMask = signBit - 1;
16const implicitBit = @as(rep_t, 1) << significandBits;
17const significandMask = implicitBit - 1;
18const exponentMask = absMask ^ significandMask;
19const infRep = exponentMask;
20
21const builtin = @import("builtin");
22const is_test = builtin.is_test;
23
24pub fn __letf2(a: f128, b: f128) callconv(.C) c_int {
25 @setRuntimeSafety(is_test);
26
27 const aInt = @bitCast(rep_t, a);
28 const bInt = @bitCast(rep_t, b);
29
30 const aAbs: rep_t = aInt & absMask;
31 const bAbs: rep_t = bInt & absMask;
32
33 // If either a or b is NaN, they are unordered.
34 if (aAbs > infRep or bAbs > infRep) return LE_UNORDERED;
35
36 // If a and b are both zeros, they are equal.
37 if ((aAbs | bAbs) == 0) return LE_EQUAL;
38
39 // If at least one of a and b is positive, we get the same result comparing
40 // a and b as signed integers as we would with a floating-point compare.
41 return if ((aInt & bInt) >= 0)
42 if (aInt < bInt)
43 LE_LESS
44 else if (aInt == bInt)
45 LE_EQUAL
46 else
47 LE_GREATER
48 else
49 // Otherwise, both are negative, so we need to flip the sense of the
50 // comparison to get the correct result. (This assumes a twos- or ones-
51 // complement integer representation; if integers are represented in a
52 // sign-magnitude representation, then this flip is incorrect).
53 if (aInt > bInt)
54 LE_LESS
55 else if (aInt == bInt)
56 LE_EQUAL
57 else
58 LE_GREATER;
59}
60
61// TODO https://github.com/ziglang/zig/issues/641
62// and then make the return types of some of these functions the enum instead of c_int
63const GE_LESS = @as(c_int, -1);
64const GE_EQUAL = @as(c_int, 0);
65const GE_GREATER = @as(c_int, 1);
66const GE_UNORDERED = @as(c_int, -1); // Note: different from LE_UNORDERED
67
68pub fn __getf2(a: f128, b: f128) callconv(.C) c_int {
69 @setRuntimeSafety(is_test);
70
71 const aInt = @bitCast(srep_t, a);
72 const bInt = @bitCast(srep_t, b);
73 const aAbs = @bitCast(rep_t, aInt) & absMask;
74 const bAbs = @bitCast(rep_t, bInt) & absMask;
75
76 if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED;
77 if ((aAbs | bAbs) == 0) return GE_EQUAL;
78 return if ((aInt & bInt) >= 0)
79 if (aInt < bInt)
80 GE_LESS
81 else if (aInt == bInt)
82 GE_EQUAL
83 else
84 GE_GREATER
85 else if (aInt > bInt)
86 GE_LESS
87 else if (aInt == bInt)
88 GE_EQUAL
89 else
90 GE_GREATER;
91}
92
93pub fn __unordtf2(a: f128, b: f128) callconv(.C) c_int {
94 @setRuntimeSafety(is_test);
95
96 const aAbs = @bitCast(rep_t, a) & absMask;
97 const bAbs = @bitCast(rep_t, b) & absMask;
98 return @boolToInt(aAbs > infRep or bAbs > infRep);
99}