Debian Codegraph @

gcc/ada/libgnat/s-dorepr__fma.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S Y S T E M . D O U B L E _ R E A L . P R O D U C T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2021-2025, Free Software Foundation, Inc. --
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 is the version of the separate package body for targets with an FMA
33
34 separate (System.Double_Real)
35
36 package body Product is
37
38 function Fused_Multiply_Add (A, B, C : Num) return Num;
39 -- Return the result of A * B + C without intermediate rounding
40
41 ------------------------
42 -- Fused_Multiply_Add --
43 ------------------------
44
45 function Fused_Multiply_Add (A, B, C : Num) return Num is
46 begin
47 case Num'Size is
48 when 32 =>
49 declare
50 function Do_FMA (A, B, C : Num) return Num;
51 pragma Import (Intrinsic, Do_FMA, "__builtin_fmaf");
52
53 begin
54 return Do_FMA (A, B, C);
55 end;
56
57 when 64 =>
58 declare
59 function Do_FMA (A, B, C : Num) return Num;
60 pragma Import (Intrinsic, Do_FMA, "__builtin_fma");
61
62 begin
63 return Do_FMA (A, B, C);
64 end;
65
66 when others =>
67 raise Program_Error;
68 end case;
69 end Fused_Multiply_Add;
70
71 --------------
72 -- Two_Prod --
73 --------------
74
75 function Two_Prod (A, B : Num) return Double_T is
76 P : constant Num := A * B;
77
78 E : Num;
79
80 begin
81 if Is_Infinity (P) or else Is_Zero (P) then
82 return (P, 0.0);
83
84 else
85 E := Fused_Multiply_Add (A, B, -P);
86
87 return (P, E);
88 end if;
89 end Two_Prod;
90
91 -------------
92 -- Two_Sqr --
93 -------------
94
95 function Two_Sqr (A : Num) return Double_T is (Two_Prod (A, A));
96
97 end Product;