[FFmpeg-devel] [PATCH] hardcoded ff_cos tables
Reimar Döffinger
Reimar.Doeffinger
Wed Oct 14 13:35:10 CEST 2009
On Wed, Oct 14, 2009 at 11:57:18AM +0100, M?ns Rullg?rd wrote:
> Reimar D?ffinger <Reimar.Doeffinger at gmx.de> writes:
>
> > On Wed, Oct 14, 2009 at 11:20:23AM +0200, Diego Biurrun wrote:
> >> On Wed, Oct 14, 2009 at 11:14:40AM +0200, Reimar D?ffinger wrote:
> >> > --- libavcodec/Makefile (revision 20231)
> >> > +++ libavcodec/Makefile (working copy)
> >> > @@ -574,3 +574,12 @@
> >> > +
> >> > +clean::
> >> > + rm -f $(SUBDIR)cos_tables.h
> >>
> >> IIRC we have CLEANFILES for this.
> >
> > Another try, also adding an explicit dependency for cos_tables.h,
> > otherwise the first run without .d files fails.
>
> Why not call it cos_tables.c and compile it separately? Seems cleaner
> to me.
Seems uglier to me as long as it is only one file.
-------------- next part --------------
Index: libavcodec/dsputil.h
===================================================================
--- libavcodec/dsputil.h (revision 20231)
+++ libavcodec/dsputil.h (working copy)
@@ -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.
Index: libavcodec/Makefile
===================================================================
--- libavcodec/Makefile (revision 20231)
+++ libavcodec/Makefile (working copy)
@@ -28,6 +28,7 @@
OBJS-$(CONFIG_AANDCT) += aandcttab.o
OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o
OBJS-$(CONFIG_FFT) += fft.o
+HARDCODED-TABLES-OBJS-$(CONFIG_FFT) += cos_tables.o
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)
+ ./$< > $@
Index: libavcodec/costablegen.c
===================================================================
--- libavcodec/costablegen.c (revision 0)
+++ libavcodec/costablegen.c (revision 0)
@@ -0,0 +1,50 @@
+/*
+ * Generate a header file for hardcoded ff_cos_* 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 <math.h>
+
+#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 \"cos_tables.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;
+}
Index: libavcodec/fft.c
===================================================================
--- libavcodec/fft.c (revision 20231)
+++ 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/cos_tables.h
===================================================================
--- libavcodec/cos_tables.h (revision 0)
+++ libavcodec/cos_tables.h (revision 0)
@@ -0,0 +1,17 @@
+#ifndef AVCODEC_COS_TABLES_H
+#define AVCODEC_COS_TABLES_H
+#include "dsputil.h"
+extern const FFTSample ff_cos_16[];
+extern const FFTSample ff_cos_32[];
+extern const FFTSample ff_cos_64[];
+extern const FFTSample ff_cos_128[];
+extern const FFTSample ff_cos_256[];
+extern const FFTSample ff_cos_512[];
+extern const FFTSample ff_cos_1024[];
+extern const FFTSample ff_cos_2048[];
+extern const FFTSample ff_cos_4096[];
+extern const FFTSample ff_cos_8192[];
+extern const FFTSample ff_cos_16384[];
+extern const FFTSample ff_cos_32768[];
+extern const FFTSample ff_cos_65536[];
+#endif
Index: Makefile
===================================================================
--- Makefile (revision 20231)
+++ Makefile (working copy)
@@ -47,6 +47,7 @@
$(STRIP) $@
SUBDIR_VARS := OBJS FFLIBS CLEANFILES DIRS TESTPROGS EXAMPLES SKIPHEADERS \
+ HARDCODED-TABLES-OBJS \
ALTIVEC-OBJS MMX-OBJS NEON-OBJS X86-OBJS YASM-OBJS-FFT YASM-OBJS
define RESET
Index: common.mak
===================================================================
--- common.mak (revision 20231)
+++ common.mak (working copy)
@@ -49,6 +49,7 @@
endif
OBJS-$(HAVE_MMX) += $(MMX-OBJS-yes)
+OBJS-$(CONFIG_HARDCODED_TABLES) += $(HARDCODED-TABLES-OBJS-yes)
CFLAGS += $(CFLAGS-yes)
OBJS += $(OBJS-yes)
More information about the ffmpeg-devel
mailing list