Debian Codegraph @

clang/test/CodeGen/rounding-math.cpp

raw
1 // RUN: %clang_cc1 -emit-llvm -triple i386-linux -Wno-unknown-pragmas -frounding-math %s -o - | FileCheck %s
2
3 constexpr float func_01(float x, float y) {
4 return x + y;
5 }
6
7 float V1 = func_01(1.0F, 0x0.000001p0F);
8 float V2 = 1.0F + 0x0.000001p0F;
9 float V3 = func_01(1.0F, 2.0F);
10
11 // CHECK: @V1 = {{.*}}global float 1.000000e+00, align 4
12 // CHECK: @V2 = {{.*}}global float 1.000000e+00, align 4
13 // CHECK: @V3 = {{.*}}global float 3.000000e+00, align 4
14
15 void test_builtin_elementwise_fma_round_upward() {
16 #pragma STDC FENV_ACCESS ON
17 #pragma STDC FENV_ROUND FE_UPWARD
18
19 // CHECK: store float 0x4018000100000000, ptr %f1
20 // CHECK: store float 0x4018000100000000, ptr %f2
21 constexpr float f1 = __builtin_elementwise_fma(2.0F, 3.000001F, 0.000001F);
22 constexpr float f2 = 2.0F * 3.000001F + 0.000001F;
23 static_assert(f1 == f2);
24 static_assert(f1 == 6.00000381F);
25 // CHECK: store double 0x40180000C9539B89, ptr %d1
26 // CHECK: store double 0x40180000C9539B89, ptr %d2
27 constexpr double d1 = __builtin_elementwise_fma(2.0, 3.000001, 0.000001);
28 constexpr double d2 = 2.0 * 3.000001 + 0.000001;
29 static_assert(d1 == d2);
30 static_assert(d1 == 6.0000030000000004);
31 }
32
33 void test_builtin_elementwise_fma_round_downward() {
34 #pragma STDC FENV_ACCESS ON
35 #pragma STDC FENV_ROUND FE_DOWNWARD
36
37 // CHECK: store float 0x40180000C0000000, ptr %f3
38 // CHECK: store float 0x40180000C0000000, ptr %f4
39 constexpr float f3 = __builtin_elementwise_fma(2.0F, 3.000001F, 0.000001F);
40 constexpr float f4 = 2.0F * 3.000001F + 0.000001F;
41 static_assert(f3 == f4);
42 // CHECK: store double 0x40180000C9539B87, ptr %d3
43 // CHECK: store double 0x40180000C9539B87, ptr %d4
44 constexpr double d3 = __builtin_elementwise_fma(2.0, 3.000001, 0.000001);
45 constexpr double d4 = 2.0 * 3.000001 + 0.000001;
46 static_assert(d3 == d4);
47 }
48
49 void test_builtin_elementwise_fma_round_nearest() {
50 #pragma STDC FENV_ACCESS ON
51 #pragma STDC FENV_ROUND FE_TONEAREST
52
53 // CHECK: store float 0x40180000C0000000, ptr %f5
54 // CHECK: store float 0x40180000C0000000, ptr %f6
55 constexpr float f5 = __builtin_elementwise_fma(2.0F, 3.000001F, 0.000001F);
56 constexpr float f6 = 2.0F * 3.000001F + 0.000001F;
57 static_assert(f5 == f6);
58 static_assert(f5 == 6.00000286F);
59 // CHECK: store double 0x40180000C9539B89, ptr %d5
60 // CHECK: store double 0x40180000C9539B89, ptr %d6
61 constexpr double d5 = __builtin_elementwise_fma(2.0, 3.000001, 0.000001);
62 constexpr double d6 = 2.0 * 3.000001 + 0.000001;
63 static_assert(d5 == d6);
64 static_assert(d5 == 6.0000030000000004);
65 }