A var real parameter's address in an integer register chooseRegs gave a var F64 or F32 parameter, used three times or more, one of XVarRegs by its type, though it holds an address; the prologue moved that into the integer register of the same number, another variable's. A parameter passed by its address now takes one integer register whatever its type, a var slice's too. Met in rgui's slider; conform/run/VarReal tests it.
| @@ -154,62 +154,3 @@ | ||
| 154 | 154 | a failed check in it is still told at its line; 60 to 100 lines of |
| 155 | 155 | the budget; and, across modules, the imported module's |
| 156 | 156 | text kept to be read again, which is to be checked. |
| 157 | - | |
| 158 | -## A var real parameter given an xmm register | |
| 159 | - | |
| 160 | -Not the language's but the compiler's, and a defect: a procedure | |
| 161 | -with a `var` parameter of type `F64` or `F32`, used three times or | |
| 162 | -more, may read another variable's value as that parameter's address, | |
| 163 | -and stop "by a nil pointer" or reach any memory. 0.12.0 and `main` | |
| 164 | -both do it: | |
| 165 | - | |
| 166 | -``` | |
| 167 | -module M; | |
| 168 | -import Out; | |
| 169 | - | |
| 170 | -proc show(var v: F64; a, b: INT): INT; | |
| 171 | -begin | |
| 172 | - Out.int(a + b); Out.int(a + b); Out.int(a + b); | |
| 173 | - Out.ln; | |
| 174 | - if v > 0.0 then return 1; end; | |
| 175 | - if v < 0.0 then return 2; end; | |
| 176 | - if v = 0.0 then return 3; end; | |
| 177 | - return 0; | |
| 178 | -end; | |
| 179 | - | |
| 180 | -proc main*; | |
| 181 | -var x: F64; | |
| 182 | -begin | |
| 183 | - Out.int(show(x, 1, 2)); | |
| 184 | - Out.ln; | |
| 185 | -end; | |
| 186 | - | |
| 187 | -end M. | |
| 188 | -``` | |
| 189 | - | |
| 190 | -stops at the first `if`, where it should print 3. | |
| 191 | - | |
| 192 | -The cause is in `Parse.chooseRegs`. `regFit` lets a parameter passed | |
| 193 | -by its address (`ind`) live in a register, which holds the address; | |
| 194 | -but the loop that hands out registers looks only at the type, so a | |
| 195 | -real's address is given one of `XVarRegs`, and a slice's address two | |
| 196 | -of `VarRegs`. The prologue then moves the address into the integer | |
| 197 | -register of the xmm register's number: xmm12, `XVarRegs[0]`, becomes | |
| 198 | -r12, which is `VarRegs[1]`, the second busiest integer variable's. In | |
| 199 | -the program above, `a` and `b` take rbx and r12, and `v`'s address | |
| 200 | -goes to r12 too, under `b`'s value. | |
| 201 | - | |
| 202 | -The fix, two lines: an `ind` candidate needs one integer register, | |
| 203 | -whatever its type. | |
| 204 | - | |
| 205 | -``` | |
| 206 | -need := 1; | |
| 207 | -if (cand[best]^.typ^.form = Sym.fSlice) and not cand[best]^.ind then need := 2; end; | |
| 208 | -if (cand[best]^.typ^.form = Sym.fReal) and not cand[best]^.ind then | |
| 209 | -``` | |
| 210 | - | |
| 211 | -Tried on `main`: the program above, and rgui's slider, then run as | |
| 212 | -they should, and `make check` passes as it does without it (but for | |
| 213 | -the manual pages, which fail alike where groff is missing). Met in | |
| 214 | -rgui, whose `Gui.slide` takes its knob's place in and gives it back, | |
| 215 | -rather than by a `var`, until this is mended. |
| @@ -0,0 +1,9 @@ | ||
| 1 | +333 | |
| 2 | +3 | |
| 3 | +333 | |
| 4 | +2 | |
| 5 | +121212 | |
| 6 | +65 | |
| 7 | +121212 | |
| 8 | +100 | |
| 9 | +365656568 |
| @@ -0,0 +1,55 @@ | ||
| 1 | +(* A var parameter of a real or a slice, used often, beside integers | |
| 2 | + that are used more: each is read and written through its address. *) | |
| 3 | +module VarReal; | |
| 4 | +import Out; | |
| 5 | + | |
| 6 | +proc sign(var v: F64; a, b: INT): INT; | |
| 7 | +begin | |
| 8 | + Out.int(a + b); Out.int(a + b); Out.int(a + b); | |
| 9 | + Out.ln; | |
| 10 | + if v > 0.0 then return 1; end; | |
| 11 | + if v < 0.0 then return 2; end; | |
| 12 | + if v = 0.0 then return 3; end; | |
| 13 | + return 0; | |
| 14 | +end; | |
| 15 | + | |
| 16 | +(* a knob's place, kept between lo and hi *) | |
| 17 | +proc slide(var x: F32; lo, hi, step: INT); | |
| 18 | +begin | |
| 19 | + x := x + F32(step) + F32(step) + F32(step); | |
| 20 | + if x < F32(lo) then x := F32(lo); end; | |
| 21 | + if x > F32(hi) then x := F32(hi); end; | |
| 22 | + Out.int(lo + hi + step); Out.int(lo + hi + step); Out.int(lo + hi + step); | |
| 23 | + Out.ln; | |
| 24 | +end; | |
| 25 | + | |
| 26 | +proc fill(var s: []U8; a, b: INT); | |
| 27 | +var i: INT; | |
| 28 | +begin | |
| 29 | + for i := 0 to LEN(s) - 1 do s[i] := U8(a + b + i); end; | |
| 30 | + s := s[1..LEN(s)]; | |
| 31 | + s[0] := U8(a + b); s[1] := U8(a + b); | |
| 32 | +end; | |
| 33 | + | |
| 34 | +proc main*; | |
| 35 | +var | |
| 36 | + x: F64; | |
| 37 | + y: F32; | |
| 38 | + buf: [4]U8; | |
| 39 | + s: []U8; | |
| 40 | +begin | |
| 41 | + Out.int(sign(x, 1, 2)); Out.ln; | |
| 42 | + x := -1.5; | |
| 43 | + Out.int(sign(x, 1, 2)); Out.ln; | |
| 44 | + y := 0.5; | |
| 45 | + slide(y, 0, 10, 2); | |
| 46 | + Out.int(INT(y * 10.0)); Out.ln; | |
| 47 | + slide(y, 0, 10, 2); | |
| 48 | + Out.int(INT(y * 10.0)); Out.ln; | |
| 49 | + s := buf[0..4]; | |
| 50 | + fill(s, 60, 5); | |
| 51 | + Out.int(LEN(s)); Out.int(INT(buf[0])); Out.int(INT(buf[1])); Out.int(INT(buf[2])); Out.int(INT(buf[3])); | |
| 52 | + Out.ln; | |
| 53 | +end; | |
| 54 | + | |
| 55 | +end VarReal. |
An empty file.
| @@ -609,6 +609,12 @@ | ||
| 609 | 609 | nothing in the trap report, bought 3% more on that copy and nothing |
| 610 | 610 | on NBody. |
| 611 | 611 | |
| 612 | + A `var` parameter of a real holds the real's address, an integer: | |
| 613 | + it takes one of `VarRegs`, not of `XVarRegs`, and a `var` slice's | |
| 614 | + one, not two. Through 0.12.0 it was given an xmm register, which the | |
| 615 | + prologue took for the integer register of its number, another | |
| 616 | + variable's (`chooseRegs`). | |
| 617 | + | |
| 612 | 618 | All told, against v0.8.0: Jacobi 251 ms to 103, 3.1 times FPC |
| 613 | 619 | `-O2`'s time to 1.3; NBody 375 ms to 116, 4.4 times to 1.4; rat and |
| 614 | 620 | the integer kernels as they were. What is left of Jacobi is its index, |
| @@ -2622,9 +2622,10 @@ | ||
| 2622 | 2622 | end; |
| 2623 | 2623 | if i > 4 then xmax := 4; end; |
| 2624 | 2624 | end; |
| 2625 | - (* a slice's weight is shared by its two registers *) | |
| 2625 | + (* a slice's weight is shared by its two registers; one passed by | |
| 2626 | + its address has one *) | |
| 2626 | 2627 | for i := 0 to numCand - 1 do |
| 2627 | - if cand[i]^.typ^.form = Sym.fSlice then weight[i] := weight[i] div 2; end; | |
| 2628 | + if (cand[i]^.typ^.form = Sym.fSlice) and not cand[i]^.ind then weight[i] := weight[i] div 2; end; | |
| 2628 | 2629 | end; |
| 2629 | 2630 | (* the heaviest, each used at least three times a register, take the |
| 2630 | 2631 | five registers in turn, while there are enough for each, and the |
| @@ -2636,9 +2637,13 @@ | ||
| 2636 | 2637 | if (cand[i]^.reg = 0) and (weight[i] >= 3) and ((best < 0) or (weight[i] > weight[best])) then best := i; end; |
| 2637 | 2638 | end; |
| 2638 | 2639 | if best < 0 then break; end; |
| 2640 | + (* a parameter passed by its address (ind) holds the address, one | |
| 2641 | + integer register whatever its type: a var real's address in | |
| 2642 | + an xmm register would be moved, by the prologue, into the | |
| 2643 | + integer register of the same number, another variable's *) | |
| 2639 | 2644 | need := 1; |
| 2640 | - if cand[best]^.typ^.form = Sym.fSlice then need := 2; end; | |
| 2641 | - if cand[best]^.typ^.form = Sym.fReal then | |
| 2645 | + if (cand[best]^.typ^.form = Sym.fSlice) and not cand[best]^.ind then need := 2; end; | |
| 2646 | + if (cand[best]^.typ^.form = Sym.fReal) and not cand[best]^.ind then | |
| 2642 | 2647 | if kx < xmax then |
| 2643 | 2648 | cand[best]^.reg := Gen.XVarRegs[kx]; |
| 2644 | 2649 | INC(kx); |