// Copyright 2023 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include namespace DB { namespace { template || IsDecimal> struct BitRotateLeftImpl; template struct BitRotateLeftImpl { using ResultType = typename NumberTraits::ResultOfBit::Type; template static Result apply(A a, B b) { return (static_cast(a) << static_cast(b)) | (static_cast(a) >> ((sizeof(Result) * 8) - static_cast(b))); } template static Result apply(A, B, UInt8 &) { throw Exception("Should not reach here"); } }; template struct BitRotateLeftImpl { using ResultType = If || std::is_unsigned_v, uint64_t, int64_t>; template static Result apply(A a, B b) { Result x, y; if constexpr (IsDecimal) { x = static_cast(a.value); } else { x = static_cast(a); } if constexpr (IsDecimal) { y = static_cast(b.value); } else { y = static_cast(b); } return BitRotateLeftImpl::apply(x, y); } template static Result apply(A, B, UInt8 &) { throw Exception("Should not reach here"); } }; // clang-format off struct NameBitRotateLeft { static constexpr auto name = "bitRotateLeft"; }; // clang-format on template using BitRotateLeftImpl_t = BitRotateLeftImpl; using FunctionBitRotateLeft = FunctionBinaryArithmetic; } // namespace void registerFunctionBitRotateLeft(FunctionFactory & factory) { factory.registerFunction(); } } // namespace DB