Conversation
|
I've implemented Currently, either signed division or equality comparison on integers of width smaller than 64 but not equal to 64 or 32 is broken for stage2 wasm. After division, the result is sign extended (incorrectly in the case of overflow) to either 32 or 64 bits, but the When targeting wasm, the LLVM backend currently expects inputs to be sign extended, and ensures that the result is sign extended: pub export fn div(x: i8, y: i8) i8 {
return @divTrunc(x, y);
}Gives (with the LLVM backend): (func $div (type 0) (param i32 i32) (result i32)
local.get 0
local.get 1
i32.div_s
i32.extend8_s))Note that inputs are assumed to already be sign extended and the result is sign extended (only necessary in the The stage2 wasm backend sign extends the arguments before performing the division, then doesn't do anything after the division, meaning the result will be sign extended if overflow didn't occur, and 0 extended if overflow did occur. A consistent convention needs to be decided on for the stage2 wasm backend (@andrewrk please advise!) and either equality comparison or division changed. My current Also, I haven't had any more feedback on |
|
Well I'm not a maintainer so I can't tell you what to do so I was more or less waiting for a maintainer to tell you the same thing (unless I'm wrong of course) but I believe this kind of thing where in a ReleaseFast build undefined behavior occurs with unexpected input is very much it works in Zig. This is what we write tests for. If the assumption is incorrect then you get a crash in a debug build of the program and UB in a ReleaseFast build. It's similar with
Debug mode is where we catch bugs. ReleaseFast is where we use However, in ReleaseSafe mode, which is another optimize mode, you get good performance and safety so And there is actually an accepted issue for changing master builds of the compiler to use ReleaseSafe instead of ReleaseFast (#15194) precisely because it just makes it easier to debug and report issues for users and contributors. I think lib/std/Build.zig: }) catch @panic("OOM");
lib/std/Build.zig: }) catch @panic("OOM");
lib/std/Build.zig: }) catch @panic("OOM");
lib/std/Build.zig: }) catch @panic("OOM");
lib/std/Build.zig: .value = .{ .scalar = std.fmt.allocPrint(allocator, "{d}", .{v}) catch @panic("OOM") },
lib/std/Build.zig: }) catch @panic("OOM");
lib/std/Build.zig: }) catch @panic("OOM");
lib/std/Build.zig: ordered.append(OrderedUserInputOption.fromUnordered(allocator, entry.value_ptr.*)) catch @panic("OOM");
lib/std/Build.zig: (self.build_root.join(self.allocator, &.{"zig-out"}) catch @panic("unhandled error"));or if you implement debug functionality: export fn __stack_chk_fail() callconv(.C) noreturn {
@panic("stack smashing detected");
}
export fn __chk_fail() callconv(.C) noreturn {
@panic("buffer overflow detected");
}and just explicit debugging in general. |
|
It looks like the previous CI failure was due to the change to |
|
Hmm I was able to add langref docs for the Lines 73 to 75 in 49075d2 I would try running that locally and viewing the langref locally as well to spot any mistakes. It might be some unnecessary (leading/trailing) whitespace. |
There is: |
I just tried that (with the version of The |
a3254a9 to
733b6a9
Compare
fb5a9dc to
f587d60
Compare
289768a to
5d9e6c2
Compare
Includes implementation for comptime evaluation and lowering code for LLVM and C backends.
Add section on `@divCeil` to language reference Replace some `@panic`s with `unreachable`s Add test cases for `@divCeil` for the stage2 wasm backend Fix breakage after rebase
Add `@divCeil` to binary operators list in documentation Fix breakage after rebase
Fix execution reaching `unreachable` when calling `@divCeil` on `u128` or `i128` with x86_64 backend Fix breakage after rebase
|
@andrewrk @kristoff-it Ready for review. |
|
I'm sorry, I didn't review this in time, and now it has bitrotted. Furthermore, so many pull requests have stacked up that I can't keep up and I am therefore declaring Pull Request Bankruptcy and closing old PRs that now have conflicts with master branch. If you want to reroll, you are by all means welcome to revisit this changeset with respect to the current state of master branch, and there's a decent chance your patch will be reviewed the second time around. Either way, I'm closing this now, otherwise the PR queue will continue to grow indefinitely. |
Closes #16022.
Includes implementation for comptime evaluation and lowering code for the LLVM, wasm and C backends. The C backend is untested (when I run
zig build-exe -ofmt=c file.zig, the resulting C code does not have amainfunction and will not link).Lowering code for all other backends has not been implemented.
Bigint ceiling division is implemented so that
@divCeilworks oncomptime_int, but no method has been added to thestd.math.bigbigint type to expose this in the standard library.There are existing duplicate tests in
test/behavior/int_div.zigandtest/behavior/math.zig. I've added new tests across both files.