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