Skip to content

Commit 1a768d9

Browse files
committed
Refactor simd/conf.rb - duplicate code
Integrate duplicate code by extracting headers, types and initialization code.
1 parent b08e1ca commit 1a768d9

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

ext/json/ext/simd/conf.rb

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

2920
have_header('cpuid.h')

0 commit comments

Comments
 (0)