Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ext/json/ext/parser/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@
have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby
have_func("ruby_xfree_sized", "ruby.h") # RUBY_VERSION >= 4.1

def have_builtin_func(name, check_expr, opt = "", &b)
checking_for checking_message(name.funcall_style, nil, opt) do
if try_compile(<<SRC, opt, &b)
int foo;
int main() { #{check_expr}; return 0; }
SRC
$defs.push(format("-DHAVE_BUILTIN_%s", name.tr_cpp))
true
else
false
end
end
end

have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")

if have_header("x86intrin.h")
have_func("_lzcnt_u64", "x86intrin.h")
end

if have_header("intrin.h")
have_func("__lzcnt64", "intrin.h")
have_func("_BitScanReverse64", "intrin.h")
end

if RUBY_ENGINE == "ruby"
have_const("RUBY_TYPED_EMBEDDABLE", "ruby.h") # RUBY_VERSION >= 3.3
end
Expand Down
6 changes: 6 additions & 0 deletions ext/json/ext/vendor/fast_float_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,12 @@ static inline double ffp_bits2double(uint64_t bits) {
return d;
}

#if defined(__x86_64__) && defined(HAVE_X86INTRIN_H)
# include <x86intrin.h>
#elif defined(_MSC_VER) && defined(HAVE_INTRIN_H)
# include <intrin.h>
#endif

static inline unsigned int
ffc_nlz_int64(uint64_t x)
{
Expand Down
Loading