Skip to content

Commit dc7bdaa

Browse files
committed
fast_float_parser.h: handle more environments
Inspired by bigdecimal
1 parent 34bc289 commit dc7bdaa

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

ext/json/ext/parser/extconf.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88
have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby
99
have_func("ruby_xfree_sized", "ruby.h") # RUBY_VERSION >= 4.1
1010

11+
def have_builtin_func(name, check_expr, opt = "", &b)
12+
checking_for checking_message(name.funcall_style, nil, opt) do
13+
if try_compile(<<SRC, opt, &b)
14+
int foo;
15+
int main() { #{check_expr}; return 0; }
16+
SRC
17+
$defs.push(format("-DHAVE_BUILTIN_%s", name.tr_cpp))
18+
true
19+
else
20+
false
21+
end
22+
end
23+
end
24+
25+
have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
26+
27+
if have_header("x86intrin.h")
28+
have_func("_lzcnt_u64", "x86intrin.h")
29+
end
30+
31+
if have_header("intrin.h")
32+
have_func("__lzcnt64", "intrin.h")
33+
have_func("_BitScanReverse64", "intrin.h")
34+
end
35+
1136
if RUBY_ENGINE == "ruby"
1237
have_const("RUBY_TYPED_EMBEDDABLE", "ruby.h") # RUBY_VERSION >= 3.3
1338
end

ext/json/ext/vendor/fast_float_parser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ static inline double ffp_bits2double(uint64_t bits) {
707707
return d;
708708
}
709709

710+
#if defined(__x86_64__) && defined(HAVE_X86INTRIN_H)
711+
# include <x86intrin.h>
712+
#elif defined(_MSC_VER) && defined(HAVE_INTRIN_H)
713+
# include <intrin.h>
714+
#endif
715+
710716
static inline unsigned int
711717
ffc_nlz_int64(uint64_t x)
712718
{

0 commit comments

Comments
 (0)