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;

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-07-10  Eric Botcazou  <ebotca...@adacore.com>

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.

Attachment: patch.diff.gz
Description: application/gzip

Reply via email to