gdc or ldc for faster programs?

Patrick Schluter Patrick.Schluter at bbox.fr
Mon Jan 31 08:54:16 UTC 2022


On Tuesday, 25 January 2022 at 22:41:35 UTC, Elronnd wrote:
> On Tuesday, 25 January 2022 at 22:33:37 UTC, H. S. Teoh wrote:
>> interesting because idivl is known to be one of the slower 
>> instructions, but gdc nevertheless considered it not 
>> worthwhile to replace it, whereas ldc seems obsessed about 
>> avoid idivl at all costs.
>
> Interesting indeed.  Two remarks:
>
> 1. Actual performance cost of div depends a lot on hardware.  
> IIRC on my old intel laptop it's like 40-60 cycles; on my newer 
> amd chip it's more like 20; on my mac it's ~10.  GCC may be 
> assuming newer hardware than llvm.  Could be worth popping on a 
> -march=native -mtune=native.  Also could depend on how many 
> ports can do divs; i.e. how many of them you can have running 
> at a time.
>
> 2. LLVM is more aggressive wrt certain optimizations than gcc, 
> by default.  Though I don't know how relevant that is at -O3.

-O3 often chooses longer code and unrollsmore agressively 
inducing higher miss rates in the instruction caches.
-O2 can beat -O3 in some cases when code size is important.


More information about the Digitalmars-d-learn mailing list