Commit Graph
82 Commits
Author SHA1 Message Date
Davide FacontiandClaude Opus 5.5 c2f367e286 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
2026-11-15 20:03:51 +01:00
Davide FacontiandClaude Opus 5.5 933c235c1c kiss_fftndr: fix allocation size check, odd sizes and ndims == 1
kiss_fftndr_alloc had three problems:

- Its overflow check divided the required size (truncated to an int) by
  every dimension and failed when fewer than sizeof(kiss_fft_scalar)
  bytes per element remained. The buffers only need slightly more than
  that per element, so valid sizes were rejected: 230 of the even NxN
  sizes from 2 to 512 (starting at 54x54) returned NULL. Replace it with
  a direct check that dimOther*(dimReal+2) scalars fit in size_t with a
  margin and that dimOther fits the int that kiss_fftnd counts it in,
  and make prod() saturate instead of wrapping.

- An odd last dimension is not supported by kiss_fftr, but the failure
  of the kiss_fftr_alloc size query was ignored and a config with a
  NULL kiss_fftr state was returned. Now kiss_fftndr_alloc returns NULL.

- With ndims == 1 the inner kiss_fftnd has zero dimensions, and
  kiss_fftnd never wrote its output in that case (the even-ndims path
  leaves the result in tmpbuf and the loop body never runs), so
  kiss_fftndr/kiss_fftndri returned garbage. Make a zero-dimensional
  kiss_fftnd the identity, which fixes both directions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ME1hnNaoD3ZcMj9H8TSYkZ
2026-11-15 20:02:21 +01:00
Davide FacontiandClaude Opus 5.5 24fa326186 kiss_fft: validate sizes in the alloc functions and next_fast_size
- kiss_fft_alloc(0) passed the overflow check and computed
  sizeof(kiss_fft_cpx)*(nfft-1) with nfft-1 == -1, returning a config.
  Reject nfft <= 0 (negative sizes were only rejected by accident of the
  signed/unsigned comparison, which is now an explicit cast).
- kiss_fftr_alloc(0) halved 0 and built a config around a NULL
  sub-state. Reject nfft <= 0 along with odd sizes, and compute
  nfft*3/2 in size_t.
- kiss_fftnd_alloc multiplied the dimensions in an int, so {65536,65536}
  wrapped to 0 and {46342,46342} to a negative value: the size query
  reported a bogus size and a far too small buffer was accepted. Reject
  dims <= 0 and products that do not fit in an int (st->dimprod) or whose
  buffer size overflows size_t, reporting *lenmem = (size_t)-1 as
  kiss_fftndr_alloc does.
- kiss_fft_next_fast_size incremented n past INT_MAX for
  n > 2125764000 (the largest 2,3,5-smooth int) and returned a negative
  value. It now returns n itself there (documented in kiss_fft.h): no
  2,3,5-smooth int >= n exists, and n is still a valid, if slower, size
  for callers that pass the result straight to an alloc.
- kfc.c read an uninitialized length when the size query rejected nfft;
  it now returns NULL for an invalid size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ME1hnNaoD3ZcMj9H8TSYkZ
2026-11-11 10:12:39 +01:00
mborgerdingandGitHub 6398d8a1d0 Merge pull request #111 from HecaiYuan/master
loongarch: add loongarch simd opt
2026-05-11 20:03:41 -04:00
Martin RysandMartin 8e2620a597 Remove Python 2 mentions
Also fix up indents
2025-11-28 20:29:11 +01:00
yuanhecai eeb2e98ff6 loongarch: add lasx simd opt 2025-09-01 18:07:43 +08:00
yuanhecai c94458d8f2 loongarch: add lsx simd opt 2025-09-01 18:07:39 +08:00
Felix J. Ogris 1c3c9a5c94 call $(MAKE) instead of make 2025-02-01 18:19:23 +01:00
razor_laptop 59c8cdfb08 fixed test/Makefile line 137 missing ')' 2021-10-18 00:43:05 +08:00
Vasyl Gello 2e2747c129 Overhaul Make makefiles
* Header files and correspondent C sources that define
    functions recently added to public API moved from
    'tools' directory to root

  * By default, install prefix is '/usr/local/', and header
    install path is '${PREFIX}/include/kissfft'

  * Added detection of external libraries like FFTW or libPNG

Signed-off-by: Vasyl Gello <[email protected]>
2021-02-05 13:34:16 +02:00
Mark Borgerding e321f7a4d7 dropped -Waggregate-return from warning flags as it created spurious warnings for recent c++ compilation (found through cmake build on CentOS 8) 2021-01-23 11:53:53 -05:00
Mark Borgerding cf5813a1b4 added test for simd crash to "make testall" and thus travis CI 2020-04-19 10:06:56 -04:00
Mark Borgerding b30b93cd97 A test case for issue #40. Segfaults with: make -C test test_simd && ./test/test_simd 2020-04-19 09:57:40 -04:00
Mark Borgerding cbf1f0eed1 removed unused and unmaintained mk_test.py 2019-02-01 07:40:39 -05:00
Mark Borgerding 8a01c6085d merge and fixes for RedHat 5.5 gcc 64bit 2012-07-18 00:19:37 -04:00
Mark Borgerding dc6bfad0ab previous gcc versions might've been silently adding -lm at the end of the link line. 2012-07-15 22:35:28 -04:00
Mark Borgerding 57925fd126 made threadsafe 2010-05-27 22:54:01 -04:00
Mark Borgerding 089923378d working sourecforge bug 2009-11-28 04:14:47 +00:00
Mark Borgerding 51e95088b3 *** empty log message *** 2009-10-09 19:06:16 +00:00
Mark Borgerding 26f8faa6e8 changed code from memalign to _mm_malloc 2009-09-28 15:55:19 +00:00
Mark Borgerding 0aaf69c005 using -mtune=native 2009-09-22 01:53:33 +00:00
Mark Borgerding 3a27b71226 *** empty log message *** 2009-05-18 02:30:47 +00:00
Mark Borgerding 2b5477d54c first addition of kissfft.hh the C++ template fft engine 2009-05-17 23:57:26 +00:00
Mark Borgerding 3df04c8671 openmp directives 2008-08-22 21:43:25 +00:00
Mark Borgerding 348d8dd530 removed x86 specifics 2007-01-07 00:01:59 +00:00
Mark Borgerding 1922ba0d4e update benchmark tool to allow multi-dimensional and/or real FFTs 2006-11-14 19:40:58 +00:00
Mark Borgerding 7f68a2916b *** empty log message *** 2006-11-13 21:06:39 +00:00
Mark Borgerding a95fbd464f woops bad file paths 2006-07-13 02:43:34 +00:00
Mark Borgerding a09fc4a364 *** empty log message *** 2006-05-31 03:49:02 +00:00
Mark Borgerding 18d0ad1604 *** empty log message *** 2005-10-07 12:29:36 +00:00
Mark Borgerding 3b5dfee961 added kiss_fft_cleanup
updated Makefiles for long and simd targets
2005-07-09 03:42:07 +00:00
Mark Borgerding 4be23bffa4 polishing SIMD changes 2005-06-25 04:38:19 +00:00
Mark Borgerding 7f6cbeab2e added simd capability 2005-06-24 03:03:31 +00:00
Mark Borgerding 10dbc47ff3 added some code for 32 bit fixed point fft -- may not be suitable for all platforms 2005-05-31 02:19:07 +00:00
Mark Borgerding ed1a5f0cfc made easy to use longs for fixed point 2005-05-11 02:36:33 +00:00
Mark Borgerding 0b11af8bea default CFLAGS 2004-04-04 22:02:16 +00:00
Mark Borgerding 5d25194d0f compile flags 2004-04-04 19:41:16 +00:00
Mark Borgerding 0fd8da731a compiles clean with lots of -W switches 2004-02-26 03:43:23 +00:00
Mark Borgerding ebd0d360e0 reset flags back to safe values 2004-02-24 02:49:59 +00:00
Mark Borgerding b61061d52a *** empty log message *** 2004-02-03 13:14:52 +00:00
Mark Borgerding 029fad7a65 *** empty log message *** 2004-02-02 02:05:05 +00:00
Mark Borgerding 36f5d5b68b *** empty log message *** 2004-02-02 01:54:17 +00:00
Mark Borgerding 2d2bfb6794 only good for float 2004-02-02 01:53:29 +00:00
Mark Borgerding 490a602472 test code for in-place odd rank multidimensional FFTs 2004-02-02 01:47:32 +00:00
Mark Borgerding 1a5f860757 v110 2004-01-31 02:46:20 +00:00
Mark Borgerding 366f17e379 getting ready for 1.1 2004-01-31 01:28:21 +00:00
Mark Borgerding 9ddb2bb744 *** empty log message *** 2004-01-30 03:40:54 +00:00
Mark Borgerding 25e377eaa8 fast conv filtering small edits
2d files no longer needed with kiss_fftnd
2004-01-24 01:34:01 +00:00
Mark Borgerding 227c021f39 extra cleanup 2004-01-04 23:15:44 +00:00
Mark Borgerding e749a114cb real fast convolution filtering works mostly, sometimes it does not
make all the samples ( obeserved with ./fastfir.py -n 1024 -r -l 100000 )
2004-01-01 18:51:17 +00:00