raz / commit 859c14f2

commit
859c14f224c4015c6ff4ce1e74e3c7ddf7582fbb
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
9907e9ec
release
v0.7.0
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.

patch · log

3 files changed, +47 -83

CLAUDE.md modified +5 -5

@@ -85,8 +85,9 @@
8585 `Info`'s `file` and `symlink` for rloc (2026-10.6, step 49d), and
8686 stage 9, several results in place of var parameters (2026-10.8,
8787 steps 52-53), and v0.5.0, the library of report 2026-10.9, which the
88-compiler says it follows. v0.7.0, better code (`PLAN.md`), has its
89-seven steps pushed and awaits the owner's review before its tag.
88+compiler says it follows, and v0.7.0, better code. Next, by
89+`PLAN.md`: the manual (v0.7.1), then better code again (v0.8.0), each
90+on the owner's go.
9091
9192 **The freeze.** Since v0.5.0 the language changes only to mend a
9293 defect, and the library grows only by what breaks no program written
@@ -99,8 +100,7 @@
99100 rounding and the inverse functions, and `Sys` `space` (10.15), and
100101 whose constants may be records and tables of them, with `Str.copy`
101102 (10.16), and `COPY` (10.17), also by the owner's word. Its parser
102-reaches the machine only through `gen.pas`; its steps 5 to 10 await
103-the owner's review, and git has them. Keep
103+reaches the machine only through `gen.pas`. Keep
104104 `doc/compiler.md`'s table of lines and its routine names true when the
105105 compiler changes.
106106
@@ -111,7 +111,7 @@
111111 `.github/workflows/ci.yml`, which checks it and makes the GitHub
112112 release with a tarball of `raz` and `lib/`; it also checks every push
113113 to `main`. `README.md`'s "Versions" gives the commands. v0.3.0 is
114-the first; v0.6.0, report 2026-10.12, the latest.
114+the first; v0.7.0, report 2026-10.17, the latest.
115115
116116 `test/libc` runs its programs over `lib/Sys.raz`, the C one, through
117117 a link in its `mods`. A test or example without `.expect` is only

PLAN.md (history) modified +38 -74

@@ -5,81 +5,11 @@
55 stopping for the owner's review. A finished milestone is cut from this
66 file: git keeps the history, and the report's section 12 the language's.
77
8-v0.7.0, better code, has all its steps done and awaits the owner's
9-review before its tag. v0.6.0 is tagged; its steps 5 to 10 await
10-the owner's review.
11-
12-## Done, for review: better code (v0.7.0)
13-
14-For: rat within 1.25 times the time of pt built by FPC `-O2 -Cr`
15-(today 634 ms against 428, 1.48 times), with the compiler still a
16-model of clarity. No change to the language. Measured on rat's 26 MB
17-workload, best of 9 interleaved runs, and on `make bench`.
18-
19-Where rat's time goes (ulam-prof): `Utf8.next` 22%, `Str.decode` 15%,
20-`Screen.put` 11%, `Parser.feed` 11%, `Screen.unsplit` 9%. Their
21-listings show the steps below. ulam's `doc/codegen.md` measured the
22-same rewrites in a compiler of the same kind; its gains are quoted.
23-
24-**Where it stands.** All seven steps are done and pushed. rat takes
25-513 ms against 622 for the same workload built by the milestone's
26-first compiler (-18%), on a machine that drifts by 3%; pt built with
27-`-O2 -Cr` takes 426 ms the same hour, so rat is at 1.20 times, inside
28-the goal. Text is 1.5% smaller; the compiler is 8,559 lines of code
29-and compiles 980,000 lines a second. Each step:
30-
31-| Step | rat | Its kernel |
32-|---|---|---|
33-| 1. Prologue | -12% | |
34-| 2. Two words in rax, rdx | noise | calls returning two results, -9% |
35-| 3. Two results on the stack | -8% | |
36-| 4. Conditions as jumps | noise | a search leaving by break, -28% |
37-| 5. Shifts, constants right | noise | heap sort and list walk, -11% |
38-| 6. for loops | noise | matrix product -14%, sum -21% |
39-| 7. Read by a beginner | | |
40-
41-Steps that left rat's time alone stayed for their kernels, which the
42-2% rule allows. Moves between registers bought size, not time: this
43-machine renames them away, as ulam found.
44-
45-1. **A prologue that does only what it must.** A register variable
46- keeps a frame slot that is zeroed for nothing, and so do the slots
47- the registers are saved in: `Str.decode`, whose four variables are
48- all in registers, zeroes seven quadwords in a loop on every call.
49-2. **Two results in rax and rdx** for every procedure whose two
50- results are each one word, as a code procedure's are now; not
51- through a hidden pointer to the caller's slots. Changes a reading
52- of the report already taken: the owner's to approve.
53-3. **Values left where they are.** Gen's value stack keeps a value in
54- the place it is until it must move: a slice made from a slice
55- (`s[i..LEN(s)]`) isn't written to the frame and read back to be
56- passed; `v := v + x` adds into `v`'s register; a value is not moved
57- through `r8` on its way from one register to another; a value that
58- fits its type already isn't extended again (ulam's P1).
59-4. **Conditions as jumps.** `test` for a compare with zero; a `BOOL`
60- result tested where it is; a jump over a jump made one jump (ulam's
61- P7: with step 5, `heap` 11% faster); no dead jump after a `return`
62- or `break`; no check of what a slice's own length makes certain
63- (`s[i..LEN(s)]`'s upper bound).
64-5. **Addresses as the machine makes them.** An index scaled in the
65- address (`[rdi + rax*8]`), not by `imul` and `add`; a product by a
66- power of two as a shift; a constant on the right of `+ * & |`,
67- where it becomes an immediate (ulam's P5: `tree` 5 to 10% faster).
68-6. **`for` loops as FPC writes them**: stepped at the top, one compare
69- and one jump back at the bottom, the limit in a register when one is
70- free (ulam's P2: `matmul` 16% faster).
71-7. **Read by a beginner.** A reader with no part in this milestone
72- (a fresh agent) reads `gen.pas` and `doc/compiler.md` and lists
73- every place it can't follow; each is mended. `doc/compiler.md`
74- gains a section, "How the code is made good", walking one of rat's
75- procedures through the steps, before and after.
76-
77-Each step stops if it buys less than its lines: one that gains under
78-2% on rat and on no kernel is reverted and noted here. Short branches
79-(code 5 to 8% smaller in ulam's estimate) are left for after, measured
80-on their own.
8+No milestone is under way. v0.7.0, better code, is tagged, and all
9+before it is approved by the owner. Next come the manual (v0.7.1), then
10+better code again (v0.8.0), each when the owner says go.
8111
82-## Proposed: the manual
12+## Next: the manual (v0.7.1)
8313
8414 For: someone who has never seen raz can learn it from `man`, and come
8515 back to it as a reference, without the report open; the report stays
@@ -122,6 +52,40 @@
12252
12353 Each step is a commit and stops for review. Step 1 stands on its own
12454 and is most of the worth; 2 to 4 can wait.
55+
56+## Then: better code again (v0.8.0)
57+
58+For: on the same program, raz within 1.3 times the time of FPC `-O2`
59+with `check off;` (today 1.3 on a heap sort, 1.7 on a sum over a slice,
60+1.8 on a search: these kernels go in
61+`test/bench` first, with their Pascal twins, so anyone can measure
62+them), and every default program smaller; the compiler as clear as
63+v0.7.0 left it, and under 10,000 lines. No change to the language.
64+Each step is measured as v0.7.0's were, on rat and on its kernel, and
65+one that buys less than 2% on both is reverted and noted here.
66+
67+1. **Slices in registers.** A slice parameter or variable whose address
68+ isn't taken lives in two of the variables' registers, its pointer and
69+ its length, chosen by the read-ahead as a single value is, and
70+ counted as two. FPC's search keeps its slice in `rdi` and `rsi`;
71+ raz's reads both from the frame on every round.
72+2. **Parameters left where they arrive.** In a procedure that calls
73+ nothing, copies no block and divides by no variable, as the
74+ read-ahead can tell, a parameter stays in the register it came in,
75+ and no register is saved for it. Most of rat's hot procedures are
76+ such small ones (`unsplit`, `Width.cells`), and each call now saves
77+ and restores what it uses.
78+3. **Addresses and operands as the machine has them.** An element of a
79+ slice in registers is `[base + i*8]`, read where it is used; a
80+ compare or an addition takes its right operand from memory
81+ (`cmp r8, [rbp - 16]`), not through a register first.
82+4. **`while` tested at the bottom**, its test moved after the body and
83+ jumped to first, as `for` is now. ulam found nothing in it, and lost
84+ 3% where the test was long: measured, and kept only if it pays.
85+5. **One table of lines, not two.** Rt finds a place in `.debug_line`,
86+ loaded with the program, which gdb reads already, in place of the
87+ places' own 16 bytes a line: about 7 KB off hello, more off a big
88+ program, for a decoder of DWARF's line program in Rt.
12589
12690 ## Next, when the owner says
12791

README.md (history) modified +4 -4

@@ -184,16 +184,16 @@
184184 The compiler says its own version and that of the report it follows:
185185
186186 $ ./raz --version
187- raz 0.6.0, report 2026-10.12
187+ raz 0.7.0, report 2026-10.17
188188
189189 The compiler's version is git's name for the commit it was built from:
190-`0.6.0` at the tag `v0.6.0`, `0.6.0-5-g38d29a8` five commits past it.
190+`0.7.0` at the tag `v0.7.0`, `0.7.0-5-g38d29a8` five commits past it.
191191 To release, check `main` and tag it; the tag's message is what
192192 `raz --version` will print:
193193
194194 $ make check
195- $ git tag -a v0.6.1 -m 'raz 0.6.1, report 2026-10.12'
196- $ git push origin v0.6.1
195+ $ git tag -a v0.7.1 -m 'raz 0.7.1, report 2026-10.17'
196+ $ git push origin v0.7.1
197197
198198 GitHub then builds and checks the tag, and makes a release of it with
199199 a tarball of `raz` and its `lib/`. A tag pushed before the workflow