From 859c14f224c4015c6ff4ce1e74e3c7ddf7582fbb Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 12 Oct 2026 16:56:23 +0100 Subject: [PATCH] PLAN: v0.7.0 released; the manual (v0.7.1), then v0.8.0 The owner approves v0.7.0 and all before it. v0.8.0: slices in registers, parameters left where they arrive, scaled addresses and memory operands, while tested at the bottom (if it pays), one table of lines. --- diff --git a/CLAUDE.md b/CLAUDE.md index a70bdb5..4b769c0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -85,8 +85,9 @@ `Info`'s `file` and `symlink` for rloc (2026-10.6, step 49d), and stage 9, several results in place of var parameters (2026-10.8, steps 52-53), and v0.5.0, the library of report 2026-10.9, which the -compiler says it follows. v0.7.0, better code (`PLAN.md`), has its -seven steps pushed and awaits the owner's review before its tag. +compiler says it follows, and v0.7.0, better code. Next, by +`PLAN.md`: the manual (v0.7.1), then better code again (v0.8.0), each +on the owner's go. **The freeze.** Since v0.5.0 the language changes only to mend a defect, and the library grows only by what breaks no program written @@ -99,8 +100,7 @@ rounding and the inverse functions, and `Sys` `space` (10.15), and whose constants may be records and tables of them, with `Str.copy` (10.16), and `COPY` (10.17), also by the owner's word. Its parser -reaches the machine only through `gen.pas`; its steps 5 to 10 await -the owner's review, and git has them. Keep +reaches the machine only through `gen.pas`. Keep `doc/compiler.md`'s table of lines and its routine names true when the compiler changes. @@ -111,7 +111,7 @@ `.github/workflows/ci.yml`, which checks it and makes the GitHub release with a tarball of `raz` and `lib/`; it also checks every push to `main`. `README.md`'s "Versions" gives the commands. v0.3.0 is -the first; v0.6.0, report 2026-10.12, the latest. +the first; v0.7.0, report 2026-10.17, the latest. `test/libc` runs its programs over `lib/Sys.raz`, the C one, through a link in its `mods`. A test or example without `.expect` is only diff --git a/PLAN.md b/PLAN.md index a49a597..4bb1f02 100644 --- a/PLAN.md +++ b/PLAN.md @@ -5,81 +5,11 @@ stopping for the owner's review. A finished milestone is cut from this file: git keeps the history, and the report's section 12 the language's. -v0.7.0, better code, has all its steps done and awaits the owner's -review before its tag. v0.6.0 is tagged; its steps 5 to 10 await -the owner's review. - -## Done, for review: better code (v0.7.0) - -For: rat within 1.25 times the time of pt built by FPC `-O2 -Cr` -(today 634 ms against 428, 1.48 times), with the compiler still a -model of clarity. No change to the language. Measured on rat's 26 MB -workload, best of 9 interleaved runs, and on `make bench`. - -Where rat's time goes (ulam-prof): `Utf8.next` 22%, `Str.decode` 15%, -`Screen.put` 11%, `Parser.feed` 11%, `Screen.unsplit` 9%. Their -listings show the steps below. ulam's `doc/codegen.md` measured the -same rewrites in a compiler of the same kind; its gains are quoted. - -**Where it stands.** All seven steps are done and pushed. rat takes -513 ms against 622 for the same workload built by the milestone's -first compiler (-18%), on a machine that drifts by 3%; pt built with -`-O2 -Cr` takes 426 ms the same hour, so rat is at 1.20 times, inside -the goal. Text is 1.5% smaller; the compiler is 8,559 lines of code -and compiles 980,000 lines a second. Each step: - -| Step | rat | Its kernel | -|---|---|---| -| 1. Prologue | -12% | | -| 2. Two words in rax, rdx | noise | calls returning two results, -9% | -| 3. Two results on the stack | -8% | | -| 4. Conditions as jumps | noise | a search leaving by break, -28% | -| 5. Shifts, constants right | noise | heap sort and list walk, -11% | -| 6. for loops | noise | matrix product -14%, sum -21% | -| 7. Read by a beginner | | | - -Steps that left rat's time alone stayed for their kernels, which the -2% rule allows. Moves between registers bought size, not time: this -machine renames them away, as ulam found. - -1. **A prologue that does only what it must.** A register variable - keeps a frame slot that is zeroed for nothing, and so do the slots - the registers are saved in: `Str.decode`, whose four variables are - all in registers, zeroes seven quadwords in a loop on every call. -2. **Two results in rax and rdx** for every procedure whose two - results are each one word, as a code procedure's are now; not - through a hidden pointer to the caller's slots. Changes a reading - of the report already taken: the owner's to approve. -3. **Values left where they are.** Gen's value stack keeps a value in - the place it is until it must move: a slice made from a slice - (`s[i..LEN(s)]`) isn't written to the frame and read back to be - passed; `v := v + x` adds into `v`'s register; a value is not moved - through `r8` on its way from one register to another; a value that - fits its type already isn't extended again (ulam's P1). -4. **Conditions as jumps.** `test` for a compare with zero; a `BOOL` - result tested where it is; a jump over a jump made one jump (ulam's - P7: with step 5, `heap` 11% faster); no dead jump after a `return` - or `break`; no check of what a slice's own length makes certain - (`s[i..LEN(s)]`'s upper bound). -5. **Addresses as the machine makes them.** An index scaled in the - address (`[rdi + rax*8]`), not by `imul` and `add`; a product by a - power of two as a shift; a constant on the right of `+ * & |`, - where it becomes an immediate (ulam's P5: `tree` 5 to 10% faster). -6. **`for` loops as FPC writes them**: stepped at the top, one compare - and one jump back at the bottom, the limit in a register when one is - free (ulam's P2: `matmul` 16% faster). -7. **Read by a beginner.** A reader with no part in this milestone - (a fresh agent) reads `gen.pas` and `doc/compiler.md` and lists - every place it can't follow; each is mended. `doc/compiler.md` - gains a section, "How the code is made good", walking one of rat's - procedures through the steps, before and after. - -Each step stops if it buys less than its lines: one that gains under -2% on rat and on no kernel is reverted and noted here. Short branches -(code 5 to 8% smaller in ulam's estimate) are left for after, measured -on their own. +No milestone is under way. v0.7.0, better code, is tagged, and all +before it is approved by the owner. Next come the manual (v0.7.1), then +better code again (v0.8.0), each when the owner says go. -## Proposed: the manual +## Next: the manual (v0.7.1) For: someone who has never seen raz can learn it from `man`, and come back to it as a reference, without the report open; the report stays @@ -122,6 +52,40 @@ Each step is a commit and stops for review. Step 1 stands on its own and is most of the worth; 2 to 4 can wait. + +## Then: better code again (v0.8.0) + +For: on the same program, raz within 1.3 times the time of FPC `-O2` +with `check off;` (today 1.3 on a heap sort, 1.7 on a sum over a slice, +1.8 on a search: these kernels go in +`test/bench` first, with their Pascal twins, so anyone can measure +them), and every default program smaller; the compiler as clear as +v0.7.0 left it, and under 10,000 lines. No change to the language. +Each step is measured as v0.7.0's were, on rat and on its kernel, and +one that buys less than 2% on both is reverted and noted here. + +1. **Slices in registers.** A slice parameter or variable whose address + isn't taken lives in two of the variables' registers, its pointer and + its length, chosen by the read-ahead as a single value is, and + counted as two. FPC's search keeps its slice in `rdi` and `rsi`; + raz's reads both from the frame on every round. +2. **Parameters left where they arrive.** In a procedure that calls + nothing, copies no block and divides by no variable, as the + read-ahead can tell, a parameter stays in the register it came in, + and no register is saved for it. Most of rat's hot procedures are + such small ones (`unsplit`, `Width.cells`), and each call now saves + and restores what it uses. +3. **Addresses and operands as the machine has them.** An element of a + slice in registers is `[base + i*8]`, read where it is used; a + compare or an addition takes its right operand from memory + (`cmp r8, [rbp - 16]`), not through a register first. +4. **`while` tested at the bottom**, its test moved after the body and + jumped to first, as `for` is now. ulam found nothing in it, and lost + 3% where the test was long: measured, and kept only if it pays. +5. **One table of lines, not two.** Rt finds a place in `.debug_line`, + loaded with the program, which gdb reads already, in place of the + places' own 16 bytes a line: about 7 KB off hello, more off a big + program, for a decoder of DWARF's line program in Rt. ## Next, when the owner says diff --git a/README.md b/README.md index 7e0d9e1..2fcaeea 100644 --- a/README.md +++ b/README.md @@ -184,16 +184,16 @@ The compiler says its own version and that of the report it follows: $ ./raz --version - raz 0.6.0, report 2026-10.12 + raz 0.7.0, report 2026-10.17 The compiler's version is git's name for the commit it was built from: -`0.6.0` at the tag `v0.6.0`, `0.6.0-5-g38d29a8` five commits past it. +`0.7.0` at the tag `v0.7.0`, `0.7.0-5-g38d29a8` five commits past it. To release, check `main` and tag it; the tag's message is what `raz --version` will print: $ make check - $ git tag -a v0.6.1 -m 'raz 0.6.1, report 2026-10.12' - $ git push origin v0.6.1 + $ git tag -a v0.7.1 -m 'raz 0.7.1, report 2026-10.17' + $ git push origin v0.7.1 GitHub then builds and checks the tag, and makes a release of it with a tarball of `raz` and its `lib/`. A tag pushed before the workflow