# HG changeset patch # User reimar # Date 1255556484 0 # Node ID 866dffa620d12063cf66eaa0895382cd88d5d7cf # Parent 136334ad62b338b9e03bbea6030f2ce11b056021 Use hardcoded instead of runtime-calculated ff_cos_* tables if --enable-hardcoded-tables was used. Due to the size, the code for the tables is generated at compile time. diff -r 136334ad62b3 -r 866dffa620d1 Makefile --- a/Makefile Wed Oct 14 05:28:24 2009 +0000 +++ b/Makefile Wed Oct 14 21:41:24 2009 +0000 @@ -27,7 +27,8 @@ # parts needed for many different codecs OBJS-$(CONFIG_AANDCT) += aandcttab.o OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o -OBJS-$(CONFIG_FFT) += fft.o +FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o +OBJS-$(CONFIG_FFT) += fft.o $(FFT-OBJS-yes) OBJS-$(CONFIG_GOLOMB) += golomb.o OBJS-$(CONFIG_MDCT) += mdct.o OBJS-$(CONFIG_RDFT) += rdft.o @@ -571,6 +572,14 @@ DIRS = alpha arm bfin mlib ppc ps2 sh4 sparc x86 +CLEANFILES = cos_tables.c costablegen$(HOSTEXESUF) + include $(SUBDIR)../subdir.mak $(SUBDIR)dct-test$(EXESUF): $(SUBDIR)dctref.o + +$(SUBDIR)costablegen$(HOSTEXESUF): $(SUBDIR)costablegen.c + $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $< $(HOSTLIBS) + +$(SUBDIR)cos_tables.c: $(SUBDIR)costablegen$(HOSTEXESUF) + ./$< > $@ diff -r 136334ad62b3 -r 866dffa620d1 costablegen.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/costablegen.c Wed Oct 14 21:41:24 2009 +0000 @@ -0,0 +1,50 @@ +/* + * Generate a header file for hardcoded ff_cos_* 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 + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#define BITS 16 +#define FLOATFMT "%.18e" + +int main(void) +{ + int i, j; + printf("/* This file was generated by libavcodec/costablegen */\n"); + printf("#include \"dsputil.h\"\n"); + for (i = 4; i <= BITS; i++) { + int m = 1 << i; + double freq = 2*M_PI/m; + printf("const DECLARE_ALIGNED_16(FFTSample, ff_cos_%i[]) = {\n ", m); + for (j = 0; j < m/2 - 1; j++) { + int idx = j > m/4 ? m/2 - j : j; + printf(" "FLOATFMT",", cos(idx*freq)); + if ((j & 3) == 3) + printf("\n "); + } + printf(" "FLOATFMT"\n};\n", cos(freq)); + } + return 0; +} diff -r 136334ad62b3 -r 866dffa620d1 dsputil.h --- a/dsputil.h Wed Oct 14 05:28:24 2009 +0000 +++ b/dsputil.h Wed Oct 14 21:41:24 2009 +0000 @@ -742,7 +742,11 @@ #define FF_MDCT_PERM_INTERLEAVE 1 } FFTContext; +#if CONFIG_HARDCODED_TABLES +extern const FFTSample* const ff_cos_tabs[13]; +#else extern FFTSample* const ff_cos_tabs[13]; +#endif /** * Sets up a complex FFT. diff -r 136334ad62b3 -r 866dffa620d1 fft.c --- a/fft.c Wed Oct 14 05:28:24 2009 +0000 +++ b/fft.c Wed Oct 14 21:41:24 2009 +0000 @@ -28,20 +28,31 @@ #include "dsputil.h" +#if CONFIG_HARDCODED_TABLES +#define COSTABLE(size) \ + extern const DECLARE_ALIGNED_16(FFTSample, ff_cos_##size[size/2]); +#else +#define COSTABLE(size) \ + DECLARE_ALIGNED_16(FFTSample, ff_cos_##size[size/2]); +#endif + /* 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]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_64[32]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_128[64]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_256[128]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_512[256]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_1024[512]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_2048[1024]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_4096[2048]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_8192[4096]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_16384[8192]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_32768[16384]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_65536[32768]); +COSTABLE(16) +COSTABLE(32) +COSTABLE(64) +COSTABLE(128) +COSTABLE(256) +COSTABLE(512) +COSTABLE(1024) +COSTABLE(2048) +COSTABLE(4096) +COSTABLE(8192) +COSTABLE(16384) +COSTABLE(32768) +COSTABLE(65536) +#if CONFIG_HARDCODED_TABLES +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 +104,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<revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i; s->tmp_buf = av_malloc(n * sizeof(FFTComplex));