From 6ae631d1a74e6918a67f55217a2581c65672b4dc Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 1 Oct 2017 11:11:38 -0400 Subject: [PATCH] add windows 32 bit to test matrix See #302 --- ci/travis_linux_install | 2 +- ci/travis_linux_script | 19 ++++++++ std/rand.zig | 6 +-- std/special/compiler_rt/index.zig | 72 +++++++++++++++++++++++++++++++ test/tests.zig | 5 +++ 5 files changed, 100 insertions(+), 4 deletions(-) diff --git a/ci/travis_linux_install b/ci/travis_linux_install index 1613487f8b74..0dfbe8aa21e2 100755 --- a/ci/travis_linux_install +++ b/ci/travis_linux_install @@ -4,4 +4,4 @@ set -x sudo apt-get remove -y llvm-* sudo rm -rf /usr/local/* -sudo apt-get install -y clang-5.0 libclang-5.0 libclang-5.0-dev llvm-5.0 llvm-5.0-dev liblld-5.0 liblld-5.0-dev cmake +sudo apt-get install -y clang-5.0 libclang-5.0 libclang-5.0-dev llvm-5.0 llvm-5.0-dev liblld-5.0 liblld-5.0-dev cmake wine1.6-amd64 diff --git a/ci/travis_linux_script b/ci/travis_linux_script index d841127fbfce..a226bba9472c 100755 --- a/ci/travis_linux_script +++ b/ci/travis_linux_script @@ -13,3 +13,22 @@ cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $($CC -print make VERBOSE=1 make install ./zig build --build-file ../build.zig test + +./zig test ../std/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc +wine64 test.exe + +./zig test ../std/behavior.zig --target-os windows --target-arch i386 --target-environ msvc +wine test.exe + +./zig test ../std/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc --release-fast +wine64 test.exe + +./zig test ../std/behavior.zig --target-os windows --target-arch i386 --target-environ msvc --release-fast +wine test.exe + +# TODO fix bug +# ./zig test ../std/behavior.zig --target-os windows --target-arch x86_64 --target-environ msvc --release-safe +# wine64 test.exe + +./zig test ../std/behavior.zig --target-os windows --target-arch i386 --target-environ msvc --release-safe +wine test.exe diff --git a/std/rand.zig b/std/rand.zig index f61c100e5381..4e8bcde4efa9 100644 --- a/std/rand.zig +++ b/std/rand.zig @@ -164,16 +164,16 @@ fn MersenneTwister( while (i < n - m) : (i += 1) { const x = (mt.array[i] & UM) | (mt.array[i + 1] & LM); - mt.array[i] = mt.array[i + m] ^ (x >> 1) ^ mag01[x & 0x1]; + mt.array[i] = mt.array[i + m] ^ (x >> 1) ^ mag01[usize(x & 0x1)]; } while (i < n - 1) : (i += 1) { const x = (mt.array[i] & UM) | (mt.array[i + 1] & LM); - mt.array[i] = mt.array[i + m - n] ^ (x >> 1) ^ mag01[x & 0x1]; + mt.array[i] = mt.array[i + m - n] ^ (x >> 1) ^ mag01[usize(x & 0x1)]; } const x = (mt.array[i] & UM) | (mt.array[0] & LM); - mt.array[i] = mt.array[m - 1] ^ (x >> 1) ^ mag01[x & 0x1]; + mt.array[i] = mt.array[m - 1] ^ (x >> 1) ^ mag01[usize(x & 0x1)]; mt.index = 0; } diff --git a/std/special/compiler_rt/index.zig b/std/special/compiler_rt/index.zig index d005c92ba10d..39b2b5b8ab32 100644 --- a/std/special/compiler_rt/index.zig +++ b/std/special/compiler_rt/index.zig @@ -110,6 +110,44 @@ export nakedcc fn __aeabi_uidivmod() { @setGlobalLinkage(__aeabi_uidivmod, builtin.GlobalLinkage.Internal); } +// _chkstk (_alloca) routine - probe stack between %esp and (%esp-%eax) in 4k increments, +// then decrement %esp by %eax. Preserves all registers except %esp and flags. +// This routine is windows specific +// http://msdn.microsoft.com/en-us/library/ms648426.aspx +export nakedcc fn _chkstk() align(4) { + @setDebugSafety(this, false); + + if (comptime builtin.os == builtin.Os.windows) { + if (comptime builtin.arch == builtin.Arch.i386) { + asm volatile ( + \\ push %%ecx + \\ cmp $0x1000,%%eax + \\ lea 8(%%esp),%%ecx // esp before calling this routine -> ecx + \\ jb 1f + \\ 2: + \\ sub $0x1000,%%ecx + \\ test %%ecx,(%%ecx) + \\ sub $0x1000,%%eax + \\ cmp $0x1000,%%eax + \\ ja 2b + \\ 1: + \\ sub %%eax,%%ecx + \\ test %%ecx,(%%ecx) + \\ + \\ lea 4(%%esp),%%eax // load pointer to the return address into eax + \\ mov %%ecx,%%esp // install the new top of stack pointer into esp + \\ mov -4(%%eax),%%ecx // restore ecx + \\ push (%%eax) // push return address onto the stack + \\ sub %%esp,%%eax // restore the original value in eax + \\ ret + ); + unreachable; + } + } + + @setGlobalLinkage(_chkstk, builtin.GlobalLinkage.Internal); +} + export nakedcc fn __chkstk() align(4) { @setDebugSafety(this, false); @@ -144,6 +182,40 @@ export nakedcc fn __chkstk() align(4) { @setGlobalLinkage(__chkstk, builtin.GlobalLinkage.Internal); } +// _chkstk routine +// This routine is windows specific +// http://msdn.microsoft.com/en-us/library/ms648426.aspx +export nakedcc fn __chkstk_ms() align(4) { + @setDebugSafety(this, false); + + if (comptime builtin.os == builtin.Os.windows) { + if (comptime builtin.arch == builtin.Arch.i386) { + asm volatile ( + \\ push %%ecx + \\ push %%eax + \\ cmp $0x1000,%%eax + \\ lea 12(%%esp),%%ecx + \\ jb 1f + \\ 2: + \\ sub $0x1000,%%ecx + \\ test %%ecx,(%%ecx) + \\ sub $0x1000,%%eax + \\ cmp $0x1000,%%eax + \\ ja 2b + \\ 1: + \\ sub %%eax,%%ecx + \\ test %%ecx,(%%ecx) + \\ pop %%eax + \\ pop %%ecx + \\ ret + ); + unreachable; + } + } + + @setGlobalLinkage(__chkstk_ms, builtin.GlobalLinkage.Internal); +} + export nakedcc fn ___chkstk_ms() align(4) { @setDebugSafety(this, false); diff --git a/test/tests.zig b/test/tests.zig index 6a44a1e353ab..3e5608daf1c4 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -41,6 +41,11 @@ const test_targets = []TestTarget { .arch = builtin.Arch.x86_64, .environ = builtin.Environ.msvc, }, + TestTarget { + .os = builtin.Os.windows, + .arch = builtin.Arch.i386, + .environ = builtin.Environ.msvc, + }, }; error TestFailed;