mirror of https://github.com/FFmpeg/FFmpeg.git
Reduces .bss size by about 194 kB. Originally committed as revision 20400 to svn://svn.ffmpeg.org/ffmpeg/trunkrelease/0.6
parent
1a04d4c722
commit
eadaa00c6f
6 changed files with 273 additions and 28 deletions
@ -0,0 +1,60 @@ |
|||||||
|
/*
|
||||||
|
* Generate a header file for hardcoded mpegaudiodec tables |
||||||
|
* |
||||||
|
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@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 } |
||||||
|
}; |
@ -0,0 +1,68 @@ |
|||||||
|
/*
|
||||||
|
* Header file for hardcoded mpegaudiodec tables |
||||||
|
* |
||||||
|
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@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 */ |
@ -0,0 +1,72 @@ |
|||||||
|
/*
|
||||||
|
* Generate a file for hardcoded tables |
||||||
|
* |
||||||
|
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@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; |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
/*
|
||||||
|
* Generate a file for hardcoded tables |
||||||
|
* |
||||||
|
* Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@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 */ |
Loading…
Reference in new issue