Debian Codegraph @

gcc/ada/libgnat/g-brapre.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- G N A T . B R A N C H _ P R E D I C T I O N --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2019-2025, AdaCore --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- This package provides routines giving hints to the branch predictor of the
33 -- code generator. These hints are useful when optimization is enabled and the
34 -- branch probability heuristics are used (which is the default), but they are
35 -- overridden when profile feedback-directed optimization is used instead.
36
37 -- The canonical pattern is to use them as the condition of an If statement:
38 --
39 -- if Likely (X > 0) then
40 -- Do_Something;
41 -- end if;
42 --
43 -- when it is not obvious that one outcome of the condition is more likely
44 -- than the other, or else to reverse the prediction made by the heuristics
45 -- in very peculiar cases. In the other cases, it is better not to use them,
46 -- because predicting how programs actually perform is notoriously hard.
47
48 package GNAT.Branch_Prediction is
49 pragma Pure;
50
51 function Expect (Condition : Boolean; Outcome : Boolean) return Boolean;
52 pragma Import (Intrinsic, Expect, "__builtin_expect");
53 -- This function returns the value of its first parameter Condition and
54 -- tells the branch predictor that this value is expected to be Outcome.
55
56 function Likely (Condition : Boolean) return Boolean;
57 pragma Import (Intrinsic, Likely, "__builtin_likely");
58 -- This function returns the value of its parameter Condition and tells
59 -- the branch predictor that this value is expected to be True. Calling
60 -- it is strictly equivalent to calling Expect with Outcome set to True.
61
62 function Unlikely (Condition : Boolean) return Boolean;
63 pragma Import (Intrinsic, Unlikely, "__builtin_unlikely");
64 -- This function returns the value of its parameter Condition and tells
65 -- the branch predictor that this value is expected to be False. Calling
66 -- it is strictly equivalent to calling Expect with Outcome set to False.
67
68 end GNAT.Branch_Prediction;