@@ -49,38 +49,57 @@ SOURCES_C := \
4949 $(CORE_DIR)/src/wavetable.c
5050
5151# SIMD-accelerated blitter operations: select arch-specific implementation.
52- # Override with BLITTER_SIMD=scalar|sse2|neon for cross-compilation.
53- # Default to portable scalar fallback.
52+ # BLITTER_SIMD may be set explicitly to one of: scalar, sse2, neon.
5453BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_scalar.c
5554
56- ifdef BLITTER_SIMD
57- # Explicit override for cross-compilation or custom builds
58- BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_$(BLITTER_SIMD).c
59- else
60- # Auto-detect from host architecture (native builds only)
61- # x86/x64: use SSE2 (baseline for all x86_64, available since Pentium 4)
62- ifneq (,$(filter x86_64 x86 i686 i386,$(shell uname -m 2>/dev/null)))
63- BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_sse2.c
64- endif
65- # MSYS2/MinGW on x86_64
66- ifneq (,$(filter MINGW64%,$(MSYSTEM)))
67- BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_sse2.c
68- endif
69- # ARM64 (AArch64): NEON is always available
70- ifneq (,$(filter aarch64 arm64,$(shell uname -m 2>/dev/null)))
71- BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_neon.c
72- endif
55+ ifneq ($(BLITTER_SIMD),)
56+ ifeq (,$(filter scalar sse2 neon,$(BLITTER_SIMD)))
57+ $(error Unsupported BLITTER_SIMD '$(BLITTER_SIMD)'; expected one of: scalar sse2 neon)
58+ endif
7359endif
7460
75- # Platform-based overrides (cross-compilation targets)
61+ ifeq ($(BLITTER_SIMD),sse2)
62+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_sse2.c
63+ else ifeq ($(BLITTER_SIMD),neon)
64+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_neon.c
65+ else ifeq ($(BLITTER_SIMD),scalar)
66+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_scalar.c
67+ else
68+ # ARM targets: prefer NEON when the target configuration says it is available.
69+ ifeq ($(HAVE_NEON), 1)
70+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_neon.c
71+ endif
7672ifneq (,$(filter ios-arm64 tvos-arm64,$(platform)))
7773 BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_neon.c
7874endif
79- # ARMv7 with NEON (set by Makefile for classic_armv7 targets)
80- ifeq ($(HAVE_NEON), 1)
75+ ifneq (,$(filter aarch64 arm64 arm,$(ARCH)))
76+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_neon.c
77+ endif
78+ ifneq (,$(filter arm64 armv8% armv7% armhf arm,$(platform)))
8179 BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_neon.c
8280endif
8381
82+ # x86/x64 targets: use SSE2.
83+ ifneq (,$(filter x86_64 x86 i686 i386,$(ARCH)))
84+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_sse2.c
85+ endif
86+ ifneq (,$(filter x86_64 x86 i686 i386 win-x64 win32,$(platform)))
87+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_sse2.c
88+ endif
89+ # MSYS2/MinGW on x86_64
90+ ifneq (,$(filter MINGW64%,$(MSYSTEM)))
91+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_sse2.c
92+ endif
93+
94+ # Native build fallback: auto-detect from host architecture
95+ ifneq (,$(filter x86_64 x86 i686 i386,$(shell uname -m 2>/dev/null)))
96+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_sse2.c
97+ endif
98+ ifneq (,$(filter aarch64 arm64,$(shell uname -m 2>/dev/null)))
99+ BLITTER_SIMD_SRC := $(CORE_DIR)/src/blitter_simd_neon.c
100+ endif
101+ endif
102+
84103SOURCES_C += $(BLITTER_SIMD_SRC)
85104
86105ifneq ($(STATIC_LINKING), 1)
0 commit comments