[PATCH v2 3/5] math: Improve fmod

Wilco Dijkstra Wilco.Dijkstra@arm.com
Fri Mar 17 14:55:40 GMT 2023


Hi Adhemerval,

>> It's these cases where x87 is still faster than the generic version:
>> 
>>> E5-2640          | close-exponents | 39.298   | 22.2742
>>>
>>> i7-4510U         | close-exponents | 29.463   | 22.8572
>> 
>> Are these mostly x < y or cases where the exponent difference is just over 11 and
>> thus we do not use the fast path?
>
> In fact the fast path will be used on ~83% of the cases (849 from 1024 entries).
> Profiling shows that the initial checks might be the culprit, since generic 
> compat wrapper uses compiler builtins that might map to fp instructions. But even
> trying to mimic did not improve much.  It seems that for some CPU the integer
> operations to create the final floating number is what is costly.

If it is mostly the fast path we could further tune it and reduce instruction counts.
It takes 6 if statements to enter this fast path, we could reduce that to 3. There are
several large constants which could be simplified (older x86 cores might have
issues with multiple 10-byte MOVABS in the instruction stream).

Also I think your results for generic above use the wrapper, so we'd still get the
> 20% speedup which should make things closer.

Cheers,
Wilco


More information about the Libc-alpha mailing list