Change/simplify the tableprint/tablegen API.
Originally committed as revision 22761 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
27eecec359
commit
8eaa6e0e04
@ -7,32 +7,39 @@ Basic concepts
|
|||||||
|
|
||||||
A table generator consists of two files, *_tablegen.c and *_tablegen.h.
|
A table generator consists of two files, *_tablegen.c and *_tablegen.h.
|
||||||
The .h file will provide the variable declarations and initialization
|
The .h file will provide the variable declarations and initialization
|
||||||
code for the tables, the .c describes the tables so they can be printed
|
code for the tables, the .c calls the initialization code and then prints
|
||||||
as a header file.
|
the tables as a header file using the tableprint.h helpers.
|
||||||
Both of these files will be compiled for the host system, so to avoid
|
Both of these files will be compiled for the host system, so to avoid
|
||||||
breakage with cross-compilation neither of them may include, directly
|
breakage with cross-compilation neither of them may include, directly
|
||||||
or indirectly, config.h or avconfig.h.
|
or indirectly, config.h or avconfig.h.
|
||||||
Due to this, the .c file or Makefile may have to provide additional defines
|
Due to this, the .c file or Makefile may have to provide additional defines
|
||||||
or stubs, though if possible this should be avoided.
|
or stubs, though if possible this should be avoided.
|
||||||
|
In particular, CONFIG_HARDCODED_TABLES should always be defined to 0.
|
||||||
|
|
||||||
The .c file
|
The .c file
|
||||||
|
|
||||||
This file should include the *_tablegen.h and tableprint.h files and
|
This file should include the *_tablegen.h and tableprint.h files and
|
||||||
anything else it needs as long as it does not depend on config.h or
|
anything else it needs as long as it does not depend on config.h or
|
||||||
avconfig.h.
|
avconfig.h.
|
||||||
In addition to that it must contain a void tableinit(void) function
|
In addition to that it must contain a main() function which initializes
|
||||||
which initializes all tables by calling the init functions from the .h
|
all tables by calling the init functions from the .h file and then prints
|
||||||
file.
|
them.
|
||||||
It must also contain a "const struct tabledef tables[]" array describing
|
The printing code typically looks like this:
|
||||||
the tables to be generated.
|
write_fileheader();
|
||||||
Its entries consist of (in order):
|
printf("static const uint8_t my_array[100] = {\n");
|
||||||
- a string suitable for declaring the table, up to but not including the =
|
write_uint8_array(my_array, 100);
|
||||||
NULL terminates the table
|
printf("};\n");
|
||||||
- a function to print the table - tableprint.h defines some defaults,
|
|
||||||
e.g. write_uint8_array to print a uint8_t array.
|
write_fileheader() adds some minor things like a "this is a generated file"
|
||||||
- a pointer to the table
|
comment and some standard includes.
|
||||||
- the size of the first dimension of the array
|
tablegen.h defines some write functions for one- and two-dimensional arrays
|
||||||
- if applicable, the size of the second dimension of the array
|
for standard types - they print only the "core" parts so they are easier
|
||||||
|
to reuse for multi-dimensional arrays so the outermost {} must be printed
|
||||||
|
separately.
|
||||||
|
If there's no standard function for printing the type you need, the
|
||||||
|
WRITE_1D_FUNC_ARGV macro is a very quick way to create one.
|
||||||
|
See libavcodec/dv_tablegen.c for an example.
|
||||||
|
|
||||||
|
|
||||||
The .h file
|
The .h file
|
||||||
|
|
||||||
|
@ -25,18 +25,15 @@
|
|||||||
#include "cbrt_tablegen.h"
|
#include "cbrt_tablegen.h"
|
||||||
#include "tableprint.h"
|
#include "tableprint.h"
|
||||||
|
|
||||||
void tableinit(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
cbrt_tableinit();
|
cbrt_tableinit();
|
||||||
}
|
|
||||||
|
|
||||||
const struct tabledef tables[] = {
|
write_fileheader();
|
||||||
{
|
|
||||||
"static const uint32_t cbrt_tab[1<<13]",
|
printf("static const uint32_t cbrt_tab[1<<13] = {\n");
|
||||||
write_uint32_array,
|
write_uint32_array(cbrt_tab, 1 << 13);
|
||||||
cbrt_tab,
|
printf("};\n");
|
||||||
1 << 13,
|
|
||||||
0
|
return 0;
|
||||||
},
|
}
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
@ -33,18 +33,15 @@ WRITE_1D_FUNC_ARGV(vlc_pair, struct dv_vlc_pair, 7,
|
|||||||
"{0x%"PRIx32", %"PRId8"}", data[i].vlc, data[i].size)
|
"{0x%"PRIx32", %"PRId8"}", data[i].vlc, data[i].size)
|
||||||
WRITE_2D_FUNC(vlc_pair, struct dv_vlc_pair)
|
WRITE_2D_FUNC(vlc_pair, struct dv_vlc_pair)
|
||||||
|
|
||||||
void tableinit(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
dv_vlc_map_tableinit();
|
dv_vlc_map_tableinit();
|
||||||
}
|
|
||||||
|
|
||||||
const struct tabledef tables[] = {
|
write_fileheader();
|
||||||
{
|
|
||||||
"static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]",
|
printf("static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE] = {\n");
|
||||||
write_vlc_pair_2d_array,
|
write_vlc_pair_2d_array(dv_vlc_map, DV_VLC_MAP_RUN_SIZE, DV_VLC_MAP_LEV_SIZE);
|
||||||
dv_vlc_map,
|
printf("};\n");
|
||||||
DV_VLC_MAP_RUN_SIZE,
|
|
||||||
DV_VLC_MAP_LEV_SIZE
|
return 0;
|
||||||
},
|
}
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
@ -32,29 +32,18 @@
|
|||||||
#include "mdct_tablegen.h"
|
#include "mdct_tablegen.h"
|
||||||
#include "tableprint.h"
|
#include "tableprint.h"
|
||||||
|
|
||||||
void tableinit(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 5; i <= 12; i++)
|
|
||||||
|
write_fileheader();
|
||||||
|
|
||||||
|
for (i = 5; i <= 12; i++) {
|
||||||
ff_init_ff_sine_windows(i);
|
ff_init_ff_sine_windows(i);
|
||||||
|
printf("SINETABLE(%4i) = {\n", 1 << i);
|
||||||
|
write_float_array(ff_sine_windows[i], 1 << i);
|
||||||
|
printf("};\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SINE_TABLE_DEF(size) \
|
|
||||||
{ \
|
|
||||||
"SINETABLE("#size")", \
|
|
||||||
write_float_array, \
|
|
||||||
ff_sine_##size, \
|
|
||||||
size \
|
|
||||||
},
|
|
||||||
|
|
||||||
const struct tabledef tables[] = {
|
|
||||||
SINE_TABLE_DEF( 32)
|
|
||||||
SINE_TABLE_DEF( 64)
|
|
||||||
SINE_TABLE_DEF( 128)
|
|
||||||
SINE_TABLE_DEF( 256)
|
|
||||||
SINE_TABLE_DEF( 512)
|
|
||||||
SINE_TABLE_DEF(1024)
|
|
||||||
SINE_TABLE_DEF(2048)
|
|
||||||
SINE_TABLE_DEF(4096)
|
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
@ -27,18 +27,15 @@
|
|||||||
#include "motionpixels_tablegen.h"
|
#include "motionpixels_tablegen.h"
|
||||||
#include "tableprint.h"
|
#include "tableprint.h"
|
||||||
|
|
||||||
void tableinit(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
motionpixels_tableinit();
|
motionpixels_tableinit();
|
||||||
}
|
|
||||||
|
|
||||||
const struct tabledef tables[] = {
|
write_fileheader();
|
||||||
{
|
|
||||||
"static const YuvPixel mp_rgb_yuv_table[1 << 15]",
|
printf("static const YuvPixel mp_rgb_yuv_table[1 << 15] = {\n");
|
||||||
write_int8_2d_array,
|
write_int8_2d_array(mp_rgb_yuv_table, 1 << 15, 3);
|
||||||
mp_rgb_yuv_table,
|
printf("};\n");
|
||||||
1 << 15,
|
|
||||||
3
|
return 0;
|
||||||
},
|
}
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
@ -25,36 +25,27 @@
|
|||||||
#include "mpegaudio_tablegen.h"
|
#include "mpegaudio_tablegen.h"
|
||||||
#include "tableprint.h"
|
#include "tableprint.h"
|
||||||
|
|
||||||
void tableinit(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
mpegaudio_tableinit();
|
mpegaudio_tableinit();
|
||||||
}
|
|
||||||
|
|
||||||
const struct tabledef tables[] = {
|
write_fileheader();
|
||||||
{
|
|
||||||
"static const int8_t table_4_3_exp[TABLE_4_3_SIZE]",
|
printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n");
|
||||||
write_int8_array,
|
write_int8_array(table_4_3_exp, TABLE_4_3_SIZE);
|
||||||
table_4_3_exp,
|
printf("};\n");
|
||||||
TABLE_4_3_SIZE
|
|
||||||
},
|
printf("static const uint32_t table_4_3_value[TABLE_4_3_SIZE] = {\n");
|
||||||
{
|
write_uint32_array(table_4_3_value, TABLE_4_3_SIZE);
|
||||||
"static const uint32_t table_4_3_value[TABLE_4_3_SIZE]",
|
printf("};\n");
|
||||||
write_uint32_array,
|
|
||||||
table_4_3_value,
|
printf("static const uint32_t exp_table[512] = {\n");
|
||||||
TABLE_4_3_SIZE
|
write_uint32_array(exp_table, 512);
|
||||||
},
|
printf("};\n");
|
||||||
{
|
|
||||||
"static const uint32_t exp_table[512]",
|
printf("static const uint32_t expval_table[512][16] = {\n");
|
||||||
write_uint32_array,
|
write_uint32_2d_array(expval_table, 512, 16);
|
||||||
exp_table,
|
printf("};\n");
|
||||||
512
|
|
||||||
},
|
return 0;
|
||||||
{
|
}
|
||||||
"static const uint32_t expval_table[512][16]",
|
|
||||||
write_uint32_2d_array,
|
|
||||||
expval_table,
|
|
||||||
512,
|
|
||||||
16
|
|
||||||
},
|
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
@ -25,48 +25,33 @@
|
|||||||
#include "qdm2_tablegen.h"
|
#include "qdm2_tablegen.h"
|
||||||
#include "tableprint.h"
|
#include "tableprint.h"
|
||||||
|
|
||||||
void tableinit(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
softclip_table_init();
|
softclip_table_init();
|
||||||
rnd_table_init();
|
rnd_table_init();
|
||||||
init_noise_samples();
|
init_noise_samples();
|
||||||
}
|
|
||||||
|
|
||||||
const struct tabledef tables[] = {
|
write_fileheader();
|
||||||
{
|
|
||||||
"static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]",
|
printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n");
|
||||||
write_uint16_array,
|
write_uint16_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1);
|
||||||
softclip_table,
|
printf("};\n");
|
||||||
HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1,
|
|
||||||
0
|
printf("static const float noise_table[4096] = {\n");
|
||||||
},
|
write_float_array(noise_table, 4096);
|
||||||
{
|
printf("};\n");
|
||||||
"static const float noise_table[4096]",
|
|
||||||
write_float_array,
|
printf("static const uint8_t random_dequant_index[256][5] = {\n");
|
||||||
noise_table,
|
write_uint8_2d_array(random_dequant_index, 256, 5);
|
||||||
4096,
|
printf("};\n");
|
||||||
0
|
|
||||||
},
|
printf("static const uint8_t random_dequant_type24[128][3] = {\n");
|
||||||
{
|
write_uint8_2d_array(random_dequant_type24, 128, 3);
|
||||||
"static const uint8_t random_dequant_index[256][5]",
|
printf("};\n");
|
||||||
write_uint8_2d_array,
|
|
||||||
random_dequant_index,
|
printf("static const float noise_samples[128] = {\n");
|
||||||
256,
|
write_float_array(noise_samples, 128);
|
||||||
5
|
printf("};\n");
|
||||||
},
|
|
||||||
{
|
return 0;
|
||||||
"static const uint8_t random_dequant_type24[128][3]",
|
}
|
||||||
write_uint8_2d_array,
|
|
||||||
random_dequant_type24,
|
|
||||||
128,
|
|
||||||
3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"static const float noise_samples[128]",
|
|
||||||
write_float_array,
|
|
||||||
noise_samples,
|
|
||||||
128,
|
|
||||||
0
|
|
||||||
},
|
|
||||||
{ NULL }
|
|
||||||
};
|
|
||||||
|
@ -34,18 +34,7 @@ WRITE_2D_FUNC(int8, int8_t)
|
|||||||
WRITE_2D_FUNC(uint8, uint8_t)
|
WRITE_2D_FUNC(uint8, uint8_t)
|
||||||
WRITE_2D_FUNC(uint32, uint32_t)
|
WRITE_2D_FUNC(uint32, uint32_t)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
void write_fileheader(void) {
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("/* This file was generated by libavcodec/tableprint */\n");
|
printf("/* This file was generated by libavcodec/tableprint */\n");
|
||||||
printf("#include <stdint.h>\n");
|
printf("#include <stdint.h>\n");
|
||||||
tableinit();
|
|
||||||
|
|
||||||
for (i = 0; tables[i].declaration; i++) {
|
|
||||||
printf("%s = {\n", tables[i].declaration);
|
|
||||||
tables[i].printfunc(tables[i].data, tables[i].size, tables[i].size2);
|
|
||||||
printf("};\n");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define WRITE_1D_FUNC_ARGV(name, type, linebrk, fmtstr, ...)\
|
#define WRITE_1D_FUNC_ARGV(name, type, linebrk, fmtstr, ...)\
|
||||||
void write_##name##_array(const void *arg, int len, int dummy)\
|
void write_##name##_array(const type *data, int len)\
|
||||||
{\
|
{\
|
||||||
const type *data = arg;\
|
|
||||||
int i;\
|
int i;\
|
||||||
printf(" ");\
|
printf(" ");\
|
||||||
for (i = 0; i < len - 1; i++) {\
|
for (i = 0; i < len - 1; i++) {\
|
||||||
@ -49,7 +48,7 @@ void write_##name##_2d_array(const void *arg, int len, int len2)\
|
|||||||
int i;\
|
int i;\
|
||||||
printf(" {\n");\
|
printf(" {\n");\
|
||||||
for (i = 0; i < len; i++) {\
|
for (i = 0; i < len; i++) {\
|
||||||
write_##name##_array(data + i * len2, len2, 0);\
|
write_##name##_array(data + i * len2, len2);\
|
||||||
printf(i == len - 1 ? " }\n" : " }, {\n");\
|
printf(i == len - 1 ? " }\n" : " }, {\n");\
|
||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
@ -59,34 +58,17 @@ void write_##name##_2d_array(const void *arg, int len, int len2)\
|
|||||||
*
|
*
|
||||||
* \{
|
* \{
|
||||||
*/
|
*/
|
||||||
void write_int8_array (const void *, int, int);
|
void write_int8_array (const int8_t *, int);
|
||||||
void write_uint8_array (const void *, int, int);
|
void write_uint8_array (const uint8_t *, int);
|
||||||
void write_uint16_array (const void *, int, int);
|
void write_uint16_array (const uint16_t *, int);
|
||||||
void write_uint32_array (const void *, int, int);
|
void write_uint32_array (const uint32_t *, int);
|
||||||
void write_float_array (const void *, int, int);
|
void write_float_array (const float *, int);
|
||||||
void write_int8_2d_array (const void *, int, int);
|
void write_int8_2d_array (const void *, int, int);
|
||||||
void write_uint8_2d_array (const void *, int, int);
|
void write_uint8_2d_array (const void *, int, int);
|
||||||
void write_uint32_2d_array(const void *, int, int);
|
void write_uint32_2d_array(const void *, int, int);
|
||||||
/** \} */ // end of printfuncs group
|
/** \} */ // end of printfuncs group
|
||||||
|
|
||||||
struct tabledef {
|
/** Write a standard file header */
|
||||||
/** String that declares the array. Adding " = { ..." after it should
|
void write_fileheader(void);
|
||||||
* make a valid initializer, adding "extern" before and ";" if possible
|
|
||||||
* should make a valid extern declaration. */
|
|
||||||
const char *declaration;
|
|
||||||
/** Function used to print the table data (i.e. the part in {}).
|
|
||||||
* Should be one of the predefined write_*_array functions. */
|
|
||||||
void (*printfunc)(const void *, int, int);
|
|
||||||
/** Pointer passed to the printfunc, usually a pointer to the start
|
|
||||||
* of the array to be printed. */
|
|
||||||
const void *data;
|
|
||||||
int size; ///< size of the first dimension of the array
|
|
||||||
int size2; ///< size of the second dimension of the array if any
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Initializes all the tables described in the tables array */
|
|
||||||
void tableinit(void);
|
|
||||||
/** Describes the tables that should be printed */
|
|
||||||
extern const struct tabledef tables[];
|
|
||||||
|
|
||||||
#endif /* AVCODEC_TABLEPRINT_H */
|
#endif /* AVCODEC_TABLEPRINT_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user