[FFmpeg-cvslog] r20400 - in trunk/libavcodec: Makefile mpegaudio_tablegen.c mpegaudio_tablegen.h mpegaudiodec.c tableprint.c tableprint.h

reimar subversion
Wed Oct 28 19:42:53 CET 2009


Author: reimar
Date: Wed Oct 28 19:42:52 2009
New Revision: 20400

Log:
Add support for hardcoding the mpegaudiodec tables.
Reduces .bss size by about 194 kB.

Added:
   trunk/libavcodec/mpegaudio_tablegen.c
   trunk/libavcodec/mpegaudio_tablegen.h
   trunk/libavcodec/tableprint.c
   trunk/libavcodec/tableprint.h
Modified:
   trunk/libavcodec/Makefile
   trunk/libavcodec/mpegaudiodec.c

Modified: trunk/libavcodec/Makefile
==============================================================================
--- trunk/libavcodec/Makefile	Wed Oct 28 19:04:31 2009	(r20399)
+++ trunk/libavcodec/Makefile	Wed Oct 28 19:42:52 2009	(r20400)
@@ -687,7 +687,7 @@ TESTPROGS-$(HAVE_MMX) += motion
 
 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)cos_tables.c: $(SUBDIR)costable
 
 $(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)
+	./$< > $@

Added: trunk/libavcodec/mpegaudio_tablegen.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/libavcodec/mpegaudio_tablegen.c	Wed Oct 28 19:42:52 2009	(r20400)
@@ -0,0 +1,60 @@
+/*
+ * Generate a header file for hardcoded mpegaudiodec tables
+ *
+ * Copyright (c) 2009 Reimar D?ffinger <Reimar.Doeffinger at gmx.de>
+ *
+ * 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 <stdlib.h>
+#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 }
+};

Added: trunk/libavcodec/mpegaudio_tablegen.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/libavcodec/mpegaudio_tablegen.h	Wed Oct 28 19:42:52 2009	(r20400)
@@ -0,0 +1,68 @@
+/*
+ * Header file for hardcoded mpegaudiodec tables
+ *
+ * Copyright (c) 2009 Reimar D?ffinger <Reimar.Doeffinger at gmx.de>
+ *
+ * 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 <stdint.h>
+// 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 <math.h>
+
+#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<TABLE_4_3_SIZE;i++) {
+        double value = i/4;
+        double f, fm;
+        int e, m;
+        f = value * cbrtf(value) * pow(2, (i&3)*0.25);
+        fm = frexp(f, &e);
+        m = (uint32_t)(fm*(1LL<<31) + 0.5);
+        e+= FRAC_BITS - 31 + 5 - 100;
+
+        /* normalized to FRAC_BITS */
+        table_4_3_value[i] = m;
+        table_4_3_exp[i] = -e;
+    }
+    for(i=0; i<512*16; i++){
+        double value = i & 15;
+        int exponent= (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 */

Modified: trunk/libavcodec/mpegaudiodec.c
==============================================================================
--- trunk/libavcodec/mpegaudiodec.c	Wed Oct 28 19:04:31 2009	(r20399)
+++ trunk/libavcodec/mpegaudiodec.c	Wed Oct 28 19:42:52 2009	(r20400)
@@ -92,12 +92,7 @@ static const int huff_quad_vlc_tables_si
 };
 /* 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 @@ static av_cold int decode_init(AVCodecCo
         /* compute n ^ (4/3) and store it in mantissa/exp format */
 
         int_pow_init();
-        for(i=1;i<TABLE_4_3_SIZE;i++) {
-            double value = i/4;
-            double f, fm;
-            int e, m;
-            f = value * cbrtf(value) * pow(2, (i&3)*0.25);
-            fm = frexp(f, &e);
-            m = (uint32_t)(fm*(1LL<<31) + 0.5);
-            e+= FRAC_BITS - 31 + 5 - 100;
-
-            /* normalized to FRAC_BITS */
-            table_4_3_value[i] = m;
-            table_4_3_exp[i] = -e;
-        }
-        for(i=0; i<512*16; i++){
-            double value = i & 15;
-            int exponent= (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;

Added: trunk/libavcodec/tableprint.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/libavcodec/tableprint.c	Wed Oct 28 19:42:52 2009	(r20400)
@@ -0,0 +1,72 @@
+/*
+ * Generate a file for hardcoded tables
+ *
+ * Copyright (c) 2009 Reimar D?ffinger <Reimar.Doeffinger at gmx.de>
+ *
+ * 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 <stdio.h>
+#include <inttypes.h>
+#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 <stdint.h>\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;
+}

Added: trunk/libavcodec/tableprint.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/libavcodec/tableprint.h	Wed Oct 28 19:42:52 2009	(r20400)
@@ -0,0 +1,58 @@
+/*
+ * Generate a file for hardcoded tables
+ *
+ * Copyright (c) 2009 Reimar D?ffinger <Reimar.Doeffinger at gmx.de>
+ *
+ * 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 <stdint.h>
+
+/**
+ * \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 */



More information about the ffmpeg-cvslog mailing list