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
2 changes: 1 addition & 1 deletion ext/json/ext/generator/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"]

if enable_config('generator-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
require_relative "../simd/conf.rb"
load __dir__ + "/../simd/conf.rb"
end

create_makefile 'json/ext/generator'
Expand Down
2 changes: 1 addition & 1 deletion ext/json/ext/parser/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
append_cflags("-std=c99")

if enable_config('parser-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
require_relative "../simd/conf.rb"
load __dir__ + "/../simd/conf.rb"
end

create_makefile 'json/ext/parser'
2 changes: 1 addition & 1 deletion ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ static inline bool FORCE_INLINE string_scan(JSON_ParserState *state)
{
#ifdef HAVE_SIMD
#if defined(HAVE_SIMD_NEON)

uint64_t mask = 0;
if (string_scan_simd_neon(&state->cursor, state->end, &mask)) {
state->cursor += trailing_zeros64(mask) >> 2;
Expand Down
31 changes: 13 additions & 18 deletions ext/json/ext/simd/conf.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
if RbConfig::CONFIG['host_cpu'] =~ /^(arm.*|aarch64.*)/
case RbConfig::CONFIG['host_cpu']
when /^(arm|aarch64)/
# Try to compile a small program using NEON instructions
if have_header('arm_neon.h')
have_type('uint8x16_t', headers=['arm_neon.h']) && try_compile(<<~'SRC')
#include <arm_neon.h>
int main() {
uint8x16_t test = vdupq_n_u8(32);
return 0;
}
SRC
$defs.push("-DJSON_ENABLE_SIMD")
end
header, type, init = 'arm_neon.h', 'uint8x16_t', 'vdupq_n_u8(32)'
when /^(x86_64|x64)/
header, type, init = 'x86intrin.h', '__m128i', '_mm_set1_epi8(32)'
end

if have_header('x86intrin.h') && have_type('__m128i', headers=['x86intrin.h']) && try_compile(<<~'SRC')
#include <x86intrin.h>
int main() {
__m128i test = _mm_set1_epi8(32);
if header
have_header(header) && try_compile(<<~SRC)
#{cpp_include(header)}
int main(int argc, char **argv) {
#{type} test = #{init};
if (argc > 100000) printf("%p", &test);
return 0;
}
}
SRC
$defs.push("-DJSON_ENABLE_SIMD")
$defs.push("-DJSON_ENABLE_SIMD")
end

have_header('cpuid.h')