@@ -148,17 +148,65 @@ set(CAS_CORE_PORTABLE_SOURCES
148148set (CAS_CORE_POSIX_SOURCES
149149 src/cas/control_socket.cpp
150150)
151+
152+ option (AGENTVFS_BLAKE3_SIMD "Enable runtime-dispatched BLAKE3 SIMD paths" ON )
153+
151154add_library (cas_core STATIC ${CAS_CORE_PORTABLE_SOURCES} )
152155if (UNIX )
153156 target_sources (cas_core PRIVATE ${CAS_CORE_POSIX_SOURCES} )
154157endif ()
155158target_include_directories (cas_core PUBLIC src/cas include include /blake3 )
156- target_compile_definitions (cas_core PRIVATE
157- BLAKE3_NO_AVX512 BLAKE3_NO_AVX2 BLAKE3_NO_SSE41 BLAKE3_NO_SSE2
158- # On aarch64 the vendored blake3 auto-enables NEON, but we only
159- # compile blake3_portable.c — link would fail with an unresolved
160- # blake3_hash_many_neon. Force the portable path on every arch.
161- BLAKE3_USE_NEON=0 )
159+
160+ if (AGENTVFS_BLAKE3_SIMD)
161+ set (_blake3_amd64_names amd64 AMD64 x86_64)
162+ set (_blake3_arm64_names aarch64 AArch64 arm64 ARM64 armv8 armv8a)
163+
164+ if (CMAKE_SYSTEM_PROCESSOR IN_LIST _blake3_amd64_names)
165+ target_sources (cas_core PRIVATE
166+ include /blake3/blake3_sse2.c
167+ include /blake3/blake3_sse41.c
168+ include /blake3/blake3_avx2.c
169+ include /blake3/blake3_avx512.c )
170+ if (MSVC )
171+ # MSVC has no dedicated /arch:SSE4.1 — /arch:AVX is the
172+ # narrowest flag that turns on SSE4.1 codegen. /arch:SSE2 is
173+ # x86-only; on x64 SSE2 is the implicit baseline and MSVC
174+ # silently ignores the flag, which is harmless.
175+ set_source_files_properties (include/blake3/blake3_sse2.c
176+ PROPERTIES COMPILE_OPTIONS "/arch:SSE2" )
177+ set_source_files_properties (include/blake3/blake3_sse41.c
178+ PROPERTIES COMPILE_OPTIONS "/arch:AVX" )
179+ set_source_files_properties (include/blake3/blake3_avx2.c
180+ PROPERTIES COMPILE_OPTIONS "/arch:AVX2" )
181+ set_source_files_properties (include/blake3/blake3_avx512.c
182+ PROPERTIES COMPILE_OPTIONS "/arch:AVX512" )
183+ else ()
184+ set_source_files_properties (include/blake3/blake3_sse2.c
185+ PROPERTIES COMPILE_OPTIONS "-msse2" )
186+ set_source_files_properties (include/blake3/blake3_sse41.c
187+ PROPERTIES COMPILE_OPTIONS "-msse4.1" )
188+ set_source_files_properties (include/blake3/blake3_avx2.c
189+ PROPERTIES COMPILE_OPTIONS "-mavx2" )
190+ set_source_files_properties (include/blake3/blake3_avx512.c
191+ PROPERTIES COMPILE_OPTIONS "-mavx512f;-mavx512vl" )
192+ endif ()
193+ elseif (CMAKE_SYSTEM_PROCESSOR IN_LIST _blake3_arm64_names)
194+ target_sources (cas_core PRIVATE include /blake3/blake3_neon.c )
195+ # 64-bit aarch64 has NEON unconditionally; no -mfpu flag needed.
196+ # blake3_dispatch.c picks NEON automatically when BLAKE3_USE_NEON
197+ # is unset (the upstream default).
198+ else ()
199+ # Unknown arch — fall back to portable, same as
200+ # AGENTVFS_BLAKE3_SIMD=OFF.
201+ target_compile_definitions (cas_core PRIVATE
202+ BLAKE3_NO_AVX512 BLAKE3_NO_AVX2 BLAKE3_NO_SSE41 BLAKE3_NO_SSE2
203+ BLAKE3_USE_NEON=0 )
204+ endif ()
205+ else ()
206+ target_compile_definitions (cas_core PRIVATE
207+ BLAKE3_NO_AVX512 BLAKE3_NO_AVX2 BLAKE3_NO_SSE41 BLAKE3_NO_SSE2
208+ BLAKE3_USE_NEON=0 )
209+ endif ()
162210if (NOT MSVC )
163211 target_compile_options (cas_core PRIVATE -Wall -Wextra -Wpedantic )
164212endif ()
@@ -523,6 +571,11 @@ target_include_directories(cas_test_telemetry_registry PRIVATE include src src/c
523571target_compile_features (cas_test_telemetry_registry PRIVATE cxx_std_17 )
524572endif ()
525573
574+ if (AGENTVFS_BLAKE3_SIMD)
575+ add_executable (cas_test_blake3_simd tests/cas/test_blake3_simd.cpp )
576+ target_link_libraries (cas_test_blake3_simd PRIVATE cas_core )
577+ endif ()
578+
526579if (LINUX )
527580add_executable (cas_test_ebpf_backend
528581 tests/cas/test_ebpf_backend.cpp
0 commit comments