Repository navigation
wasm: inline @byteSwap, SIMD cmp->bitselect, reused-local DSE, and multivalue inlining - #238
Merged
Merged
Conversation
… and multivalue inlining - CodeGen.zig: lower @byteswap inline for <=128-bit integers using i32.rotl / byte-mask shifts instead of out-of-line __bswapsi2 / __bswapdi2 calls. - CodeGen.zig: keep direct SIMD cmp_vector lane masks in v128 locals when consumed by matching @select, emitting v128.bitselect directly without shadow-stack [N]bool round-trips. - Optimizer.zig: add conservative intra-block backward dead-overwrite elimination for reused Wasm locals + pure-expression popping, shrink ReleaseSmall binaries (-21 KB on knots, -105 KB on wazig.wasm), and align inliner thresholds with 8-result multivalue ABI and 1-call capacity wrappers. - test/behavior/wasm.zig & Optimizer.zig: add unit and runtime behavior tests across signed/unsigned byteSwap widths, SIMD vector select, and reused-local overwrite DSE. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cataggar
enabled auto-merge (squash)
November 11, 2026 04:32
cataggar
added a commit
to cataggar/knots
that referenced
this pull request
Nov 11, 2026
…aths and update 0.17.1-wazig.1 benchmarks (#36) - unicode/itemize/linebreak: add 8-byte SWAR ASCII fast paths for decodeUtf8 and properties, single-pass .latn ASCII itemization, comptime ASCII UAX#14 class table + common-pair fast checks, and unwrapped single-line fast path when wrap_width <= 0. - TextSystem/TextLayout/GlyphStore/Outline: replace Face.glyphs hash map with dense O(1) glyph_slots array, reuse persistent LayoutScratch and outline_vertices buffers, consolidate TextLayout into a single contiguous slab allocation, bypass word cache on plain space runs, encode glyphs directly into GlyphStore.words with reciprocal quantization, and pre-validate Outline.Points bounds. - UI/DrawList: cache measured/reflowed TextLayout on Decoration.Text across a frame, hoist uniform f16 color conversion in paintText, and replace per-command gridCoord float divisions with reciprocal multiplies. - benchmarks: update bench-wazig.py, WAZIG_BENCHMARKS.md, and wazig-vs-zig.json for wazig v0.17.1-wazig.1 (with cataggar/zig#238), v0.17.0-wazig.6, v0.17.0-wazigl.6, and zig v0.17.1. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pre-
v0.17.1-wazig.1Wasm backend & post-link optimizer improvements driven byknotsWasmtime guest CPU profiling:src/codegen/wasm/CodeGen.zig(Inline@byteSwap): Lower@byteSwapinline for<= 128-bit signed and unsigned integers usingi32.rotland byte-mask shifts instead of out-of-line__bswapsi2/__bswapdi2calls.src/codegen/wasm/CodeGen.zig(SIMDcmp_vector->v128.bitselect): ExtendCmpVectorReduceAnalysisandairSelectsocmp_vectorresults consumed by width-matching@selectstay inv128registers and lower directly tov128.bitselectwithout spilling to a shadow-stack[N]boolbuffer.src/link/Wasm/component/Optimizer.zig(Backward Reused-Local Overwrite DSE & Multi-Value Inlining):local.set/local.teeoverwrites across reusedLocalPoollocals within basic blocks and pop pure non-trapping producer expressions.max_inline_resultsto8to match#237's multivalue ABI and allow tiny 1-call wrappers (e.g. 13BArrayList.appendAssumeCapacity) in.smallandensureUnusedCapacityin.fast.Verification & Impact
Optimizer.zig(140/140),Optimize.zig(28/28), andtest/behavior/wasm.zig(wasm32-wasiDebug/ReleaseSmall/ReleaseFast +simd128andwasm64-wasip3) all pass.wazig.wasm(0.17.1-wazig.1) shrinks by -105.5 KB (31,829,228 B->31,723,703 B;wazig.tar.zst8.08 MiB).knotssource,ReleaseSmallshrinks by -21.3 KB while speeding uptotal_bench_msby 6.6%–8.8% (matching LLVM 22-fllvmoverall at250.56msvs250.21ms), andReleaseFast +simd128beats LLVM 22 overall (213.78msvs230.48ms).