diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-19 22:31:10 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 00:39:13 -0300 |
| commit | 406f34120e3013c1900abfadb7a812dfd54ba89e (patch) | |
| tree | f7ddf1f045c8bdfb71ecf42f20658e885481df62 /build | |
| parent | dcf6d58f8aacefd9a66817ef4589f68ce2d42e8a (diff) | |
| download | pardes-406f34120e3013c1900abfadb7a812dfd54ba89e.tar.gz pardes-406f34120e3013c1900abfadb7a812dfd54ba89e.zip | |
build: no fused multiply-add in zstbi's resize (build/patches.zig `zstbi_cut`: `#pragma STDC FP_CONTRACT OFF`, docs/zstbi-fp-contract.md), so a kitty PNG over 1280 pixels downscales to the same pixels on an Apple silicon Mac as on Linux and FreeBSD, as a client that replays its session's bytes needs: clang contracts `a * b + c` where the CPU has a fused multiply-add, aarch64 always does (the Mac binary had 98 fmadd/fmla in stbir__resize_arbitrary and stbir__resample_horizontal_downsample; the x86-64 ones have none), a fused one rounds once, and the two downscaled pictures of the cross-check's PNG stream came out other pixels on the Mac (the snapshot differed; images are not in the digest) while the one under the bound and raw RGBA did not; with the pragma the Mac's are Linux's; the proof, the cross-check driver built from this tree (and the change before) with no patch of its own (only its step added to a scratch copy): its 18 lines (eight streams by two read sizes, two at 7 bytes: digest and full snapshot after two resizes) the same on Linux x86-64, FreeBSD 15.1 amd64 and the Mac (Darwin 25.6 arm64) (.scratch/sketch/reports/pardes-term-xcheck.md, "Landed"); no zstbi or stb upstream is on this machine to compare; tui term-test 15/15, kitty-test 45/45, core-test 848/991 (143 skipped), shell-test 1027/1030, image-harness and kitty-harness pass; gui unit-test 1625/1629 (4 skipped; the perf check's BaselineHarnessMismatch, the base's), image-harness and kitty-harness pass; the macOS library builds for Linux and aarch64-macos, the FreeBSD tui builds (load 19 to 47); the frame and perf gate (gpu/xcheck-c3, against tree1, with the change before): 77/77 frames byte-identical, perfab corpus2x -0.076%, perfops 97 of 97 within 0.1%
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build')
| -rw-r--r-- | build/patches.zig | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/build/patches.zig b/build/patches.zig index f58fb926..3d956d26 100644 --- a/build/patches.zig +++ b/build/patches.zig @@ -175,8 +175,14 @@ pub fn vaxis(b: *std.Build, patch: *std.Build.Step.Compile, vaxis_dep: *std.Buil /// zstbi with stb_image and its writer cut out: of it only its resize is /// left, for a terminal PNG's downscale (build/core.zig, "One PNG /// decoder"). zstbi.deinit still resets the reader's and the writer's flip -/// flags, and Image.deinit frees the resize's output. +/// flags, and Image.deinit frees the resize's output. And no fused +/// multiply-add in the resize: clang contracts `a * b + c` where the CPU +/// has one (aarch64 always does), which rounds once, so a PNG downscaled +/// on an Apple silicon Mac came out pixels apart from Linux's, and the same +/// bytes must give the same terminal on every machine a client runs on +/// (docs/zstbi-fp-contract.md). const zstbi_cut = [_]Edit{ + .{ .old = "#include <stdlib.h>\n", .new = "#include <stdlib.h>\n#pragma STDC FP_CONTRACT OFF\n" }, .{ .old = "#define STB_IMAGE_IMPLEMENTATION\n#include \"stb_image.h\"\n", .new = "void stbi_set_flip_vertically_on_load(int flag) { (void)flag; }\nvoid stbi_image_free(void *p) { zstbiFreePtr(p); }\n" }, .{ .old = "#define STB_IMAGE_WRITE_IMPLEMENTATION\n#include \"stb_image_write.h\"\n", .new = "void stbi_flip_vertically_on_write(int flag) { (void)flag; }\n" }, }; |
