fix compiler-rt ABI for x86_64 windows

This commit is contained in:
Andrew Kelley 2018-04-28 22:03:07 -04:00
parent 7270f35c93
commit ec2a81a081
6 changed files with 46 additions and 9 deletions

View File

@ -281,7 +281,7 @@ test "os.time.Timer" {
debug.assert(time_0 > 0 and time_0 < margin);
const time_1 = timer.lap();
debug.assert(time_1 > time_0);
debug.assert(time_1 >= time_0);
timer.reset();
debug.assert(timer.read() < time_1);

View File

@ -32,10 +32,6 @@ comptime {
@export("__fixunstfti", @import("fixunstfti.zig").__fixunstfti, linkage);
@export("__udivmoddi4", @import("udivmoddi4.zig").__udivmoddi4, linkage);
@export("__udivmodti4", @import("udivmodti4.zig").__udivmodti4, linkage);
@export("__udivti3", @import("udivti3.zig").__udivti3, linkage);
@export("__umodti3", @import("umodti3.zig").__umodti3, linkage);
@export("__udivsi3", __udivsi3, linkage);
@export("__udivdi3", __udivdi3, linkage);
@ -62,9 +58,16 @@ comptime {
@export("__chkstk", __chkstk, strong_linkage);
@export("___chkstk_ms", ___chkstk_ms, linkage);
}
@export("__udivti3", @import("udivti3.zig").__udivti3_windows_x86_64, linkage);
@export("__udivmodti4", @import("udivmodti4.zig").__udivmodti4_windows_x86_64, linkage);
@export("__umodti3", @import("umodti3.zig").__umodti3_windows_x86_64, linkage);
},
else => {},
}
} else {
@export("__udivti3", @import("udivti3.zig").__udivti3, linkage);
@export("__udivmodti4", @import("udivmodti4.zig").__udivmodti4, linkage);
@export("__umodti3", @import("umodti3.zig").__umodti3, linkage);
}
}
@ -83,6 +86,16 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) noreturn
}
}
pub fn setXmm0(comptime T: type, value: T) void {
comptime assert(builtin.arch == builtin.Arch.x86_64);
const aligned_value: T align(16) = value;
asm volatile (
\\movaps (%[ptr]), %%xmm0
:
: [ptr] "r" (&aligned_value)
: "xmm0");
}
extern fn __udivdi3(a: u64, b: u64) u64 {
@setRuntimeSafety(is_test);
return __udivmoddi4(a, b, null);

View File

@ -1,11 +1,17 @@
const udivmod = @import("udivmod.zig").udivmod;
const builtin = @import("builtin");
const compiler_rt = @import("index.zig");
pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) u128 {
@setRuntimeSafety(builtin.is_test);
return udivmod(u128, a, b, maybe_rem);
}
pub extern fn __udivmodti4_windows_x86_64(a: &const u128, b: &const u128, maybe_rem: ?&u128) void {
@setRuntimeSafety(builtin.is_test);
compiler_rt.setXmm0(u128, udivmod(u128, *a, *b, maybe_rem));
}
test "import udivmodti4" {
_ = @import("udivmodti4_test.zig");
}

View File

@ -1,7 +1,12 @@
const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
const udivmodti4 = @import("udivmodti4.zig");
const builtin = @import("builtin");
pub extern fn __udivti3(a: u128, b: u128) u128 {
@setRuntimeSafety(builtin.is_test);
return __udivmodti4(a, b, null);
return udivmodti4.__udivmodti4(a, b, null);
}
pub extern fn __udivti3_windows_x86_64(a: &const u128, b: &const u128) void {
@setRuntimeSafety(builtin.is_test);
udivmodti4.__udivmodti4_windows_x86_64(a, b, null);
}

View File

@ -1,9 +1,15 @@
const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
const udivmodti4 = @import("udivmodti4.zig");
const builtin = @import("builtin");
const compiler_rt = @import("index.zig");
pub extern fn __umodti3(a: u128, b: u128) u128 {
@setRuntimeSafety(builtin.is_test);
var r: u128 = undefined;
_ = __udivmodti4(a, b, &r);
_ = udivmodti4.__udivmodti4(a, b, &r);
return r;
}
pub extern fn __umodti3_windows_x86_64(a: &const u128, b: &const u128) void {
@setRuntimeSafety(builtin.is_test);
compiler_rt.setXmm0(u128, __umodti3(*a, *b));
}

View File

@ -529,3 +529,10 @@ test "comptime shlWithOverflow" {
assert(ct_shifted == rt_shifted);
}
test "runtime 128 bit integer division" {
var a: u128 = 152313999999999991610955792383;
var b: u128 = 10000000000000000000;
var c = a / b;
assert(c == 15231399999);
}