1#include <Functions/FunctionFactory.h>
2#include <Functions/FunctionBinaryArithmetic.h>
3
4
5namespace DB
6{
7
8template <typename A, typename B>
9struct BitAndImpl
10{
11 using ResultType = typename NumberTraits::ResultOfBit<A, B>::Type;
12
13 template <typename Result = ResultType>
14 static inline Result apply(A a, B b)
15 {
16 return static_cast<Result>(a) & static_cast<Result>(b);
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 * left, llvm::Value * right, bool)
23 {
24 if (!left->getType()->isIntegerTy())
25 throw Exception("BitAndImpl expected an integral type", ErrorCodes::LOGICAL_ERROR);
26 return b.CreateAnd(left, right);
27 }
28#endif
29};
30
31struct NameBitAnd { static constexpr auto name = "bitAnd"; };
32using FunctionBitAnd = FunctionBinaryArithmetic<BitAndImpl, NameBitAnd>;
33
34void registerFunctionBitAnd(FunctionFactory & factory)
35{
36 factory.registerFunction<FunctionBitAnd>();
37}
38
39}
40