Commit Graph
20 Commits
Author SHA1 Message Date
waozi d2db9d35fe Extend verified direct assembly execution and optimization 2026-11-11 21:28:27 -03:00
waozi 4dc2da6b09 Publish measured desktop, Android and web target matrix
Compare five real examples across four targets on three measured platforms, preserving raw samples, independent output verification and artifact provenance.

Complete the WebAssembly support needed by the examples, inspect ZX bundles, prune generated C dependencies while preserving C++ linkage, and validate native script execution. Optimize only the temporary bootstrap seed and retain fresh-build measurements and historical benchmark records under bench/results.

Local tests: all 522 cases passed across the full run and corrected header-test rerun; all 16 bootstrap modules match. Playground runtime, bundle runtime, private browser layouts and matrix controls, published artifacts and local site links passed.
2026-11-10 23:50:12 -03:00
waozi 347b3c8437 Move compiler parsing, linking and effect laws into Ziran 2026-11-07 19:16:39 -03:00
waozi 441ecbae77 Prove indices in else branches and through constant left shifts
An else branch runs where every branch before it in its chain was false,
so range narrowing and guard facts now use those conditions too: after
if i == 0 { ... } else if j == 0 { ... }, the else reads
view[(i - 1) * width + j - 1] without a check. x != c, or a false x == c,
moves an end of x's range that equals c, so t[i] under if i != 8 in
for i: 0..8 and text[0] after if text.count == 0 { return } need no check.
x << k by a constant count has the range of x * 2^k when that fits its
type, so bytes[(row << 4) + t] is proven; a shift that may wrap keeps its
check.

tests/loop_guard_ranges.sh adds two proven functions and two reads that
keep their checks: an else after i < 8 and a value ruled out inside the
range. tests/field_guard_ranges.sh adds a call in an else if condition,
and tests/proven_index_ranges.sh a shift past the s64 range. The bootstrap
C drops the three checks these rules prove in the compiler.

site/packages/av1.html lists the av1 decoder's new StoreSampleRow.
2026-11-07 07:53:23 -03:00
waozi 508e28135d Keep bounds checks behind guards on sums that may wrap
Since "Prove indices through ifx choices and narrow guard steps", a guard
operation whose bound overflows 64 bits counted as exact: record_sides
noted no side for it, so after if first + 1 + second > view.count
{ return }, view[first] lost its check although the sum wraps negative
for large terms and passes the guard. The same went through a local, an
ifx choice, a loop limit and row * stride + column, and the compiler's
own QualifiedName stored output[first.count] unchecked.

record_sides now bounds each end of the operation by itself. An end that
overflows or leaves the type needs its side, which no s64 operation can
have, so such a guard gives no fact.

tests/guarded_index_ranges.sh checks five more reads that keep their
checks; the released compiler reads past the slice on four of them.
2026-11-07 07:08:12 -03:00
waozi 31e97f3585 Run std/simd multiplies, narrowing and gathers inline under TinyCC
Under TinyCC on x86-64 the 32-bit multiplies, rounding shifts, half
widening and the signed narrowings are SSE2 assembly macros, and a gather
reads its lanes straight from the table, two to a 64-bit word, instead
of four memcpy calls. Each result is stored as one 128-bit block: the
next operation's 64-bit half loads still forward from it. TinyCC's
assembler learns pmuludq and pshufd.

Where nothing inlines (TinyCC, unoptimized GCC and Clang), zi_simd_at,
zi_simd_gather_check and SliceRange check in place and call only to
report. A whole slice a[:] is the view itself in C, and a vector load,
store or gather of a whole named array addresses the array directly.
TinyCC zeroes small braced locals with stores instead of memset.

AV1's s32x4 self-guided restoration (tree-s3) against its scalar form
(tree-s2), `ziran run`, best of 3 on one core:
  d352  cached 95 -> 76 ms (scalar 79 -> 71), uncached 356 -> 336 ms (scalar 328 -> 325)
  d1080 cached 488 -> 408 ms (scalar 484 -> 408), uncached 793 -> 703 ms (scalar 802 -> 703)
The bootstrap C is regenerated.
2026-11-07 04:51:58 -03:00
waozi cbc9e2d3ab Test a computed range bound once and leave the loop at its last value
A range over a computed bound was emitted as `while (i <= last)` with a
second exit, `if (i == last) break;`, before its step, so GCC refused to
vectorize it ("can't vectorize early exit"). When the counter and bound
are locals declared just before the loop, nothing takes their address and
every change of the counter is a step guarded by that last-value test, the
counter can never pass the bound, and C now writes
`if (i <= last) for (;;)`: one exit, which GCC can vectorize or turn into
memset, and TinyCC no longer tests the bound in every iteration.

AV1 1080p q40 decode (same hashes): gcc -O2 89 -> 86-88 ms, -O0 340 ->
335 ms, ziran run 609 -> 605 ms, -O3 unchanged at 77-79 ms.
2026-11-06 20:14:29 -03:00
waozi f0e2e2fcfa Emit calls of small same-module procedures as their bodies in C
TinyCC never inlines, so under `ziran run` every call of a tiny helper
paid a full call with all its locals on the stack. Generated C now writes
a call of a small straight-line procedure of the same module (no loops,
no module variables, scalars, pointers and small records only) as its
body in a block: arguments still run once, left to right, a return jumps
past the body, and the inlined call still costs the step its entry did.
Calls of foreign procedures stay out of inlined bodies, and private
procedures are declared ZIRAN_MAYBE_UNUSED for when every caller inlined
them.

A 1080p AV1 decode runs about 7% faster under `ziran run` and 4% faster
at -O0 with the same output; -O3 is unchanged. The bootstrap C is
regenerated. tests/call_site_inlining.sh covers argument order, name
clashes, early returns and the warning-free build.
2026-11-06 19:03:21 -03:00
waozi dd799d389d Read nested constant tables in place
A constant array of arrays writes each row with its type, as in
GRID :: [3]s32.[s32.[1, 2, 3], s32.[4, 5, 6]], and #run can build one in
a procedure that sets g[a][b][c]. The expression grammar now reads an
array type before .[, including inside parentheses, and compile-time
evaluation stores into nested elements. GRID[i][j] indexes the shared
table in place in C, Go and the portable VM instead of copying the row,
and a file-scope variable can start from a nested table.
2026-11-06 16:24:55 -03:00
waozi 8de755c348 Prove indices through ifx choices and narrow guard steps
AV1's AddResidual still checked samples[at], where at is
yy * stride + xx and a flip picks yy and xx with ifx, and even
samples[i * stride + j], because its guard reads
cast(s64)(height - 1) * stride + width with height - 1 in s32.

- A local declared from ifx stays an atom in index polynomials. The
  proof replaces it by each branch in turn and needs both to hold; it is
  never negative when neither branch is.
- Where an index only shrinks as a binding grows, the binding is replaced
  by a lower bound: a fact v - bound >= 0 or its smallest value.
- A cast to a type that holds every value of its operand's type is exact.
- In a guard comparison, + - * that may leave its type still gives an
  exact fact, with sides saying what must hold for it not to have wrapped.
  Where an index is read, the other facts must show the sides, as
  height - 1 - i >= 0 and i >= 0 show height - 1 did not wrap.
- poly_nonnegative tries each fact alone before searching pairs, so a guard
  that matches directly no longer spends the step budget under every
  other fact.

tests/loop_guard_ranges.sh adds Flip, proven with both flips and the s32
guard, and Mirror and Wrap, a branch one row past the end and a guard
whose height + 1 wraps, which keep their checks and still abort on C, Go,
native and the VM. AV1's generated C drops from 424 to 414 checks
(inverse transform 11 to 8, CfL 6 to 3, deblock 4 to 1) with its source
unchanged; the 1080p q20 benchmark median moves from 180.7 to 179.0 ms.
The compiler's own QualifiedName store output[first.count] is now proven
too, so bootstrap/compiler_expression is regenerated.
2026-11-06 14:09:44 -03:00
waozi e834d1ccfe Prove two-dimensional indexes from guards
Generated C leaves out the bounds check of an index such as
row * stride + column when a guard bounds it: an earlier if that returns,
breaks or continues, an enclosing if or while condition, or the earlier
operands of && and ||, until a value they compare changes. Indexes and
guard comparisons become polynomials over parameters, invariant locals
and slice counts; each loop counter is replaced by its upper bound, and
the index is proven below the count or length when every step is exact.
Guards that miss the read, values moved after the guard and else-if
exits keep their checks.

On the AV1 benchmark (fixed binaries, interleaved, one core) 1080p q20
drops from 185.1 to 182.2 ms and 720p 4:4:4 is unchanged, but 1080p
10-bit q30 rises from 201.5 to 212 ms. All of that comes from the one
check left out of FindCdefDirection's sample read; the function alone runs
faster without it (102 against 105 ns per call), so the loss is a layout
effect in the decoder's context.
2026-11-06 12:41:04 -03:00
waozi f3202b3d66 Leave out bounds checks generated C proves always pass 2026-11-06 07:37:16 -03:00
waozi 320637d835 Keep final short-circuit calls in native C expressions 2026-10-23 15:50:56 -03:00
waozi 244f36d7b0 Omit redundant C operand snapshots and regenerate bootstrap seeds 2026-10-23 15:47:12 -03:00
waozi ca0f6c2940 Reduce generated native runtime header dependencies 2026-10-15 22:21:02 -03:00
waozi 009c218cab Use each statement keyword's own length 2026-10-08 00:57:15 -03:00
waozi bf880017f8 Avoid redundant aggregate temporaries and preserve value arguments 2026-10-02 04:44:41 -03:00
waozi b9b20c325b Parse primary and prefix expressions in Ziran 2026-10-01 13:14:14 -03:00
waozi 10a85e4df3 Parse postfix expressions and nested initializers in Ziran 2026-10-01 12:53:32 -03:00
waozi 17f8c40b82 Compile binary expression grammar and statement extraction from Ziran 2026-10-01 12:06:06 -03:00