FFmpeg
tx_priv.h
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 #ifndef AVUTIL_TX_PRIV_H
20 #define AVUTIL_TX_PRIV_H
21 
22 #include "tx.h"
23 #include "thread.h"
24 #include "mem_internal.h"
25 #include "avassert.h"
26 #include "attributes.h"
27 
28 #ifdef TX_FLOAT
29 #define TX_NAME(x) x ## _float
30 #define SCALE_TYPE float
31 typedef float FFTSample;
33 #elif defined(TX_DOUBLE)
34 #define TX_NAME(x) x ## _double
35 #define SCALE_TYPE double
36 typedef double FFTSample;
38 #elif defined(TX_INT32)
39 #define TX_NAME(x) x ## _int32
40 #define SCALE_TYPE float
41 typedef int32_t FFTSample;
43 #else
44 typedef void FFTComplex;
45 #endif
46 
47 #if defined(TX_FLOAT) || defined(TX_DOUBLE)
48 
49 #define CMUL(dre, dim, are, aim, bre, bim) \
50  do { \
51  (dre) = (are) * (bre) - (aim) * (bim); \
52  (dim) = (are) * (bim) + (aim) * (bre); \
53  } while (0)
54 
55 #define SMUL(dre, dim, are, aim, bre, bim) \
56  do { \
57  (dre) = (are) * (bre) - (aim) * (bim); \
58  (dim) = (are) * (bim) - (aim) * (bre); \
59  } while (0)
60 
61 #define UNSCALE(x) (x)
62 #define RESCALE(x) (x)
63 
64 #define FOLD(a, b) ((a) + (b))
65 
66 #elif defined(TX_INT32)
67 
68 /* Properly rounds the result */
69 #define CMUL(dre, dim, are, aim, bre, bim) \
70  do { \
71  int64_t accu; \
72  (accu) = (int64_t)(bre) * (are); \
73  (accu) -= (int64_t)(bim) * (aim); \
74  (dre) = (int)(((accu) + 0x40000000) >> 31); \
75  (accu) = (int64_t)(bim) * (are); \
76  (accu) += (int64_t)(bre) * (aim); \
77  (dim) = (int)(((accu) + 0x40000000) >> 31); \
78  } while (0)
79 
80 #define SMUL(dre, dim, are, aim, bre, bim) \
81  do { \
82  int64_t accu; \
83  (accu) = (int64_t)(bre) * (are); \
84  (accu) -= (int64_t)(bim) * (aim); \
85  (dre) = (int)(((accu) + 0x40000000) >> 31); \
86  (accu) = (int64_t)(bim) * (are); \
87  (accu) -= (int64_t)(bre) * (aim); \
88  (dim) = (int)(((accu) + 0x40000000) >> 31); \
89  } while (0)
90 
91 #define UNSCALE(x) ((double)x/2147483648.0)
92 #define RESCALE(x) (av_clip64(lrintf((x) * 2147483648.0), INT32_MIN, INT32_MAX))
93 
94 #define FOLD(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
95 
96 #endif
97 
98 #define BF(x, y, a, b) \
99  do { \
100  x = (a) - (b); \
101  y = (a) + (b); \
102  } while (0)
103 
104 #define CMUL3(c, a, b) \
105  CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
106 
107 #define COSTABLE(size) \
108  DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/4 + 1]
109 
110 /* Used by asm, reorder with care */
111 struct AVTXContext {
112  int n; /* Non-power-of-two part */
113  int m; /* Power-of-two part */
114  int inv; /* Is inverse */
115  int type; /* Type */
116  uint64_t flags; /* Flags */
117  double scale; /* Scale */
118 
119  FFTComplex *exptab; /* MDCT exptab */
120  FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */
121  int *pfatab; /* Input/Output mapping for compound transforms */
122  int *revtab; /* Input mapping for power of two transforms */
123  int *inplace_idx; /* Required indices to revtab for in-place transforms */
124 
125  int *revtab_c; /* Revtab for only the C transforms, needed because
126  * checkasm makes us reuse the same context. */
127 
128  av_tx_fn top_tx; /* Used for computing transforms derived from other
129  * transforms, like full-length iMDCTs and RDFTs.
130  * NOTE: Do NOT use this to mix assembly with C code. */
131 };
132 
133 /* Checks if type is an MDCT */
135 
136 /*
137  * Generates the PFA permutation table into AVTXContext->pfatab. The end table
138  * is appended to the start table.
139  */
141 
142 /*
143  * Generates a standard-ish (slightly modified) Split-Radix revtab into
144  * AVTXContext->revtab
145  */
146 int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup);
147 
148 /*
149  * Generates an index into AVTXContext->inplace_idx that if followed in the
150  * specific order, allows the revtab to be done in-place. AVTXContext->revtab
151  * must already exist.
152  */
154 
155 /*
156  * This generates a parity-based revtab of length len and direction inv.
157  *
158  * Parity means even and odd complex numbers will be split, e.g. the even
159  * coefficients will come first, after which the odd coefficients will be
160  * placed. For example, a 4-point transform's coefficients after reordering:
161  * z[0].re, z[0].im, z[2].re, z[2].im, z[1].re, z[1].im, z[3].re, z[3].im
162  *
163  * The basis argument is the length of the largest non-composite transform
164  * supported, and also implies that the basis/2 transform is supported as well,
165  * as the split-radix algorithm requires it to be.
166  *
167  * The dual_stride argument indicates that both the basis, as well as the
168  * basis/2 transforms support doing two transforms at once, and the coefficients
169  * will be interleaved between each pair in a split-radix like so (stride == 2):
170  * tx1[0], tx1[2], tx2[0], tx2[2], tx1[1], tx1[3], tx2[1], tx2[3]
171  * A non-zero number switches this on, with the value indicating the stride
172  * (how many values of 1 transform to put first before switching to the other).
173  * Must be a power of two or 0. Must be less than the basis.
174  * Value will be clipped to the transform size, so for a basis of 16 and a
175  * dual_stride of 8, dual 8-point transforms will be laid out as if dual_stride
176  * was set to 4.
177  * Usually you'll set this to half the complex numbers that fit in a single
178  * register or 0. This allows to reuse SSE functions as dual-transform
179  * functions in AVX mode.
180  *
181  * If length is smaller than basis/2 this function will not do anything.
182  */
183 void ff_tx_gen_split_radix_parity_revtab(int *revtab, int len, int inv,
184  int basis, int dual_stride);
185 
186 /* Templated init functions */
188  enum AVTXType type, int inv, int len,
189  const void *scale, uint64_t flags);
191  enum AVTXType type, int inv, int len,
192  const void *scale, uint64_t flags);
194  enum AVTXType type, int inv, int len,
195  const void *scale, uint64_t flags);
196 
197 typedef struct CosTabsInitOnce {
198  void (*func)(void);
199  AVOnce control;
201 
203 
204 #endif /* AVUTIL_TX_PRIV_H */
AVTXContext::top_tx
av_tx_fn top_tx
Definition: tx_priv.h:128
mem_internal.h
thread.h
AVTXContext::pfatab
int * pfatab
Definition: tx_priv.h:121
AVTXContext
Definition: tx_priv.h:111
basis
static int16_t basis[64][64]
Definition: mpegvideo_enc.c:4121
AVComplexFloat
Definition: tx.h:27
AVTXContext::exptab
FFTComplex * exptab
Definition: tx_priv.h:119
CosTabsInitOnce::func
void(* func)(void)
Definition: fft_template.c:70
ff_tx_type_is_mdct
int ff_tx_type_is_mdct(enum AVTXType type)
Definition: tx.c:21
AVTXContext::revtab
int * revtab
Definition: tx_priv.h:122
AVTXContext::revtab_c
int * revtab_c
Definition: tx_priv.h:125
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
CosTabsInitOnce::control
AVOnce control
Definition: fft_template.c:71
ff_tx_init_float_x86
void ff_tx_init_float_x86(AVTXContext *s, av_tx_fn *tx)
Definition: tx_float_init.c:37
avassert.h
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:102
AVComplexInt32
Definition: tx.h:35
ff_tx_init_mdct_fft_double
int ff_tx_init_mdct_fft_double(AVTXContext *s, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVTXContext::scale
double scale
Definition: tx_priv.h:117
ff_tx_init_mdct_fft_float
int ff_tx_init_mdct_fft_float(AVTXContext *s, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
FFTSample
float FFTSample
Definition: avfft.h:35
AVOnce
#define AVOnce
Definition: thread.h:172
FFTComplex
void FFTComplex
Definition: tx_priv.h:44
AVTXType
AVTXType
Definition: tx.h:39
CosTabsInitOnce
Definition: fft_template.c:69
ff_tx_init_mdct_fft_int32
int ff_tx_init_mdct_fft_int32(AVTXContext *s, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
attributes.h
AVTXContext::inv
int inv
Definition: tx_priv.h:114
AVTXContext::inplace_idx
int * inplace_idx
Definition: tx_priv.h:123
ff_tx_gen_ptwo_inplace_revtab_idx
int ff_tx_gen_ptwo_inplace_revtab_idx(AVTXContext *s, int *revtab)
Definition: tx.c:126
ff_tx_gen_split_radix_parity_revtab
void ff_tx_gen_split_radix_parity_revtab(int *revtab, int len, int inv, int basis, int dual_stride)
Definition: tx.c:201
ff_tx_gen_ptwo_revtab
int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup)
Definition: tx.c:105
len
int len
Definition: vorbis_enc_data.h:452
ff_tx_gen_compound_mapping
int ff_tx_gen_compound_mapping(AVTXContext *s)
Definition: tx.c:44
AVComplexDouble
Definition: tx.h:31
AVTXContext::flags
uint64_t flags
Definition: tx_priv.h:116
int32_t
int32_t
Definition: audioconvert.c:56
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVTXContext::m
int m
Definition: tx_priv.h:113
AVTXContext::n
int n
Definition: tx_priv.h:112
AVTXContext::tmp
FFTComplex * tmp
Definition: tx_priv.h:120
FFTComplex
Definition: avfft.h:37
tx.h
AVTXContext::type
int type
Definition: tx_priv.h:115