poor codegen for abs(), and div by literal?
NaN
divide at by.zero
Thu Feb 7 23:15:08 UTC 2019
Given the following code...
module ohreally;
import std.math;
float foo(float y, float x)
{
float ax = fabs(x);
float ay = fabs(y);
return ax*ay/3.142f;
}
the compiler outputs the following for the function body,
(excluding prolog and epilogue code)...
movss -010h[RBP],XMM0
movss -8[RBP],XMM1
fld float ptr -010h[RBP]
fabs
fstp qword ptr -020h[RBP]
movsd XMM0,-020h[RBP]
cvtsd2ss XMM0,XMM0
fld float ptr -8[RBP]
fabs
fstp qword ptr -020h[RBP]
movsd XMM1,-020h[RBP]
cvtsd2ss XMM2,XMM1
mulss XMM0,XMM2
movss XMM3,FLAT:.rodata[00h][RIP]
divss XMM0,XMM3
So to do the abs(), it stores to memory from XMM reg, loads into
x87 FPU regs, does the abs with the old FPU instruction, then for
some reason stores the result as a double, loads that back into
an XMM, converts it back to single.
And the div by 3.142f, is there a reason it cant be converted to
a multiply? I know I can coax the multiply by doing
*(1.0f/3.142f) instead, but I wondered if there's some reasoning
in why its not done automatically?
Is any of this worth add to the bug tracker?
More information about the Digitalmars-d
mailing list