Skip to content
Merged
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
24 changes: 9 additions & 15 deletions ext/digest/blake3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def blake3_disable(macro)
end

# Probe used to confirm the compiler both accepts +flag+ and can compile the
# intrinsics the backend relies on.
# intrinsics the backend relies on. It compiles the backend source itself:
# a small snippet misses assemblers that reject what the compiler emits (e.g.
# binutils 2.30 on RHEL 8 rejects AVX-512 code from gcc 8.5).
def blake3_have_isa?(name, flag, snippet)
checking_for("#{name} intrinsics" + (flag ? " (#{flag})" : "")) do
try_compile(snippet, flag)
Expand All @@ -40,23 +42,15 @@ def blake3_have_isa?(name, flag, snippet)
when /\A(x86_64|amd64|x64)\z/i
# Try to detect which SIMD features this x86 machine and compiler has
x86_backends = [
["blake3_sse2", "SSE2", ["-msse2", "-arch:SSE2"],
"#include <immintrin.h>\nint main(void){ volatile __m128i x = _mm_setzero_si128(); (void)x; return 0; }\n",
"BLAKE3_NO_SSE2"],
["blake3_sse41", "SSE4.1", ["-msse4.1", "-arch:AVX"],
"#include <immintrin.h>\nint main(void){ volatile __m128i x = _mm_setzero_si128(); return _mm_testz_si128(x, x); }\n",
"BLAKE3_NO_SSE41"],
["blake3_avx2", "AVX2", ["-mavx2", "-arch:AVX2"],
"#include <immintrin.h>\nint main(void){ volatile __m256i x = _mm256_setzero_si256(); (void)x; return 0; }\n",
"BLAKE3_NO_AVX2"],
["blake3_avx512", "AVX-512", ["-mavx512f -mavx512vl", "-arch:AVX512"],
"#include <immintrin.h>\nint main(void){ volatile __m512i x = _mm512_setzero_si512(); (void)x; return 0; }\n",
"BLAKE3_NO_AVX512"],
["blake3_sse2", "SSE2", ["-msse2", "-arch:SSE2"], "BLAKE3_NO_SSE2"],
["blake3_sse41", "SSE4.1", ["-msse4.1", "-arch:AVX"], "BLAKE3_NO_SSE41"],
["blake3_avx2", "AVX2", ["-mavx2", "-arch:AVX2"], "BLAKE3_NO_AVX2"],
["blake3_avx512", "AVX-512", ["-mavx512f -mavx512vl", "-arch:AVX512"], "BLAKE3_NO_AVX512"],
]

x86_backends.each do |obj, name, flags, snippet, no_macro|
x86_backends.each do |obj, name, flags, no_macro|
[nil, *flags].any? do |flag|
if blake3_have_isa?(name, flag, snippet)
if blake3_have_isa?(name, flag, %{#include "#{$srcdir}/#{obj}.c"\n})
objs << obj
simd_cflags[obj] = flag
true
Expand Down