# HG changeset patch # User reimar # Date 1256755372 0 # Node ID 23ca6d60184dc3b21a06157f62fdbac091cecbfc # Parent fedf07e14bee1c9d8ac1f547e876fe7fb2bed23a Add support for hardcoding the mpegaudiodec tables. Reduces .bss size by about 194 kB. diff -r fedf07e14bee -r 23ca6d60184d Makefile --- a/Makefile Wed Oct 28 14:40:05 2009 +0000 +++ b/Makefile Wed Oct 28 18:42:52 2009 +0000 @@ -687,7 +687,7 @@ DIRS = alpha arm bfin mlib ppc ps2 sh4 sparc x86 -CLEANFILES = sin_tables.c cos_tables.c costablegen$(HOSTEXESUF) +CLEANFILES = sin_tables.c cos_tables.c costablegen$(HOSTEXESUF) *_tables.h *_tablegen$(HOSTEXESUF) include $(SUBDIR)../subdir.mak @@ -701,3 +701,15 @@ $(SUBDIR)sin_tables.c: $(SUBDIR)costablegen$(HOSTEXESUF) ./$< sin > $@ + +ifeq ($(CONFIG_MPEGAUDIO_HP),yes) +$(SUBDIR)mpegaudio_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DFRAC_BITS=23 +else +$(SUBDIR)mpegaudio_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DFRAC_BITS=15 +endif +$(SUBDIR)%_tablegen$(HOSTEXESUF): $(SUBDIR)%_tablegen.c $(SUBDIR)tableprint.c + $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^ $(HOSTLIBS) + +$(SUBDIR)mpegaudiodec.c: $(SUBDIR)mpegaudio_tables.h +$(SUBDIR)%_tables.h: $(SUBDIR)%_tablegen$(HOSTEXESUF) + ./$< > $@ diff -r fedf07e14bee -r 23ca6d60184d mpegaudio_tablegen.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mpegaudio_tablegen.c Wed Oct 28 18:42:52 2009 +0000 @@ -0,0 +1,60 @@ +/* + * Generate a header file for hardcoded mpegaudiodec tables + * + * Copyright (c) 2009 Reimar Döffinger + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#define CONFIG_HARDCODED_TABLES 0 +#include "mpegaudio_tablegen.h" +#include "tableprint.h" + +void tableinit(void) +{ + mpegaudio_tableinit(); +} + +const struct tabledef tables[] = { + { + "static const int8_t table_4_3_exp[TABLE_4_3_SIZE]", + write_int8_array, + table_4_3_exp, + TABLE_4_3_SIZE + }, + { + "static const uint32_t table_4_3_value[TABLE_4_3_SIZE]", + write_uint32_array, + table_4_3_value, + TABLE_4_3_SIZE + }, + { + "static const uint32_t exp_table[512]", + write_uint32_array, + exp_table, + 512 + }, + { + "static const uint32_t expval_table[512][16]", + write_uint32_2d_array, + expval_table, + 512, + 16 + }, + { NULL } +}; diff -r fedf07e14bee -r 23ca6d60184d mpegaudio_tablegen.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mpegaudio_tablegen.h Wed Oct 28 18:42:52 2009 +0000 @@ -0,0 +1,68 @@ +/* + * Header file for hardcoded mpegaudiodec tables + * + * Copyright (c) 2009 Reimar Döffinger + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef MPEGAUDIO_TABLEGEN_H +#define MPEGAUDIO_TABLEGEN_H + +#include +// do not use libavutil/mathematics.h since this is compiled both +// for the host and the target and config.h is only valid for the target +#include + +#define TABLE_4_3_SIZE (8191 + 16)*4 +#if CONFIG_HARDCODED_TABLES +#define mpegaudio_tableinit() +#include "mpegaudio_tables.h" +#else +static int8_t table_4_3_exp[TABLE_4_3_SIZE]; +static uint32_t table_4_3_value[TABLE_4_3_SIZE]; +static uint32_t exp_table[512]; +static uint32_t expval_table[512][16]; + +static void mpegaudio_tableinit(void) +{ + int i; + for(i=1;i>4); + double f= value * cbrtf(value) * pow(2, (exponent-400)*0.25 + FRAC_BITS + 5); + expval_table[exponent][i&15]= llrint(f); + if((i&15)==1) + exp_table[exponent]= llrint(f); + } +} +#endif /* CONFIG_HARDCODED_TABLES && !TABLEGEN */ + +#endif /* MPEGAUDIO_TABLEGEN_H */ diff -r fedf07e14bee -r 23ca6d60184d mpegaudiodec.c --- a/mpegaudiodec.c Wed Oct 28 14:40:05 2009 +0000 +++ b/mpegaudiodec.c Wed Oct 28 18:42:52 2009 +0000 @@ -92,12 +92,7 @@ }; /* computed from band_size_long */ static uint16_t band_index_long[9][23]; -/* XXX: free when all decoders are closed */ -#define TABLE_4_3_SIZE (8191 + 16)*4 -static int8_t table_4_3_exp[TABLE_4_3_SIZE]; -static uint32_t table_4_3_value[TABLE_4_3_SIZE]; -static uint32_t exp_table[512]; -static uint32_t expval_table[512][16]; +#include "mpegaudio_tablegen.h" /* intensity stereo coef table */ static int32_t is_table[2][16]; static int32_t is_table_lsf[2][2][16]; @@ -407,27 +402,7 @@ /* compute n ^ (4/3) and store it in mantissa/exp format */ int_pow_init(); - for(i=1;i>4); - double f= value * cbrtf(value) * pow(2, (exponent-400)*0.25 + FRAC_BITS + 5); - expval_table[exponent][i&15]= llrint(f); - if((i&15)==1) - exp_table[exponent]= llrint(f); - } + mpegaudio_tableinit(); for(i=0;i<7;i++) { float f; diff -r fedf07e14bee -r 23ca6d60184d tableprint.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tableprint.c Wed Oct 28 18:42:52 2009 +0000 @@ -0,0 +1,72 @@ +/* + * Generate a file for hardcoded tables + * + * Copyright (c) 2009 Reimar Döffinger + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include "tableprint.h" + +#define WRITE_1D_FUNC(name, type, fmtstr, linebrk)\ +void write_##name##_array(const void *arg, int len, int dummy)\ +{\ + const type *data = arg;\ + int i;\ + printf(" ");\ + for (i = 0; i < len - 1; i++) {\ + printf(" "fmtstr",", data[i]);\ + if ((i & linebrk) == linebrk) printf("\n ");\ + }\ + printf(" "fmtstr"\n", data[i]);\ +} + +WRITE_1D_FUNC(int8, int8_t, "%3"PRIi8, 15) +WRITE_1D_FUNC(uint32, uint32_t, "0x%08x", 7) + +#define WRITE_2D_FUNC(name, type)\ +void write_##name##_2d_array(const void *arg, int len, int len2)\ +{\ + const type *data = arg;\ + int i;\ + printf(" {");\ + for (i = 0; i < len; i++) {\ + write_##name##_array(data + i * len2, len2, 0);\ + printf(i == len - 1 ? " }\n" : " }, {\n");\ + }\ +} + +WRITE_2D_FUNC(uint32, uint32_t) + +int main(int argc, char *argv[]) +{ + int i; + + printf("/* This file was generated by libavcodec/tableprint */\n"); + printf("#include \n"); + tableinit(); + + for (i = 0; tables[i].declaration; i++) { + printf(tables[i].declaration); + printf(" = {\n"); + tables[i].printfunc(tables[i].data, tables[i].size, tables[i].size2); + printf("};\n"); + } + return 0; +} diff -r fedf07e14bee -r 23ca6d60184d tableprint.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tableprint.h Wed Oct 28 18:42:52 2009 +0000 @@ -0,0 +1,58 @@ +/* + * Generate a file for hardcoded tables + * + * Copyright (c) 2009 Reimar Döffinger + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_TABLEPRINT_H +#define AVCODEC_TABLEPRINT_H + +#include + +/** + * \defgroup printfuncs Predefined functions for printing tables + * + * \{ + */ +void write_int8_array (const void *, int, int); +void write_uint32_array (const void *, int, int); +void write_uint32_2d_array(const void *, int, int); +/** \} */ // end of printfuncs group + +struct tabledef { + /** String that declares the array. Adding " = { ..." after it should + * 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 */