Hello Pascal Lovers
I'm not sure if I'm typing here with the goal to save time to others in the case that they get the same error as I got or if I want to know if I found a bug. Anyway, here we go.
I have 3 functions: A, B and C. Function A calls B. B calls C. C contains both pascal and asm code.
Function A shows strange floating point errors including division by zero error.
This is a portion of function C:
asm
...
vmovups ymm6, [rax+64]
...
end
[
'RAX',
'XMM6',
'ymm6'
];
After 4 or 5 hours debugging, I found that a floating point value stored on XMM6 on function A was being lost. Then, I found this link:
http://wiki.lazarus.freepascal.org/Win64/AMD64_APIFrom above link, I can read:
other nonvolatile registers, if used, should be pushed on stack. These registers are R12 through R15, RDI, RSI, RBX, XMM6 through XMM15
I though that signaling usage of either XMM6 or YMM6 would solve the problem:
https://www.freepascal.org/docs-html/prog/progse12.html#x149-1500003.4But I think that this is not the case. Not sure if this is a bug or not. If I were coding the compiler, I would not to be sure although I'm tempted to look at how the signaling was implemented.
HOW TO SOLVEThis is how I solved in my case:
var
mxmm6: array[0..3] of Single;
begin
...
asm
movups mxmm6, xmm6 // saves xmm6
...
movups xmm6, mxmm6 // restores xmm6 - YAY!!!
end ['RAX'];
So far, this problem shows up on Windows 64 only. Linux 64 with same code works well so far.
Please feel free to comment.
wish everyone happy coding