xref: /llvm-project/mlir/test/mlir-runner/math-polynomial-approx.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1// RUN:   mlir-opt %s -pass-pipeline="builtin.module(func.func(test-math-polynomial-approximation),convert-vector-to-scf,convert-scf-to-cf,convert-vector-to-llvm,convert-to-llvm,reconcile-unrealized-casts)" \
2// RUN: | mlir-runner                                                      \
3// RUN:     -e main -entry-point-result=void -O0                               \
4// RUN:     -shared-libs=%mlir_c_runner_utils  \
5// RUN:     -shared-libs=%mlir_runner_utils    \
6// RUN: | FileCheck %s
7
8// -------------------------------------------------------------------------- //
9// Tanh.
10// -------------------------------------------------------------------------- //
11
12func.func @tanh_f32(%a : f32) {
13  %r = math.tanh %a : f32
14  vector.print %r : f32
15  return
16}
17
18func.func @tanh_4xf32(%a : vector<4xf32>) {
19  %r = math.tanh %a : vector<4xf32>
20  vector.print %r : vector<4xf32>
21  return
22}
23
24func.func @tanh_8xf32(%a : vector<8xf32>) {
25  %r = math.tanh %a : vector<8xf32>
26  vector.print %r : vector<8xf32>
27  return
28}
29
30func.func @tanh() {
31  // CHECK: 0.848284
32  %f0 = arith.constant 1.25 : f32
33  call @tanh_f32(%f0) : (f32) -> ()
34
35  // CHECK: 0.244919, 0.635149, 0.761594, 0.848284
36  %v1 = arith.constant dense<[0.25, 0.75, 1.0, 1.25]> : vector<4xf32>
37  call @tanh_4xf32(%v1) : (vector<4xf32>) -> ()
38
39  // CHECK: 0.099668, 0.197375, 0.291313, 0.379949, 0.462117, 0.53705, 0.604368, 0.664037
40  %v2 = arith.constant dense<[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]> : vector<8xf32>
41  call @tanh_8xf32(%v2) : (vector<8xf32>) -> ()
42
43  // CHECK: nan
44  %nan = arith.constant 0x7fc00000 : f32
45  call @tanh_f32(%nan) : (f32) -> ()
46
47 return
48}
49
50// -------------------------------------------------------------------------- //
51// Log.
52// -------------------------------------------------------------------------- //
53
54func.func @log_f32(%a : f32) {
55  %r = math.log %a : f32
56  vector.print %r : f32
57  return
58}
59
60func.func @log_4xf32(%a : vector<4xf32>) {
61  %r = math.log %a : vector<4xf32>
62  vector.print %r : vector<4xf32>
63  return
64}
65
66func.func @log_8xf32(%a : vector<8xf32>) {
67  %r = math.log %a : vector<8xf32>
68  vector.print %r : vector<8xf32>
69  return
70}
71
72func.func @log() {
73  // CHECK: 2.64704
74  %f1 = arith.constant 14.112233 : f32
75  call @log_f32(%f1) : (f32) -> ()
76
77  // CHECK: -1.38629, -0.287682, 0, 0.223144
78  %v1 = arith.constant dense<[0.25, 0.75, 1.0, 1.25]> : vector<4xf32>
79  call @log_4xf32(%v1) : (vector<4xf32>) -> ()
80
81  // CHECK: -2.30259, -1.60944, -1.20397, -0.916291, -0.693147, -0.510826, -0.356675, -0.223144
82  %v2 = arith.constant dense<[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]> : vector<8xf32>
83  call @log_8xf32(%v2) : (vector<8xf32>) -> ()
84
85  // CHECK: -inf
86  %zero = arith.constant 0.0 : f32
87  call @log_f32(%zero) : (f32) -> ()
88
89  // CHECK: nan
90  %nan = arith.constant 0x7fc00000 : f32
91  call @log_f32(%nan) : (f32) -> ()
92
93  // CHECK: inf
94  %inf = arith.constant 0x7f800000 : f32
95  call @log_f32(%inf) : (f32) -> ()
96
97  // CHECK: -inf, nan, inf, 0.693147
98  %special_vec = arith.constant dense<[0.0, -1.0, 0x7f800000, 2.0]> : vector<4xf32>
99  call @log_4xf32(%special_vec) : (vector<4xf32>) -> ()
100
101  return
102}
103
104func.func @log2_f32(%a : f32) {
105  %r = math.log2 %a : f32
106  vector.print %r : f32
107  return
108}
109
110func.func @log2_4xf32(%a : vector<4xf32>) {
111  %r = math.log2 %a : vector<4xf32>
112  vector.print %r : vector<4xf32>
113  return
114}
115
116func.func @log2_8xf32(%a : vector<8xf32>) {
117  %r = math.log2 %a : vector<8xf32>
118  vector.print %r : vector<8xf32>
119  return
120}
121
122func.func @log2() {
123  // CHECK: 3.81887
124  %f0 = arith.constant 14.112233 : f32
125  call @log2_f32(%f0) : (f32) -> ()
126
127  // CHECK: -2, -0.415037, 0, 0.321928
128  %v1 = arith.constant dense<[0.25, 0.75, 1.0, 1.25]> : vector<4xf32>
129  call @log2_4xf32(%v1) : (vector<4xf32>) -> ()
130
131  // CHECK: -3.32193, -2.32193, -1.73697, -1.32193, -1, -0.736966, -0.514573, -0.321928
132  %v2 = arith.constant dense<[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]> : vector<8xf32>
133  call @log2_8xf32(%v2) : (vector<8xf32>) -> ()
134
135  // CHECK: -inf
136  %zero = arith.constant 0.0 : f32
137  call @log2_f32(%zero) : (f32) -> ()
138
139  // CHECK: nan
140  %neg_one = arith.constant -1.0 : f32
141  call @log2_f32(%neg_one) : (f32) -> ()
142
143  // CHECK: inf
144  %inf = arith.constant 0x7f800000 : f32
145  call @log2_f32(%inf) : (f32) -> ()
146
147  // CHECK: -inf, nan, inf, 1.58496
148  %special_vec = arith.constant dense<[0.0, -1.0, 0x7f800000, 3.0]> : vector<4xf32>
149  call @log2_4xf32(%special_vec) : (vector<4xf32>) -> ()
150
151  return
152}
153
154func.func @log1p_f32(%a : f32) {
155  %r = math.log1p %a : f32
156  vector.print %r : f32
157  return
158}
159
160func.func @log1p_4xf32(%a : vector<4xf32>) {
161  %r = math.log1p %a : vector<4xf32>
162  vector.print %r : vector<4xf32>
163  return
164}
165
166func.func @log1p_8xf32(%a : vector<8xf32>) {
167  %r = math.log1p %a : vector<8xf32>
168  vector.print %r : vector<8xf32>
169  return
170}
171
172func.func @log1p() {
173  // CHECK: 0.00995033
174  %f0 = arith.constant 0.01 : f32
175  call @log1p_f32(%f0) : (f32) -> ()
176
177
178  // CHECK: -4.60517, -0.693147, 0, 1.38629
179  %v1 = arith.constant dense<[-0.99, -0.5, 0.0, 3.0]> : vector<4xf32>
180  call @log1p_4xf32(%v1) : (vector<4xf32>) -> ()
181
182  // CHECK: 0.0953102, 0.182322, 0.262364, 0.336472, 0.405465, 0.470004, 0.530628, 0.587787
183  %v2 = arith.constant dense<[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]> : vector<8xf32>
184  call @log1p_8xf32(%v2) : (vector<8xf32>) -> ()
185
186  // CHECK: -inf
187  %neg_one = arith.constant -1.0 : f32
188  call @log1p_f32(%neg_one) : (f32) -> ()
189
190  // CHECK: nan
191  %neg_two = arith.constant -2.0 : f32
192  call @log1p_f32(%neg_two) : (f32) -> ()
193
194  // CHECK: inf
195  %inf = arith.constant 0x7f800000 : f32
196  call @log1p_f32(%inf) : (f32) -> ()
197
198  // CHECK: -inf, nan, inf, 9.99995e-06
199  %special_vec = arith.constant dense<[-1.0, -1.1, 0x7f800000, 0.00001]> : vector<4xf32>
200  call @log1p_4xf32(%special_vec) : (vector<4xf32>) -> ()
201
202  return
203}
204
205// -------------------------------------------------------------------------- //
206// Erf.
207// -------------------------------------------------------------------------- //
208func.func @erf_f32(%a : f32) {
209  %r = math.erf %a : f32
210  vector.print %r : f32
211  return
212}
213
214func.func @erf_4xf32(%a : vector<4xf32>) {
215  %r = math.erf %a : vector<4xf32>
216  vector.print %r : vector<4xf32>
217  return
218}
219
220func.func @erf() {
221  // CHECK: -0.000274406
222  %val1 = arith.constant -2.431864e-4 : f32
223  call @erf_f32(%val1) : (f32) -> ()
224
225  // CHECK: 0.742095
226  %val2 = arith.constant 0.79999 : f32
227  call @erf_f32(%val2) : (f32) -> ()
228
229  // CHECK: 0.742101
230  %val3 = arith.constant 0.8 : f32
231  call @erf_f32(%val3) : (f32) -> ()
232
233  // CHECK: 0.995322
234  %val4 = arith.constant 1.99999 : f32
235  call @erf_f32(%val4) : (f32) -> ()
236
237  // CHECK: 0.995322
238  %val5 = arith.constant 2.0 : f32
239  call @erf_f32(%val5) : (f32) -> ()
240
241  // CHECK: 1
242  %val6 = arith.constant 3.74999 : f32
243  call @erf_f32(%val6) : (f32) -> ()
244
245  // CHECK: 1
246  %val7 = arith.constant 3.75 : f32
247  call @erf_f32(%val7) : (f32) -> ()
248
249  // CHECK: -1
250  %negativeInf = arith.constant 0xff800000 : f32
251  call @erf_f32(%negativeInf) : (f32) -> ()
252
253  // CHECK: -1, -1, -0.913759, -0.731446
254  %vecVals1 = arith.constant dense<[-3.4028235e+38, -4.54318, -1.2130899, -7.8234202e-01]> : vector<4xf32>
255  call @erf_4xf32(%vecVals1) : (vector<4xf32>) -> ()
256
257  // CHECK: -1.3264e-38, 0, 1.3264e-38, 0.121319
258  %vecVals2 = arith.constant dense<[-1.1754944e-38, 0.0, 1.1754944e-38, 1.0793410e-01]> : vector<4xf32>
259  call @erf_4xf32(%vecVals2) : (vector<4xf32>) -> ()
260
261  // CHECK: 0.919477, 0.999069, 1, 1
262  %vecVals3 = arith.constant dense<[1.23578, 2.34093, 3.82342, 3.4028235e+38]> : vector<4xf32>
263  call @erf_4xf32(%vecVals3) : (vector<4xf32>) -> ()
264
265  // CHECK: 1
266  %inf = arith.constant 0x7f800000 : f32
267  call @erf_f32(%inf) : (f32) -> ()
268
269  // CHECK: nan
270  %nan = arith.constant 0x7fc00000 : f32
271  call @erf_f32(%nan) : (f32) -> ()
272
273  return
274}
275
276// -------------------------------------------------------------------------- //
277// Exp.
278// -------------------------------------------------------------------------- //
279func.func @exp_f32(%a : f32) {
280  %r = math.exp %a : f32
281  vector.print %r : f32
282  return
283}
284
285func.func @exp_4xf32(%a : vector<4xf32>) {
286  %r = math.exp %a : vector<4xf32>
287  vector.print %r : vector<4xf32>
288  return
289}
290
291func.func @exp() {
292  // CHECK: 2.71828
293  %f0 = arith.constant 1.0 : f32
294  call @exp_f32(%f0) : (f32) -> ()
295
296  // CHECK: 0.778801, 2.117, 2.71828, 3.85743
297  %v1 = arith.constant dense<[-0.25, 0.75, 1.0, 1.35]> : vector<4xf32>
298  call @exp_4xf32(%v1) : (vector<4xf32>) -> ()
299
300  // CHECK: 1
301  %zero = arith.constant 0.0 : f32
302  call @exp_f32(%zero) : (f32) -> ()
303
304  // CHECK: 0, 1.38879e-11, 7.20049e+10, inf
305  %special_vec = arith.constant dense<[-89.0, -25.0, 25.0, 89.0]> : vector<4xf32>
306  call @exp_4xf32(%special_vec) : (vector<4xf32>) -> ()
307
308  // CHECK: inf
309  %inf = arith.constant 0x7f800000 : f32
310  call @exp_f32(%inf) : (f32) -> ()
311
312  // CHECK: 0
313  %negative_inf = arith.constant 0xff800000 : f32
314  call @exp_f32(%negative_inf) : (f32) -> ()
315
316  // CHECK: nan
317  %nan = arith.constant 0x7fc00000 : f32
318  call @exp_f32(%nan) : (f32) -> ()
319
320  return
321}
322
323func.func @expm1_f32(%a : f32) {
324  %r = math.expm1 %a : f32
325  vector.print %r : f32
326  return
327}
328
329func.func @expm1_3xf32(%a : vector<3xf32>) {
330  %r = math.expm1 %a : vector<3xf32>
331  vector.print %r : vector<3xf32>
332  return
333}
334
335func.func @expm1_4xf32(%a : vector<4xf32>) {
336  %r = math.expm1 %a : vector<4xf32>
337  vector.print %r : vector<4xf32>
338  return
339}
340
341func.func @expm1_8xf32(%a : vector<8xf32>) {
342  %r = math.expm1 %a : vector<8xf32>
343  vector.print %r : vector<8xf32>
344  return
345}
346
347func.func @expm1() {
348  // CHECK: 1e-10
349  %f0 = arith.constant 1.0e-10 : f32
350  call @expm1_f32(%f0) : (f32) -> ()
351
352  // CHECK: -0.00995017, 0.0100502, 0.648721, 6.38906
353  %v1 = arith.constant dense<[-0.01, 0.01, 0.5, 2.0]> : vector<4xf32>
354  call @expm1_4xf32(%v1) : (vector<4xf32>) -> ()
355
356  // CHECK: -0.181269, 0, 0.221403, 0.491825, 0.822119, 1.22554, 1.71828, 2.32012
357  %v2 = arith.constant dense<[-0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2]> : vector<8xf32>
358  call @expm1_8xf32(%v2) : (vector<8xf32>) -> ()
359
360  // CHECK: -1
361  %neg_inf = arith.constant 0xff800000 : f32
362  call @expm1_f32(%neg_inf) : (f32) -> ()
363
364  // CHECK: inf
365  %inf = arith.constant 0x7f800000 : f32
366  call @expm1_f32(%inf) : (f32) -> ()
367
368  // CHECK: -1, inf, 1e-10
369  %special_vec = arith.constant dense<[0xff800000, 0x7f800000, 1.0e-10]> : vector<3xf32>
370  call @expm1_3xf32(%special_vec) : (vector<3xf32>) -> ()
371
372  // CHECK: nan
373  %nan = arith.constant 0x7fc00000 : f32
374  call @expm1_f32(%nan) : (f32) -> ()
375
376  return
377}
378// -------------------------------------------------------------------------- //
379// Sin.
380// -------------------------------------------------------------------------- //
381func.func @sin_f32(%a : f32) {
382  %r = math.sin %a : f32
383  vector.print %r : f32
384  return
385}
386
387func.func @sin_3xf32(%a : vector<3xf32>) {
388  %r = math.sin %a : vector<3xf32>
389  vector.print %r : vector<3xf32>
390  return
391}
392
393func.func @sin() {
394  // CHECK: 0
395  %zero = arith.constant 0.0 : f32
396  call @sin_f32(%zero) : (f32) -> ()
397
398  // CHECK: 0.707107
399  %pi_over_4 = arith.constant 0.78539816339 : f32
400  call @sin_f32(%pi_over_4) : (f32) -> ()
401
402  // CHECK: 1
403  %pi_over_2 = arith.constant 1.57079632679 : f32
404  call @sin_f32(%pi_over_2) : (f32) -> ()
405
406  // CHECK: 0
407  %pi = arith.constant 3.14159265359 : f32
408  call @sin_f32(%pi) : (f32) -> ()
409
410  // CHECK: -1
411  %pi_3_over_2 = arith.constant 4.71238898038 : f32
412  call @sin_f32(%pi_3_over_2) : (f32) -> ()
413
414  // CHECK: 0, 0.866025, -1
415  %vec_x = arith.constant dense<[9.42477796077, 2.09439510239, -1.57079632679]> : vector<3xf32>
416  call @sin_3xf32(%vec_x) : (vector<3xf32>) -> ()
417
418  return
419}
420
421// -------------------------------------------------------------------------- //
422// cos.
423// -------------------------------------------------------------------------- //
424func.func @cos_f32(%a : f32) {
425  %r = math.cos %a : f32
426  vector.print %r : f32
427  return
428}
429
430func.func @cos_3xf32(%a : vector<3xf32>) {
431  %r = math.cos %a : vector<3xf32>
432  vector.print %r : vector<3xf32>
433  return
434}
435
436func.func @cos() {
437  // CHECK: 1
438  %zero = arith.constant 0.0 : f32
439  call @cos_f32(%zero) : (f32) -> ()
440
441  // CHECK: 0.707107
442  %pi_over_4 = arith.constant 0.78539816339 : f32
443  call @cos_f32(%pi_over_4) : (f32) -> ()
444
445  // CHECK: 0
446  %pi_over_2 = arith.constant 1.57079632679 : f32
447  call @cos_f32(%pi_over_2) : (f32) -> ()
448
449  // CHECK: -1
450  %pi = arith.constant 3.14159265359 : f32
451  call @cos_f32(%pi) : (f32) -> ()
452
453  // CHECK: 0
454  %pi_3_over_2 = arith.constant 4.71238898038 : f32
455  call @cos_f32(%pi_3_over_2) : (f32) -> ()
456
457  // CHECK: -1, -0.5, 0
458  %vec_x = arith.constant dense<[9.42477796077, 2.09439510239, -1.57079632679]> : vector<3xf32>
459  call @cos_3xf32(%vec_x) : (vector<3xf32>) -> ()
460
461  return
462}
463
464// -------------------------------------------------------------------------- //
465// Asin.
466// -------------------------------------------------------------------------- //
467func.func @asin_f32(%a : f32) {
468  %r = math.asin %a : f32
469  vector.print %r : f32
470  return
471}
472
473func.func @asin_3xf32(%a : vector<3xf32>) {
474  %r = math.asin %a : vector<3xf32>
475  vector.print %r : vector<3xf32>
476  return
477}
478
479func.func @asin() {
480  // CHECK: 0
481  %zero = arith.constant 0.0 : f32
482  call @asin_f32(%zero) : (f32) -> ()
483
484  // CHECK: -0.597406
485  %cst1 = arith.constant -0.5625 : f32
486  call @asin_f32(%cst1) : (f32) -> ()
487
488  // CHECK: -0.384397
489  %cst2 = arith.constant -0.375 : f32
490  call @asin_f32(%cst2) : (f32) -> ()
491
492  // CHECK: -0.25268
493  %cst3 = arith.constant -0.25 : f32
494  call @asin_f32(%cst3) : (f32) -> ()
495
496  // CHECK: -1.1197
497  %cst4 = arith.constant -0.90 : f32
498  call @asin_f32(%cst4) : (f32) -> ()
499
500  // CHECK: 0.25268, 0.384397, 0.597406
501  %vec_x = arith.constant dense<[0.25, 0.375, 0.5625]> : vector<3xf32>
502  call @asin_3xf32(%vec_x) : (vector<3xf32>) -> ()
503
504  return
505}
506
507// -------------------------------------------------------------------------- //
508// Acos.
509// -------------------------------------------------------------------------- //
510func.func @acos_f32(%a : f32) {
511  %r = math.acos %a : f32
512  vector.print %r : f32
513  return
514}
515
516func.func @acos_3xf32(%a : vector<3xf32>) {
517  %r = math.acos %a : vector<3xf32>
518  vector.print %r : vector<3xf32>
519  return
520}
521
522func.func @acos() {
523  // CHECK: 1.5708
524  %zero = arith.constant 0.0 : f32
525  call @acos_f32(%zero) : (f32) -> ()
526
527  // CHECK: 2.1682
528  %cst1 = arith.constant -0.5625 : f32
529  call @acos_f32(%cst1) : (f32) -> ()
530
531  // CHECK: 1.95519
532  %cst2 = arith.constant -0.375 : f32
533  call @acos_f32(%cst2) : (f32) -> ()
534
535  // CHECK: 1.82348
536  %cst3 = arith.constant -0.25 : f32
537  call @acos_f32(%cst3) : (f32) -> ()
538
539  // CHECK: 1.31812, 1.1864, 0.97339
540  %vec_x = arith.constant dense<[0.25, 0.375, 0.5625]> : vector<3xf32>
541  call @acos_3xf32(%vec_x) : (vector<3xf32>) -> ()
542
543  return
544}
545
546// -------------------------------------------------------------------------- //
547// Atan.
548// -------------------------------------------------------------------------- //
549func.func @atan_f32(%a : f32) {
550  %r = math.atan %a : f32
551  vector.print %r : f32
552  return
553}
554
555func.func @atan() {
556  // CHECK: -0.785398
557  %0 = arith.constant -1.0 : f32
558  call @atan_f32(%0) : (f32) -> ()
559
560  // CHECK: 0.785398
561  %1 = arith.constant 1.0 : f32
562  call @atan_f32(%1) : (f32) -> ()
563
564  // CHECK: -0.463648
565  %2 = arith.constant -0.5 : f32
566  call @atan_f32(%2) : (f32) -> ()
567
568  // CHECK: 0.463648
569  %3 = arith.constant 0.5 : f32
570  call @atan_f32(%3) : (f32) -> ()
571
572  // CHECK: 0
573  %4 = arith.constant 0.0 : f32
574  call @atan_f32(%4) : (f32) -> ()
575
576  // CHECK: -1.10715
577  %5 = arith.constant -2.0 : f32
578  call @atan_f32(%5) : (f32) -> ()
579
580  // CHECK: 1.10715
581  %6 = arith.constant 2.0 : f32
582  call @atan_f32(%6) : (f32) -> ()
583
584  return
585}
586
587
588// -------------------------------------------------------------------------- //
589// Atan2.
590// -------------------------------------------------------------------------- //
591func.func @atan2_f32(%a : f32, %b : f32) {
592  %r = math.atan2 %a, %b : f32
593  vector.print %r : f32
594  return
595}
596
597func.func @atan2() {
598  %zero = arith.constant 0.0 : f32
599  %one = arith.constant 1.0 : f32
600  %two = arith.constant 2.0 : f32
601  %neg_one = arith.constant -1.0 : f32
602  %neg_two = arith.constant -2.0 : f32
603
604  // CHECK: 0
605  call @atan2_f32(%zero, %one) : (f32, f32) -> ()
606
607  // CHECK: 1.5708
608  call @atan2_f32(%one, %zero) : (f32, f32) -> ()
609
610  // CHECK: 3.14159
611  call @atan2_f32(%zero, %neg_one) : (f32, f32) -> ()
612
613  // CHECK: -1.5708
614  call @atan2_f32(%neg_one, %zero) : (f32, f32) -> ()
615
616  // CHECK: nan
617  call @atan2_f32(%zero, %zero) : (f32, f32) -> ()
618
619  // CHECK: 1.10715
620  call @atan2_f32(%two, %one) : (f32, f32) -> ()
621
622  // CHECK: 2.03444
623  %x6 = arith.constant -1.0 : f32
624  %y6 = arith.constant 2.0 : f32
625  call @atan2_f32(%two, %neg_one) : (f32, f32) -> ()
626
627  // CHECK: -2.03444
628  call @atan2_f32(%neg_two, %neg_one) : (f32, f32) -> ()
629
630  // CHECK: -1.10715
631  call @atan2_f32(%neg_two, %one) : (f32, f32) -> ()
632
633  // CHECK: 0.463648
634  call @atan2_f32(%one, %two) : (f32, f32) -> ()
635
636  // CHECK: 2.67795
637  %x10 = arith.constant -2.0 : f32
638  %y10 = arith.constant 1.0 : f32
639  call @atan2_f32(%one, %neg_two) : (f32, f32) -> ()
640
641  // CHECK: -2.67795
642  %x11 = arith.constant -2.0 : f32
643  %y11 = arith.constant -1.0 : f32
644  call @atan2_f32(%neg_one, %neg_two) : (f32, f32) -> ()
645
646  // CHECK: -0.463648
647  call @atan2_f32(%neg_one, %two) : (f32, f32) -> ()
648
649  return
650}
651
652
653// -------------------------------------------------------------------------- //
654// Cbrt.
655// -------------------------------------------------------------------------- //
656
657func.func @cbrt_f32(%a : f32) {
658  %r = math.cbrt %a : f32
659  vector.print %r : f32
660  return
661}
662
663func.func @cbrt() {
664  // CHECK: 1
665  %a = arith.constant 1.0 : f32
666  call @cbrt_f32(%a) : (f32) -> ()
667
668  // CHECK: -1
669  %b = arith.constant -1.0 : f32
670  call @cbrt_f32(%b) : (f32) -> ()
671
672  // CHECK: 0
673  %c = arith.constant 0.0 : f32
674  call @cbrt_f32(%c) : (f32) -> ()
675
676  // CHECK: -0
677  %d = arith.constant -0.0 : f32
678  call @cbrt_f32(%d) : (f32) -> ()
679
680  // CHECK: 10
681  %e = arith.constant 1000.0 : f32
682  call @cbrt_f32(%e) : (f32) -> ()
683
684  // CHECK: -10
685  %f = arith.constant -1000.0 : f32
686  call @cbrt_f32(%f) : (f32) -> ()
687
688  // CHECK: 2.57128
689  %g = arith.constant 17.0 : f32
690  call @cbrt_f32(%g) : (f32) -> ()
691
692  return
693}
694
695// -------------------------------------------------------------------------- //
696// floor.
697// -------------------------------------------------------------------------- //
698func.func @func_floorf32(%a : f32) {
699  %r = math.floor %a : f32
700  vector.print %r : f32
701  return
702}
703
704func.func @floorf() {
705  // CHECK: 3
706  %a = arith.constant 3.8 : f32
707  call @func_floorf32(%a) : (f32) -> ()
708
709  // CHECK: -4
710  %b = arith.constant -3.8 : f32
711  call @func_floorf32(%b) : (f32) -> ()
712
713  // CHECK: 0
714  %c = arith.constant 0.0 : f32
715  call @func_floorf32(%c) : (f32) -> ()
716
717  // CHECK: -5
718  %d = arith.constant -4.2 : f32
719  call @func_floorf32(%d) : (f32) -> ()
720
721  // CHECK: -2
722  %e = arith.constant -2.0 : f32
723  call @func_floorf32(%e) : (f32) -> ()
724
725  // CHECK: 2
726  %f = arith.constant 2.0 : f32
727  call @func_floorf32(%f) : (f32) -> ()
728
729  return
730}
731
732// -------------------------------------------------------------------------- //
733// ceil.
734// -------------------------------------------------------------------------- //
735func.func @func_ceilf32(%a : f32) {
736  %r = math.ceil %a : f32
737  vector.print %r : f32
738  return
739}
740
741func.func @ceilf() {
742  // CHECK: 4
743  %a = arith.constant 3.8 : f32
744  call @func_ceilf32(%a) : (f32) -> ()
745
746  // CHECK: -3
747  %b = arith.constant -3.8 : f32
748  call @func_ceilf32(%b) : (f32) -> ()
749
750  // CHECK: 0
751  %c = arith.constant 0.0 : f32
752  call @func_ceilf32(%c) : (f32) -> ()
753
754  // CHECK: -4
755  %d = arith.constant -4.2 : f32
756  call @func_ceilf32(%d) : (f32) -> ()
757
758  // CHECK: -495
759  %e = arith.constant -495.0 : f32
760  call @func_ceilf32(%e) : (f32) -> ()
761
762  // CHECK: 495
763  %f = arith.constant 495.0 : f32
764  call @func_ceilf32(%f) : (f32) -> ()
765
766  return
767}
768
769func.func @main() {
770  call @tanh(): () -> ()
771  call @log(): () -> ()
772  call @log2(): () -> ()
773  call @log1p(): () -> ()
774  call @erf(): () -> ()
775  call @exp(): () -> ()
776  call @expm1(): () -> ()
777  call @sin(): () -> ()
778  call @cos(): () -> ()
779  call @asin(): () -> ()
780  call @acos(): () -> ()
781  call @atan() : () -> ()
782  call @atan2() : () -> ()
783  call @cbrt() : () -> ()
784  call @floorf() : () -> ()
785  call @ceilf() : () -> ()
786  return
787}
788