Commit a369d69c51

Marc Tiehuis <marctiehuis@gmail.com>
2018-06-14 11:18:36
Add windows x86_64 i128 abi workaround
1 parent 9110140
Changed files (4)
std/special/compiler_rt/divti3.zig
@@ -1,5 +1,6 @@
 const udivmod = @import("udivmod.zig").udivmod;
 const builtin = @import("builtin");
+const compiler_rt = @import("index.zig");
 
 pub extern fn __divti3(a: i128, b: i128) i128 {
     @setRuntimeSafety(builtin.is_test);
@@ -14,3 +15,12 @@ pub extern fn __divti3(a: i128, b: i128) i128 {
     const s = s_a ^ s_b;
     return (i128(r) ^ s) -% s;
 }
+
+pub extern fn __divti3_windows_x86_64(a: *const i128, b: *const i128) void {
+    @setRuntimeSafety(builtin.is_test);
+    compiler_rt.setXmm0(i128, __divti3(a.*, b.*));
+}
+
+test "import divti3" {
+    _ = @import("divti3_test.zig");
+}
std/special/compiler_rt/index.zig
@@ -38,9 +38,6 @@ comptime {
     @export("__umoddi3", __umoddi3, linkage);
     @export("__udivmodsi4", __udivmodsi4, linkage);
 
-    @export("__divti3", @import("divti3.zig").__divti3, linkage);
-    @export("__muloti4", @import("muloti4.zig").__muloti4, linkage);
-
     if (isArmArch()) {
         @export("__aeabi_uldivmod", __aeabi_uldivmod, linkage);
         @export("__aeabi_uidivmod", __aeabi_uidivmod, linkage);
@@ -61,6 +58,8 @@ comptime {
                     @export("__chkstk", __chkstk, strong_linkage);
                     @export("___chkstk_ms", ___chkstk_ms, linkage);
                 }
+                @export("__divti3", @import("divti3.zig").__divti3_windows_x86_64, linkage);
+                @export("__muloti4", @import("muloti4.zig").__muloti4_windows_x86_64, 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);
@@ -68,6 +67,8 @@ comptime {
             else => {},
         }
     } else {
+        @export("__divti3", @import("divti3.zig").__divti3, linkage);
+        @export("__muloti4", @import("muloti4.zig").__muloti4, linkage);
         @export("__udivti3", @import("udivti3.zig").__udivti3, linkage);
         @export("__udivmodti4", @import("udivmodti4.zig").__udivmodti4, linkage);
         @export("__umodti3", @import("umodti3.zig").__umodti3, linkage);
std/special/compiler_rt/muloti4.zig
@@ -1,5 +1,6 @@
 const udivmod = @import("udivmod.zig").udivmod;
 const builtin = @import("builtin");
+const compiler_rt = @import("index.zig");
 
 pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 {
     @setRuntimeSafety(builtin.is_test);
@@ -43,3 +44,12 @@ pub extern fn __muloti4(a: i128, b: i128, overflow: *c_int) i128 {
 
     return r;
 }
+
+pub extern fn __muloti4_windows_x86_64(a: *const i128, b: *const i128, overflow: *c_int) void {
+    @setRuntimeSafety(builtin.is_test);
+    compiler_rt.setXmm0(i128, __muloti4(a.*, b.*, overflow));
+}
+
+test "import muloti4" {
+    _ = @import("muloti4_test.zig");
+}
std/special/compiler_rt/muloti4_test.zig
@@ -4,7 +4,7 @@ const assert = @import("std").debug.assert;
 fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void {
     var overflow: c_int = undefined;
     const x = __muloti4(a, b, &overflow);
-    assert(overflow == expected_overflow and (overflow != 0 or x == expected));
+    assert(overflow == expected_overflow and (expected_overflow != 0 or x == expected));
 }
 
 test "muloti4" {