From 3b8093234c6c60e9b6a5390f6d373db1517a2fbf Mon Sep 17 00:00:00 2001 From: hcz Date: Tue, 25 Feb 2020 17:45:23 +0800 Subject: [PATCH] Add DivisionUtils.h --- .../Functions/{intDiv.h => DivisionUtils.h} | 18 +++++++++++++++ dbms/src/Functions/FunctionBinaryArithmetic.h | 2 +- dbms/src/Functions/intDiv.cpp | 1 - dbms/src/Functions/intDivOrZero.cpp | 2 -- dbms/src/Functions/modulo.cpp | 23 +------------------ 5 files changed, 20 insertions(+), 26 deletions(-) rename dbms/src/Functions/{intDiv.h => DivisionUtils.h} (75%) diff --git a/dbms/src/Functions/intDiv.h b/dbms/src/Functions/DivisionUtils.h similarity index 75% rename from dbms/src/Functions/intDiv.h rename to dbms/src/Functions/DivisionUtils.h index 18de5cddb13..9bf153d4d6e 100644 --- a/dbms/src/Functions/intDiv.h +++ b/dbms/src/Functions/DivisionUtils.h @@ -70,4 +70,22 @@ struct DivideIntegralImpl #endif }; +template +struct ModuloImpl +{ + using ResultType = typename NumberTraits::ResultOfModulo::Type; + static const constexpr bool allow_fixed_string = false; + + template + static inline Result apply(A a, B b) + { + throwIfDivisionLeadsToFPE(typename NumberTraits::ToInteger::Type(a), typename NumberTraits::ToInteger::Type(b)); + return typename NumberTraits::ToInteger::Type(a) % typename NumberTraits::ToInteger::Type(b); + } + +#if USE_EMBEDDED_COMPILER + static constexpr bool compilable = false; /// don't know how to throw from LLVM IR +#endif +}; + } diff --git a/dbms/src/Functions/FunctionBinaryArithmetic.h b/dbms/src/Functions/FunctionBinaryArithmetic.h index 43563e7c6c5..024e9405877 100644 --- a/dbms/src/Functions/FunctionBinaryArithmetic.h +++ b/dbms/src/Functions/FunctionBinaryArithmetic.h @@ -22,7 +22,7 @@ #include #include "IFunctionImpl.h" #include "FunctionHelpers.h" -#include "intDiv.h" +#include "DivisionUtils.h" #include "castTypeToEither.h" #include "FunctionFactory.h" #include diff --git a/dbms/src/Functions/intDiv.cpp b/dbms/src/Functions/intDiv.cpp index cda3f26357b..40205611187 100644 --- a/dbms/src/Functions/intDiv.cpp +++ b/dbms/src/Functions/intDiv.cpp @@ -1,6 +1,5 @@ #include #include -#include #ifdef __SSE2__ #define LIBDIVIDE_USE_SSE2 1 diff --git a/dbms/src/Functions/intDivOrZero.cpp b/dbms/src/Functions/intDivOrZero.cpp index f38a6650fd2..64b6994d438 100644 --- a/dbms/src/Functions/intDivOrZero.cpp +++ b/dbms/src/Functions/intDivOrZero.cpp @@ -1,8 +1,6 @@ #include #include -#include "intDiv.h" - namespace DB { diff --git a/dbms/src/Functions/modulo.cpp b/dbms/src/Functions/modulo.cpp index 34931db7003..08412de60bd 100644 --- a/dbms/src/Functions/modulo.cpp +++ b/dbms/src/Functions/modulo.cpp @@ -11,28 +11,7 @@ namespace DB { -namespace ErrorCodes -{ - extern const int ILLEGAL_DIVISION; -} - -template -struct ModuloImpl -{ - using ResultType = typename NumberTraits::ResultOfModulo::Type; - static const constexpr bool allow_fixed_string = false; - - template - static inline Result apply(A a, B b) - { - throwIfDivisionLeadsToFPE(typename NumberTraits::ToInteger::Type(a), typename NumberTraits::ToInteger::Type(b)); - return typename NumberTraits::ToInteger::Type(a) % typename NumberTraits::ToInteger::Type(b); - } - -#if USE_EMBEDDED_COMPILER - static constexpr bool compilable = false; /// don't know how to throw from LLVM IR -#endif -}; +/// Optimizations for integer modulo by a constant. template struct ModuloByConstantImpl