authorgravatar for bratishkaerik@getgoogleoff.meEric Joldasov <bratishkaerik@getgoogleoff.me> 2022-11-15 20:40:32+06:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-16 13:08:41+02:00
log684264908e50bc8537fc10859e93ccdf8d94509e
tree65c9efdc2f61264f945328914ff13d82074eb6ba
parenteed82ca287afb04261c94458efd624758bbc6669

compiler_rt: fix TODOs in udivmod.zig


3 files changed, 12 insertions(+), 12 deletions(-)

lib/compiler_rt/udivmod.zig+8-8
...@@ -18,8 +18,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -18,8 +18,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
18 const SignedDoubleInt = std.meta.Int(.signed, double_int_bits);18 const SignedDoubleInt = std.meta.Int(.signed, double_int_bits);
19 const Log2SingleInt = std.math.Log2Int(SingleInt);19 const Log2SingleInt = std.math.Log2Int(SingleInt);
2020
21 const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #42121 const n = @bitCast([2]SingleInt, a);
22 const d = @ptrCast(*const [2]SingleInt, &b).*; // TODO issue #42122 const d = @bitCast([2]SingleInt, b);
23 var q: [2]SingleInt = undefined;23 var q: [2]SingleInt = undefined;
24 var r: [2]SingleInt = undefined;24 var r: [2]SingleInt = undefined;
25 var sr: c_uint = undefined;25 var sr: c_uint = undefined;
...@@ -61,7 +61,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -61,7 +61,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
61 if (maybe_rem) |rem| {61 if (maybe_rem) |rem| {
62 r[high] = n[high] % d[high];62 r[high] = n[high] % d[high];
63 r[low] = 0;63 r[low] = 0;
64 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #42164 rem.* = @bitCast(DoubleInt, r);
65 }65 }
66 return n[high] / d[high];66 return n[high] / d[high];
67 }67 }
...@@ -73,7 +73,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -73,7 +73,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
73 if (maybe_rem) |rem| {73 if (maybe_rem) |rem| {
74 r[low] = n[low];74 r[low] = n[low];
75 r[high] = n[high] & (d[high] - 1);75 r[high] = n[high] & (d[high] - 1);
76 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #42176 rem.* = @bitCast(DoubleInt, r);
77 }77 }
78 return n[high] >> @intCast(Log2SingleInt, @ctz(d[high]));78 return n[high] >> @intCast(Log2SingleInt, @ctz(d[high]));
79 }79 }
...@@ -113,7 +113,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -113,7 +113,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
113 sr = @ctz(d[low]);113 sr = @ctz(d[low]);
114 q[high] = n[high] >> @intCast(Log2SingleInt, sr);114 q[high] = n[high] >> @intCast(Log2SingleInt, sr);
115 q[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));115 q[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
116 return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421116 return @bitCast(DoubleInt, q);
117 }117 }
118 // K X118 // K X
119 // ---119 // ---
...@@ -187,13 +187,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -187,13 +187,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
187 // r.all -= b;187 // r.all -= b;
188 // carry = 1;188 // carry = 1;
189 // }189 // }
190 r_all = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421190 r_all = @bitCast(DoubleInt, r);
191 const s: SignedDoubleInt = @bitCast(SignedDoubleInt, b -% r_all -% 1) >> (double_int_bits - 1);191 const s: SignedDoubleInt = @bitCast(SignedDoubleInt, b -% r_all -% 1) >> (double_int_bits - 1);
192 carry = @intCast(u32, s & 1);192 carry = @intCast(u32, s & 1);
193 r_all -= b & @bitCast(DoubleInt, s);193 r_all -= b & @bitCast(DoubleInt, s);
194 r = @ptrCast(*[2]SingleInt, &r_all).*; // TODO issue #421194 r = @bitCast([2]SingleInt, r_all);
195 }195 }
196 const q_all = ((@ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421196 const q_all = (@bitCast(DoubleInt, q) << 1) | carry;
197 if (maybe_rem) |rem| {197 if (maybe_rem) |rem| {
198 rem.* = r_all;198 rem.* = r_all;
199 }199 }
lib/compiler_rt/udivmoddi4_test.zig+2-2
...@@ -6,8 +6,8 @@ const testing = @import("std").testing;...@@ -6,8 +6,8 @@ const testing = @import("std").testing;
6fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {6fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
7 var r: u64 = undefined;7 var r: u64 = undefined;
8 const q = __udivmoddi4(a, b, &r);8 const q = __udivmoddi4(a, b, &r);
9 try testing.expect(q == expected_q);9 try testing.expectEqual(expected_q, q);
10 try testing.expect(r == expected_r);10 try testing.expectEqual(expected_r, r);
11}11}
1212
13test "udivmoddi4" {13test "udivmoddi4" {
lib/compiler_rt/udivmodti4_test.zig+2-2
...@@ -6,8 +6,8 @@ const testing = @import("std").testing;...@@ -6,8 +6,8 @@ const testing = @import("std").testing;
6fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) !void {6fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) !void {
7 var r: u128 = undefined;7 var r: u128 = undefined;
8 const q = __udivmodti4(a, b, &r);8 const q = __udivmodti4(a, b, &r);
9 try testing.expect(q == expected_q);9 try testing.expectEqual(expected_q, q);
10 try testing.expect(r == expected_r);10 try testing.expectEqual(expected_r, r);
11}11}
1212
13test "udivmodti4" {13test "udivmodti4" {