[PATCH] D83212: [Fixed Point] Add fixed-point shift operations and consteval.
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGaa0d19a0c8f5: [Fixed Point] Add fixed-point shift operations and consteval. (authored by ebevhan). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D83212/new/ https://reviews.llvm.org/D83212 Files: clang/include/clang/Basic/FixedPoint.h clang/lib/AST/ExprConstant.cpp clang/lib/Basic/FixedPoint.cpp clang/lib/Sema/SemaExpr.cpp clang/test/Frontend/fixed_point_errors.c clang/test/Frontend/fixed_point_shift.c Index: clang/test/Frontend/fixed_point_shift.c === --- /dev/null +++ clang/test/Frontend/fixed_point_shift.c @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED +// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED + +short _Accum sa_const1 = 1.0hk << 2; // CHECK-DAG: @sa_const1 = {{.*}}global i16 512 +short _Accum sa_const2 = 0.5hk << 2; // CHECK-DAG: @sa_const2 = {{.*}}global i16 256 +short _Accum sa_const3 = 10.0hk >> 3; // CHECK-DAG: @sa_const3 = {{.*}}global i16 160 +short _Accum sa_const4 = 0.0546875hk << 8; // CHECK-DAG: @sa_const4 = {{.*}}global i16 1792 +short _Accum sa_const5 = -1.0hk << 2; // CHECK-DAG: @sa_const5 = {{.*}}global i16 -512 +short _Accum sa_const6 = -255.0hk >> 8;// CHECK-DAG: @sa_const6 = {{.*}}global i16 -128 + +_Fract f_const1 = -1.0r >> 5; // CHECK-DAG: @f_const1 = {{.*}}global i16 -1024 +_Fract f_const2 = 0.0052490234375r >> 3; // CHECK-DAG: @f_const2 = {{.*}}global i16 21 +_Fract f_const3 = -0.0001r << 5; // CHECK-DAG: @f_const3 = {{.*}}global i16 -96 +_Fract f_const4 = -0.75r >> 15;// CHECK-DAG: @f_const4 = {{.*}}global i16 -1 +_Fract f_const5 = 0.078216552734375r << 3; // CHECK-DAG: @f_const5 = {{.*}}global i16 20504 + +unsigned _Fract uf_const1 = 0.375ur >> 13; +// SIGNED-DAG: @uf_const1 = {{.*}}global i16 3 +// UNSIGNED-DAG: @uf_const1 = {{.*}}global i16 1 +unsigned _Fract uf_const2 = 0.0546875ur << 3; +// SIGNED-DAG: @uf_const2 = {{.*}}global i16 28672 +// UNSIGNED-DAG: @uf_const2 = {{.*}}global i16 14336 + +_Sat short _Accum ssa_const1 = (_Sat short _Accum)31.875hk << 4; // CHECK-DAG: @ssa_const1 = {{.*}}global i16 32767 +_Sat short _Accum ssa_const2 = (_Sat short _Accum) - 1.0hk << 8; // CHECK-DAG: @ssa_const2 = {{.*}}global i16 -32768 +_Sat short _Accum ssa_const3 = (_Sat short _Accum)128.0hk << 8; // CHECK-DAG: @ssa_const3 = {{.*}}global i16 32767 +_Sat short _Fract ssf_const1 = (_Sat short _Fract) - 0.5hr << 3; // CHECK-DAG: @ssf_const1 = {{.*}}global i8 -128 + +_Sat unsigned _Fract suf_const1 = (_Sat unsigned _Fract)0.5r << 1; +// SIGNED-DAG: @suf_const1 = {{.*}}global i16 -1 +// UNSIGNED-DAG: @suf_const1 = {{.*}}global i16 32767 +_Sat unsigned _Fract suf_const2 = (_Sat unsigned _Fract)0.25r << 1; +// SIGNED-DAG: @suf_const2 = {{.*}}global i16 -32768 +// UNSIGNED-DAG: @suf_const2 = {{.*}}global i16 16384 +_Sat unsigned _Accum sua_const2 = (_Sat unsigned _Accum)128.0uk << 10; +// SIGNED-DAG: @sua_const2 = {{.*}}global i32 -1 +// UNSIGNED-DAG: @sua_const2 = {{.*}}global i32 2147483647 Index: clang/test/Frontend/fixed_point_errors.c === --- clang/test/Frontend/fixed_point_errors.c +++ clang/test/Frontend/fixed_point_errors.c @@ -259,11 +259,30 @@ short _Accum mul_ovf2 = (-0.5hr - 0.5hr) * (-0.5hr - 0.5hr); // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}} short _Accum div_ovf1 = 255.0hk / 0.5hk; // expected-warning {{overflow in expression; result is -2.0 with type 'short _Accum'}} +short _Accum shl_ovf1 = 255.0hk << 8; // expected-warning {{overflow in expression; result is -256.0 with type 'short _Accum'}} +short _Fract shl_ovf2 = -0.25hr << 3; // expected-warning {{overflow in expression; result is 0.0 with type 'short _Fract'}} +unsigned short _Accum shl_ovf3 = 100.5uhk << 3; // expected-warning {{overflow in expression; result is 36.0 with type 'unsigned short _Accum'}} +short _Fract shl_ovf4 = 0.25hr << 2;// expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}} + +_Accum shl_bw1 = 0.91552734375k << 32; // expected-warning {{shift count >= width of type}} \ + expected-warning {{overflow in expression; result is -65536.0 with type '_Accum'}} +unsigned _Fract shl_bw2 = 0.65ur << 16; // expected-warning {{shift count >= width of type}} \ + expected-warning {{overflow in expression; result is 0.0 with type 'unsigned
[PATCH] D83212: [Fixed Point] Add fixed-point shift operations and consteval.
ebevhan updated this revision to Diff 275962. ebevhan added a comment. Fix test. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D83212/new/ https://reviews.llvm.org/D83212 Files: clang/include/clang/Basic/FixedPoint.h clang/lib/AST/ExprConstant.cpp clang/lib/Basic/FixedPoint.cpp clang/lib/Sema/SemaExpr.cpp clang/test/Frontend/fixed_point_errors.c clang/test/Frontend/fixed_point_shift.c Index: clang/test/Frontend/fixed_point_shift.c === --- /dev/null +++ clang/test/Frontend/fixed_point_shift.c @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED +// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED + +short _Accum sa_const1 = 1.0hk << 2; // CHECK-DAG: @sa_const1 = {{.*}}global i16 512 +short _Accum sa_const2 = 0.5hk << 2; // CHECK-DAG: @sa_const2 = {{.*}}global i16 256 +short _Accum sa_const3 = 10.0hk >> 3; // CHECK-DAG: @sa_const3 = {{.*}}global i16 160 +short _Accum sa_const4 = 0.0546875hk << 8; // CHECK-DAG: @sa_const4 = {{.*}}global i16 1792 +short _Accum sa_const5 = -1.0hk << 2; // CHECK-DAG: @sa_const5 = {{.*}}global i16 -512 +short _Accum sa_const6 = -255.0hk >> 8;// CHECK-DAG: @sa_const6 = {{.*}}global i16 -128 + +_Fract f_const1 = -1.0r >> 5; // CHECK-DAG: @f_const1 = {{.*}}global i16 -1024 +_Fract f_const2 = 0.0052490234375r >> 3; // CHECK-DAG: @f_const2 = {{.*}}global i16 21 +_Fract f_const3 = -0.0001r << 5; // CHECK-DAG: @f_const3 = {{.*}}global i16 -96 +_Fract f_const4 = -0.75r >> 15;// CHECK-DAG: @f_const4 = {{.*}}global i16 -1 +_Fract f_const5 = 0.078216552734375r << 3; // CHECK-DAG: @f_const5 = {{.*}}global i16 20504 + +unsigned _Fract uf_const1 = 0.375ur >> 13; +// SIGNED-DAG: @uf_const1 = {{.*}}global i16 3 +// UNSIGNED-DAG: @uf_const1 = {{.*}}global i16 1 +unsigned _Fract uf_const2 = 0.0546875ur << 3; +// SIGNED-DAG: @uf_const2 = {{.*}}global i16 28672 +// UNSIGNED-DAG: @uf_const2 = {{.*}}global i16 14336 + +_Sat short _Accum ssa_const1 = (_Sat short _Accum)31.875hk << 4; // CHECK-DAG: @ssa_const1 = {{.*}}global i16 32767 +_Sat short _Accum ssa_const2 = (_Sat short _Accum) - 1.0hk << 8; // CHECK-DAG: @ssa_const2 = {{.*}}global i16 -32768 +_Sat short _Accum ssa_const3 = (_Sat short _Accum)128.0hk << 8; // CHECK-DAG: @ssa_const3 = {{.*}}global i16 32767 +_Sat short _Fract ssf_const1 = (_Sat short _Fract) - 0.5hr << 3; // CHECK-DAG: @ssf_const1 = {{.*}}global i8 -128 + +_Sat unsigned _Fract suf_const1 = (_Sat unsigned _Fract)0.5r << 1; +// SIGNED-DAG: @suf_const1 = {{.*}}global i16 -1 +// UNSIGNED-DAG: @suf_const1 = {{.*}}global i16 32767 +_Sat unsigned _Fract suf_const2 = (_Sat unsigned _Fract)0.25r << 1; +// SIGNED-DAG: @suf_const2 = {{.*}}global i16 -32768 +// UNSIGNED-DAG: @suf_const2 = {{.*}}global i16 16384 +_Sat unsigned _Accum sua_const2 = (_Sat unsigned _Accum)128.0uk << 10; +// SIGNED-DAG: @sua_const2 = {{.*}}global i32 -1 +// UNSIGNED-DAG: @sua_const2 = {{.*}}global i32 2147483647 Index: clang/test/Frontend/fixed_point_errors.c === --- clang/test/Frontend/fixed_point_errors.c +++ clang/test/Frontend/fixed_point_errors.c @@ -259,11 +259,30 @@ short _Accum mul_ovf2 = (-0.5hr - 0.5hr) * (-0.5hr - 0.5hr); // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}} short _Accum div_ovf1 = 255.0hk / 0.5hk; // expected-warning {{overflow in expression; result is -2.0 with type 'short _Accum'}} +short _Accum shl_ovf1 = 255.0hk << 8; // expected-warning {{overflow in expression; result is -256.0 with type 'short _Accum'}} +short _Fract shl_ovf2 = -0.25hr << 3; // expected-warning {{overflow in expression; result is 0.0 with type 'short _Fract'}} +unsigned short _Accum shl_ovf3 = 100.5uhk << 3; // expected-warning {{overflow in expression; result is 36.0 with type 'unsigned short _Accum'}} +short _Fract shl_ovf4 = 0.25hr << 2;// expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}} + +_Accum shl_bw1 = 0.91552734375k << 32; // expected-warning {{shift count >= width of type}} \ + expected-warning {{overflow in expression; result is -65536.0 with type '_Accum'}} +unsigned _Fract shl_bw2 = 0.65ur << 16; // expected-warning {{shift count >= width of type}} \ + expected-warning {{overflow in expression; result is 0.0 with type 'unsigned _Fract'}} +_Sat short _Accum shl_bw3 = (_Sat short _Accum)80.0hk << 17; // expected-warning {{shift count >= width of type}} +short _Accum shr_bw1 = 1.0hk >> 17;
[PATCH] D83212: [Fixed Point] Add fixed-point shift operations and consteval.
ebevhan created this revision. ebevhan added reviewers: rjmccall, leonardchan, bjope. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D83212 Files: clang/include/clang/Basic/FixedPoint.h clang/lib/AST/ExprConstant.cpp clang/lib/Basic/FixedPoint.cpp clang/lib/Sema/SemaExpr.cpp clang/test/Frontend/fixed_point_errors.c clang/test/Frontend/fixed_point_shift.c Index: clang/test/Frontend/fixed_point_shift.c === --- /dev/null +++ clang/test/Frontend/fixed_point_shift.c @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED +// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED + +short _Accum sa_const1 = 1.0hk << 2; // CHECK-DAG: @sa_const1 = global i16 512 +short _Accum sa_const2 = 0.5hk << 2; // CHECK-DAG: @sa_const2 = global i16 256 +short _Accum sa_const3 = 10.0hk >> 3; // CHECK-DAG: @sa_const3 = global i16 160 +short _Accum sa_const4 = 0.0546875hk << 8; // CHECK-DAG: @sa_const4 = global i16 1792 +short _Accum sa_const5 = -1.0hk << 2; // CHECK-DAG: @sa_const5 = global i16 -512 +short _Accum sa_const6 = -255.0hk >> 8;// CHECK-DAG: @sa_const6 = global i16 -128 + +_Fract f_const1 = -1.0r >> 5; // CHECK-DAG: @f_const1 = global i16 -1024 +_Fract f_const2 = 0.0052490234375r >> 3; // CHECK-DAG: @f_const2 = global i16 21 +_Fract f_const3 = -0.0001r << 5; // CHECK-DAG: @f_const3 = global i16 -96 +_Fract f_const4 = -0.75r >> 15;// CHECK-DAG: @f_const4 = global i16 -1 +_Fract f_const5 = 0.078216552734375r << 3; // CHECK-DAG: @f_const5 = global i16 20504 + +unsigned _Fract uf_const1 = 0.375ur >> 13; +// SIGNED-DAG: @uf_const1 = global i16 3 +// UNSIGNED-DAG: @uf_const1 = global i16 1 +unsigned _Fract uf_const2 = 0.0546875ur << 3; +// SIGNED-DAG: @uf_const2 = global i16 28672 +// UNSIGNED-DAG: @uf_const2 = global i16 14336 + +_Sat short _Accum ssa_const1 = (_Sat short _Accum)31.875hk << 4; // CHECK-DAG: @ssa_const1 = global i16 32767 +_Sat short _Accum ssa_const2 = (_Sat short _Accum) - 1.0hk << 8; // CHECK-DAG: @ssa_const2 = global i16 -32768 +_Sat short _Accum ssa_const3 = (_Sat short _Accum)128.0hk << 8; // CHECK-DAG: @ssa_const3 = global i16 32767 +_Sat short _Fract ssf_const1 = (_Sat short _Fract) - 0.5hr << 3; // CHECK-DAG: @ssf_const1 = global i8 -128 + +_Sat unsigned _Fract suf_const1 = (_Sat unsigned _Fract)0.5r << 1; +// SIGNED-DAG: @suf_const1 = global i16 -1 +// UNSIGNED-DAG: @suf_const1 = global i16 32767 +_Sat unsigned _Fract suf_const2 = (_Sat unsigned _Fract)0.25r << 1; +// SIGNED-DAG: @suf_const2 = global i16 -32768 +// UNSIGNED-DAG: @suf_const2 = global i16 16384 +_Sat unsigned _Accum sua_const2 = (_Sat unsigned _Accum)128.0uk << 10; +// SIGNED-DAG: @sua_const2 = global i32 -1 +// UNSIGNED-DAG: @sua_const2 = global i32 2147483647 Index: clang/test/Frontend/fixed_point_errors.c === --- clang/test/Frontend/fixed_point_errors.c +++ clang/test/Frontend/fixed_point_errors.c @@ -259,11 +259,30 @@ short _Accum mul_ovf2 = (-0.5hr - 0.5hr) * (-0.5hr - 0.5hr); // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}} short _Accum div_ovf1 = 255.0hk / 0.5hk; // expected-warning {{overflow in expression; result is -2.0 with type 'short _Accum'}} +short _Accum shl_ovf1 = 255.0hk << 8; // expected-warning {{overflow in expression; result is -256.0 with type 'short _Accum'}} +short _Fract shl_ovf2 = -0.25hr << 3; // expected-warning {{overflow in expression; result is 0.0 with type 'short _Fract'}} +unsigned short _Accum shl_ovf3 = 100.5uhk << 3; // expected-warning {{overflow in expression; result is 36.0 with type 'unsigned short _Accum'}} +short _Fract shl_ovf4 = 0.25hr << 2;// expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}} + +_Accum shl_bw1 = 0.91552734375k << 32; // expected-warning {{shift count >= width of type}} \ + expected-warning {{overflow in expression; result is -65536.0 with type '_Accum'}} +unsigned _Fract shl_bw2 = 0.65ur << 16; // expected-warning {{shift count >= width of type}} \ + expected-warning {{overflow in expression; result is 0.0 with type 'unsigned _Fract'}} +_Sat short _Accum shl_bw3 = (_Sat short _Accum)80.0hk << 17; // expected-warning {{shift count >= width of type}} +short _Accum shr_bw1 = 1.0hk >> 17; // expected-warning {{shift count >= width of type}} + +_Accum shl_neg1 = 25.5k << -5; // expected-warning {{shift count is