ClickHouse/src/Functions/bitNot.cpp

59 lines
1.3 KiB
C++
Raw Normal View History

#include <Functions/FunctionFactory.h>
#include <Functions/FunctionUnaryArithmetic.h>
#include <DataTypes/NumberTraits.h>
2019-12-29 01:13:17 +00:00
namespace DB
{
2020-02-25 18:10:48 +00:00
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
2020-09-07 18:00:37 +00:00
namespace
{
template <typename A>
struct BitNotImpl
{
using ResultType = typename NumberTraits::ResultOfBitNot<A>::Type;
2023-04-22 17:21:43 +00:00
static constexpr bool allow_string_or_fixed_string = true;
2023-04-18 13:38:41 +00:00
static inline ResultType NO_SANITIZE_UNDEFINED apply(A a)
{
return ~static_cast<ResultType>(a);
}
#if USE_EMBEDDED_COMPILER
static constexpr bool compilable = true;
static inline llvm::Value * compile(llvm::IRBuilder<> & b, llvm::Value * arg, bool)
{
if (!arg->getType()->isIntegerTy())
throw Exception(ErrorCodes::LOGICAL_ERROR, "BitNotImpl expected an integral type");
return b.CreateNot(arg);
}
#endif
};
struct NameBitNot { static constexpr auto name = "bitNot"; };
using FunctionBitNot = FunctionUnaryArithmetic<BitNotImpl, NameBitNot, true>;
2020-09-07 18:00:37 +00:00
}
template <> struct FunctionUnaryArithmeticMonotonicity<NameBitNot>
{
static bool has() { return false; }
static IFunction::Monotonicity get(const Field &, const Field &)
{
return {};
}
};
REGISTER_FUNCTION(BitNot)
{
factory.registerFunction<FunctionBitNot>();
}
}