Bevin Hansson | 9c26eb8 | 2020-08-25 15:59:12 +0200 | [diff] [blame] | 1 | // 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 |
| 5 | short _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 |
| 9 | short _Accum sa_const2 = 2.5k; |
| 10 | // CHECK-DAG: @sa_const2 = {{.*}}global i16 320, align 2 |
| 11 | |
| 12 | short _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 | |
| 17 | unsigned short _Accum usa_const = 2.5uk; |
| 18 | unsigned _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 |
| 25 | int i_const = -128.0hk; |
| 26 | // CHECK-DAG: @i_const = {{.*}}global i32 -128, align 4 |
| 27 | int i_const2 = 128.0hk; |
| 28 | // CHECK-DAG: @i_const2 = {{.*}}global i32 128, align 4 |
| 29 | int i_const3 = -128.0k; |
| 30 | // CHECK-DAG: @i_const3 = {{.*}}global i32 -128, align 4 |
| 31 | int i_const4 = 128.0k; |
| 32 | // CHECK-DAG: @i_const4 = {{.*}}global i32 128, align 4 |
| 33 | short s_const = -128.0k; |
| 34 | // CHECK-DAG: @s_const = {{.*}}global i16 -128, align 2 |
| 35 | short s_const2 = 128.0k; |
| 36 | // CHECK-DAG: @s_const2 = {{.*}}global i16 128, align 2 |
| 37 | |
| 38 | // Integer to fixed point |
| 39 | short _Accum sa_const5 = 2; |
| 40 | // CHECK-DAG: @sa_const5 = {{.*}}global i16 256, align 2 |
| 41 | short _Accum sa_const6 = -2; |
| 42 | // CHECK-DAG: @sa_const6 = {{.*}}global i16 -256, align 2 |
| 43 | short _Accum sa_const7 = -256; |
| 44 | // CHECK-DAG: @sa_const7 = {{.*}}global i16 -32768, align 2 |
| 45 | |
Bevin Hansson | 9fa7f484 | 2020-08-26 16:46:57 +0200 | [diff] [blame] | 46 | // Fixed point to floating point |
| 47 | float fl_const = 1.0hk; |
| 48 | // CHECK-DAG: @fl_const = {{.*}}global float 1.000000e+00, align 4 |
| 49 | float fl_const2 = -128.0k; |
| 50 | // CHECK-DAG: @fl_const2 = {{.*}}global float -1.280000e+02, align 4 |
| 51 | float fl_const3 = 0.0872802734375k; |
| 52 | // CHECK-DAG: @fl_const3 = {{.*}}global float 0x3FB6580000000000, align 4 |
| 53 | float fl_const4 = 192.5k; |
| 54 | // CHECK-DAG: @fl_const4 = {{.*}}global float 1.925000e+02, align 4 |
| 55 | float 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 |
| 73 | unsigned 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 Hansson | 9c26eb8 | 2020-08-25 15:59:12 +0200 | [diff] [blame] | 77 | // Signedness |
| 78 | unsigned 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 |
| 81 | short _Accum sa_const3 = 2.5hk; |
| 82 | // CHECK-DAG: @sa_const3 = {{.*}}global i16 320, align 2 |
| 83 | |
| 84 | int i_const5 = 128.0uhk; |
| 85 | unsigned 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 | |
| 89 | short _Accum sa_const9 = 2u; |
| 90 | // CHECK-DAG: @sa_const9 = {{.*}}global i16 256, align 2 |
| 91 | unsigned 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) |
| 96 | short _Accum sa_const4 = 256.0k; |
| 97 | unsigned int ui_const2 = -2.5hk; |
| 98 | short _Accum sa_const8 = 256; |
| 99 | unsigned 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 |