[llvm-commits] CVS: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/LICENSE Makefile README ddc.h ddcmath.h fftmisc.c fourier.h fourierf.c main.c
Chris Lattner
sabre at nondot.org
Tue Jan 9 16:01:38 PST 2007
Changes in directory llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT:
LICENSE added (r1.1)
Makefile added (r1.1)
README added (r1.1)
ddc.h added (r1.1)
ddcmath.h added (r1.1)
fftmisc.c added (r1.1)
fourier.h added (r1.1)
fourierf.c added (r1.1)
main.c added (r1.1)
---
Log message:
readd mibench
---
Diffs of the changes: (+560 -0)
LICENSE | 42 +++++++++++++++++
Makefile | 7 ++
README | 42 +++++++++++++++++
ddc.h | 57 +++++++++++++++++++++++
ddcmath.h | 16 ++++++
fftmisc.c | 95 ++++++++++++++++++++++++++++++++++++++
fourier.h | 65 ++++++++++++++++++++++++++
fourierf.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
main.c | 86 ++++++++++++++++++++++++++++++++++
9 files changed, 560 insertions(+)
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/LICENSE
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/LICENSE:1.1
*** /dev/null Tue Jan 9 18:01:25 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/LICENSE Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,42 ----
+
+ ==============================================================
+ | |
+ | readme.txt - by Don Cross <dcross at intersrv.com> |
+ | |
+ ==============================================================
+
+ The file FFT.ZIP contains C source code for performing Discrete Fast Fourier
+ Transforms (DFFTs) and inverse DFFTs. This source code is public domain.
+ Use at your own risk. For more information, point your web browser at:
+
+ http://www.intersrv.com/~dcross/fft.html
+
+ Also, feel free to send questions/comments about this source code to me
+ by e-mail at the address above.
+
+ ------------------------------------------------------------------------------
+
+ *** SMALL REQUESTS ****
+
+ If you want to give away copies of this source code, that's fine, so long
+ as you do the following:
+
+ - Do not charge any money for this source code, except for possibly a
+ reasonable fee to cover postage, disk duplication, etc. I wrote this
+ code and I want it to be FREE to EVERYONE!
+
+ - Do not remove my name, e-mail address, or URL from any of the files in
+ this collection.
+
+ - Please keep this readme.txt file with the source and headers so that others
+ can get in touch with me to ask questions and/or find my web page to read
+ the online tutorial.
+
+ - If you make any modifications to the source code, please add comments to
+ it which include your name, e-mail address, web page URL (if any), and
+ explain what you did to the code.
+
+ - If you use this source code in an interesting program, please let me know.
+ I promise will never try to get money from you, even if you use this code
+ in a commercial program. I just want to know what kind of clever and
+ creative things people do with Fourier Transforms.
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile:1.1
*** /dev/null Tue Jan 9 18:01:37 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/Makefile Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,7 ----
+ LEVEL = ../../../..
+
+ PROG = telecomm-fft
+ LDFLAGS = -lm
+ RUN_OPTIONS = 8 32768 -i
+
+ include $(LEVEL)/MultiSource/Makefile.multisrc
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/README
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/README:1.1
*** /dev/null Tue Jan 9 18:01:37 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/README Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,42 ----
+
+ ==============================================================
+ | |
+ | readme.txt - by Don Cross <dcross at intersrv.com> |
+ | |
+ ==============================================================
+
+ The file FFT.ZIP contains C source code for performing Discrete Fast Fourier
+ Transforms (DFFTs) and inverse DFFTs. This source code is public domain.
+ Use at your own risk. For more information, point your web browser at:
+
+ http://www.intersrv.com/~dcross/fft.html
+
+ Also, feel free to send questions/comments about this source code to me
+ by e-mail at the address above.
+
+ ------------------------------------------------------------------------------
+
+ *** SMALL REQUESTS ****
+
+ If you want to give away copies of this source code, that's fine, so long
+ as you do the following:
+
+ - Do not charge any money for this source code, except for possibly a
+ reasonable fee to cover postage, disk duplication, etc. I wrote this
+ code and I want it to be FREE to EVERYONE!
+
+ - Do not remove my name, e-mail address, or URL from any of the files in
+ this collection.
+
+ - Please keep this readme.txt file with the source and headers so that others
+ can get in touch with me to ask questions and/or find my web page to read
+ the online tutorial.
+
+ - If you make any modifications to the source code, please add comments to
+ it which include your name, e-mail address, web page URL (if any), and
+ explain what you did to the code.
+
+ - If you use this source code in an interesting program, please let me know.
+ I promise will never try to get money from you, even if you use this code
+ in a commercial program. I just want to know what kind of clever and
+ creative things people do with Fourier Transforms.
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/ddc.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/ddc.h:1.1
*** /dev/null Tue Jan 9 18:01:37 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/ddc.h Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,57 ----
+ /*============================================================================
+
+ ddc.h - Don Cross, October 1992.
+
+ Generic ddclib stuff.
+
+ ============================================================================*/
+
+ #ifndef __DDC_DDC_H
+ #define __DDC_DDC_H
+
+ // If you add something to DDCRET, please add the appropriate string
+ // to the function DDCRET_String() in the file 'source\ddcret.cpp'.
+
+ enum DDCRET
+ {
+ DDC_SUCCESS, // The operation succeded
+ DDC_FAILURE, // The operation failed for unspecified reasons
+ DDC_OUT_OF_MEMORY, // Operation failed due to running out of memory
+ DDC_FILE_ERROR, // Operation encountered file I/O error
+ DDC_INVALID_CALL, // Operation was called with invalid parameters
+ DDC_USER_ABORT, // Operation was aborted by the user
+ DDC_INVALID_FILE // File format does not match
+ };
+
+
+ const char *DDCRET_String ( DDCRET ); // See source\ddcret.cpp
+
+
+ #define TRUE 1
+ #define FALSE 0
+
+ typedef int dBOOLEAN;
+
+ typedef unsigned char BYTE;
+
+ typedef unsigned char UINT8;
+ typedef signed char INT8;
+
+ typedef unsigned short int UINT16;
+ typedef signed short int INT16;
+ typedef unsigned long int UINT32;
+ typedef signed long int INT32;
+
+ #ifdef __BORLANDC__
+ #if sizeof(UINT16) != 2
+ #error Need to fix UINT16 and INT16
+ #endif
+
+ #if sizeof(UINT32) != 4
+ #error Need to fix UINT32 and INT32
+ #endif
+ #endif
+
+ #endif /* __DDC_DDC_H */
+
+ /*--- end of file ddc.h ---*/
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/ddcmath.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/ddcmath.h:1.1
*** /dev/null Tue Jan 9 18:01:37 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/ddcmath.h Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,16 ----
+ /*==========================================================================
+
+ ddcmath.h - Don Cross <dcross at intersrv.com>, October 1994.
+
+ Contains useful math stuff.
+
+ ==========================================================================*/
+
+ #ifndef __ddcmath_h
+ #define __ddcmath_h
+
+ #define DDC_PI (3.14159265358979323846)
+
+ #endif /* __ddcmath_h */
+
+ /*--- end of file ddcmath.h ---*/
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fftmisc.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fftmisc.c:1.1
*** /dev/null Tue Jan 9 18:01:37 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fftmisc.c Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,95 ----
+ /*============================================================================
+
+ fftmisc.c - Don Cross <dcross at intersrv.com>
+
+ http://www.intersrv.com/~dcross/fft.html
+
+ Helper routines for Fast Fourier Transform implementation.
+ Contains common code for fft_float() and fft_double().
+
+ See also:
+ fourierf.c
+ fourierd.c
+ ..\include\fourier.h
+
+ Revision history:
+
+ 1998 September 19 [Don Cross]
+ Improved the efficiency of IsPowerOfTwo().
+ Updated coding standards.
+
+ ============================================================================*/
+
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <math.h>
+
+ #include "fourier.h"
+
+ #define TRUE 1
+ #define FALSE 0
+
+ #define BITS_PER_WORD (sizeof(unsigned) * 8)
+
+
+ int IsPowerOfTwo ( unsigned x )
+ {
+ if ( x < 2 )
+ return FALSE;
+
+ if ( x & (x-1) ) // Thanks to 'byang' for this cute trick!
+ return FALSE;
+
+ return TRUE;
+ }
+
+
+ unsigned NumberOfBitsNeeded ( unsigned PowerOfTwo )
+ {
+ unsigned i;
+
+ if ( PowerOfTwo < 2 )
+ {
+ fprintf (
+ stderr,
+ ">>> Error in fftmisc.c: argument %d to NumberOfBitsNeeded is too small.\n",
+ PowerOfTwo );
+
+ exit(1);
+ }
+
+ for ( i=0; ; i++ )
+ {
+ if ( PowerOfTwo & (1 << i) )
+ return i;
+ }
+ }
+
+
+
+ unsigned ReverseBits ( unsigned index, unsigned NumBits )
+ {
+ unsigned i, rev;
+
+ for ( i=rev=0; i < NumBits; i++ )
+ {
+ rev = (rev << 1) | (index & 1);
+ index >>= 1;
+ }
+
+ return rev;
+ }
+
+
+ double Index_to_frequency ( unsigned NumSamples, unsigned Index )
+ {
+ if ( Index >= NumSamples )
+ return 0.0;
+ else if ( Index <= NumSamples/2 )
+ return (double)Index / (double)NumSamples;
+
+ return -(double)(NumSamples-Index) / (double)NumSamples;
+ }
+
+
+ /*--- end of file fftmisc.c---*/
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fourier.h
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fourier.h:1.1
*** /dev/null Tue Jan 9 18:01:37 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fourier.h Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,65 ----
+ /*============================================================================
+
+ fourier.h - Don Cross <dcross at intersrv.com>
+
+ http://www.intersrv.com/~dcross/fft.html
+
+ Contains definitions for doing Fourier transforms
+ and inverse Fourier transforms.
+
+ ============================================================================*/
+
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
+ /*
+ ** fft() computes the Fourier transform or inverse transform
+ ** of the complex inputs to produce the complex outputs.
+ ** The number of samples must be a power of two to do the
+ ** recursive decomposition of the FFT algorithm.
+ ** See Chapter 12 of "Numerical Recipes in FORTRAN" by
+ ** Press, Teukolsky, Vetterling, and Flannery,
+ ** Cambridge University Press.
+ **
+ ** Notes: If you pass ImaginaryIn = NULL, this function will "pretend"
+ ** that it is an array of all zeroes. This is convenient for
+ ** transforming digital samples of real number data without
+ ** wasting memory.
+ */
+
+ void fft_double (
+ unsigned NumSamples, /* must be a power of 2 */
+ int InverseTransform, /* 0=forward FFT, 1=inverse FFT */
+ double *RealIn, /* array of input's real samples */
+ double *ImaginaryIn, /* array of input's imag samples */
+ double *RealOut, /* array of output's reals */
+ double *ImaginaryOut ); /* array of output's imaginaries */
+
+
+ void fft_float (
+ unsigned NumSamples, /* must be a power of 2 */
+ int InverseTransform, /* 0=forward FFT, 1=inverse FFT */
+ float *RealIn, /* array of input's real samples */
+ float *ImaginaryIn, /* array of input's imag samples */
+ float *RealOut, /* array of output's reals */
+ float *ImaginaryOut ); /* array of output's imaginaries */
+
+
+ int IsPowerOfTwo ( unsigned x );
+ unsigned NumberOfBitsNeeded ( unsigned PowerOfTwo );
+ unsigned ReverseBits ( unsigned index, unsigned NumBits );
+
+ /*
+ ** The following function returns an "abstract frequency" of a
+ ** given index into a buffer with a given number of frequency samples.
+ ** Multiply return value by sampling rate to get frequency expressed in Hz.
+ */
+ double Index_to_frequency ( unsigned NumSamples, unsigned Index );
+
+ #ifdef __cplusplus
+ }
+ #endif
+
+
+ /*--- end of file fourier.h ---*/
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fourierf.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fourierf.c:1.1
*** /dev/null Tue Jan 9 18:01:37 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/fourierf.c Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,150 ----
+ /*============================================================================
+
+ fourierf.c - Don Cross <dcross at intersrv.com>
+
+ http://www.intersrv.com/~dcross/fft.html
+
+ Contains definitions for doing Fourier transforms
+ and inverse Fourier transforms.
+
+ This module performs operations on arrays of 'float'.
+
+ Revision history:
+
+ 1998 September 19 [Don Cross]
+ Updated coding standards.
+ Improved efficiency of trig calculations.
+
+ ============================================================================*/
+
+ #include <stdlib.h>
+ #include <stdio.h>
+ #include <math.h>
+
+ #include "fourier.h"
+ #include "ddcmath.h"
+
+ #define CHECKPOINTER(p) CheckPointer(p,#p)
+
+ static void CheckPointer ( void *p, char *name )
+ {
+ if ( p == NULL )
+ {
+ fprintf ( stderr, "Error in fft_float(): %s == NULL\n", name );
+ exit(1);
+ }
+ }
+
+
+ void fft_float (
+ unsigned NumSamples,
+ int InverseTransform,
+ float *RealIn,
+ float *ImagIn,
+ float *RealOut,
+ float *ImagOut )
+ {
+ unsigned NumBits; /* Number of bits needed to store indices */
+ unsigned i, j, k, n;
+ unsigned BlockSize, BlockEnd;
+
+ double angle_numerator = 2.0 * DDC_PI;
+ double tr, ti; /* temp real, temp imaginary */
+
+ if ( !IsPowerOfTwo(NumSamples) )
+ {
+ fprintf (
+ stderr,
+ "Error in fft(): NumSamples=%u is not power of two\n",
+ NumSamples );
+
+ exit(1);
+ }
+
+ if ( InverseTransform )
+ angle_numerator = -angle_numerator;
+
+ CHECKPOINTER ( RealIn );
+ CHECKPOINTER ( RealOut );
+ CHECKPOINTER ( ImagOut );
+
+ NumBits = NumberOfBitsNeeded ( NumSamples );
+
+ /*
+ ** Do simultaneous data copy and bit-reversal ordering into outputs...
+ */
+
+ for ( i=0; i < NumSamples; i++ )
+ {
+ j = ReverseBits ( i, NumBits );
+ RealOut[j] = RealIn[i];
+ ImagOut[j] = (ImagIn == NULL) ? 0.0 : ImagIn[i];
+ }
+
+ /*
+ ** Do the FFT itself...
+ */
+
+ BlockEnd = 1;
+ for ( BlockSize = 2; BlockSize <= NumSamples; BlockSize <<= 1 )
+ {
+ double delta_angle = angle_numerator / (double)BlockSize;
+ double sm2 = sin ( -2 * delta_angle );
+ double sm1 = sin ( -delta_angle );
+ double cm2 = cos ( -2 * delta_angle );
+ double cm1 = cos ( -delta_angle );
+ double w = 2 * cm1;
+ double ar[3], ai[3];
+ double temp;
+
+ for ( i=0; i < NumSamples; i += BlockSize )
+ {
+ ar[2] = cm2;
+ ar[1] = cm1;
+
+ ai[2] = sm2;
+ ai[1] = sm1;
+
+ for ( j=i, n=0; n < BlockEnd; j++, n++ )
+ {
+ ar[0] = w*ar[1] - ar[2];
+ ar[2] = ar[1];
+ ar[1] = ar[0];
+
+ ai[0] = w*ai[1] - ai[2];
+ ai[2] = ai[1];
+ ai[1] = ai[0];
+
+ k = j + BlockEnd;
+ tr = ar[0]*RealOut[k] - ai[0]*ImagOut[k];
+ ti = ar[0]*ImagOut[k] + ai[0]*RealOut[k];
+
+ RealOut[k] = RealOut[j] - tr;
+ ImagOut[k] = ImagOut[j] - ti;
+
+ RealOut[j] += tr;
+ ImagOut[j] += ti;
+ }
+ }
+
+ BlockEnd = BlockSize;
+ }
+
+ /*
+ ** Need to normalize if inverse transform...
+ */
+
+ if ( InverseTransform )
+ {
+ double denom = (double)NumSamples;
+
+ for ( i=0; i < NumSamples; i++ )
+ {
+ RealOut[i] /= denom;
+ ImagOut[i] /= denom;
+ }
+ }
+ }
+
+
+ /*--- end of file fourierf.c ---*/
Index: llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/main.c
diff -c /dev/null llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/main.c:1.1
*** /dev/null Tue Jan 9 18:01:38 2007
--- llvm-test/MultiSource/Benchmarks/MiBench/telecomm-FFT/main.c Tue Jan 9 18:01:15 2007
***************
*** 0 ****
--- 1,86 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <math.h>
+
+ int main(int argc, char *argv[]) {
+ unsigned MAXSIZE;
+ unsigned MAXWAVES;
+ unsigned i,j;
+ float *RealIn;
+ float *ImagIn;
+ float *RealOut;
+ float *ImagOut;
+ float *coeff;
+ float *amp;
+ int invfft=0;
+
+ if (argc<3)
+ {
+ printf("Usage: fft <waves> <length> -i\n");
+ printf("-i performs an inverse fft\n");
+ printf("make <waves> random sinusoids");
+ printf("<length> is the number of samples\n");
+ exit(-1);
+ }
+ else if (argc==4)
+ invfft = !strncmp(argv[3],"-i",2);
+ MAXSIZE=atoi(argv[2]);
+ MAXWAVES=atoi(argv[1]);
+
+ srand(1);
+
+ RealIn=(float*)malloc(sizeof(float)*MAXSIZE);
+ ImagIn=(float*)malloc(sizeof(float)*MAXSIZE);
+ RealOut=(float*)malloc(sizeof(float)*MAXSIZE);
+ ImagOut=(float*)malloc(sizeof(float)*MAXSIZE);
+ coeff=(float*)malloc(sizeof(float)*MAXWAVES);
+ amp=(float*)malloc(sizeof(float)*MAXWAVES);
+
+ /* Makes MAXWAVES waves of random amplitude and period */
+ for(i=0;i<MAXWAVES;i++)
+ {
+ coeff[i] = rand()%1000;
+ amp[i] = rand()%1000;
+ }
+ for(i=0;i<MAXSIZE;i++)
+ {
+ /* RealIn[i]=rand();*/
+ RealIn[i]=0;
+ for(j=0;j<MAXWAVES;j++)
+ {
+ /* randomly select sin or cos */
+ if (rand()%2)
+ {
+ RealIn[i]+=coeff[j]*cos(amp[j]*i);
+ }
+ else
+ {
+ RealIn[i]+=coeff[j]*sin(amp[j]*i);
+ }
+ ImagIn[i]=0;
+ }
+ }
+
+ /* regular*/
+ fft_float (MAXSIZE,invfft,RealIn,ImagIn,RealOut,ImagOut);
+
+ printf("RealOut:\n");
+ for (i=0;i<MAXSIZE;i++)
+ printf("%f \t", RealOut[i]);
+ printf("\n");
+
+ printf("ImagOut:\n");
+ for (i=0;i<MAXSIZE;i++)
+ printf("%f \t", ImagOut[i]);
+ printf("\n");
+
+ free(RealIn);
+ free(ImagIn);
+ free(RealOut);
+ free(ImagOut);
+ free(coeff);
+ free(amp);
+ exit(0);
+
+
+ }
More information about the llvm-commits
mailing list