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:
@@ -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)
|
||||
Reference in New Issue
Block a user