| 1 | #include <Functions/FunctionFactory.h> |
| 2 | #include <Functions/FunctionBinaryArithmetic.h> |
| 3 | |
| 4 | namespace DB |
| 5 | { |
| 6 | |
| 7 | template <typename A, typename B> |
| 8 | struct BitShiftRightImpl |
| 9 | { |
| 10 | using ResultType = typename NumberTraits::ResultOfBit<A, B>::Type; |
| 11 | |
| 12 | template <typename Result = ResultType> |
| 13 | static inline NO_SANITIZE_UNDEFINED Result apply(A a, B b) |
| 14 | { |
| 15 | return static_cast<Result>(a) >> static_cast<Result>(b); |
| 16 | } |
| 17 | |
| 18 | #if USE_EMBEDDED_COMPILER |
| 19 | static constexpr bool compilable = true; |
| 20 | |
| 21 | static inline llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * left, llvm::Value * right, bool is_signed) |
| 22 | { |
| 23 | if (!left->getType()->isIntegerTy()) |
| 24 | throw Exception("BitShiftRightImpl expected an integral type" , ErrorCodes::LOGICAL_ERROR); |
| 25 | return is_signed ? b.CreateAShr(left, right) : b.CreateLShr(left, right); |
| 26 | } |
| 27 | #endif |
| 28 | }; |
| 29 | |
| 30 | struct NameBitShiftRight { static constexpr auto name = "bitShiftRight" ; }; |
| 31 | using FunctionBitShiftRight = FunctionBinaryArithmetic<BitShiftRightImpl, NameBitShiftRight>; |
| 32 | |
| 33 | void registerFunctionBitShiftRight(FunctionFactory & factory) |
| 34 | { |
| 35 | factory.registerFunction<FunctionBitShiftRight>(); |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | |