[Ada] Improve support for tuning branch probability heuristics

Programming / Compilers / GCC - pmderodat [138bc75d-0d04-0410-961f-82ee72b054a4] - 10 July 2019 09:01 EDT

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);

end Q;

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

gcc/ada/

- 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(-)

Upstream: gcc.gnu.org


  • Share