Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ae3eeb

Browse files
committed
Reduce duplication in extconf.rb
1 parent 51054bf commit 3ae3eeb

File tree

4 files changed

+29
-52
lines changed

4 files changed

+29
-52
lines changed

ext/json/ext/generator/extconf.rb

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

1111
if enable_config('generator-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
12-
if RbConfig::CONFIG['host_cpu'] =~ /^(arm.*|aarch64.*)/
13-
# Try to compile a small program using NEON instructions
14-
if have_header('arm_neon.h')
15-
have_type('uint8x16_t', headers=['arm_neon.h']) && try_compile(<<~'SRC')
16-
#include <arm_neon.h>
17-
int main() {
18-
uint8x16_t test = vdupq_n_u8(32);
19-
return 0;
20-
}
21-
SRC
22-
$defs.push("-DJSON_ENABLE_SIMD")
23-
end
24-
end
25-
26-
if have_header('x86intrin.h') && have_type('__m128i', headers=['x86intrin.h']) && try_compile(<<~'SRC')
27-
#include <x86intrin.h>
28-
int main() {
29-
__m128i test = _mm_set1_epi8(32);
30-
return 0;
31-
}
32-
SRC
33-
$defs.push("-DJSON_ENABLE_SIMD")
34-
end
35-
36-
have_header('cpuid.h')
12+
require_relative "../simd/conf.rb"
3713
end
3814

3915
create_makefile 'json/ext/generator'

ext/json/ext/parser/extconf.rb

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,7 @@
99
append_cflags("-std=c99")
1010

1111
if enable_config('parser-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
12-
if RbConfig::CONFIG['host_cpu'] =~ /^(arm.*|aarch64.*)/
13-
# Try to compile a small program using NEON instructions
14-
if have_header('arm_neon.h')
15-
have_type('uint8x16_t', headers=['arm_neon.h']) && try_compile(<<~'SRC')
16-
#include <arm_neon.h>
17-
int main() {
18-
uint8x16_t test = vdupq_n_u8(32);
19-
return 0;
20-
}
21-
SRC
22-
$defs.push("-DJSON_ENABLE_SIMD")
23-
end
24-
end
25-
26-
if have_header('x86intrin.h') && have_type('__m128i', headers=['x86intrin.h']) && try_compile(<<~'SRC')
27-
#include <x86intrin.h>
28-
int main() {
29-
__m128i test = _mm_set1_epi8(32);
30-
return 0;
31-
}
32-
SRC
33-
$defs.push("-DJSON_ENABLE_SIMD")
34-
end
35-
36-
have_header('cpuid.h')
37-
end
12+
require_relative "../simd/conf.rb"
13+
end
3814

3915
create_makefile 'json/ext/parser'

ext/json/ext/simd/conf.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
if RbConfig::CONFIG['host_cpu'] =~ /^(arm.*|aarch64.*)/
2+
# 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
13+
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);
19+
return 0;
20+
}
21+
SRC
22+
$defs.push("-DJSON_ENABLE_SIMD")
23+
end
24+
25+
have_header('cpuid.h')

json.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ spec = Gem::Specification.new do |s|
5252
s.files += Dir["lib/json/ext/**/*.jar"]
5353
else
5454
s.extensions = Dir["ext/json/**/extconf.rb"]
55-
s.files += Dir["ext/json/**/*.{c,h}"]
55+
s.files += Dir["ext/json/**/*.{c,h,rb}"]
5656
end
5757
end
5858

0 commit comments

Comments
 (0)