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;
1010const common = @import("common.zig");
1111const udivmod = @import("udivmod.zig").udivmod;
1212const __divti3 = @import("divti3.zig").__divti3;
13const arm = @import("arm.zig");
1413
1514pub const panic = common.panic;
1615
......@@ -102,25 +101,6 @@ test "test_divmoddi4" {
102101 }
103102}
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
124104pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {
125105 return udivmod(u64, a, b, maybe_rem);
126106}
......@@ -261,25 +241,6 @@ test "test_divmodsi4" {
261241 }
262242}
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
283244pub fn __udivmodsi4(a: u32, b: u32, rem: *u32) callconv(.C) u32 {
284245 const d = __udivsi3(a, b);
285246 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 @@
33const testing = @import("std").testing;
44const builtin = @import("builtin");
55const __udivmoddi4 = @import("int.zig").__udivmoddi4;
6const __aeabi_uldivmod = @import("arm.zig").__aeabi_uldivmod;
76
87fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
98 var r: u64 = undefined;
......@@ -18,26 +17,6 @@ test "udivmoddi4" {
1817 }
1918}
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
4120const cases = [_][4]u64{
4221 [_]u64{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},
4322 [_]u64{0x0000000000000000, 0x0000000000000002, 0x0000000000000000, 0x0000000000000000},
lib/compiler_rt/udivmodsi4_test.zig+8-17
......@@ -2,27 +2,18 @@
22// zig fmt: off
33const testing = @import("std").testing;
44const builtin = @import("builtin");
5const __aeabi_uidivmod = @import("arm.zig").__aeabi_uidivmod;
5const __udivmodsi4 = @import("int.zig").__udivmodsi4;
66
7const ARMRes = extern struct {
8 q: u32, // r0
9 r: u32, // r1
10};
11
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);
7fn test__udivmodsi4(a: u32, b: u32, expected_q: u32, expected_r: u32) !void {
8 var r: u32 = undefined;
9 const q = __udivmodsi4(a, b, &r);
10 try testing.expectEqual(expected_q, q);
11 try testing.expectEqual(expected_r, r);
1712}
1813
19test "arm.__aeabi_uidivmod" {
20 if (!builtin.cpu.arch.isARM()) return error.SkipZigTest;
21
22 var i: i32 = 0;
14test "udivmodsi4" {
2315 for (cases) |case| {
24 try test__aeabi_uidivmod(case[0], case[1], case[2], case[3]);
25 i+=1;
16 try test__udivmodsi4(case[0], case[1], case[2], case[3]);
2617 }
2718}
2819