FFmpeg
Loading...
Searching...
No Matches
tx_float_init.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#define TX_FLOAT
20#include "libavutil/tx_priv.h"
22#include "libavutil/mem.h"
24
25TX_DECL_FN(fft2, neon)
26TX_DECL_FN(fft4_fwd, neon)
27TX_DECL_FN(fft4_inv, neon)
28TX_DECL_FN(fft8, neon)
29TX_DECL_FN(fft8_ns, neon)
30TX_DECL_FN(fft15, neon)
31TX_DECL_FN(fft15_ns, neon)
32TX_DECL_FN(fft16, neon)
33TX_DECL_FN(fft16_ns, neon)
34TX_DECL_FN(fft32, neon)
35TX_DECL_FN(fft32_ns, neon)
36TX_DECL_FN(fft_sr, neon)
37TX_DECL_FN(fft_sr_ns, neon)
38TX_DECL_FN(fft_pfa_15xM, neon)
39TX_DECL_FN(fft_pfa_15xM_ns, neon)
40TX_DECL_FN(mdct_inv, neon)
41
42static av_cold int neon_init(AVTXContext *s, const FFTXCodelet *cd,
43 uint64_t flags, FFTXCodeletOptions *opts,
44 int len, int inv, const void *scale)
45{
47 if (cd->max_len == 2)
49 else
50 return ff_tx_gen_split_radix_parity_revtab(s, len, inv, opts, 8, 0);
51}
52
53/* Reorder one 15-point map so the loads in the pre-permuted assembly path
54 * become simple contiguous chunks. Mirrors the x86 FFT15 init. */
55static void fft15_permute_map(int *map)
56{
57 int cnt = 0, tmp[15];
58 memcpy(tmp, map, 15*sizeof(*tmp));
59 for (int i = 1; i < 15; i += 3)
60 map[cnt++] = tmp[i];
61 for (int i = 2; i < 15; i += 3)
62 map[cnt++] = tmp[i];
63 for (int i = 0; i < 15; i += 3)
64 map[cnt++] = tmp[i];
65 memmove(&map[7], &map[6], 4*sizeof(int));
66 memmove(&map[3], &map[1], 4*sizeof(int));
67 map[1] = tmp[2];
68 map[2] = tmp[0];
69}
70
72 uint64_t flags, FFTXCodeletOptions *opts,
73 int len, int inv, const void *scale)
74{
75 int ret;
76 FFTXCodeletOptions sub_opts = { .map_dir = FF_TX_MAP_GATHER };
77
79
80 if ((ret = ff_tx_gen_pfa_input_map(s, &sub_opts, 3, 5)) < 0)
81 return ret;
82
83 fft15_permute_map(s->map);
84
85 return 0;
86}
87
88/* 15xM prime-factor FFT: M inlined 15-point transforms followed by 15 calls to
89 * a power-of-two subtransform. Mirrors the x86 fft_pfa_15xM, but the aarch64
90 * ABI lets us call the subtransform normally, so no FF_TX_ASM_CALL is needed. */
92 uint64_t flags, FFTXCodeletOptions *opts,
93 int len, int inv, const void *scale)
94{
95 int ret;
96 int sub_len = len / cd->factors[0];
97 FFTXCodeletOptions sub_opts = { .map_dir = FF_TX_MAP_SCATTER };
98
99 flags &= ~FF_TX_OUT_OF_PLACE; /* We want the subtransform to be */
100 flags |= AV_TX_INPLACE; /* in-place */
101 flags |= FF_TX_PRESHUFFLE; /* This function handles the permute step */
102
103 if ((ret = ff_tx_init_subtx(s, TX_TYPE(FFT), flags, &sub_opts,
104 sub_len, inv, scale)))
105 return ret;
106
107 if ((ret = ff_tx_gen_compound_mapping(s, opts, s->inv,
108 cd->factors[0], sub_len)))
109 return ret;
110
111 /* The 15-point transform is itself a compound one, so embed its input map
112 * and apply the same load-friendly reorder used by fft15_init. */
113 TX_EMBED_INPUT_PFA_MAP(s->map, len, 3, 5);
114 for (int k = 0; k < sub_len; k++)
115 fft15_permute_map(&s->map[k*15]);
116
117 if (!(s->tmp = av_malloc(len*sizeof(*s->tmp))))
118 return AVERROR(ENOMEM);
119
120 ff_tx_init_tabs_float(len / sub_len);
121
122 return 0;
123}
124
125/* Inverse MDCT: a pre-rotation, an in-place len/2 complex FFT, and a
126 * post-rotation. Mirrors the generic ff_tx_mdct_init / x86 m_inv_init, but the
127 * subtransform is called with a normal blr (no FF_TX_ASM_CALL on aarch64). */
129 uint64_t flags, FFTXCodeletOptions *opts,
130 int len, int inv, const void *scale)
131{
132 int ret;
133 FFTXCodeletOptions sub_opts = { .map_dir = FF_TX_MAP_GATHER };
134
135 /* The pre-rotation processes two output complex at a time, so len/2 must
136 * be even. Real codecs always satisfy this; bail out otherwise so the
137 * generic C MDCT is used. */
138 if (len & 3)
139 return AVERROR(ENOSYS);
140
141 s->scale_d = *((const float *)scale);
142 s->scale_f = s->scale_d;
143
144 flags &= ~FF_TX_OUT_OF_PLACE; /* The subtransform is in-place */
146 flags |= FF_TX_PRESHUFFLE; /* This function handles the permute step */
147
148 if ((ret = ff_tx_init_subtx(s, TX_TYPE(FFT), flags, &sub_opts, len >> 1,
149 inv, scale)))
150 return ret;
151
152 /* The map holds the gather map (first half, used by the strided
153 * pre-rotation) followed by its inverse (second half): the contiguous
154 * stride==4 path reads the input in order and scatters output complex i
155 * to position s->map[len2 + j], where j is the contiguous input index. */
156 s->map = av_malloc(len*sizeof(*s->map));
157 if (!s->map)
158 return AVERROR(ENOMEM);
159
160 memcpy(s->map, s->sub->map, (len >> 1)*sizeof(*s->map));
161
162 if ((ret = ff_tx_mdct_gen_exp_float(s, s->map)))
163 return ret;
164
165 /* Invert the gather map for the contiguous path (before doubling). */
166 for (int i = 0; i < (len >> 1); i++)
167 s->map[(len >> 1) + s->map[i]] = i;
168
169 /* Pre-double the gather-map indices (saves a shift in the strided path). */
170 for (int i = 0; i < (len >> 1); i++)
171 s->map[i] <<= 1;
172
173 return 0;
174}
175
177 TX_DEF(fft2, FFT, 2, 2, 2, 0, 128, NULL, neon, NEON, AV_TX_INPLACE, 0),
178 TX_DEF(fft2, FFT, 2, 2, 2, 0, 192, neon_init, neon, NEON, AV_TX_INPLACE | FF_TX_PRESHUFFLE, 0),
179 TX_DEF(fft4_fwd, FFT, 4, 4, 2, 0, 128, NULL, neon, NEON, AV_TX_INPLACE | FF_TX_FORWARD_ONLY, 0),
180 TX_DEF(fft4_fwd, FFT, 4, 4, 2, 0, 192, neon_init, neon, NEON, AV_TX_INPLACE | FF_TX_PRESHUFFLE, 0),
181 TX_DEF(fft4_inv, FFT, 4, 4, 2, 0, 128, NULL, neon, NEON, AV_TX_INPLACE | FF_TX_INVERSE_ONLY, 0),
182 TX_DEF(fft8, FFT, 8, 8, 2, 0, 128, neon_init, neon, NEON, AV_TX_INPLACE, 0),
183 TX_DEF(fft8_ns, FFT, 8, 8, 2, 0, 192, neon_init, neon, NEON, AV_TX_INPLACE | FF_TX_PRESHUFFLE, 0),
184 TX_DEF(fft15, FFT, 15, 15, 15, 0, 128, fft15_init, neon, NEON, AV_TX_INPLACE, 0),
185 TX_DEF(fft15_ns, FFT, 15, 15, 15, 0, 192, fft15_init, neon, NEON, AV_TX_INPLACE | FF_TX_PRESHUFFLE, 0),
186 TX_DEF(fft16, FFT, 16, 16, 2, 0, 128, neon_init, neon, NEON, AV_TX_INPLACE, 0),
187 TX_DEF(fft16_ns, FFT, 16, 16, 2, 0, 192, neon_init, neon, NEON, AV_TX_INPLACE | FF_TX_PRESHUFFLE, 0),
188 TX_DEF(fft32, FFT, 32, 32, 2, 0, 128, neon_init, neon, NEON, AV_TX_INPLACE, 0),
189 TX_DEF(fft32_ns, FFT, 32, 32, 2, 0, 192, neon_init, neon, NEON, AV_TX_INPLACE | FF_TX_PRESHUFFLE, 0),
190
191 TX_DEF(fft_sr, FFT, 64, 131072, 2, 0, 128, neon_init, neon, NEON, 0, 0),
192 TX_DEF(fft_sr_ns, FFT, 64, 131072, 2, 0, 192, neon_init, neon, NEON, AV_TX_INPLACE | FF_TX_PRESHUFFLE, 0),
193
194 TX_DEF(fft_pfa_15xM, FFT, 60, TX_LEN_UNLIMITED, 15, 2, 128, fft_pfa_init, neon, NEON, AV_TX_INPLACE, 0),
195 TX_DEF(fft_pfa_15xM_ns, FFT, 60, TX_LEN_UNLIMITED, 15, 2, 192, fft_pfa_init, neon, NEON, AV_TX_INPLACE | FF_TX_PRESHUFFLE, 0),
196
197 TX_DEF(mdct_inv, MDCT, 16, TX_LEN_UNLIMITED, 2, TX_FACTOR_ANY, 256, mdct_inv_init, neon, NEON, FF_TX_INVERSE_ONLY, 0),
198
199 NULL,
200};
static av_cold int neon_init(AVTXContext *s, const FFTXCodelet *cd, uint64_t flags, FFTXCodeletOptions *opts, int len, int inv, const void *scale)
static av_cold int mdct_inv_init(AVTXContext *s, const FFTXCodelet *cd, uint64_t flags, FFTXCodeletOptions *opts, int len, int inv, const void *scale)
static void fft15_permute_map(int *map)
static av_cold int fft_pfa_init(AVTXContext *s, const FFTXCodelet *cd, uint64_t flags, FFTXCodeletOptions *opts, int len, int inv, const void *scale)
static av_cold int fft15_init(AVTXContext *s, const FFTXCodelet *cd, uint64_t flags, FFTXCodeletOptions *opts, int len, int inv, const void *scale)
const FFTXCodelet *const ff_tx_codelet_list_float_aarch64[]
#define TX_TYPE
static AVDictionary * opts
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
#define AVERROR(e)
Definition error.h:45
const VDPAUPixFmtMap * map
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition intra.c:278
Macro definitions for various function/variable attributes.
#define av_cold
Definition attributes.h:117
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
int factors[TX_MAX_FACTORS]
Definition tx_priv.h:208
static uint8_t tmp[40]
Definition aes_ctr.c:52
int ff_tx_gen_ptwo_revtab(AVTXContext *s, FFTXCodeletOptions *opts)
Definition tx.c:136
av_cold int ff_tx_init_subtx(AVTXContext *s, enum AVTXType type, uint64_t flags, FFTXCodeletOptions *opts, int len, int inv, const void *scale)
Definition tx.c:712
int ff_tx_gen_compound_mapping(AVTXContext *s, FFTXCodeletOptions *opts, int inv, int n, int m)
Definition tx.c:75
int ff_tx_gen_pfa_input_map(AVTXContext *s, FFTXCodeletOptions *opts, int d1, int d2)
Definition tx.c:44
int ff_tx_gen_split_radix_parity_revtab(AVTXContext *s, int len, int inv, FFTXCodeletOptions *opts, int basis, int dual_stride)
Definition tx.c:241
@ AV_TX_INPLACE
Allows for in-place transformations, where input == output.
Definition tx.h:161
#define TX_LEN_UNLIMITED
Definition tx_priv.h:216
#define FF_TX_OUT_OF_PLACE
Definition tx_priv.h:154
void ff_tx_init_tabs_float(int len)
#define FF_TX_INVERSE_ONLY
Definition tx_priv.h:157
#define FF_TX_FORWARD_ONLY
Definition tx_priv.h:158
#define TX_DECL_FN(fn, suffix)
Definition tx_priv.h:68
@ FF_TX_MAP_GATHER
Definition tx_priv.h:176
@ FF_TX_MAP_SCATTER
Definition tx_priv.h:179
#define TX_FACTOR_ANY
Definition tx_priv.h:209
#define TX_DEF(fn, tx_type, len_min, len_max, f1, f2, p, init_fn, suffix, cf, cd_flags, cf2)
Definition tx_priv.h:71
int ff_tx_mdct_gen_exp_float(AVTXContext *s, int *pre_tab)
#define FF_TX_PRESHUFFLE
Definition tx_priv.h:156
#define TX_EMBED_INPUT_PFA_MAP(map, tot_len, d1, d2)
Definition tx_priv.h:271
static av_always_inline void fft15(TXComplex *out, TXComplex *in, ptrdiff_t stride)
int len