Skip to content

Commit b13ec7a

Browse files
committed
🐛 svg: Prevent code with fused instructions (#464)
Add a floating point conversion when multiplying when scaling coordinates so that the multiplication does not get fused with an adjacent addition or subtraction. This causes two instructions to be generated, a MUL and a ADD/SUB, instead of a single FMADD or FMSUB. A fused instruction has different rounding so ends up giving slightly different results to two instructions. This was causing different values in the SVGs generated between AMD64 and ARM64. Revert "labs: Rework random rectangle generation" as we no longer need to work around this by rounding in Evy code. Remove the parens in `randrect.evy` as they are not needed any more due to a recent change. I've tested this on AMD64 and ARM64 and the same SVGs are now generated. This merges the following commits: * svg: Prevent code with fused instructions * Revert "labs: Rework random rectangle generation" * labs: Remove unnecessary parens in randrect frontend/lab/samples/ifs/img/randrect.evy | 16 +- frontend/lab/samples/ifs/img/randrect.svg | 420 ++++++++++++++++++---- pkg/cli/svg/runtime.go | 9 +- 3 files changed, 372 insertions(+), 73 deletions(-) Link: https://go.dev/ref/spec#Floating_point_operators Pull-request: #464
2 parents 4915377 + 31f9dca commit b13ec7a

File tree

3 files changed

+372
-73
lines changed

3 files changed

+372
-73
lines changed
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
fill (hsl 270 100 50 10)
22
width 0.2
33
for range 60
4-
x := roundedRand1 * 100
5-
y := roundedRand1 * 100
6-
s1 := roundedRand1 * 25 + 2
7-
s2 := roundedRand1 * 25 + 2
4+
x := rand1 * 100
5+
y := rand1 * 100
6+
s1 := rand1 * 25 + 2
7+
s2 := rand1 * 25 + 2
88

99
move x-s1*0.5 y-s2*0.5
1010
rect s1 s2
1111
end
12-
13-
// roundedRand1 is a rounding rand1 function, to avoid rounding differences on
14-
// Mac and Linux.
15-
func roundedRand1:num
16-
r := rand1 * 1024
17-
r = round r
18-
return r / 1024
19-
end

0 commit comments

Comments
 (0)