From 01dfbf639db5994f0085144d06bd551171e68be9 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:02:10 +0100 Subject: [PATCH] PLAN: better code for reals, done Against v0.8.0, on test/bench's kernels, raz against FPC -O2: Jacobi 3.1 -> 1.3 times (251 -> 103 ms), NBody 4.4 -> 1.4 (375 -> 116); rat's workload and the integer kernels as they were. compiler.md says what is left: Jacobi's index, worked out for each element where FPC shares it; NBody's call to Math.sqrt; a comparison of reals that jumps without a BOOL. Not tagged. --- diff --git a/CLAUDE.md b/CLAUDE.md index eb3a8bf..5b77360 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -91,9 +91,12 @@ `raz-tutorial(7)`, `raz(7)` and `raz-lib(3)`, made by `tools/Doc.raz` from `lib/`, and v0.8.0, better code again: slices in registers, parameters left in rdi and rsi, operands as the machine has them, -`while` tested at the bottom, and one line table, DWARF's. `make -kernels` measures `test/bench` against FPC `-O2`. Next, by `PLAN.md`: -what the owner chooses. +`while` tested at the bottom, and one line table, DWARF's, and, +not yet tagged, better code for reals: reals on the stack and the +busiest real variables in xmm registers, and an array's element and a +constant offset as operands, measured on two kernels of reals, +`Jacobi` and `NBody`. `make kernels` measures `test/bench` against +FPC `-O2`. Next, by `PLAN.md`: what the owner chooses. **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 diff --git a/PLAN.md b/PLAN.md index 3a32956..4a34cd5 100644 --- a/PLAN.md +++ b/PLAN.md @@ -5,12 +5,12 @@ 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. -Better code for reals is under way, by the owner's word. v0.7.1, the -manual, and v0.8.0, better code again, are tagged; all before v0.7.1 -is approved by the owner, and v0.7.1 and v0.8.0 wait for the owner's -review. +Better code for reals, begun by the owner's word, is done and waits for the +owner's review; it isn't tagged. v0.7.1, the manual, and v0.8.0, +better code again, are tagged; all before v0.7.1 is approved by the +owner, and v0.7.1 and v0.8.0 wait for the owner's review. -## Now: better code for reals +## Done: better code for reals For: code with reals near FPC `-O2`'s, as integer code is. raz keeps a real in an integer register and copies it to xmm0 or xmm1 and back @@ -46,6 +46,13 @@ slot, from which the trap report reads it and a call's return loads it, as System V keeps no xmm register through a call. NBody 147 ms to 116; rat within noise. + +All told: Jacobi 3.1 times FPC `-O2`'s time to 1.3, NBody 4.4 to 1.4; +rat and the integer kernels as they were; 9,131 lines of code. Left: +Jacobi's index, worked out for each element where FPC shares it, which +one pass can't; NBody's call to `Math.sqrt`, an instruction to FPC; +a comparison of reals that jumps without making a `BOOL`, which +neither kernel needs. ## Next, when the owner says diff --git a/doc/compiler.md b/doc/compiler.md index 1830094..55cd8ce 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -603,6 +603,19 @@ nothing in the trap report, bought 3% more on that copy and nothing on NBody. +All told, against v0.8.0: Jacobi 251 ms to 103, 3.1 times FPC +`-O2`'s time to 1.3; NBody 375 ms to 116, 4.4 times to 1.4; rat and +the integer kernels as they were. What is left of Jacobi is its index, +`i * N + j`, worked out five times a round, once for each element, +where FPC works it out three times: one pass keeps no expression to +share. What is left of +NBody is mostly its call to `Math.sqrt`, an instruction FPC puts in +place, with the spills and loads around it; then the `lea` of each +array's address, which FPC makes too, and the fifth real, `d2`, for +which there is no register. A comparison of reals still makes a +`BOOL` before it jumps, as `not (a < b)` isn't `a >= b` for a NaN; +neither kernel has one. + ## diag.pas: messages Every message the compiler prints is made here. A position, `TPos`, is