1 //===-- Unittests for fma ------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 #include "src/math/fma.h"
17 struct LlvmLibcFmaTest
: public FmaTestTemplate
<double> {
18 void test_more_values() {
19 constexpr int N
= 236;
20 constexpr Inputs INPUTS
[N
] = {
21 {0x1p
+0, 0x2p
+0, 0x3p
+0},
22 {0x1.4p
+0, 0xcp
-4, 0x1p
-4},
23 {0x0p
+0, 0x0p
+0, 0x0p
+0},
24 {0x1p
+0, 0x0p
+0, 0x0p
+0},
25 {0x0p
+0, 0x1p
+0, 0x0p
+0},
26 {0x1p
+0, 0x1p
+0, 0x1p
+0},
27 {0x0p
+0, 0x0p
+0, 0x1p
+0},
28 {0x0p
+0, 0x0p
+0, 0x2p
+0},
29 {0x0p
+0, 0x0p
+0, 0xf.fffffp
+124},
30 {0x0p
+0, 0x0p
+0, 0xf.ffffffffffff8p
+1020},
31 {0x0p
+0, 0x1p
+0, 0x1p
+0},
32 {0x1p
+0, 0x0p
+0, 0x1p
+0},
33 {0x0p
+0, 0x1p
+0, 0x2p
+0},
34 {0x1p
+0, 0x0p
+0, 0x2p
+0},
35 {0x0p
+0, 0x1p
+0, 0xf.fffffp
+124},
36 {0x0p
+0, 0x1p
+0, 0xf.ffffffffffff8p
+1020},
37 {0x1p
+0, 0x0p
+0, 0xf.fffffp
+124},
38 {0x1p
+0, 0x0p
+0, 0xf.ffffffffffff8p
+1020},
39 {0x4p
-128, 0x4p
-128, 0x0p
+0},
40 {0x4p
-128, 0x4p
-1024, 0x0p
+0},
41 {0x4p
-128, 0x8p
-972, 0x0p
+0},
42 {0x4p
-1024, 0x4p
-128, 0x0p
+0},
43 {0x4p
-1024, 0x4p
-1024, 0x0p
+0},
44 {0x4p
-1024, 0x8p
-972, 0x0p
+0},
45 {0x8p
-972, 0x4p
-128, 0x0p
+0},
46 {0x8p
-972, 0x4p
-1024, 0x0p
+0},
47 {0x8p
-972, 0x8p
-972, 0x0p
+0},
48 {0x4p
-128, 0x4p
-128, 0x0p
+0},
49 {0x4p
-128, 0x4p
-1024, 0x0p
+0},
50 {0x4p
-128, 0x8p
-972, 0x0p
+0},
51 {0x4p
-1024, 0x4p
-128, 0x0p
+0},
52 {0x4p
-1024, 0x4p
-1024, 0x0p
+0},
53 {0x4p
-1024, 0x8p
-972, 0x0p
+0},
54 {0x8p
-972, 0x4p
-128, 0x0p
+0},
55 {0x8p
-972, 0x4p
-1024, 0x0p
+0},
56 {0x8p
-972, 0x8p
-972, 0x0p
+0},
57 {0x4p
-128, 0x4p
-128, 0x0p
+0},
58 {0x4p
-128, 0x4p
-1024, 0x0p
+0},
59 {0x4p
-128, 0x8p
-972, 0x0p
+0},
60 {0x4p
-1024, 0x4p
-128, 0x0p
+0},
61 {0x4p
-1024, 0x4p
-1024, 0x0p
+0},
62 {0x4p
-1024, 0x8p
-972, 0x0p
+0},
63 {0x8p
-972, 0x4p
-128, 0x0p
+0},
64 {0x8p
-972, 0x4p
-1024, 0x0p
+0},
65 {0x8p
-972, 0x8p
-972, 0x0p
+0},
66 {0x4p
-128, 0x4p
-128, 0x0p
+0},
67 {0x4p
-128, 0x4p
-1024, 0x0p
+0},
68 {0x4p
-128, 0x8p
-972, 0x0p
+0},
69 {0x4p
-1024, 0x4p
-128, 0x0p
+0},
70 {0x4p
-1024, 0x4p
-1024, 0x0p
+0},
71 {0x4p
-1024, 0x8p
-972, 0x0p
+0},
72 {0x8p
-972, 0x4p
-128, 0x0p
+0},
73 {0x8p
-972, 0x4p
-1024, 0x0p
+0},
74 {0x8p
-972, 0x8p
-972, 0x0p
+0},
75 {0x4p
-128, 0x4p
-128, 0x0p
+0},
76 {0x4p
-128, 0x4p
-1024, 0x0p
+0},
77 {0x4p
-128, 0x8p
-972, 0x0p
+0},
78 {0x4p
-1024, 0x4p
-128, 0x0p
+0},
79 {0x4p
-1024, 0x4p
-1024, 0x0p
+0},
80 {0x4p
-1024, 0x8p
-972, 0x0p
+0},
81 {0x8p
-972, 0x4p
-128, 0x0p
+0},
82 {0x8p
-972, 0x4p
-1024, 0x0p
+0},
83 {0x8p
-972, 0x8p
-972, 0x0p
+0},
84 {0x4p
-128, 0x4p
-128, 0x0p
+0},
85 {0x4p
-128, 0x4p
-1024, 0x0p
+0},
86 {0x4p
-128, 0x8p
-972, 0x0p
+0},
87 {0x4p
-1024, 0x4p
-128, 0x0p
+0},
88 {0x4p
-1024, 0x4p
-1024, 0x0p
+0},
89 {0x4p
-1024, 0x8p
-972, 0x0p
+0},
90 {0x8p
-972, 0x4p
-128, 0x0p
+0},
91 {0x8p
-972, 0x4p
-1024, 0x0p
+0},
92 {0x8p
-972, 0x8p
-972, 0x0p
+0},
93 {0x4p
-128, 0x4p
-128, 0x0p
+0},
94 {0x4p
-128, 0x4p
-1024, 0x0p
+0},
95 {0x4p
-128, 0x8p
-972, 0x0p
+0},
96 {0x4p
-1024, 0x4p
-128, 0x0p
+0},
97 {0x4p
-1024, 0x4p
-1024, 0x0p
+0},
98 {0x4p
-1024, 0x8p
-972, 0x0p
+0},
99 {0x8p
-972, 0x4p
-128, 0x0p
+0},
100 {0x8p
-972, 0x4p
-1024, 0x0p
+0},
101 {0x8p
-972, 0x8p
-972, 0x0p
+0},
102 {0x4p
-128, 0x4p
-128, 0x0p
+0},
103 {0x4p
-128, 0x4p
-1024, 0x0p
+0},
104 {0x4p
-128, 0x8p
-972, 0x0p
+0},
105 {0x4p
-1024, 0x4p
-128, 0x0p
+0},
106 {0x4p
-1024, 0x4p
-1024, 0x0p
+0},
107 {0x4p
-1024, 0x8p
-972, 0x0p
+0},
108 {0x8p
-972, 0x4p
-128, 0x0p
+0},
109 {0x8p
-972, 0x4p
-1024, 0x0p
+0},
110 {0x8p
-972, 0x8p
-972, 0x0p
+0},
111 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-128},
112 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-1024},
113 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x8p
-972},
114 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
115 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
116 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
117 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-128},
118 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-1024},
119 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x8p
-972},
120 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
121 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
122 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
123 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-128},
124 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-1024},
125 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x8p
-972},
126 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
127 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
128 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
129 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-128},
130 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-1024},
131 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x8p
-972},
132 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
133 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
134 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
135 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-128},
136 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-1024},
137 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x8p
-972},
138 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
139 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
140 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
141 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-128},
142 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-1024},
143 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x8p
-972},
144 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
145 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
146 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
147 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-128},
148 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-1024},
149 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x8p
-972},
150 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
151 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
152 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
153 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-128},
154 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-1024},
155 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x8p
-972},
156 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
157 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
158 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
159 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-128},
160 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-1024},
161 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x8p
-972},
162 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
163 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
164 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
165 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-128},
166 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-1024},
167 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x8p
-972},
168 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
169 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
170 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
171 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-128},
172 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-1024},
173 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x8p
-972},
174 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
175 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
176 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
177 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-128},
178 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-1024},
179 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x8p
-972},
180 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
181 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
182 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
183 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-128},
184 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-1024},
185 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x8p
-972},
186 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
187 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
188 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
189 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-128},
190 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-1024},
191 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x8p
-972},
192 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
193 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
194 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
195 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-128},
196 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x4p
-1024},
197 {0xf.fffffp
+124, 0xf.fffffp
+124, 0x8p
-972},
198 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
199 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
200 {0xf.fffffp
+124, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
201 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-128},
202 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x4p
-1024},
203 {0xf.ffffffffffff8p
+1020, 0xf.fffffp
+124, 0x8p
-972},
204 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-128},
205 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x4p
-1024},
206 {0xf.ffffffffffff8p
+1020, 0xf.ffffffffffff8p
+1020, 0x8p
-972},
207 {0x2.fffp
+12, 0x1.000002p
+0, 0x1.ffffp
-24},
208 {0x1.fffp
+0, 0x1.00001p
+0, 0x1.fffp
+0},
209 {0xc.d5e6fp
+124, 0x2.6af378p
-128, 0x1.f08948p
+0},
210 {0x1.9abcdep
+100, 0x2.6af378p
-128, 0x3.e1129p
-28},
211 {0xf.fffffp
+124, 0x1.001p
+0, 0xf.fffffp
+124},
212 {0xf.fffffp
+124, 0x1.fffffep
+0, 0xf.fffffp
+124},
213 {0xf.fffffp
+124, 0x2p
+0, 0xf.fffffp
+124},
214 {0x5p
-128, 0x8.00002p
-4, 0x1p
-128},
215 {0x7.ffffep
-128, 0x8.00001p
-4, 0x8p
-152},
216 {0x8p
-152, 0x8p
-4, 0x3.fffff8p
-128},
217 {0x8p
-152, 0x8.8p
-4, 0x3.fffff8p
-128},
218 {0x8p
-152, 0x8p
-152, 0x8p
+124},
219 {0x8p
-152, 0x8p
-152, 0x4p
-128},
220 {0x8p
-152, 0x8p
-152, 0x3.fffff8p
-128},
221 {0x8p
-152, 0x8p
-152, 0x8p
-152},
222 {0xf.ffp
-4, 0xf.ffp
-4, 0xf.fep
-4},
223 {0x4.000008p
-128, 0x4.000008p
-28, 0x8p
+124},
224 {0x4.000008p
-128, 0x4.000008p
-28, 0x8p
+100},
225 {0x2.fep
+12, 0x1.0000000000001p
+0, 0x1.ffep
-48},
226 {0x1.fffp
+0, 0x1.0000000000001p
+0, 0x1.fffp
+0},
227 {0x1.0000002p
+0, 0xf.fffffep
-4, 0x1p
-300},
228 {0xe.f56df7797f768p
+1020, 0x3.7ab6fbbcbfbb4p
-1024,
229 0x3.40bf1803497f6p
+0},
230 {0x1.deadbeef2feedp
+900, 0x3.7ab6fbbcbfbb4p
-1024,
231 0x6.817e300692fecp
-124},
232 {0xf.ffffffffffff8p
+1020, 0x1.001p
+0, 0xf.ffffffffffff8p
+1020},
233 {0xf.ffffffffffff8p
+1020, 0x1.fffffffffffffp
+0,
234 0xf.ffffffffffff8p
+1020},
235 {0xf.ffffffffffff8p
+1020, 0x2p
+0, 0xf.ffffffffffff8p
+1020},
236 {0x5.a827999fcef3p
-540, 0x5.a827999fcef3p
-540, 0x0p
+0},
237 {0x3.bd5b7dde5fddap
-496, 0x3.bd5b7dde5fddap
-496, 0xd.fc352bc352bap
-992},
238 {0x3.bd5b7dde5fddap
-504, 0x3.bd5b7dde5fddap
-504,
239 0xd.fc352bc352bap
-1008},
240 {0x8p
-540, 0x4p
-540, 0x4p
-1076},
241 {0x1.7fffff8p
-968, 0x4p
-108, 0x4p
-1048},
242 {0x2.8000008p
-968, 0x4p
-108, 0x4p
-1048},
243 {0x2.8p
-968, 0x4p
-108, 0x4p
-1048},
244 {0x2.33956cdae7c2ep
-960, 0x3.8e211518bfea2p
-108,
245 0x2.02c2b59766d9p
-1024},
246 {0x3.a5d5dadd1d3a6p
-980, 0x2.9c0cd8c5593bap
-64, 0x2.49179ac00d15p
-1024},
247 {0x2.2a7aca1773e0cp
-908, 0x9.6809186a42038p
-128, 0x2.c9e356b3f0fp
-1024},
248 {0x3.ffffffffffffep
-712, 0x3.ffffffffffffep
-276,
249 0x3.fffffc0000ffep
-984},
250 {0x5p
-1024, 0x8.000000000001p
-4, 0x1p
-1024},
251 {0x7.ffffffffffffp
-1024, 0x8.0000000000008p
-4, 0x4p
-1076},
252 {0x4p
-1076, 0x8p
-4, 0x3.ffffffffffffcp
-1024},
253 {0x4p
-1076, 0x8.8p
-4, 0x3.ffffffffffffcp
-1024},
254 {0x4p
-1076, 0x4p
-1076, 0x8p
+1020},
255 {0x4p
-1076, 0x4p
-1076, 0x4p
-1024},
256 {0x4p
-1076, 0x4p
-1076, 0x3.ffffffffffffcp
-1024},
257 {0x4p
-1076, 0x4p
-1076, 0x4p
-1076},
258 {0xf.ffffffffffff8p
-4, 0xf.ffffffffffff8p
-4, 0xf.ffffffffffffp
-4},
259 {0x4.0000000000004p
-1024, 0x2.0000000000002p
-56, 0x8p
+1020},
260 {0x4.0000000000004p
-1024, 0x2.0000000000002p
-56, 0x4p
+968},
261 {0x7.fffff8p
-128, 0x3.fffffcp
+24, 0xf.fffffp
+124},
262 {0x7.ffffffffffffcp
-1024, 0x7.ffffffffffffcp
+52,
263 0xf.ffffffffffff8p
+1020},
266 for (int i
= 0; i
< N
; ++i
) {
267 for (int signs
= 0; signs
< 7; ++signs
) {
268 double a
= (signs
& 4) ? -INPUTS
[i
].a
: INPUTS
[i
].a
;
269 double b
= (signs
& 2) ? -INPUTS
[i
].b
: INPUTS
[i
].b
;
270 double c
= (signs
& 1) ? -INPUTS
[i
].c
: INPUTS
[i
].c
;
271 mpfr::TernaryInput
<double> input
{a
, b
, c
};
272 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Fma
, input
,
273 LIBC_NAMESPACE::fma(a
, b
, c
), 0.5);
279 TEST_F(LlvmLibcFmaTest
, SpecialNumbers
) {
280 test_special_numbers(&LIBC_NAMESPACE::fma
);
283 TEST_F(LlvmLibcFmaTest
, SubnormalRange
) {
284 test_subnormal_range(&LIBC_NAMESPACE::fma
);
287 TEST_F(LlvmLibcFmaTest
, NormalRange
) {
288 test_normal_range(&LIBC_NAMESPACE::fma
);
291 TEST_F(LlvmLibcFmaTest
, ExtraValues
) { test_more_values(); }