Repository navigation
Conversation
blk_new wrote each cell with i % (1<<lgs), which reloads v[i%stride] every iteration. For multi-word elements (lgs>=1) that kept the fill scalar on top of bendlang#1928's trip-count fix. Walk the block by element instead: an inner loop over the stride writes v[j] (or 0 when padding). The common Array<Pt> case (lgs==1, n==2) unrolls to two invariant stores. On this Linux x86_64 host, doubling Array<Pt> to 2^23 goes from 8.00 to 5.25 instructions per element (matching U32's per-word rate); U32 doubling is unchanged. Part of bendlang#1890. Builds on bendlang#1928.
Collaborator
|
Thanks for this, and for claiming the slice cleanly in #1890. The diagnosis and the instruction counts are right. We're closing this in favor of #1946. It makes the same change to blk_new's fill: it walks whole elements with an inner loop over the stride and drops the per-cell
Both PRs rewrite the same loop, so only one can land. #1938 would also need a rebase onto #1928. |
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.
Draft — coordinating with @raramos9 on #1890 / #1928. Happy to adjust or stand down if that follow-on is already theirs.
Part of #1890. Related to #1928 (trip-count fix for runtime-depth
U32fills). This PR targets the multi-word case #1928 left open, and keeps thew = 1ull << c; i != wtrip-count form in the new loop.Cause
blk_newfilled withFor
U32(lgs == 0) that is one invariant store. For a two-field struct (lgs == 1,n == 2) it reloadsv[i % 2]every cell, so multi-word growth stays heavier than the per-wordU32rate even after #1928's trip-count fix.Change
Walk the block by element stride instead of by cell with modulo:
wis a multiple of1 << lgs(c = d + lgs), so the loops cover exactly the block. Padding whenn < stridestays a zero write. The commonArray<Pt>shape unrolls to two loop-invariant stores. The outeri != wform keeps #1928's clang-readable trip count.Benches
Linux x86_64, Bend built with the CLI's
clang -std=c11 -O3, compared againstmainplus the #1928 one-line trip-count fix as the baseline for fairness on multi-field (that fix alone does not close thePtgap). Each probe makes 100 arrays and folds one cell of each into a checksum. Instructions fromperf stat -e instructions:u(medians of three), minus the same probe at depth 0, divided by100 × 2^d. Checksums match before/after, and match the JS lane.Array<Pt>(twoU32fields) doubled to 2^23Array<U32>doubled to 2^245.25instr/element forPtis2.625instr/word — the same per-word rate asU32on this host. Wall clock here is noisy (memory-bound); instructions are the stable signal.Checks
bun gates/repo.ts: 54 / 54.comp.tsis 65,973 ttok (gpt-3.5-turbo), under the 66,000 cap.#|match on:array_fill_fold,array_boxed_get,array_size,array_poly_elem,array_map_loop,array_fork,array_copy_pair,array_nested,array_clone_boxed,array_static_default,array_equality.Array.newinside a bang fills the new block in one loop on one lane (~4.6 ns a cell) #1778 not addressed. Proof-backed init not addressed.