| ... | @@ -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); |
| 20 | | 20 | |
| 21 | const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #421 | 21 | const n = @bitCast([2]SingleInt, a); |
| 22 | const d = @ptrCast(*const [2]SingleInt, &b).*; // TODO issue #421 | 22 | 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 #421 | 64 | 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 #421 | 76 | 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 #421 | 116 | return @bitCast(DoubleInt, q); |
| 117 | } | 117 | } |
| 118 | // K X | 118 | // 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 #421 | 190 | 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 #421 | 194 | r = @bitCast([2]SingleInt, r_all); |
| 195 | } | 195 | } |
| 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; |
| 197 | if (maybe_rem) |rem| { | 197 | if (maybe_rem) |rem| { |
| 198 | rem.* = r_all; | 198 | rem.* = r_all; |
| 199 | } | 199 | } |