Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / openmax_dl / dl / sp / src / x86 / x86SP_FFT_F32_radix4_kernel.c
1 /*
2  *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  *
10  */
11 #include "dl/api/omxtypes.h"
12 #include <stdbool.h>
13
14 extern void x86SP_FFT_CToC_FC32_Fwd_Radix4_fs(
15     const OMX_F32 *in,
16     OMX_F32 *out,
17     OMX_INT n);
18
19 extern void x86SP_FFT_CToC_FC32_Inv_Radix4_fs(
20     const OMX_F32 *in,
21     OMX_F32 *out,
22     OMX_INT n);
23
24 extern void x86SP_FFT_CToC_FC32_Fwd_Radix4_fs_sse(
25     const OMX_F32 *in,
26     OMX_F32 *out,
27     OMX_INT n);
28
29 extern void x86SP_FFT_CToC_FC32_Inv_Radix4_fs_sse(
30     const OMX_F32 *in,
31     OMX_F32 *out,
32     OMX_INT n);
33
34 extern void x86SP_FFT_CToC_FC32_Fwd_Radix4_ms(
35     const OMX_F32 *in,
36     OMX_F32 *out,
37     const OMX_F32 *twiddle,
38     OMX_INT n,
39     OMX_INT sub_size,
40     OMX_INT sub_num);
41
42 extern void x86SP_FFT_CToC_FC32_Inv_Radix4_ms(
43     const OMX_F32 *in,
44     OMX_F32 *out,
45     const OMX_F32 *twiddle,
46     OMX_INT n,
47     OMX_INT sub_size,
48     OMX_INT sub_num);
49
50 extern void x86SP_FFT_CToC_FC32_Fwd_Radix4_ms_sse(
51     const OMX_F32 *in,
52     OMX_F32 *out,
53     const OMX_F32 *twiddle,
54     OMX_INT n,
55     OMX_INT sub_size,
56     OMX_INT sub_num);
57
58 extern void x86SP_FFT_CToC_FC32_Inv_Radix4_ms_sse(
59     const OMX_F32 *in,
60     OMX_F32 *out,
61     const OMX_F32 *twiddle,
62     OMX_INT n,
63     OMX_INT sub_size,
64     OMX_INT sub_num);
65
66 extern void x86SP_FFT_CToC_FC32_Fwd_Radix4_ls(
67     const OMX_F32 *in,
68     OMX_F32 *out,
69     const OMX_F32 *twiddle,
70     OMX_INT n);
71
72 extern void x86SP_FFT_CToC_FC32_Inv_Radix4_ls(
73     const OMX_F32 *in,
74     OMX_F32 *out,
75     const OMX_F32 *twiddle,
76     OMX_INT n);
77
78 extern void x86SP_FFT_CToC_FC32_Fwd_Radix4_ls_sse(
79     const OMX_F32 *in,
80     OMX_F32 *out,
81     const OMX_F32 *twiddle,
82     OMX_INT n);
83
84 extern void x86SP_FFT_CToC_FC32_Inv_Radix4_ls_sse(
85     const OMX_F32 *in,
86     OMX_F32 *out,
87     const OMX_F32 *twiddle,
88     OMX_INT n);
89
90 extern void x86SP_FFT_CToC_FC32_Fwd_Radix2_ls(
91     const OMX_F32 *in,
92     OMX_F32 *out,
93     const OMX_F32 *twiddle,
94     OMX_INT n);
95
96 extern void x86SP_FFT_CToC_FC32_Inv_Radix2_ls(
97     const OMX_F32 *in,
98     OMX_F32 *out,
99     const OMX_F32 *twiddle,
100     OMX_INT n);
101
102 extern void x86SP_FFT_CToC_FC32_Fwd_Radix2_ls_sse(
103     const OMX_F32 *in,
104     OMX_F32 *out,
105     const OMX_F32 *twiddle,
106     OMX_INT n);
107
108 extern void x86SP_FFT_CToC_FC32_Inv_Radix2_ls_sse(
109     const OMX_F32 *in,
110     OMX_F32 *out,
111     const OMX_F32 *twiddle,
112     OMX_INT n);
113
114 OMX_F32* x86SP_F32_radix4_kernel_OutOfPlace(
115     const OMX_F32 *src,
116     OMX_F32 *buf1,
117     OMX_F32 *buf2,
118     const OMX_F32 *twiddle,
119     OMX_INT n,
120     bool forward_fft) {
121   OMX_INT sub_size;
122   OMX_INT sub_num;
123   OMX_INT n_by_4 = n >> 2;
124   OMX_F32 *in = buf1;
125   OMX_F32 *out = buf2;
126
127   if (forward_fft)
128     x86SP_FFT_CToC_FC32_Fwd_Radix4_fs(src, in, n);
129   else
130     x86SP_FFT_CToC_FC32_Inv_Radix4_fs(src, in, n);
131
132   for (sub_size = 4, sub_num = n_by_4;
133        sub_size < n_by_4;
134        sub_size = sub_size << 2, sub_num = sub_num >> 2) {
135
136     if (forward_fft) {
137       x86SP_FFT_CToC_FC32_Fwd_Radix4_ms(in, out, twiddle,
138                                         n, sub_size, sub_num);
139     } else {
140       x86SP_FFT_CToC_FC32_Inv_Radix4_ms(in, out, twiddle,
141                                         n, sub_size, sub_num);
142     }
143
144     OMX_F32 *temp = out;
145     out = in;
146     in = temp;
147   }
148
149   if (forward_fft) {
150     if (sub_num == 2)
151       x86SP_FFT_CToC_FC32_Fwd_Radix2_ls(in, out, twiddle, n);
152     else
153       x86SP_FFT_CToC_FC32_Fwd_Radix4_ls(in, out, twiddle, n);
154   } else {
155     if (sub_num == 2)
156       x86SP_FFT_CToC_FC32_Inv_Radix2_ls(in, out, twiddle, n);
157     else
158       x86SP_FFT_CToC_FC32_Inv_Radix4_ls(in, out, twiddle, n);
159   }
160
161   return out;
162 }
163
164 OMX_F32* x86SP_F32_radix4_kernel_OutOfPlace_sse(
165     const OMX_F32 *src,
166     OMX_F32 *buf1,
167     OMX_F32 *buf2,
168     const OMX_F32 *twiddle,
169     OMX_INT n,
170     // true for forward, false for inverse.
171     bool forward_fft) {
172   OMX_INT sub_size, sub_num;
173   OMX_INT n_by_4 = n >> 2;
174   OMX_F32 *in, *out;
175   in = buf1;
176   out = buf2;
177
178   if (forward_fft)
179     x86SP_FFT_CToC_FC32_Fwd_Radix4_fs_sse(src, in, n);
180   else
181     x86SP_FFT_CToC_FC32_Inv_Radix4_fs_sse(src, in, n);
182
183   for (sub_size = 4, sub_num = n_by_4;
184        sub_size < n_by_4;
185        sub_size = sub_size << 2, sub_num = sub_num >> 2) {
186
187     if (forward_fft) {
188       x86SP_FFT_CToC_FC32_Fwd_Radix4_ms_sse(in, out, twiddle,
189                                             n, sub_size, sub_num);
190     } else {
191       x86SP_FFT_CToC_FC32_Inv_Radix4_ms_sse(in, out, twiddle,
192                                             n, sub_size, sub_num);
193     }
194
195     OMX_F32 *temp = out;
196     out = in;
197     in = temp;
198   }
199
200   // If n is not power of 4, sub_num == 2.
201   if (forward_fft) {
202     if (sub_num == 2)
203       x86SP_FFT_CToC_FC32_Fwd_Radix2_ls_sse(in, out, twiddle, n);
204     else
205       x86SP_FFT_CToC_FC32_Fwd_Radix4_ls_sse(in, out, twiddle, n);
206   } else {
207     if (sub_num == 2)
208       x86SP_FFT_CToC_FC32_Inv_Radix2_ls_sse(in, out, twiddle, n);
209     else
210       x86SP_FFT_CToC_FC32_Inv_Radix4_ls_sse(in, out, twiddle, n);
211   }
212
213   return out;
214 }