[FFmpeg-devel] [PATCH] hardcoded ff_cos tables
Reimar Döffinger
Reimar.Doeffinger
Tue Oct 13 13:05:04 CEST 2009
Hello,
attached patch allows hardcoding the ff_cos tables so they are in
.rodata instead of .bss.
Not included is the cos_tables.h file as generated by costablegen.c
since it is > 1.7 MB.
Which I admit is a bit of an issue, including this file directly into
SVN is not all that great, but it would be the simplest solution by far...
It also means the ffmpeg binary size increases by 256 kB if compiled
with hardcoded tables...
-------------- next part --------------
Index: tools/costablegen.c
===================================================================
--- tools/costablegen.c (revision 0)
+++ tools/costablegen.c (revision 0)
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include "libavcodec/dsputil.h"
+#undef fprintf
+#define BITS 16
+#define FLOATFMT "%.18e"
+int main(void)
+{
+ int i, j;
+ FILE *table = fopen("libavcodec/cos_tables.h", "w");
+ FFTContext ctx;
+ ctx.split_radix = 1;
+ ff_fft_init(&ctx, BITS, 0);
+ fprintf(table, "#include \"dsputil.h\"\n");
+ for (i = 4; i <= BITS; i++) {
+ int m = 1 << i;
+ fprintf(table, "const FFTSample ff_cos_%i[] = {\n ", m);
+ for (j = 0; j < m/2 - 1; j++) {
+ fprintf(table, " "FLOATFMT",", ff_cos_tabs[i-4][j]);
+ if ((j & 3) == 3)
+ fprintf(table, "\n ");
+ }
+ fprintf(table, " "FLOATFMT"\n};\n", ff_cos_tabs[i-4][m/2-1]);
+ }
+ return 0;
+}
Index: libavcodec/fft.c
===================================================================
--- libavcodec/fft.c (revision 20223)
+++ libavcodec/fft.c (working copy)
@@ -28,6 +28,7 @@
#include "dsputil.h"
+#if !CONFIG_HARDCODED_TABLES
/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */
DECLARE_ALIGNED_16(FFTSample, ff_cos_16[8]);
DECLARE_ALIGNED_16(FFTSample, ff_cos_32[16]);
@@ -42,6 +43,10 @@
DECLARE_ALIGNED_16(FFTSample, ff_cos_16384[8192]);
DECLARE_ALIGNED_16(FFTSample, ff_cos_32768[16384]);
DECLARE_ALIGNED_16(FFTSample, ff_cos_65536[32768]);
+#else
+#include "cos_tables.h"
+const
+#endif
FFTSample * const ff_cos_tabs[] = {
ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024,
ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536,
@@ -93,6 +98,7 @@
if (HAVE_MMX) ff_fft_init_mmx(s);
if (s->split_radix) {
+#if !CONFIG_HARDCODED_TABLES
for(j=4; j<=nbits; j++) {
int m = 1<<j;
double freq = 2*M_PI/m;
@@ -102,6 +108,7 @@
for(i=1; i<m/4; i++)
tab[m/2-i] = tab[i];
}
+#endif
for(i=0; i<n; i++)
s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i;
s->tmp_buf = av_malloc(n * sizeof(FFTComplex));
Index: libavcodec/dsputil.h
===================================================================
--- libavcodec/dsputil.h (revision 20222)
+++ libavcodec/dsputil.h (working copy)
@@ -742,7 +742,11 @@
#define FF_MDCT_PERM_INTERLEAVE 1
} FFTContext;
-extern FFTSample* const ff_cos_tabs[13];
+extern
+#if CONFIG_HARDCODED_TABLES
+const
+#endif
+FFTSample* const ff_cos_tabs[13];
/**
* Sets up a complex FFT.
More information about the ffmpeg-devel
mailing list