This adds a new GNAT.Branch_Prediction package to make it possible to tune the branch probability heuristics more finely. This package contains the equivalent of __builtin_expect in C/C++ plus a couple of specializations.
The following program gives a summary of the usage:
package Q is
I : Integer; pragma Volatile (I);
with GNAT.Branch_Prediction; use GNAT.Branch_Prediction; with Text_IO; use Text_IO; with Q; use Q;
procedure P is begin if Unlikely (I = 0) then Put_Line ("Zero was passed"); return; end if;
if Likely (I > 0) then Put_Line ("A positive number was passed"); else Put_Line ("A negative number was passed"); end if;
if Expect ((I rem 2) = 0, False) then Put_Line ("An even number was passed"); else Put_Line ("An odd number was passed"); end if; end;
2019-07-10 Eric Botcazou
- Makefile.rtl (GNATRTL_NONTASKING_OBJS): Add g-brapre.
- libgnat/g-brapre.ads: New package specification.
- doc/gnat_rm/the_gnat_library.rst: Document it.
- gnat_rm.texi: Regenerate.
97f0aa199fe [Ada] Improve support for tuning branch probability heuristics
gcc/ada/ChangeLog | 7 +
gcc/ada/Makefile.rtl | 1 +
gcc/ada/doc/gnat_rm/the_gnat_library.rst | 11 +
gcc/ada/gnat_rm.texi | 333 ++++++++++++++++---------------
gcc/ada/libgnat/g-brapre.ads | 68 +++++++
5 files changed, 260 insertions(+), 160 deletions(-)