kobalicek/mathpresso

Extra movsd's and some odd choice of register(s)

Zueuk opened this issue · 3 comments

Zueuk commented

I noticed that the generated asm code loads the same value into the same register multiple times.
The old Mathpresso (with an old AsmJit) version that I used before didn't do this:

x = y =1

lea rax, [L2]
movsd xmm0, [rax]
movsd [rdx], xmm0
movsd xmm0, [rax]
movsd [rdx+8], xmm0
movsd xmm0, [rax]
movsd [rcx], xmm0
ret

Another thing - a combination of an unary operation ("-", sqrt, etc.) and a function call somehow makes it use xmm6, that apparently needs to be savied/restored:

-x / sin(y)

sub rsp, 72
movaps oword ptr [rsp+48], xmm6
xorpd xmm6, xmm6
subsd xmm6, [rdx]
...
movaps xmm6, oword ptr [rsp+48]
add rsp, 72
ret

The best would be to have an implementation of all trigo functions inlinable, and this can be addressed in MathPresso as well. I'm planning to address the multiple fetches of constants in MPSL, I'm not sure if it is worth the effort to address it in MathPresso as it doesn't have IR (MSPL has).

I'm marking this as wontfix, as this will be fixed in more advanced MPSL project. After MPSL is ready there will be an expression mode so it can replace mathpresso completely.

Unnecessary MOVs will be also fixed by new asmjit's register allocator that can perform register coalescing, so no need to fix this in MathPresso.