Skip to content

Commit 4ed3a99

Browse files
committed
Math: FFT: First step for cold data twiddle factors
This patch makes a packed copy of twiddle factors to a new allocated buffer from the sparse twiddle factors for max. FFT size. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 212748e commit 4ed3a99

File tree

6 files changed

+125
-70
lines changed

6 files changed

+125
-70
lines changed

src/include/sof/math/fft.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct fft_plan {
5252
struct icomplex32 *outb32; /* pointer to output integer complex buffer */
5353
struct icomplex16 *inb16; /* pointer to input integer complex buffer */
5454
struct icomplex16 *outb16; /* pointer to output integer complex buffer */
55+
void *twiddle;
5556
};
5657

5758
struct fft_multi_plan {
@@ -62,8 +63,8 @@ struct fft_multi_plan {
6263
struct icomplex16 *tmp_o16[FFT_MULTI_COUNT_MAX]; /* pointer to output buffer */
6364
struct icomplex32 *inb32; /* pointer to input integer complex buffer */
6465
struct icomplex32 *outb32; /* pointer to output integer complex buffer */
65-
struct icomplex16 *inb16; /* pointer to input integer complex buffer */
66-
struct icomplex16 *outb16; /* pointer to output integer complex buffer */
66+
int32_t *multi_twiddle;
67+
int32_t *twiddle;
6768
uint16_t *bit_reverse_idx;
6869
uint32_t total_size;
6970
uint32_t fft_size;

src/math/fft/fft_16.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <sof/math/fft.h>
1111

1212
#ifdef FFT_GENERIC
13-
#include "coef/twiddle_16.h"
1413

1514
/*
1615
* Helpers for 16 bit FFT calculation
@@ -75,6 +74,7 @@ void fft_execute_16(struct fft_plan *plan, bool ifft)
7574
struct icomplex16 tmp2;
7675
struct icomplex16 *inb;
7776
struct icomplex16 *outb;
77+
struct icomplex16 *twiddle;
7878
int depth;
7979
int top;
8080
int bottom;
@@ -104,10 +104,11 @@ void fft_execute_16(struct fft_plan *plan, bool ifft)
104104
icomplex16_shift(&inb[i], -(plan->len), &outb[plan->bit_reverse_idx[i]]);
105105

106106
/* step 2: loop to do FFT transform in smaller size */
107+
twiddle = plan->twiddle;
107108
for (depth = 1; depth <= plan->len; ++depth) {
108109
m = 1 << depth;
109110
n = m >> 1;
110-
i = FFT_SIZE_MAX >> depth;
111+
i = plan->size >> depth;
111112

112113
/* doing FFT transforms in size m */
113114
for (k = 0; k < plan->size; k += m) {
@@ -116,8 +117,7 @@ void fft_execute_16(struct fft_plan *plan, bool ifft)
116117
index = i * j;
117118
top = k + j;
118119
bottom = top + n;
119-
tmp1.real = twiddle_real_16[index];
120-
tmp1.imag = twiddle_imag_16[index];
120+
tmp1 = twiddle[index];
121121
/* calculate the accumulator: twiddle * bottom */
122122
icomplex16_mul(&tmp1, &outb[bottom], &tmp2);
123123
tmp1 = outb[top];

src/math/fft/fft_16_hifi3.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#ifdef FFT_HIFI3
1212
#include <xtensa/tie/xt_hifi3.h>
13-
#include "coef/twiddle_16.h"
1413

1514
/**
1615
* \brief Execute the 16-bits Fast Fourier Transform (FFT) or Inverse FFT (IFFT)
@@ -29,6 +28,7 @@ void fft_execute_16(struct fft_plan *plan, bool ifft)
2928
ae_int16 *out;
3029
ae_int16x4 *in16x4;
3130
ae_int16x4 *out16x4;
31+
ae_int16 *twiddle;
3232
ae_valign inu = AE_ZALIGN64();
3333
ae_valign outu = AE_ZALIGN64();
3434
int depth, top, bottom, index;
@@ -67,6 +67,7 @@ void fft_execute_16(struct fft_plan *plan, bool ifft)
6767
}
6868

6969
/* step 2: loop to do FFT transform in smaller size */
70+
twiddle = plan->twiddle;
7071
for (depth = 1; depth <= plan->len; ++depth) {
7172
m = 1 << depth;
7273
n = m >> 1;
@@ -76,13 +77,12 @@ void fft_execute_16(struct fft_plan *plan, bool ifft)
7677
for (k = 0; k < plan->size; k += m) {
7778
/* doing one FFT transform for size m */
7879
for (j = 0; j < n; ++j) {
79-
index = i * j;
80+
index = 2 * i * j;
8081
top = k + j;
8182
bottom = top + n;
8283
/* store twiddle and bottom as Q9.23*/
8384
temp1 = AE_CVTP24A16X2_LL(outb[bottom].real, outb[bottom].imag);
84-
temp2 = AE_CVTP24A16X2_LL(twiddle_real_16[index],
85-
twiddle_imag_16[index]);
85+
temp2 = AE_CVTP24A16X2_LL(twiddle[index], twiddle[index + 1]);
8686
/* calculate the accumulator: twiddle * bottom */
8787
res = AE_MULFC24RA(temp1, temp2);
8888
/* saturate and round the result to 16bit and put it in

src/math/fft/fft_32.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#ifdef FFT_GENERIC
1616
#include "fft_32.h"
17-
#include "coef/twiddle_32.h"
18-
1917

2018
/**
2119
* \brief Execute the 32-bits Fast Fourier Transform (FFT) or Inverse FFT (IFFT)
@@ -29,6 +27,7 @@ void fft_execute_32(struct fft_plan *plan, bool ifft)
2927
struct icomplex32 tmp2;
3028
struct icomplex32 *inb;
3129
struct icomplex32 *outb;
30+
struct icomplex32 *twiddle;
3231
int depth;
3332
int top;
3433
int bottom;
@@ -58,10 +57,11 @@ void fft_execute_32(struct fft_plan *plan, bool ifft)
5857
icomplex32_shift(&inb[i], -(plan->len), &outb[plan->bit_reverse_idx[i]]);
5958

6059
/* step 2: loop to do FFT transform in smaller size */
60+
twiddle = plan->twiddle;
6161
for (depth = 1; depth <= plan->len; ++depth) {
6262
m = 1 << depth;
6363
n = m >> 1;
64-
i = FFT_SIZE_MAX >> depth;
64+
i = plan->size >> depth;
6565

6666
/* doing FFT transforms in size m */
6767
for (k = 0; k < plan->size; k += m) {
@@ -70,8 +70,7 @@ void fft_execute_32(struct fft_plan *plan, bool ifft)
7070
index = i * j;
7171
top = k + j;
7272
bottom = top + n;
73-
tmp1.real = twiddle_real_32[index];
74-
tmp1.imag = twiddle_imag_32[index];
73+
tmp1 = twiddle[index];
7574
/* calculate the accumulator: twiddle * bottom */
7675
icomplex32_mul(&tmp1, &outb[bottom], &tmp2);
7776
tmp1 = outb[top];

src/math/fft/fft_32_hifi3.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#ifdef FFT_HIFI3
1313
#include <xtensa/tie/xt_hifi3.h>
14-
#include "coef/twiddle_32.h"
1514

1615
void fft_execute_32(struct fft_plan *plan, bool ifft)
1716
{
@@ -23,6 +22,7 @@ void fft_execute_32(struct fft_plan *plan, bool ifft)
2322
ae_int32x2 *outx = (ae_int32x2 *)plan->outb32;
2423
ae_int32x2 *outtop;
2524
ae_int32x2 *outbottom;
25+
ae_int32x2 *twiddle;
2626
uint16_t *idx = &plan->bit_reverse_idx[0];
2727
int depth, top, bottom, index;
2828
int i, j, k, m, n;
@@ -55,23 +55,22 @@ void fft_execute_32(struct fft_plan *plan, bool ifft)
5555
}
5656

5757
/* step 2: loop to do FFT transform in smaller size */
58+
twiddle = plan->twiddle;
5859
for (depth = 1; depth <= len; ++depth) {
5960
m = 1 << depth;
6061
n = m >> 1;
61-
i = FFT_SIZE_MAX >> depth;
62+
i = size >> depth;
6263

6364
/* doing FFT transforms in size m */
6465
for (k = 0; k < size; k += m) {
6566
/* doing one FFT transform for size m */
6667
for (j = 0; j < n; ++j) {
67-
index = i * j;
68+
index = i * j * sizeof(ae_int32x2);
6869
top = k + j;
6970
bottom = top + n;
7071

7172
/* load twiddle factor to sample1 */
72-
sample1 = twiddle_real_32[index];
73-
sample2 = twiddle_imag_32[index];
74-
sample1 = AE_SEL32_LH(sample1, sample2);
73+
sample1 = AE_L32X2_X(twiddle, index);
7574

7675
/* calculate the accumulator: twiddle * bottom */
7776
sample2 = outx[bottom];

0 commit comments

Comments
 (0)