Skip to content

Commit 12d9221

Browse files
authored
Merge pull request #819 from nobu/simd_conf
Fix SIMD conf
2 parents 68ee9cf + 1a768d9 commit 12d9221

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

ext/json/ext/generator/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
$defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"]
1010

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

1515
create_makefile 'json/ext/generator'

ext/json/ext/parser/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
append_cflags("-std=c99")
1010

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

1515
create_makefile 'json/ext/parser'

ext/json/ext/simd/conf.rb

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
if RbConfig::CONFIG['host_cpu'] =~ /^(arm.*|aarch64.*)/
1+
case RbConfig::CONFIG['host_cpu']
2+
when /^(arm|aarch64)/
23
# Try to compile a small program using NEON instructions
3-
if have_header('arm_neon.h')
4-
have_type('uint8x16_t', headers=['arm_neon.h']) && try_compile(<<~'SRC')
5-
#include <arm_neon.h>
6-
int main() {
7-
uint8x16_t test = vdupq_n_u8(32);
8-
return 0;
9-
}
10-
SRC
11-
$defs.push("-DJSON_ENABLE_SIMD")
12-
end
4+
header, type, init = 'arm_neon.h', 'uint8x16_t', 'vdupq_n_u8(32)'
5+
when /^(x86_64|x64)/
6+
header, type, init = 'x86intrin.h', '__m128i', '_mm_set1_epi8(32)'
137
end
14-
15-
if have_header('x86intrin.h') && have_type('__m128i', headers=['x86intrin.h']) && try_compile(<<~'SRC')
16-
#include <x86intrin.h>
17-
int main() {
18-
__m128i test = _mm_set1_epi8(32);
8+
if header
9+
have_header(header) && try_compile(<<~SRC)
10+
#{cpp_include(header)}
11+
int main(int argc, char **argv) {
12+
#{type} test = #{init};
13+
if (argc > 100000) printf("%p", &test);
1914
return 0;
20-
}
15+
}
2116
SRC
22-
$defs.push("-DJSON_ENABLE_SIMD")
17+
$defs.push("-DJSON_ENABLE_SIMD")
2318
end
2419

2520
have_header('cpuid.h')

0 commit comments

Comments
 (0)