Standard way to supply hints to branches
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sun Sep 15 05:39:24 UTC 2024
On 15/09/2024 2:37 PM, Walter Bright wrote:
> Thanks for digging this up. I don't see much hope of integrating that
> into a code generator.
Agreed, you won't be able to compete with LLVM and GCC, when they have
the cpu designers contributing.
> Even worse, using different schemes for multiple
> processors that are supposedly implementing the same instruction set.
The backend does have this knowledge. Normally with GCC and LLVM, you'd
give it the specific cpu generation you want to target. Or you can use
the JIT option for LLVM and get it sorted out on execution.
https://github.com/dlang/dmd/blob/0e8e67097df1a367eec1cff2069166843ad53eb3/compiler/src/dmd/backend/cdef.d#L221
https://wiki.dlang.org/LDC-specific_language_changes#.40.28ldc.attributes.dynamicCompile.29
The dmd backend understanding of cpu generations is a little out of date
though!
Realistically you're going to be relying on user data to optimize this
for dmd. Either from PGO, or annotation in code.
I can't see PGO being worth your time to implement. If people care about
performance they are simply not going to be using dmd for it.
But for annotation in code... you can do this in the glue code, a simple
swap of condition and with that path, should work!
```
test;
jgt True;
False:
goto End;
True:
End:
ret;
```
vs
```
test;
ge False;
True:
goto End;
False:
End:
ret;
```
More information about the Digitalmars-d
mailing list