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