Re: Phix: Strange Behavior
- Posted by petelomax 2 weeks ago
- 334 views
Wow! Thanks for finding that!
The vast majority of programs rely exclusively on opSq0, which is fine and leaves e/rdx set to 0/1, however
opSq, which stores that 0/1 in a variable, is quite astonishingly simply backwards and always has been!
In many cases the compiler mitigates that by knowing what it should be rather than reloading from memory.
I even left myself the correct 32-bit code commented out and incorrectly optimised away...
Replace two uses of opAtomContinue in builtins\VM\pType.e from line 192 onwards with the two lines following it.
:%opSq -- [e/rdi]=sequence(e/rax) (NB: opSeq is dest=(p1=p2))
----------
[32]
-- calling convention
-- lea edi,[dest]
-- mov eax,[src] -- ref of src
-- mov ecx,src -- var no of src
-- call opSq -- [edi]:=sequence(eax)
-- xor ebx,ebx
cmp eax,h4
mov edx,[edi]
jl :edi0
:!opSqe92 -- exception mapped to e94vhnbaavecxfeh [DEV]
test byte[ebx+eax*4-1],0x80
-- jmp :opAtomContinue // ***WRONG*** (1/11/2026!)
jz :edi0
jmp :edi1
-- jz edi0
-- mov dword[edi],1
-- cmp edx,h4
-- jle @f
-- sub dword[ebx+edx*4-8],1
-- jz :%pDealloc
-- @@:
-- ret
[64]
-- calling convention
-- lea rdi,[dest]
-- mov rax,[src] -- ref of src
-- mov rcx,src -- var no of src
-- call opSq -- [rdi]:=sequence(rax)
mov r15,h4
mov rdx,[rdi]
cmp rax,r15
jl :edi0
:!opSqe92 -- exception mapped to e94vhnbaavecxfeh [DEV]
test byte[rbx+rax*4-1],0x80
-- jmp :opAtomContinue // ***WRONG*** (1/11/2026!)
jz :edi0
jmp :edi1
[]
You will of course need to run "p -c p" for these changes to take proper effect.

