open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
958 stars 157 forks source link

Branch prediction heuristics? #658

Closed pgrAm closed 3 years ago

pgrAm commented 3 years ago

The user guide says this about branch prediction:

When the "ob" option is specified, the code generator will try to order the blocks of code emitted such that the "expected" execution path (as determined by a set of simple heuristics) will be straight through, with other cases being handled by jumps to separate blocks of code "out of line". This will result in better cache utilization on the Pentium. If the heuristics do not apply to your code, it could result in a performance decrease.

However it gives no information as to what those heuristics are. Is anyone able to explain how watcom decides how it determines which path is expected? Maybe it can be added to the guide?

Additionally is there any way to add a hint for this such as c++ likely/unlikely attributes or gcc's __builtin_expect?

jmalak commented 3 years ago

If you are interested in algorithm it is in OW Code Generator source file bld/cg/c/object.c and main routine is SortBlocks.