authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-16 17:13:25+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-10-19 19:44:53+01:00
logcf39652500df07d33470d89ba96a97463beff986
tree47ba5af734da1fb6889b85adf871f869a696e962
parent289b2f82c3026ef17047dbe565693b15e2b84c81
signaturelock-open Commit is signed but in an unrecognized format.

compiler_rt: remove bogus tests

These only worked before because our lowering of the `AAPCS` calling convention was incorrect in a way which happened to match the ABI of these functions. The tests aren't actually very helpful -- there are already tests for `divmoddi4` etc -- so rather than using inline asm on the caller side to match the ABI, we just delete these two tests. We were for some reason missing a direct test for `__udivmodsi4`, so one has been added.

3 files changed, 8 insertions(+), 77 deletions(-)

lib/compiler_rt/int.zig-39
...@@ -10,7 +10,6 @@ const is_test = builtin.is_test;...@@ -10,7 +10,6 @@ const is_test = builtin.is_test;
10const common = @import("common.zig");10const common = @import("common.zig");
11const udivmod = @import("udivmod.zig").udivmod;11const udivmod = @import("udivmod.zig").udivmod;
12const __divti3 = @import("divti3.zig").__divti3;12const __divti3 = @import("divti3.zig").__divti3;
13const arm = @import("arm.zig");
1413
15pub const panic = common.panic;14pub const panic = common.panic;
1615
...@@ -102,25 +101,6 @@ test "test_divmoddi4" {...@@ -102,25 +101,6 @@ test "test_divmoddi4" {
102 }101 }
103}102}
104103
105fn test_one_aeabi_ldivmod(a: i64, b: i64, expected_q: i64, expected_r: i64) !void {
106 const LdivmodRes = extern struct {
107 q: i64, // r1:r0
108 r: i64, // r3:r2
109 };
110 const actualIdivmod = @as(*const fn (a: i64, b: i64) callconv(.AAPCS) LdivmodRes, @ptrCast(&arm.__aeabi_ldivmod));
111 const arm_res = actualIdivmod(a, b);
112 try testing.expectEqual(expected_q, arm_res.q);
113 try testing.expectEqual(expected_r, arm_res.r);
114}
115
116test "arm.__aeabi_ldivmod" {
117 if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;
118
119 for (cases__divmodsi4) |case| {
120 try test_one_aeabi_ldivmod(case[0], case[1], case[2], case[3]);
121 }
122}
123
124pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {104pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {
125 return udivmod(u64, a, b, maybe_rem);105 return udivmod(u64, a, b, maybe_rem);
126}106}
...@@ -261,25 +241,6 @@ test "test_divmodsi4" {...@@ -261,25 +241,6 @@ test "test_divmodsi4" {
261 }241 }
262}242}
263243
264fn test_one_aeabi_idivmod(a: i32, b: i32, expected_q: i32, expected_r: i32) !void {
265 const IdivmodRes = extern struct {
266 q: i32, // r0
267 r: i32, // r1
268 };
269 const actualIdivmod = @as(*const fn (a: i32, b: i32) callconv(.AAPCS) IdivmodRes, @ptrCast(&arm.__aeabi_idivmod));
270 const arm_res = actualIdivmod(a, b);
271 try testing.expectEqual(expected_q, arm_res.q);
272 try testing.expectEqual(expected_r, arm_res.r);
273}
274
275test "arm.__aeabi_idivmod" {
276 if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;
277
278 for (cases__divmodsi4) |case| {
279 try test_one_aeabi_idivmod(case[0], case[1], case[2], case[3]);
280 }
281}
282
283pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {244pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
284 const d = __udivsi3(a, b);245 const d = __udivsi3(a, b);
285 rem.* = @bitCast(@as(i32, @bitCast(a)) -% (@as(i32, @bitCast(d)) * @as(i32, @bitCast(b))));246 rem.* = @bitCast(@as(i32, @bitCast(a)) -% (@as(i32, @bitCast(d)) * @as(i32, @bitCast(b))));
lib/compiler_rt/udivmoddi4_test.zig-21
...@@ -3,7 +3,6 @@...@@ -3,7 +3,6 @@
3const testing = @import("std").testing;3const testing = @import("std").testing;
4const builtin = @import("builtin");4const builtin = @import("builtin");
5const __udivmoddi4 = @import("int.zig").__udivmoddi4;5const __udivmoddi4 = @import("int.zig").__udivmoddi4;
6const __aeabi_uldivmod = @import("arm.zig").__aeabi_uldivmod;
76
8fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {7fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
9 var r: u64 = undefined;8 var r: u64 = undefined;
...@@ -18,26 +17,6 @@ test "udivmoddi4" {...@@ -18,26 +17,6 @@ test "udivmoddi4" {
18 }17 }
19}18}
2019
21const ARMRes = extern struct {
22 q: u64, // r1:r0
23 r: u64, // r3:r2
24};
25
26fn test__aeabi_uldivmod(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
27 const actualUldivmod = @as(*const fn (a: u64, b: u64) callconv(.AAPCS) ARMRes, @ptrCast(&__aeabi_uldivmod));
28 const arm_res = actualUldivmod(a, b);
29 try testing.expectEqual(expected_q, arm_res.q);
30 try testing.expectEqual(expected_r, arm_res.r);
31}
32
33test "arm.__aeabi_uldivmod" {
34 if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;
35
36 for (cases) |case| {
37 try test__aeabi_uldivmod(case[0], case[1], case[2], case[3]);
38 }
39}
40
41const cases = [_][4]u64{20const cases = [_][4]u64{
42 [_]u64{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},21 [_]u64{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},
43 [_]u64{0x0000000000000000, 0x0000000000000002, 0x0000000000000000, 0x0000000000000000},22 [_]u64{0x0000000000000000, 0x0000000000000002, 0x0000000000000000, 0x0000000000000000},
lib/compiler_rt/udivmodsi4_test.zig+8-17
...@@ -2,27 +2,18 @@...@@ -2,27 +2,18 @@
2// zig fmt: off2// zig fmt: off
3const testing = @import("std").testing;3const testing = @import("std").testing;
4const builtin = @import("builtin");4const builtin = @import("builtin");
5const __aeabi_uidivmod = @import("arm.zig").__aeabi_uidivmod;5const __udivmodsi4 = @import("int.zig").__udivmodsi4;
66
7const ARMRes = extern struct {7fn test__udivmodsi4(a: u32, b: u32, expected_q: u32, expected_r: u32) !void {
8 q: u32, // r08 var r: u32 = undefined;
9 r: u32, // r19 const q = __udivmodsi4(a, b, &r);
10};10 try testing.expectEqual(expected_q, q);
1111 try testing.expectEqual(expected_r, r);
12fn test__aeabi_uidivmod(a: u32, b: u32, expected_q: u32, expected_r: u32) !void {
13 const actualUidivmod = @as(*const fn (a: u32, b: u32) callconv(.AAPCS) ARMRes, @ptrCast(&__aeabi_uidivmod));
14 const arm_res = actualUidivmod(a, b);
15 try testing.expectEqual(expected_q, arm_res.q);
16 try testing.expectEqual(expected_r, arm_res.r);
17}12}
1813
19test "arm.__aeabi_uidivmod" {14test "udivmodsi4" {
20 if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;
21
22 var i: i32 = 0;
23 for (cases) |case| {15 for (cases) |case| {
24 try test__aeabi_uidivmod(case[0], case[1], case[2], case[3]);16 try test__udivmodsi4(case[0], case[1], case[2], case[3]);
25 i+=1;
26 }17 }
27}18}
2819