| | @@ -5,81 +5,11 @@ |
| 5 | 5 | stopping for the owner's review. A finished milestone is cut from this |
| 6 | 6 | file: git keeps the history, and the report's section 12 the language's. |
| 7 | 7 | |
| 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. |
| 81 | 11 | |
| 82 | | -## Proposed: the manual |
| 12 | +## Next: the manual (v0.7.1) |
| 83 | 13 | |
| 84 | 14 | For: someone who has never seen raz can learn it from `man`, and come |
| 85 | 15 | back to it as a reference, without the report open; the report stays |
| | @@ -122,6 +52,40 @@ |
| 122 | 52 | |
| 123 | 53 | Each step is a commit and stops for review. Step 1 stands on its own |
| 124 | 54 | 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. |
| 125 | 89 | |
| 126 | 90 | ## Next, when the owner says |
| 127 | 91 | |