Add AVX2 prime check with cross-platform Makefile

Trial division by 6k+/-1 using double-precision AVX2 lanes so the quotient is exact for 32-bit n. Makefile builds on Linux and Windows (MinGW gcc).
This commit is contained in:
2026-10-20 00:07:17 +08:00
parent 7fc7700ea9
commit e4be228a5b
2 changed files with 95 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
# Builds prime_avx2 on Linux (gcc) and Windows (MinGW-w64 / MSYS2 gcc).
# make build
# make run build and run
# make clean remove build output
CC ?= gcc
CFLAGS ?= -O3 -mavx2 -Wall -Wextra
LDLIBS += -lm
ifeq ($(OS),Windows_NT)
EXE := .exe
RM := del /Q /F
# make on Windows may use cmd.exe, which needs backslashes
RUN := .\prime_avx2$(EXE)
RMTARGET := prime_avx2$(EXE)
else
EXE :=
RM := rm -f
RUN := ./prime_avx2
RMTARGET := prime_avx2
endif
TARGET := prime_avx2$(EXE)
.PHONY: all run clean
all: $(TARGET)
$(TARGET): prime_avx2.c
$(CC) $(CFLAGS) $< -o $@ $(LDLIBS)
run: $(TARGET)
$(RUN)
clean:
-$(RM) $(RMTARGET)