this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

alignment fixing for USE_SIMD - all memory allocations are rounded up to 16-byte boundaries. This fixes crashes where the sub-buffers for complex FFTs end up unaligned violating compiler expectations

+41 -22
+4 -2
kiss_fft.c
··· 332 332 * */ 333 333 kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem ) 334 334 { 335 + KISS_FFT_ALIGN_CHECK(mem) 336 + 335 337 kiss_fft_cfg st=NULL; 336 - size_t memneeded = sizeof(struct kiss_fft_state) 337 - + sizeof(kiss_fft_cpx)*(nfft-1); /* twiddle factors*/ 338 + size_t memneeded = KISS_FFT_ALIGN_SIZE_UP(sizeof(struct kiss_fft_state) 339 + + sizeof(kiss_fft_cpx)*(nfft-1)); /* twiddle factors*/ 338 340 339 341 if ( lenmem==NULL ) { 340 342 st = ( kiss_fft_cfg)KISS_FFT_MALLOC( memneeded );
+4
kiss_fft.h
··· 37 37 # define kiss_fft_scalar __m128 38 38 # ifndef KISS_FFT_MALLOC 39 39 # define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16) 40 + # define KISS_FFT_ALIGN_CHECK(ptr) assert((((uintptr_t) ptr) & 0xF) == 0); 41 + # define KISS_FFT_ALIGN_SIZE_UP(size) ((size + 15UL) & ~0xFUL) 40 42 # endif 41 43 # ifndef KISS_FFT_FREE 42 44 # define KISS_FFT_FREE _mm_free 43 45 # endif 44 46 #else 47 + # define KISS_FFT_ALIGN_CHECK(ptr) 48 + # define KISS_FFT_ALIGN_SIZE_UP(size) (size) 45 49 # ifndef KISS_FFT_MALLOC 46 50 # define KISS_FFT_MALLOC malloc 47 51 # endif
+15 -12
tools/kiss_fftnd.c
··· 19 19 20 20 kiss_fftnd_cfg kiss_fftnd_alloc(const int *dims,int ndims,int inverse_fft,void*mem,size_t*lenmem) 21 21 { 22 + KISS_FFT_ALIGN_CHECK(mem) 23 + 22 24 kiss_fftnd_cfg st = NULL; 23 25 int i; 24 26 int dimprod=1; 25 - size_t memneeded = sizeof(struct kiss_fftnd_state); 26 - char * ptr; 27 + size_t memneeded = KISS_FFT_ALIGN_SIZE_UP(sizeof(struct kiss_fftnd_state)); 28 + char * ptr = NULL; 27 29 28 30 for (i=0;i<ndims;++i) { 29 31 size_t sublen=0; ··· 31 33 memneeded += sublen; /* st->states[i] */ 32 34 dimprod *= dims[i]; 33 35 } 34 - memneeded += sizeof(int) * ndims;/* st->dims */ 35 - memneeded += sizeof(void*) * ndims;/* st->states */ 36 - memneeded += sizeof(kiss_fft_cpx) * dimprod; /* st->tmpbuf */ 36 + memneeded += KISS_FFT_ALIGN_SIZE_UP(sizeof(int) * ndims);/* st->dims */ 37 + memneeded += KISS_FFT_ALIGN_SIZE_UP(sizeof(void*) * ndims);/* st->states */ 38 + memneeded += KISS_FFT_ALIGN_SIZE_UP(sizeof(kiss_fft_cpx) * dimprod); /* st->tmpbuf */ 37 39 38 40 if (lenmem == NULL) {/* allocate for the caller*/ 39 - st = (kiss_fftnd_cfg) malloc (memneeded); 41 + ptr = (char *) malloc (memneeded); 40 42 } else { /* initialize supplied buffer if big enough */ 41 43 if (*lenmem >= memneeded) 42 - st = (kiss_fftnd_cfg) mem; 44 + ptr = (char *) mem; 43 45 *lenmem = memneeded; /*tell caller how big struct is (or would be) */ 44 46 } 45 - if (!st) 47 + if (!ptr) 46 48 return NULL; /*malloc failed or buffer too small */ 47 49 50 + st = (kiss_fftnd_cfg) ptr; 48 51 st->dimprod = dimprod; 49 52 st->ndims = ndims; 50 - ptr=(char*)(st+1); 53 + ptr += KISS_FFT_ALIGN_SIZE_UP(sizeof(struct kiss_fftnd_state)); 51 54 52 55 st->states = (kiss_fft_cfg *)ptr; 53 - ptr += sizeof(void*) * ndims; 56 + ptr += KISS_FFT_ALIGN_SIZE_UP(sizeof(void*) * ndims); 54 57 55 58 st->dims = (int*)ptr; 56 - ptr += sizeof(int) * ndims; 59 + ptr += KISS_FFT_ALIGN_SIZE_UP(sizeof(int) * ndims); 57 60 58 61 st->tmpbuf = (kiss_fft_cpx*)ptr; 59 - ptr += sizeof(kiss_fft_cpx) * dimprod; 62 + ptr += KISS_FFT_ALIGN_SIZE_UP(sizeof(kiss_fft_cpx) * dimprod); 60 63 61 64 for (i=0;i<ndims;++i) { 62 65 size_t len;
+16 -8
tools/kiss_fftndr.c
··· 29 29 30 30 kiss_fftndr_cfg kiss_fftndr_alloc(const int *dims,int ndims,int inverse_fft,void*mem,size_t*lenmem) 31 31 { 32 + KISS_FFT_ALIGN_CHECK(mem) 33 + 32 34 kiss_fftndr_cfg st = NULL; 33 35 size_t nr=0 , nd=0,ntmp=0; 34 36 int dimReal = dims[ndims-1]; 35 37 int dimOther = prod(dims,ndims-1); 36 38 size_t memneeded; 37 - 39 + char * ptr = NULL; 40 + 38 41 (void)kiss_fftr_alloc(dimReal,inverse_fft,NULL,&nr); 39 42 (void)kiss_fftnd_alloc(dims,ndims-1,inverse_fft,NULL,&nd); 40 43 ntmp = 41 44 MAX( 2*dimOther , dimReal+2) * sizeof(kiss_fft_scalar) // freq buffer for one pass 42 45 + dimOther*(dimReal+2) * sizeof(kiss_fft_scalar); // large enough to hold entire input in case of in-place 43 46 44 - memneeded = sizeof( struct kiss_fftndr_state ) + nr + nd + ntmp; 47 + memneeded = KISS_FFT_ALIGN_SIZE_UP(sizeof( struct kiss_fftndr_state )) + KISS_FFT_ALIGN_SIZE_UP(nr) + KISS_FFT_ALIGN_SIZE_UP(nd) + KISS_FFT_ALIGN_SIZE_UP(ntmp); 45 48 46 49 if (lenmem==NULL) { 47 - st = (kiss_fftndr_cfg) malloc(memneeded); 50 + ptr = (char*) malloc(memneeded); 48 51 }else{ 49 52 if (*lenmem >= memneeded) 50 - st = (kiss_fftndr_cfg)mem; 53 + ptr = (char *)mem; 51 54 *lenmem = memneeded; 52 55 } 53 - if (st==NULL) 56 + if (ptr==NULL) 54 57 return NULL; 58 + 59 + st = (kiss_fftndr_cfg) ptr; 55 60 memset( st , 0 , memneeded); 61 + ptr += KISS_FFT_ALIGN_SIZE_UP(sizeof(struct kiss_fftndr_state)); 56 62 57 63 st->dimReal = dimReal; 58 64 st->dimOther = dimOther; 59 - st->cfg_r = kiss_fftr_alloc( dimReal,inverse_fft,st+1,&nr); 60 - st->cfg_nd = kiss_fftnd_alloc(dims,ndims-1,inverse_fft, ((char*) st->cfg_r)+nr,&nd); 61 - st->tmpbuf = (char*)st->cfg_nd + nd; 65 + st->cfg_r = kiss_fftr_alloc( dimReal,inverse_fft,ptr,&nr); 66 + ptr += KISS_FFT_ALIGN_SIZE_UP(nr); 67 + st->cfg_nd = kiss_fftnd_alloc(dims,ndims-1,inverse_fft, ptr,&nd); 68 + ptr += KISS_FFT_ALIGN_SIZE_UP(nd); 69 + st->tmpbuf = ptr; 62 70 63 71 return st; 64 72 }
+2
tools/kiss_fftr.c
··· 20 20 21 21 kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem) 22 22 { 23 + KISS_FFT_ALIGN_CHECK(mem) 24 + 23 25 int i; 24 26 kiss_fftr_cfg st = NULL; 25 27 size_t subsize = 0, memneeded;