Skip to content

Fix eel2 regNN*regNN optimizer bug#34

Open
shanevbg wants to merge 1 commit into
justinfrankel:mainfrom
shanevbg:fix/eel2-regNN-multiply-bug
Open

Fix eel2 regNN*regNN optimizer bug#34
shanevbg wants to merge 1 commit into
justinfrankel:mainfrom
shanevbg:fix/eel2-regNN-multiply-bug

Conversation

@shanevbg
Copy link
Copy Markdown

Summary

  • Bug: nseel_resolve_named_symbol clears sname[0]=0 for regNN variables (line 983), which causes the x*x → sqr(x) optimizer to treat ALL regNN variables as identical (comparing empty strings). reg10*reg20 gets compiled as sqr(reg10).
  • Fix 1: Remove sname[0]=0 — the comment already says "this shouldn't be needed anyway"
  • Fix 2: Add valuePtr comparison as primary check in the VARPTR case of the sqr() optimization, consistent with the existing VARPTRPTR case. Guard the string fallback with relname[0] check.

Reproduction

Any EEL script multiplying two different regNN variables produces incorrect results:

reg10 = 3;
reg20 = 5;
result = reg10 * reg20;  // Expected: 15, Got: 9 (sqr(reg10))

Discovered in MilkDrop/Milkwave preset rendering where rotation matrices using different regNN variables produced incorrect visual output.

Changes

WDL/eel2/nseel-compiler.c — 2 insertions, 2 deletions:

  1. Line 983: Remove sname[0]=0 that cleared the variable name after resolving regNN globals
  2. Lines 2460-2461: Add valuePtr pointer comparison (like VARPTRPTR case), guard string comparison with relname[0] check

nseel_resolve_named_symbol clears sname[0] for regNN variables (line 983),
which makes the x*x → sqr(x) optimizer treat ALL regNN vars as identical
(it compares relname strings, which are now all empty). This causes
expressions like `reg10*reg20` to be compiled as `sqr(reg10)`.

Two fixes:
1. Remove `sname[0]=0` — the comment already says "this shouldn't be
   needed anyway", and it breaks the optimizer's string comparison.
2. Add valuePtr comparison as primary check in the VARPTR case of the
   sqr() optimization, consistent with the existing VARPTRPTR case
   (line 2464). Also guard the string fallback with relname[0] check
   to prevent empty-string false matches.

Discovered in MilkDrop preset rendering where rotation matrices using
different regNN variables produced incorrect results (squaring one
operand instead of multiplying two distinct registers).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant