[FFmpeg-devel] [PATCH] hardcoded ff_cos tables

Måns Rullgård mans
Wed Oct 14 12:57:18 CEST 2009


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.

> How does costablegen$(HOSTEXESUF) in CLEANFILES work? It doesn't work if
> HOSTEXESUF changed somewhere in-between...

I wouldn't worry about that.

> 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)
> @@ -571,6 +571,16 @@
>
>  DIRS = alpha arm bfin mlib ppc ps2 sh4 sparc x86
>
> +CLEANFILES = cos_tables.h 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.h: $(SUBDIR)costablegen$(HOSTEXESUF)
> +	./$< > $@

You can't have ./ there.  It won't work.

> +$(SUBDIR)fft.c: $(SUBDIR)cos_tables.h
> Index: libavcodec/costablegen.c
> ===================================================================
> --- libavcodec/costablegen.c	(revision 0)
> +++ libavcodec/costablegen.c	(revision 0)
> @@ -0,0 +1,49 @@
> +/*
> + * 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 "libavutil/mathematics.h"

You can't #include any ffmpeg headers in files to be compiled with
HOSTCC.  They will pull in asm and other definitions for the target
machine.  It doesn't look like you're using anything from that header
anyway.

> +#undef fprintf
> +
> +#define BITS 16
> +#define FLOATFMT "%.18e"
> +
> +int main(void)
> +{
> +    int i, j;
> +    FILE *table = stdout;
> +    fprintf(table, "/* This file was generated by libavcodec/costablegen */\n");
> +    fprintf(table, "#include \"dsputil.h\"\n");

Why not simply use printf()?

> +    for (i = 4; i <= BITS; i++) {
> +        int m = 1 << i;
> +        double freq = 2*M_PI/m;
> +        fprintf(table, "const FFTSample ff_cos_%i[] = {\n   ", m);
> +        for (j = 0; j < m/2 - 1; j++) {
> +            int idx = j > m/4 ? m/2 - j : j;
> +            fprintf(table, " "FLOATFMT",", cos(idx*freq));
> +            if ((j & 3) == 3)
> +                fprintf(table, "\n   ");
> +        }
> +        fprintf(table, " "FLOATFMT"\n};\n", cos(freq));
> +    }
> +    return 0;
> +}

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list