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:
1818 const SignedDoubleInt = std.meta.Int(.signed, double_int_bits);
1919 const Log2SingleInt = std.math.Log2Int(SingleInt);
2020
21 const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #421
22 const d = @ptrCast(*const [2]SingleInt, &b).*; // TODO issue #421
21 const n = @bitCast([2]SingleInt, a);
22 const d = @bitCast([2]SingleInt, b);
2323 var q: [2]SingleInt = undefined;
2424 var r: [2]SingleInt = undefined;
2525 var sr: c_uint = undefined;
......@@ -61,7 +61,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
6161 if (maybe_rem) |rem| {
6262 r[high] = n[high] % d[high];
6363 r[low] = 0;
64 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
64 rem.* = @bitCast(DoubleInt, r);
6565 }
6666 return n[high] / d[high];
6767 }
......@@ -73,7 +73,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
7373 if (maybe_rem) |rem| {
7474 r[low] = n[low];
7575 r[high] = n[high] & (d[high] - 1);
76 rem.* = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
76 rem.* = @bitCast(DoubleInt, r);
7777 }
7878 return n[high] >> @intCast(Log2SingleInt, @ctz(d[high]));
7979 }
......@@ -113,7 +113,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
113113 sr = @ctz(d[low]);
114114 q[high] = n[high] >> @intCast(Log2SingleInt, sr);
115115 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 #421
116 return @bitCast(DoubleInt, q);
117117 }
118118 // K X
119119 // ---
......@@ -187,13 +187,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
187187 // r.all -= b;
188188 // carry = 1;
189189 // }
190 r_all = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
190 r_all = @bitCast(DoubleInt, r);
191191 const s: SignedDoubleInt = @bitCast(SignedDoubleInt, b -% r_all -% 1) >> (double_int_bits - 1);
192192 carry = @intCast(u32, s & 1);
193193 r_all -= b & @bitCast(DoubleInt, s);
194 r = @ptrCast(*[2]SingleInt, &r_all).*; // TODO issue #421
194 r = @bitCast([2]SingleInt, r_all);
195195 }
196 const q_all = ((@ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421
196 const q_all = (@bitCast(DoubleInt, q) << 1) | carry;
197197 if (maybe_rem) |rem| {
198198 rem.* = r_all;
199199 }
lib/compiler_rt/udivmoddi4_test.zig+2-2
......@@ -6,8 +6,8 @@ const testing = @import("std").testing;
66fn test__udivmoddi4(a: u64, b: u64, expected_q: u64, expected_r: u64) !void {
77 var r: u64 = undefined;
88 const q = __udivmoddi4(a, b, &r);
9 try testing.expect(q == expected_q);
10 try testing.expect(r == expected_r);
9 try testing.expectEqual(expected_q, q);
10 try testing.expectEqual(expected_r, r);
1111}
1212
1313test "udivmoddi4" {
lib/compiler_rt/udivmodti4_test.zig+2-2
......@@ -6,8 +6,8 @@ const testing = @import("std").testing;
66fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) !void {
77 var r: u128 = undefined;
88 const q = __udivmodti4(a, b, &r);
9 try testing.expect(q == expected_q);
10 try testing.expect(r == expected_r);
9 try testing.expectEqual(expected_q, q);
10 try testing.expectEqual(expected_r, r);
1111}
1212
1313test "udivmodti4" {