poor codegen for abs(), and div by literal?

Basile B. b2.temp at gmx.com
Sat Feb 9 17:47:43 UTC 2019


On Saturday, 9 February 2019 at 15:14:47 UTC, NaN wrote:
> On Saturday, 9 February 2019 at 03:28:41 UTC, Basile B. wrote:
>>> [...]
>
>>   [...]
>
> 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.

Oh sorry, I got the inverse multiply manually.
I was more focused on the x87 instruction than the last part of 
the Q.


More information about the Digitalmars-d mailing list