mirror of
https://github.com/mborgerding/kissfft.git
synced 2026-11-18 20:09:30 -05:00
kiss_fftnd, kiss_fftndr: align every object packed into the state block
kiss_fftnd_alloc and kiss_fftndr_alloc carve several objects out of one allocation, advancing by KISS_FFT_ALIGN_SIZE_UP(size), which is the identity outside SIMD builds. So objects started at whatever offset the previous one ended: - kiss_fftnd: after an odd number of int dims, tmpbuf and the per-dimension kiss_fft_state objects were 4 bytes off, misaligned for double. - kiss_fftndr: the nd state (which holds pointers) followed the real-FFT state, whose size is only a multiple of 4 for int16_t. These are misaligned accesses (undefined behavior; SIGBUS on strict platforms, silent on x86). Add KISS_FFT_PACK_SIZE_UP to _kiss_fft_guts.h, which rounds a size up to a multiple of the size of a union of pointer, int and kiss_fft_cpx (a multiple of each of their alignments, and of the SIMD vector alignment), and use it for every object in both layouts. The reported sizes grow by a few bytes of padding. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01ME1hnNaoD3ZcMj9H8TSYkZ
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
933c235c1c
commit
c2f367e286
+10
-2
@@ -45,6 +45,7 @@ ifneq ($(KISSFFT_OPENMP),1)
|
||||
TESTREAL = tr-$(KISSFFT_DATATYPE)
|
||||
TESTSIZEVAL = tsizeval-$(KISSFFT_DATATYPE)
|
||||
TESTNDRALLOC = tndralloc-$(KISSFFT_DATATYPE)
|
||||
TESTNDALIGN = tndalign-$(KISSFFT_DATATYPE)
|
||||
TESTKFC = tkfc-$(KISSFFT_DATATYPE)
|
||||
TESTFASTFILT = fastfilt-$(KISSFFT_DATATYPE)
|
||||
TESTCPP = testcpp-$(KISSFFT_DATATYPE)
|
||||
@@ -56,6 +57,7 @@ else
|
||||
TESTREAL = tr-$(KISSFFT_DATATYPE)-openmp
|
||||
TESTSIZEVAL = tsizeval-$(KISSFFT_DATATYPE)-openmp
|
||||
TESTNDRALLOC = tndralloc-$(KISSFFT_DATATYPE)-openmp
|
||||
TESTNDALIGN = tndalign-$(KISSFFT_DATATYPE)-openmp
|
||||
TESTKFC = tkfc-$(KISSFFT_DATATYPE)-openmp
|
||||
TESTFASTFILT = fastfilt-$(KISSFFT_DATATYPE)-openmp
|
||||
TESTCPP = testcpp-$(KISSFFT_DATATYPE)-openmp
|
||||
@@ -107,7 +109,7 @@ endif
|
||||
# Target: "make all"
|
||||
#
|
||||
|
||||
all: $(BENCHKISS) $(SELFTEST) $(BENCHFFTW) $(TESTREAL) $(TESTSIZEVAL) $(TESTNDRALLOC) $(TESTKFC) $(TESTFASTFILT)
|
||||
all: $(BENCHKISS) $(SELFTEST) $(BENCHFFTW) $(TESTREAL) $(TESTSIZEVAL) $(TESTNDRALLOC) $(TESTNDALIGN) $(TESTKFC) $(TESTFASTFILT)
|
||||
|
||||
#
|
||||
# Individual test make rules
|
||||
@@ -128,6 +130,10 @@ $(TESTSIZEVAL): test_size_validation.c
|
||||
$(TESTNDRALLOC): test_fftndr_alloc.c
|
||||
$(CC) -o $@ $(CFLAGS) $(TYPEFLAGS) $< -L.. -l$(KISSFFTLIB_SHORTNAME) -lm
|
||||
|
||||
# includes ../kiss_fftr.c, ../kiss_fftnd.c and ../kiss_fftndr.c to reach their private structs
|
||||
$(TESTNDALIGN): test_nd_alignment.c ../kiss_fftr.c ../kiss_fftnd.c ../kiss_fftndr.c
|
||||
$(CC) -o $@ $(CFLAGS) $(TYPEFLAGS) $< -L.. -l$(KISSFFTLIB_SHORTNAME) -lm
|
||||
|
||||
$(BENCHKISS): benchkiss.c pstats.c
|
||||
$(CC) -o $@ $(CFLAGS) $(TYPEFLAGS) $^ -L.. -l$(KISSFFTLIB_SHORTNAME) -lm
|
||||
|
||||
@@ -189,6 +195,8 @@ endif
|
||||
@LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):.." ./$(TESTSIZEVAL)
|
||||
$(warning ======kiss_fftndr allocation regression test (type= $(KISSFFT_DATATYPE) ))
|
||||
@LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):.." ./$(TESTNDRALLOC)
|
||||
$(warning ======multi-dimensional FFT state alignment regression test (type= $(KISSFFT_DATATYPE) ))
|
||||
@LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):.." ./$(TESTNDALIGN)
|
||||
$(warning ======timing test (type=$(KISSFFT_DATATYPE)))
|
||||
@LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):.." ./$(BENCHKISS) -x $(NUMFFTS) -n $(NFFT)
|
||||
@[ -x ./$(BENCHFFTW) ] && LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):.." ./$(BENCHFFTW) -x $(NUMFFTS) -n $(NFFT) || true
|
||||
@@ -200,4 +208,4 @@ endif
|
||||
#
|
||||
|
||||
clean:
|
||||
rm -f *~ bm-* st-* tr-* tsizeval-* tndralloc-* kf-* tkfc-* ff-* fastfilt-* *.pyc *.pyo *.dat testcpp-* testsimd testsimd-* _test_library_dummy _test_library_dummy.c
|
||||
rm -f *~ bm-* st-* tr-* tsizeval-* tndralloc-* tndalign-* kf-* tkfc-* ff-* fastfilt-* *.pyc *.pyo *.dat testcpp-* testsimd testsimd-* _test_library_dummy _test_library_dummy.c
|
||||
|
||||
Reference in New Issue
Block a user