mathpresso icon indicating copy to clipboard operation
mathpresso copied to clipboard

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

Open Zueuk opened this issue 9 years ago • 3 comments

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

Zueuk avatar Feb 28 '16 20:02 Zueuk

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).

kobalicek avatar Feb 28 '16 20:02 kobalicek

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.

kobalicek avatar Mar 30 '16 23:03 kobalicek

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.

kobalicek avatar Apr 29 '17 11:04 kobalicek