1 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
2 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s --check-prefixes=CHECK,UNSIGNED
4 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,SIGNED
5 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,UNSIGNED
7 // Between different fixed point types
8 short _Accum sa_const
= 2.5hk
;
9 // CHECK-DAG: @sa_const = {{.*}}global i16 320, align 2
10 _Accum a_const
= 2.5hk
;
11 // CHECK-DAG: @a_const = {{.*}}global i32 81920, align 4
12 short _Accum sa_const2
= 2.5k
;
13 // CHECK-DAG: @sa_const2 = {{.*}}global i16 320, align 2
15 short _Accum sa_from_f_const
= 0.5r
;
16 // CHECK-DAG: sa_from_f_const = {{.*}}global i16 64, align 2
17 _Fract f_from_sa_const
= 0.5hk
;
18 // CHECK-DAG: f_from_sa_const = {{.*}}global i16 16384, align 2
20 unsigned short _Accum usa_const
= 2.5uk
;
21 unsigned _Accum ua_const
= 2.5uhk
;
22 // SIGNED-DAG: @usa_const = {{.*}}global i16 640, align 2
23 // SIGNED-DAG: @ua_const = {{.*}}global i32 163840, align 4
24 // UNSIGNED-DAG: @usa_const = {{.*}}global i16 320, align 2
25 // UNSIGNED-DAG: @ua_const = {{.*}}global i32 81920, align 4
27 // FixedPoint to integer
28 int i_const
= -128.0hk
;
29 // CHECK-DAG: @i_const = {{.*}}global i32 -128, align 4
30 int i_const2
= 128.0hk
;
31 // CHECK-DAG: @i_const2 = {{.*}}global i32 128, align 4
32 int i_const3
= -128.0k
;
33 // CHECK-DAG: @i_const3 = {{.*}}global i32 -128, align 4
34 int i_const4
= 128.0k
;
35 // CHECK-DAG: @i_const4 = {{.*}}global i32 128, align 4
36 short s_const
= -128.0k
;
37 // CHECK-DAG: @s_const = {{.*}}global i16 -128, align 2
38 short s_const2
= 128.0k
;
39 // CHECK-DAG: @s_const2 = {{.*}}global i16 128, align 2
41 // Integer to fixed point
42 short _Accum sa_const5
= 2;
43 // CHECK-DAG: @sa_const5 = {{.*}}global i16 256, align 2
44 short _Accum sa_const6
= -2;
45 // CHECK-DAG: @sa_const6 = {{.*}}global i16 -256, align 2
46 short _Accum sa_const7
= -256;
47 // CHECK-DAG: @sa_const7 = {{.*}}global i16 -32768, align 2
49 // Fixed point to floating point
50 float fl_const
= 1.0hk
;
51 // CHECK-DAG: @fl_const = {{.*}}global float 1.000000e+00, align 4
52 float fl_const2
= -128.0k
;
53 // CHECK-DAG: @fl_const2 = {{.*}}global float -1.280000e+02, align 4
54 float fl_const3
= 0.0872802734375k
;
55 // CHECK-DAG: @fl_const3 = {{.*}}global float 0x3FB6580000000000, align 4
56 float fl_const4
= 192.5k
;
57 // CHECK-DAG: @fl_const4 = {{.*}}global float 1.925000e+02, align 4
58 float fl_const5
= -192.5k
;
59 // CHECK-DAG: @fl_const5 = {{.*}}global float -1.925000e+02, align 4
61 // Floating point to fixed point
62 _Accum a_fl_const
= 1.0f
;
63 // CHECK-DAG: @a_fl_const = {{.*}}global i32 32768, align 4
64 _Accum a_fl_const2
= -128.0f
;
65 // CHECK-DAG: @a_fl_const2 = {{.*}}global i32 -4194304, align 4
66 _Accum a_fl_const3
= 0.0872802734375f
;
67 // CHECK-DAG: @a_fl_const3 = {{.*}}global i32 2860, align 4
68 _Accum a_fl_const4
= 0.0872802734375;
69 // CHECK-DAG: @a_fl_const4 = {{.*}}global i32 2860, align 4
70 _Accum a_fl_const5
= -0.0872802734375f
;
71 // CHECK-DAG: @a_fl_const5 = {{.*}}global i32 -2860, align 4
72 _Fract f_fl_const
= 0.5f
;
73 // CHECK-DAG: @f_fl_const = {{.*}}global i16 16384, align 2
74 _Fract f_fl_const2
= -0.75;
75 // CHECK-DAG: @f_fl_const2 = {{.*}}global i16 -24576, align 2
76 unsigned short _Accum usa_fl_const
= 48.75f
;
77 // SIGNED-DAG: @usa_fl_const = {{.*}}global i16 12480, align 2
78 // UNSIGNED-DAG: @usa_fl_const = {{.*}}global i16 6240, align 2
81 unsigned short _Accum usa_const2
= 2.5hk
;
82 // SIGNED-DAG: @usa_const2 = {{.*}}global i16 640, align 2
83 // UNSIGNED-DAG: @usa_const2 = {{.*}}global i16 320, align 2
84 short _Accum sa_const3
= 2.5hk
;
85 // CHECK-DAG: @sa_const3 = {{.*}}global i16 320, align 2
87 int i_const5
= 128.0uhk
;
88 unsigned int ui_const
= 128.0hk
;
89 // CHECK-DAG: @i_const5 = {{.*}}global i32 128, align 4
90 // CHECK-DAG: @ui_const = {{.*}}global i32 128, align 4
92 short _Accum sa_const9
= 2u;
93 // CHECK-DAG: @sa_const9 = {{.*}}global i16 256, align 2
94 unsigned short _Accum usa_const3
= 2;
95 // SIGNED-DAG: @usa_const3 = {{.*}}global i16 512, align 2
96 // UNSIGNED-DAG: @usa_const3 = {{.*}}global i16 256, align 2
98 // Overflow (this is undefined but allowed)
99 short _Accum sa_const4
= 256.0k
;
100 unsigned int ui_const2
= -2.5hk
;
101 short _Accum sa_const8
= 256;
102 unsigned short _Accum usa_const4
= -2;
105 _Sat
short _Accum sat_sa_const
= 2.5hk
;
106 // CHECK-DAG: @sat_sa_const = {{.*}}global i16 320, align 2
107 _Sat
short _Accum sat_sa_const2
= 256.0k
;
108 // CHECK-DAG: @sat_sa_const2 = {{.*}}global i16 32767, align 2
109 _Sat
unsigned short _Accum sat_usa_const
= -1.0hk
;
110 // CHECK-DAG: @sat_usa_const = {{.*}}global i16 0, align 2
111 _Sat
unsigned short _Accum sat_usa_const2
= 256.0k
;
112 // SIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 -1, align 2
113 // UNSIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2
115 _Sat
short _Accum sat_sa_const3
= 256;
116 // CHECK-DAG: @sat_sa_const3 = {{.*}}global i16 32767, align 2
117 _Sat
short _Accum sat_sa_const4
= -257;
118 // CHECK-DAG: @sat_sa_const4 = {{.*}}global i16 -32768, align 2
119 _Sat
unsigned short _Accum sat_usa_const3
= -1;
120 // CHECK-DAG: @sat_usa_const3 = {{.*}}global i16 0, align 2
121 _Sat
unsigned short _Accum sat_usa_const4
= 256;
122 // SIGNED-DAG: @sat_usa_const4 = {{.*}}global i16 -1, align 2
123 // UNSIGNED-DAG: @sat_usa_const4 = {{.*}}global i16 32767, align 2