poor codegen for abs(), and div by literal?
NaN
divide at by.zero
Sat Feb 9 15:14:47 UTC 2019
On Saturday, 9 February 2019 at 03:28:41 UTC, Basile B. wrote:
> On Thursday, 7 February 2019 at 23:15:08 UTC, NaN wrote:
>> Given the following code...
> LDC2 does almost that, excepted that the logical AND is in a
> sub program:
>
> push rax
> movss dword ptr [rsp+04h], xmm1
> call 000000000045A020h
> movss dword ptr [rsp], xmm0
> movss xmm0, dword ptr [rsp+04h]
> call 000000000045A020h
> mulss xmm0, dword ptr [rsp]
> mulss xmm0, dword ptr [<address of constant>]
> pop rax
> ret
What flags are you passing LDC? I cant get it to convert the
division into a multiply by it's inverse unless i specifically
change /3.142f to /(1.0f/3.142f).
and FWIW im using...
float fabs(float x) // need cause math.fabs not being inlined
{
uint tmp = *(cast(int*)&x) & 0x7fffffff;
float f = *(cast(float*) &tmp);
return f;
}
that compiles down to a single "andps" instruction and is inlined
if it's in the same module. I tried cross module inlining as
suggested in the LDC forum but it caused my program to hang.
More information about the Digitalmars-d
mailing list