Commit Graph
22 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 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 8f6df80860 Dispatch #target procedures to SSSE3, SSE4.1 and AVX2 clones
A #target procedure gets a clone per x86-64 SIMD tier in C, and the
procedure itself picks one through CPUID and the OS's YMM state, read
once. ZIRAN_SIMD_TIER lowers the choice for tests. Checking keeps 256-bit
vectors from crossing the procedure's boundary by value, since AVX2
clones would pass them in YMM registers. Saved IR records the modifier
(format 61). TinyCC, NEON and other targets compile the procedure once.
2026-11-06 14:41:00 -03:00
waozi 35eae0536d Add #inline and #cold procedure modifiers
#inline after a procedure's result makes generated C always inline it:
private procedures become static inline with always_inline on GCC and
Clang, and a public procedure keeps its cross-module header copy past the
usual size limits. A procedure that calls itself is rejected
(check.inline).

#cold marks a slow path: the C definition is noinline and cold, other
modules call its one definition instead of a header copy, and Go gets
//go:noinline. Neither modifier changes what a call does.

Saved IR records the modifier, so the ZIR format version is now 60.
tests/procedure_inlining.sh checks the attributes, which calls stay out
of line, C at -O0 and -O2, Go, native and portable results, saved IR, and
the rejected forms.
2026-11-06 12:56:37 -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 e859f7854f Inline small public procedures across modules through header copies 2026-11-06 06:51:58 -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 88b8acfdfe Emit native Rust assembly with checked portable fallback
Share checked operands with the Rust backend, preserve caller storage for memory operands, and isolate CPU-feature helpers behind cached runtime detection. Fix quoted-brace discovery for one-line assembly procedures and target-width Rust word types.

Add source/saved IR conformance, explicit unsupported-variant fallbacks, cross-target evidence and a repeatable native-control benchmark.
2026-10-15 20:05:44 -03:00
waozi a2b277ba66 Keep assembly annotations in existing statement storage 2026-10-15 15:53:43 -03:00
waozi be996fb8ff Support local assembly blocks with checked portable bodies 2026-10-15 15:24:02 -03:00
waozi 07fe834cda Parse blocks opened and closed together on one line
A line such as 'for y: 0..2 { for x: 0..2 {' opened only the outer
block, and '} }' closed only one, so the file failed with
"unterminated declaration at end of file". A control header whose
body stays open now passes its remaining text on as the next logical
line without queueing a closer, and '} }' splits into two closers.
Unterminated literals inside the body still leave the line unsplit.
2026-10-02 15:44:25 -03:00
waozi bf880017f8 Avoid redundant aggregate temporaries and preserve value arguments 2026-10-02 04:44:41 -03:00
waozi 938f42b8e2 Parse loop headers and using modifiers in Ziran 2026-10-01 13:45:14 -03:00
waozi 50d296b3a7 Compile procedure header parsing from Ziran source 2026-10-01 01:36:48 -03:00
waozi cd0a4327a3 Move statement classification and record separators into Ziran 2026-10-01 01:18:28 -03:00
waozi 8d4374ad6a Compile source preprocessing and logical scanning from Ziran 2026-10-01 01:09:31 -03:00