1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/bigdecimal] Check the function availabilities separately

cf839a34c8
75db4dabb9
This commit is contained in:
Kenta Murata 2021-01-05 08:12:39 +09:00
parent a0a6293e78
commit 31854403b3
No known key found for this signature in database
GPG key ID: CEFE8AFB6081B062
2 changed files with 19 additions and 12 deletions

View file

@ -5,8 +5,8 @@
#include "static_assert.h" #include "static_assert.h"
#if defined(__x86_64__) && defined(HAVE_X86INTRIN_H) #if defined(__x86_64__) && defined(HAVE_X86INTRIN_H)
# include <x86intrin.h> /* for _lzcnt_u64 */ # include <x86intrin.h> /* for _lzcnt_u64, etc. */
#elif defined(_MSC_VER) && _MSC_VER >= 1310 #elif defined(_MSC_VER) && defined(HAVE_INTRIN_H)
# include <intrin.h> /* for the following intrinsics */ # include <intrin.h> /* for the following intrinsics */
#endif #endif
@ -48,17 +48,17 @@ static inline unsigned nlz_int128(uint128_t x);
static inline unsigned int static inline unsigned int
nlz_int32(uint32_t x) nlz_int32(uint32_t x)
{ {
#if defined(_MSC_VER) && defined(__AVX2__) #if defined(_MSC_VER) && defined(__AVX2__) && defined(HAVE___LZCNT)
/* Note: It seems there is no such thing like __LZCNT__ predefined in MSVC. /* Note: It seems there is no such thing like __LZCNT__ predefined in MSVC.
* AMD CPUs have had this instruction for decades (since K10) but for * AMD CPUs have had this instruction for decades (since K10) but for
* Intel, Haswell is the oldest one. We need to use __AVX2__ for maximum * Intel, Haswell is the oldest one. We need to use __AVX2__ for maximum
* safety. */ * safety. */
return (unsigned int)__lzcnt(x); return (unsigned int)__lzcnt(x);
#elif defined(__x86_64__) && defined(__LZCNT__) /* && ! defined(MJIT_HEADER) */ #elif defined(__x86_64__) && defined(__LZCNT__) && defined(HAVE__LZCNT_U32)
return (unsigned int)_lzcnt_u32(x); return (unsigned int)_lzcnt_u32(x);
#elif defined(_MSC_VER) && _MSC_VER >= 1400 /* &&! defined(__AVX2__) */ #elif defined(_MSC_VER) && defined(HAVE__BITSCANREVERSE)
unsigned long r; unsigned long r;
return _BitScanReverse(&r, x) ? (31 - (int)r) : 32; return _BitScanReverse(&r, x) ? (31 - (int)r) : 32;
@ -81,17 +81,17 @@ nlz_int32(uint32_t x)
static inline unsigned int static inline unsigned int
nlz_int64(uint64_t x) nlz_int64(uint64_t x)
{ {
#if defined(_MSC_VER) && defined(__AVX2__) #if defined(_MSC_VER) && defined(__AVX2__) && defined(HAVE___LZCNT64)
return (unsigned int)__lzcnt64(x); return (unsigned int)__lzcnt64(x);
#elif defined(__x86_64__) && defined(__LZCNT__) /* && ! defined(MJIT_HEADER) */ #elif defined(__x86_64__) && defined(__LZCNT__) && defined(HAVE__LZCNT_U64)
return (unsigned int)_lzcnt_u64(x); return (unsigned int)_lzcnt_u64(x);
#elif defined(_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1400 /* &&! defined(__AVX2__) */ #elif defined(_WIN64) && defined(_MSC_VER) && defined(HAVE__BITSCANREVERSE64)
unsigned long r; unsigned long r;
return _BitScanReverse64(&r, x) ? (63u - (unsigned int)r) : 64; return _BitScanReverse64(&r, x) ? (63u - (unsigned int)r) : 64;
#elif __has_builtin(__builtin_clzl) && !(defined(__sun) && defined(__sparc)) #elif __has_builtin(__builtin_clzl) && __has_builtin(__builtin_clzll) && !(defined(__sun) && defined(__sparc))
if (x == 0) { if (x == 0) {
return 64; return 64;
} }

View file

@ -44,15 +44,22 @@ check_bigdecimal_version(gemspec_path)
have_builtin_func("__builtin_clz", "__builtin_clz(0)") have_builtin_func("__builtin_clz", "__builtin_clz(0)")
have_builtin_func("__builtin_clzl", "__builtin_clzl(0)") have_builtin_func("__builtin_clzl", "__builtin_clzl(0)")
have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
have_header("float.h") have_header("float.h")
have_header("math.h") have_header("math.h")
have_header("stdbool.h") have_header("stdbool.h")
have_header("stdlib.h") have_header("stdlib.h")
if have_func("_lzcnt_u64", "x86intrin.h") # check availability have_header("x86intrin.h")
$defs << "-DHAVE_X86INTRIN_H" have_func("_lzcnt_u32", "x86intrin.h")
end have_func("_lzcnt_u64", "x86intrin.h")
have_header("intrin.h")
have_func("__lzcnt", "intrin.h")
have_func("__lzcnt64", "intrin.h")
have_func("_BitScanReverse", "intrin.h")
have_func("_BitScanReverse64", "intrin.h")
have_func("labs", "stdlib.h") have_func("labs", "stdlib.h")
have_func("llabs", "stdlib.h") have_func("llabs", "stdlib.h")