1 | #include <Functions/FunctionFactory.h> |
---|---|
2 | #include <Functions/FunctionUnaryArithmetic.h> |
3 | #include <DataTypes/NumberTraits.h> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | template <typename A> |
10 | struct BitNotImpl |
11 | { |
12 | using ResultType = typename NumberTraits::ResultOfBitNot<A>::Type; |
13 | |
14 | static inline ResultType apply(A a) |
15 | { |
16 | return ~static_cast<ResultType>(a); |
17 | } |
18 | |
19 | #if USE_EMBEDDED_COMPILER |
20 | static constexpr bool compilable = true; |
21 | |
22 | static inline llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * arg, bool) |
23 | { |
24 | if (!arg->getType()->isIntegerTy()) |
25 | throw Exception("BitNotImpl expected an integral type", ErrorCodes::LOGICAL_ERROR); |
26 | return b.CreateNot(arg); |
27 | } |
28 | #endif |
29 | }; |
30 | |
31 | struct NameBitNot { static constexpr auto name = "bitNot"; }; |
32 | using FunctionBitNot = FunctionUnaryArithmetic<BitNotImpl, NameBitNot, true>; |
33 | |
34 | template <> struct FunctionUnaryArithmeticMonotonicity<NameBitNot> |
35 | { |
36 | static bool has() { return false; } |
37 | static IFunction::Monotonicity get(const Field &, const Field &) |
38 | { |
39 | return {}; |
40 | } |
41 | }; |
42 | |
43 | void registerFunctionBitNot(FunctionFactory & factory) |
44 | { |
45 | factory.registerFunction<FunctionBitNot>(); |
46 | } |
47 | |
48 | } |
49 |