/* * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak * * SPDX-License-Identifier: BSD-3-Clause */ #ifndef LIBCPP_BITS_BUILTINS #define LIBCPP_BITS_BUILTINS /** * Note: While the primary target of libcpp is the * g++ compiler, using builtin functions that would * unnecessarily limit the library to any specific * compiler is discouraged and as such all the used * builtins should be available atleast in g++ and * clang++. * GCC: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html * LLVM: https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/Builtins.def * (If anyone has a better link for LLVM, feel free to update it.) */ #include namespace std::aux { template constexpr double log2(T val) { return __builtin_log2(static_cast(val)); } template constexpr double pow2(T exp) { return __builtin_pow(2.0, static_cast(exp)); } template constexpr size_t pow2u(T exp) { return static_cast(pow2(exp)); } template constexpr T pow(T base, U exp) { return static_cast( __builtin_pow(static_cast(base), static_cast(exp)) ); } template constexpr size_t ceil(T val) { return static_cast(__builtin_ceil(static_cast(val))); } template constexpr size_t floor(T val) { return static_cast(__builtin_floor(static_cast(val))); } } #endif