authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-09 13:22:16-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-10-09 13:22:16-04:00
logf929a58d5f69c26c25ced89f31f60d0a92ffc46a
tree498df11397ec8025c5cd8625954f0a14fcf1e1f5
parent0fc97015e2898bb2ae9de04dd087d5d3220faf71
parent6a687bda76a34775bde35ee386e59f53961341f7
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #3389 from LemonBoy/win32

Win32

7 files changed, 176 insertions(+), 103 deletions(-)

lib/std/special/compiler_rt.zig+9
...@@ -248,8 +248,17 @@ comptime {...@@ -248,8 +248,17 @@ comptime {
248248
249 switch (builtin.arch) {249 switch (builtin.arch) {
250 .i386 => {250 .i386 => {
251 @export("_alldiv", @import("compiler_rt/aulldiv.zig")._alldiv, strong_linkage);
251 @export("_aulldiv", @import("compiler_rt/aulldiv.zig")._aulldiv, strong_linkage);252 @export("_aulldiv", @import("compiler_rt/aulldiv.zig")._aulldiv, strong_linkage);
253 @export("_allrem", @import("compiler_rt/aullrem.zig")._allrem, strong_linkage);
252 @export("_aullrem", @import("compiler_rt/aullrem.zig")._aullrem, strong_linkage);254 @export("_aullrem", @import("compiler_rt/aullrem.zig")._aullrem, strong_linkage);
255
256 @export("__divti3", @import("compiler_rt/divti3.zig").__divti3, linkage);
257 @export("__modti3", @import("compiler_rt/modti3.zig").__modti3, linkage);
258 @export("__multi3", @import("compiler_rt/multi3.zig").__multi3, linkage);
259 @export("__udivti3", @import("compiler_rt/udivti3.zig").__udivti3, linkage);
260 @export("__udivmodti4", @import("compiler_rt/udivmodti4.zig").__udivmodti4, linkage);
261 @export("__umodti3", @import("compiler_rt/umodti3.zig").__umodti3, linkage);
253 },262 },
254 .x86_64 => {263 .x86_64 => {
255 // The "ti" functions must use @Vector(2, u64) parameter types to adhere to the ABI264 // The "ti" functions must use @Vector(2, u64) parameter types to adhere to the ABI
lib/std/special/compiler_rt/aulldiv.zig+71-50
...@@ -1,55 +1,76 @@...@@ -1,55 +1,76 @@
1const builtin = @import("builtin");
2
3pub extern stdcallcc fn _alldiv(a: i64, b: i64) i64 {
4 @setRuntimeSafety(builtin.is_test);
5 const s_a = a >> (i64.bit_count - 1);
6 const s_b = b >> (i64.bit_count - 1);
7
8 const an = (a ^ s_a) -% s_a;
9 const bn = (b ^ s_b) -% s_b;
10
11 const r = @bitCast(u64, an) / @bitCast(u64, bn);
12 const s = s_a ^ s_b;
13 return (@bitCast(i64, r) ^ s) -% s;
14}
15
1pub nakedcc fn _aulldiv() void {16pub nakedcc fn _aulldiv() void {
2 @setRuntimeSafety(false);17 @setRuntimeSafety(false);
18
19 // The stack layout is:
20 // ESP+16 divisor (hi)
21 // ESP+12 divisor (low)
22 // ESP+8 dividend (hi)
23 // ESP+4 dividend (low)
24 // ESP return address
25
3 asm volatile (26 asm volatile (
4 \\.intel_syntax noprefix27 \\ push %%ebx
5 \\28 \\ push %%esi
6 \\ push ebx29 \\ mov 0x18(%%esp),%%eax
7 \\ push esi30 \\ or %%eax,%%eax
8 \\ mov eax,dword ptr [esp+18h]31 \\ jne 1f
9 \\ or eax,eax32 \\ mov 0x14(%%esp),%%ecx
10 \\ jne L133 \\ mov 0x10(%%esp),%%eax
11 \\ mov ecx,dword ptr [esp+14h]34 \\ xor %%edx,%%edx
12 \\ mov eax,dword ptr [esp+10h]35 \\ div %%ecx
13 \\ xor edx,edx36 \\ mov %%eax,%%ebx
14 \\ div ecx37 \\ mov 0xc(%%esp),%%eax
15 \\ mov ebx,eax38 \\ div %%ecx
16 \\ mov eax,dword ptr [esp+0Ch]39 \\ mov %%ebx,%%edx
17 \\ div ecx40 \\ jmp 5f
18 \\ mov edx,ebx41 \\ 1:
19 \\ jmp L242 \\ mov %%eax,%%ecx
20 \\ L1:43 \\ mov 0x14(%%esp),%%ebx
21 \\ mov ecx,eax44 \\ mov 0x10(%%esp),%%edx
22 \\ mov ebx,dword ptr [esp+14h]45 \\ mov 0xc(%%esp),%%eax
23 \\ mov edx,dword ptr [esp+10h]46 \\ 2:
24 \\ mov eax,dword ptr [esp+0Ch]47 \\ shr %%ecx
25 \\ L3:48 \\ rcr %%ebx
26 \\ shr ecx,149 \\ shr %%edx
27 \\ rcr ebx,150 \\ rcr %%eax
28 \\ shr edx,151 \\ or %%ecx,%%ecx
29 \\ rcr eax,152 \\ jne 2b
30 \\ or ecx,ecx53 \\ div %%ebx
31 \\ jne L354 \\ mov %%eax,%%esi
32 \\ div ebx55 \\ mull 0x18(%%esp)
33 \\ mov esi,eax56 \\ mov %%eax,%%ecx
34 \\ mul dword ptr [esp+18h]57 \\ mov 0x14(%%esp),%%eax
35 \\ mov ecx,eax58 \\ mul %%esi
36 \\ mov eax,dword ptr [esp+14h]59 \\ add %%ecx,%%edx
37 \\ mul esi60 \\ jb 3f
38 \\ add edx,ecx61 \\ cmp 0x10(%%esp),%%edx
39 \\ jb L462 \\ ja 3f
40 \\ cmp edx,dword ptr [esp+10h]63 \\ jb 4f
41 \\ ja L464 \\ cmp 0xc(%%esp),%%eax
42 \\ jb L565 \\ jbe 4f
43 \\ cmp eax,dword ptr [esp+0Ch]66 \\ 3:
44 \\ jbe L567 \\ dec %%esi
45 \\ L4:68 \\ 4:
46 \\ dec esi69 \\ xor %%edx,%%edx
47 \\ L5:70 \\ mov %%esi,%%eax
48 \\ xor edx,edx71 \\ 5:
49 \\ mov eax,esi72 \\ pop %%esi
50 \\ L2:73 \\ pop %%ebx
51 \\ pop esi74 \\ ret $0x10
52 \\ pop ebx
53 \\ ret 10h
54 );75 );
55}76}
lib/std/special/compiler_rt/aullrem.zig+72-51
...@@ -1,56 +1,77 @@...@@ -1,56 +1,77 @@
1const builtin = @import("builtin");
2
3pub extern stdcallcc fn _allrem(a: i64, b: i64) i64 {
4 @setRuntimeSafety(builtin.is_test);
5 const s_a = a >> (i64.bit_count - 1);
6 const s_b = b >> (i64.bit_count - 1);
7
8 const an = (a ^ s_a) -% s_a;
9 const bn = (b ^ s_b) -% s_b;
10
11 const r = @bitCast(u64, an) % @bitCast(u64, bn);
12 const s = s_a ^ s_b;
13 return (@bitCast(i64, r) ^ s) -% s;
14}
15
1pub nakedcc fn _aullrem() void {16pub nakedcc fn _aullrem() void {
2 @setRuntimeSafety(false);17 @setRuntimeSafety(false);
18
19 // The stack layout is:
20 // ESP+16 divisor (hi)
21 // ESP+12 divisor (low)
22 // ESP+8 dividend (hi)
23 // ESP+4 dividend (low)
24 // ESP return address
25
3 asm volatile (26 asm volatile (
4 \\.intel_syntax noprefix27 \\ push %%ebx
5 \\28 \\ mov 0x14(%%esp),%%eax
6 \\ push ebx29 \\ or %%eax,%%eax
7 \\ mov eax,dword ptr [esp+14h]30 \\ jne 1f
8 \\ or eax,eax31 \\ mov 0x10(%%esp),%%ecx
9 \\ jne L1a32 \\ mov 0xc(%%esp),%%eax
10 \\ mov ecx,dword ptr [esp+10h]33 \\ xor %%edx,%%edx
11 \\ mov eax,dword ptr [esp+0Ch]34 \\ div %%ecx
12 \\ xor edx,edx35 \\ mov 0x8(%%esp),%%eax
13 \\ div ecx36 \\ div %%ecx
14 \\ mov eax,dword ptr [esp+8]37 \\ mov %%edx,%%eax
15 \\ div ecx38 \\ xor %%edx,%%edx
16 \\ mov eax,edx39 \\ jmp 6f
17 \\ xor edx,edx40 \\ 1:
18 \\ jmp L2a41 \\ mov %%eax,%%ecx
19 \\ L1a:42 \\ mov 0x10(%%esp),%%ebx
20 \\ mov ecx,eax43 \\ mov 0xc(%%esp),%%edx
21 \\ mov ebx,dword ptr [esp+10h]44 \\ mov 0x8(%%esp),%%eax
22 \\ mov edx,dword ptr [esp+0Ch]45 \\ 2:
23 \\ mov eax,dword ptr [esp+8]46 \\ shr %%ecx
24 \\ L3a:47 \\ rcr %%ebx
25 \\ shr ecx,148 \\ shr %%edx
26 \\ rcr ebx,149 \\ rcr %%eax
27 \\ shr edx,150 \\ or %%ecx,%%ecx
28 \\ rcr eax,151 \\ jne 2b
29 \\ or ecx,ecx52 \\ div %%ebx
30 \\ jne L3a53 \\ mov %%eax,%%ecx
31 \\ div ebx54 \\ mull 0x14(%%esp)
32 \\ mov ecx,eax55 \\ xchg %%eax,%%ecx
33 \\ mul dword ptr [esp+14h]56 \\ mull 0x10(%%esp)
34 \\ xchg eax,ecx57 \\ add %%ecx,%%edx
35 \\ mul dword ptr [esp+10h]58 \\ jb 3f
36 \\ add edx,ecx59 \\ cmp 0xc(%%esp),%%edx
37 \\ jb L4a60 \\ ja 3f
38 \\ cmp edx,dword ptr [esp+0Ch]61 \\ jb 4f
39 \\ ja L4a62 \\ cmp 0x8(%%esp),%%eax
40 \\ jb L5a63 \\ jbe 4f
41 \\ cmp eax,dword ptr [esp+8]64 \\ 3:
42 \\ jbe L5a65 \\ sub 0x10(%%esp),%%eax
43 \\ L4a:66 \\ sbb 0x14(%%esp),%%edx
44 \\ sub eax,dword ptr [esp+10h]67 \\ 4:
45 \\ sbb edx,dword ptr [esp+14h]68 \\ sub 0x8(%%esp),%%eax
46 \\ L5a:69 \\ sbb 0xc(%%esp),%%edx
47 \\ sub eax,dword ptr [esp+8]70 \\ neg %%edx
48 \\ sbb edx,dword ptr [esp+0Ch]71 \\ neg %%eax
49 \\ neg edx72 \\ sbb $0x0,%%edx
50 \\ neg eax73 \\ 6:
51 \\ sbb edx,074 \\ pop %%ebx
52 \\ L2a:75 \\ ret $0x10
53 \\ pop ebx
54 \\ ret 10h
55 );76 );
56}77}
lib/std/special/compiler_rt/extendXfYf2_test.zig+5-1
...@@ -1,3 +1,4 @@...@@ -1,3 +1,4 @@
1const builtin = @import("builtin");
1const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;2const __extenddftf2 = @import("extendXfYf2.zig").__extenddftf2;
2const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2;3const __extendhfsf2 = @import("extendXfYf2.zig").__extendhfsf2;
3const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;4const __extendsftf2 = @import("extendXfYf2.zig").__extendsftf2;
...@@ -87,7 +88,10 @@ test "extenddftf2" {...@@ -87,7 +88,10 @@ test "extenddftf2" {
87test "extendhfsf2" {88test "extendhfsf2" {
88 test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN89 test__extendhfsf2(0x7e00, 0x7fc00000); // qNaN
89 test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN90 test__extendhfsf2(0x7f00, 0x7fe00000); // sNaN
90 test__extendhfsf2(0x7c01, 0x7f802000); // sNaN91 // On x86 the NaN becomes quiet because the return is pushed on the x87
92 // stack due to ABI requirements
93 if (builtin.arch != .i386 and builtin.os == .windows)
94 test__extendhfsf2(0x7c01, 0x7f802000); // sNaN
9195
92 test__extendhfsf2(0, 0); // 096 test__extendhfsf2(0, 0); // 0
93 test__extendhfsf2(0x8000, 0x80000000); // -097 test__extendhfsf2(0x8000, 0x80000000); // -0
lib/std/special/start_windows_tls.zig+12
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
23
3export var _tls_index: u32 = std.os.windows.TLS_OUT_OF_INDEXES;4export var _tls_index: u32 = std.os.windows.TLS_OUT_OF_INDEXES;
4export var _tls_start: u8 linksection(".tls") = 0;5export var _tls_start: u8 linksection(".tls") = 0;
...@@ -6,6 +7,17 @@ export var _tls_end: u8 linksection(".tls$ZZZ") = 0;...@@ -6,6 +7,17 @@ export var _tls_end: u8 linksection(".tls$ZZZ") = 0;
6export var __xl_a: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLA") = null;7export var __xl_a: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLA") = null;
7export var __xl_z: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLZ") = null;8export var __xl_z: std.os.windows.PIMAGE_TLS_CALLBACK linksection(".CRT$XLZ") = null;
89
10comptime {
11 if (builtin.arch == .i386) {
12 // The __tls_array is the offset of the ThreadLocalStoragePointer field
13 // in the TEB block whose base address held in the %fs segment.
14 asm (
15 \\ .global __tls_array
16 \\ __tls_array = 0x2C
17 );
18 }
19}
20
9// TODO this is how I would like it to be expressed21// TODO this is how I would like it to be expressed
10// TODO also note, ReactOS has a +1 on StartAddressOfRawData and AddressOfCallBacks. Investigate22// TODO also note, ReactOS has a +1 on StartAddressOfRawData and AddressOfCallBacks. Investigate
11// why they do that.23// why they do that.
src/analyze.cpp+4-1
...@@ -913,7 +913,10 @@ bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {...@@ -913,7 +913,10 @@ bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) {
913 if (type_is_c_abi_int(g, fn_type_id->return_type)) {913 if (type_is_c_abi_int(g, fn_type_id->return_type)) {
914 return false;914 return false;
915 }915 }
916 if (g->zig_target->arch == ZigLLVM_x86_64) {916 if (g->zig_target->arch == ZigLLVM_x86) {
917 X64CABIClass abi_class = type_c_abi_x86_64_class(g, fn_type_id->return_type);
918 return abi_class == X64CABIClass_MEMORY;
919 } else if (g->zig_target->arch == ZigLLVM_x86_64) {
917 X64CABIClass abi_class = type_c_abi_x86_64_class(g, fn_type_id->return_type);920 X64CABIClass abi_class = type_c_abi_x86_64_class(g, fn_type_id->return_type);
918 return abi_class == X64CABIClass_MEMORY;921 return abi_class == X64CABIClass_MEMORY;
919 } else if (target_is_arm(g->zig_target) || target_is_riscv(g->zig_target)) {922 } else if (target_is_arm(g->zig_target) || target_is_riscv(g->zig_target)) {
src/codegen.cpp+3
...@@ -8727,6 +8727,9 @@ static void init(CodeGen *g) {...@@ -8727,6 +8727,9 @@ static void init(CodeGen *g) {
8727 // Be aware of https://github.com/ziglang/zig/issues/32758727 // Be aware of https://github.com/ziglang/zig/issues/3275
8728 target_specific_cpu_args = "";8728 target_specific_cpu_args = "";
8729 target_specific_features = riscv_default_features;8729 target_specific_features = riscv_default_features;
8730 } else if (g->zig_target->arch == ZigLLVM_x86) {
8731 target_specific_cpu_args = "pentium4";
8732 target_specific_features = "";
8730 } else {8733 } else {
8731 target_specific_cpu_args = "";8734 target_specific_cpu_args = "";
8732 target_specific_features = "";8735 target_specific_features = "";