authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2023-04-14 18:29:42+12:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2023-06-17 13:50:05+12:00
log59a6f482e205c2f8ee60771a3d05652fd63e11e6
tree1843962ee88e294ca09b8d3b30ca896b984547f8
parent947dd36341bdef0cb359a008257e7f1638f60594

disable udivmod asm divq on windows


1 files changed, 11 insertions(+), 19 deletions(-)

lib/compiler_rt/udivmod.zig+11-19
......@@ -2,6 +2,7 @@ const std = @import("std");
22const builtin = @import("builtin");
33const is_test = builtin.is_test;
44const Log2Int = std.math.Log2Int;
5const HalveInt = @import("common.zig").HalveInt;
56
67const lo = switch (builtin.cpu.arch.endian()) {
78 .Big => 1,
......@@ -9,19 +10,10 @@ const lo = switch (builtin.cpu.arch.endian()) {
910};
1011const hi = 1 - lo;
1112
12fn HalfInt(comptime T: type) type {
13 std.debug.assert(@typeInfo(T) == .Int);
14 std.debug.assert(@bitSizeOf(T) % 2 == 0);
15 return std.meta.Int(.unsigned, @bitSizeOf(T) / 2);
16}
17
18// Performs division of a double-word specified in its single-word components. Most commonly used
19// for computing u128 bit divisions in terms of 64-bit integers.
20//
21// q = U / v
22// r = U % v
23// where U = (u1 | u0)
13// Let _u1 and _u0 be the high and low limbs of U respectively.
14// Returns U / v_ and sets r = U % v_.
2415fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {
16 const HalfT = HalveInt(T, false).HalfT;
2517 @setRuntimeSafety(is_test);
2618 var v = v_;
2719
......@@ -43,11 +35,11 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {
4335
4436 // Break divisor up into two 32-bit digits
4537 const vn1 = v >> (@bitSizeOf(T) / 2);
46 const vn0 = v & std.math.maxInt(HalfInt(T));
38 const vn0 = v & std.math.maxInt(HalfT);
4739
4840 // Break right half of dividend into two digits
4941 const un1 = un10 >> (@bitSizeOf(T) / 2);
50 const un0 = un10 & std.math.maxInt(HalfInt(T));
42 const un0 = un10 & std.math.maxInt(HalfT);
5143
5244 // Compute the first quotient digit, q1
5345 var q1 = un64 / vn1;
......@@ -79,7 +71,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T {
7971
8072fn divwide(comptime T: type, _u1: T, _u0: T, v: T, r: *T) T {
8173 @setRuntimeSafety(is_test);
82 if (T == u64 and builtin.target.cpu.arch == .x86_64) {
74 if (T == u64 and builtin.target.cpu.arch == .x86_64 and builtin.target.os.tag != .windows) {
8375 var rem: T = undefined;
8476 const quo = asm (
8577 \\divq %[v]
......@@ -96,10 +88,10 @@ fn divwide(comptime T: type, _u1: T, _u0: T, v: T, r: *T) T {
9688 }
9789}
9890
99// return q = a / b, *r = a % b
91// Returns a_ / b_ and sets maybe_rem = a_ % b.
10092pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
10193 @setRuntimeSafety(is_test);
102 const HalfT = HalfInt(T);
94 const HalfT = HalveInt(T, false).HalfT;
10395 const SignedT = std.meta.Int(.signed, @bitSizeOf(T));
10496
10597 if (b_ > a_) {
......@@ -141,8 +133,8 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T {
141133 for (0..shift + 1) |_| {
142134 q[lo] <<= 1;
143135 // Branchless version of:
144 // if (a >= b) {
145 // a -= b;
136 // if (af >= bf) {
137 // af -= bf;
146138 // q[lo] |= 1;
147139 // }
148140 const s = @bitCast(SignedT, bf -% af -% 1) >> (@bitSizeOf(T) - 1);