authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-22 14:37:08-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-22 14:37:08-04:00
log317d1ecb2cf3234b0259daf6cc0baac7d86264e2
tree17c8c50e096fd23e0f9b9194a8a6ac0b8a028711
parentfcadeb50c04199fce2d9675ba2976680c71c67ff
parent16be70cbbf8e6dc658b9fcacd3366df8f83fffa8
signature Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into rewrite-coroutines


9 files changed, 139 insertions(+), 18 deletions(-)

build.zig+6-3
......@@ -122,16 +122,19 @@ pub fn build(b: *Builder) !void {
122122 }
123123 const modes = chosen_modes[0..chosen_mode_index];
124124
125 const multi_and_single = [_]bool{ false, true };
126 const just_multi = [_]bool{false};
127
125128 // run stage1 `zig fmt` on this build.zig file just to make sure it works
126129 test_step.dependOn(&fmt_build_zig.step);
127130 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
128131 fmt_step.dependOn(&fmt_build_zig.step);
129132
130 test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, skip_non_native));
133 test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, multi_and_single, skip_non_native));
131134
132 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, skip_non_native));
135 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, multi_and_single, skip_non_native));
133136
134 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, skip_non_native));
137 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, just_multi, skip_non_native));
135138
136139 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
137140 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
src/analyze.cpp+2-1
......@@ -3346,7 +3346,8 @@ static void resolve_use_decl(CodeGen *g, TldUsingNamespace *tld_using_namespace,
33463346
33473347static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, ScopeDecls *dest_decls_scope) {
33483348 if (using_namespace->base.resolution == TldResolutionOk ||
3349 using_namespace->base.resolution == TldResolutionInvalid)
3349 using_namespace->base.resolution == TldResolutionInvalid ||
3350 using_namespace->using_namespace_value != nullptr)
33503351 {
33513352 return;
33523353 }
std/build.zig+20-11
......@@ -41,9 +41,11 @@ pub const Builder = struct {
4141 env_map: *BufMap,
4242 top_level_steps: ArrayList(*TopLevelStep),
4343 install_prefix: ?[]const u8,
44 search_prefixes: ArrayList([]const u8),
44 dest_dir: ?[]const u8,
4545 lib_dir: ?[]const u8,
4646 exe_dir: ?[]const u8,
47 install_path: []const u8,
48 search_prefixes: ArrayList([]const u8),
4749 installed_files: ArrayList(InstalledFile),
4850 build_root: []const u8,
4951 cache_root: []const u8,
......@@ -125,10 +127,11 @@ pub const Builder = struct {
125127 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),
126128 .default_step = undefined,
127129 .env_map = env_map,
128 .install_prefix = null,
129130 .search_prefixes = ArrayList([]const u8).init(allocator),
131 .install_prefix = null,
130132 .lib_dir = null,
131133 .exe_dir = null,
134 .dest_dir = env_map.get("DESTDIR"),
132135 .installed_files = ArrayList(InstalledFile).init(allocator),
133136 .install_tls = TopLevelStep{
134137 .step = Step.initNoOp("install", allocator),
......@@ -142,6 +145,7 @@ pub const Builder = struct {
142145 .is_release = false,
143146 .override_std_dir = null,
144147 .override_lib_dir = null,
148 .install_path = undefined,
145149 };
146150 try self.top_level_steps.append(&self.install_tls);
147151 try self.top_level_steps.append(&self.uninstall_tls);
......@@ -164,14 +168,19 @@ pub const Builder = struct {
164168 }
165169
166170 fn resolveInstallPrefix(self: *Builder) void {
167 const prefix = if (self.install_prefix) |prefix| prefix else blk: {
168 const prefix = self.cache_root;
169 self.install_prefix = prefix;
170 break :blk prefix;
171 };
172
173 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "lib" }) catch unreachable;
174 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "bin" }) catch unreachable;
171 if (self.dest_dir) |dest_dir| {
172 const install_prefix = self.install_prefix orelse "/usr";
173 self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable;
174 } else {
175 const install_prefix = self.install_prefix orelse blk: {
176 const p = self.cache_root;
177 self.install_prefix = p;
178 break :blk p;
179 };
180 self.install_path = install_prefix;
181 }
182 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable;
183 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable;
175184 }
176185
177186 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
......@@ -884,7 +893,7 @@ pub const Builder = struct {
884893
885894 fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
886895 const base_dir = switch (dir) {
887 .Prefix => self.install_prefix.?,
896 .Prefix => self.install_path,
888897 .Bin => self.exe_dir.?,
889898 .Lib => self.lib_dir.?,
890899 };
std/debug.zig+1-1
......@@ -2353,7 +2353,7 @@ pub fn attachSegfaultHandler() void {
23532353fn resetSegfaultHandler() void {
23542354 if (windows.is_the_target) {
23552355 if (windows_segfault_handle) |handle| {
2356 assert(windows.kernel32.RemoveVectoredExceptionHandler() != 0);
2356 assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0);
23572357 windows_segfault_handle = null;
23582358 }
23592359 return;
std/special/compiler_rt.zig+3
......@@ -127,6 +127,7 @@ comptime {
127127 @export("__udivmoddi4", @import("compiler_rt/udivmoddi4.zig").__udivmoddi4, linkage);
128128 @export("__popcountdi2", @import("compiler_rt/popcountdi2.zig").__popcountdi2, linkage);
129129
130 @export("__muldi3", @import("compiler_rt/muldi3.zig").__muldi3, linkage);
130131 @export("__divmoddi4", __divmoddi4, linkage);
131132 @export("__divsi3", __divsi3, linkage);
132133 @export("__divdi3", __divdi3, linkage);
......@@ -147,6 +148,8 @@ comptime {
147148 @export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage);
148149 @export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage);
149150
151 @export("__aeabi_lmul", @import("compiler_rt/muldi3.zig").__muldi3, linkage);
152
150153 @export("__aeabi_ldivmod", __aeabi_ldivmod, linkage);
151154 @export("__aeabi_uldivmod", __aeabi_uldivmod, linkage);
152155
std/special/compiler_rt/divti3.zig-1
......@@ -1,6 +1,5 @@
11const udivmod = @import("udivmod.zig").udivmod;
22const builtin = @import("builtin");
3const compiler_rt = @import("../compiler_rt.zig");
43
54pub extern fn __divti3(a: i128, b: i128) i128 {
65 @setRuntimeSafety(builtin.is_test);
std/special/compiler_rt/muldi3.zig created+54
......@@ -0,0 +1,54 @@
1const builtin = @import("builtin");
2
3// Ported from
4// https://github.com/llvm/llvm-project/blob/552c2c09d354a3ad9c1c9647e0a3bb5099c31088/compiler-rt/lib/builtins/muldi3.c
5
6const dwords = extern union {
7 all: i64,
8 s: switch (builtin.endian) {
9 .Little => extern struct {
10 low: u32,
11 high: u32,
12 },
13 .Big => extern struct {
14 high: u32,
15 low: u32,
16 },
17 },
18};
19
20fn __muldsi3(a: u32, b: u32) i64 {
21 @setRuntimeSafety(builtin.is_test);
22
23 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
24 const lower_mask = (~u32(0)) >> bits_in_word_2;
25
26 var r: dwords = undefined;
27 r.s.low = (a & lower_mask) *% (b & lower_mask);
28 var t: u32 = r.s.low >> bits_in_word_2;
29 r.s.low &= lower_mask;
30 t += (a >> bits_in_word_2) *% (b & lower_mask);
31 r.s.low +%= (t & lower_mask) << bits_in_word_2;
32 r.s.high = t >> bits_in_word_2;
33 t = r.s.low >> bits_in_word_2;
34 r.s.low &= lower_mask;
35 t +%= (b >> bits_in_word_2) *% (a & lower_mask);
36 r.s.low +%= (t & lower_mask) << bits_in_word_2;
37 r.s.high +%= t >> bits_in_word_2;
38 r.s.high +%= (a >> bits_in_word_2) *% (b >> bits_in_word_2);
39 return r.all;
40}
41
42pub extern fn __muldi3(a: i64, b: i64) i64 {
43 @setRuntimeSafety(builtin.is_test);
44
45 const x = dwords{ .all = a };
46 const y = dwords{ .all = b };
47 var r = dwords{ .all = __muldsi3(x.s.low, y.s.low) };
48 r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
49 return r.all;
50}
51
52test "import muldi3" {
53 _ = @import("muldi3_test.zig");
54}
std/special/compiler_rt/muldi3_test.zig created+51
......@@ -0,0 +1,51 @@
1const __muldi3 = @import("muldi3.zig").__muldi3;
2const testing = @import("std").testing;
3
4fn test__muldi3(a: i64, b: i64, expected: i64) void {
5 const x = __muldi3(a, b);
6 testing.expect(x == expected);
7}
8
9test "muldi3" {
10 test__muldi3(0, 0, 0);
11 test__muldi3(0, 1, 0);
12 test__muldi3(1, 0, 0);
13 test__muldi3(0, 10, 0);
14 test__muldi3(10, 0, 0);
15 test__muldi3(0, 81985529216486895, 0);
16 test__muldi3(81985529216486895, 0, 0);
17
18 test__muldi3(0, -1, 0);
19 test__muldi3(-1, 0, 0);
20 test__muldi3(0, -10, 0);
21 test__muldi3(-10, 0, 0);
22 test__muldi3(0, -81985529216486895, 0);
23 test__muldi3(-81985529216486895, 0, 0);
24
25 test__muldi3(1, 1, 1);
26 test__muldi3(1, 10, 10);
27 test__muldi3(10, 1, 10);
28 test__muldi3(1, 81985529216486895, 81985529216486895);
29 test__muldi3(81985529216486895, 1, 81985529216486895);
30
31 test__muldi3(1, -1, -1);
32 test__muldi3(1, -10, -10);
33 test__muldi3(-10, 1, -10);
34 test__muldi3(1, -81985529216486895, -81985529216486895);
35 test__muldi3(-81985529216486895, 1, -81985529216486895);
36
37 test__muldi3(3037000499, 3037000499, 9223372030926249001);
38 test__muldi3(-3037000499, 3037000499, -9223372030926249001);
39 test__muldi3(3037000499, -3037000499, -9223372030926249001);
40 test__muldi3(-3037000499, -3037000499, 9223372030926249001);
41
42 test__muldi3(4398046511103, 2097152, 9223372036852678656);
43 test__muldi3(-4398046511103, 2097152, -9223372036852678656);
44 test__muldi3(4398046511103, -2097152, -9223372036852678656);
45 test__muldi3(-4398046511103, -2097152, 9223372036852678656);
46
47 test__muldi3(2097152, 4398046511103, 9223372036852678656);
48 test__muldi3(-2097152, 4398046511103, -9223372036852678656);
49 test__muldi3(2097152, -4398046511103, -9223372036852678656);
50 test__muldi3(-2097152, -4398046511103, 9223372036852678656);
51}
test/tests.zig+2-1
......@@ -170,6 +170,7 @@ pub fn addPkgTests(
170170 name: []const u8,
171171 desc: []const u8,
172172 modes: []const Mode,
173 single_threaded_list: []const bool,
173174 skip_non_native: bool,
174175) *build.Step {
175176 const step = b.step(b.fmt("test-{}", name), desc);
......@@ -179,7 +180,7 @@ pub fn addPkgTests(
179180 continue;
180181 for (modes) |mode| {
181182 for ([_]bool{ false, true }) |link_libc| {
182 for ([_]bool{ false, true }) |single_threaded| {
183 for (single_threaded_list) |single_threaded| {
183184 if (link_libc and !is_native) {
184185 // don't assume we have a cross-compiling libc set up
185186 continue;