主程序如下:
/* ======================================================================== */ /* TEXAS INSTRUMENTS, INC. */ /* */ /* DSPLIB Application Note Example (DSP_fft32x32) */ /* */ /* Release: Version 1.0 */ /* */ /* This file contains proprietary intellectual property of Texas */ /* Instruments, Inc. Its source and binary codes are protected by */ /* various copyrights, and portions may also be protected by patents or */ /* other legal protections. */ /* */ /* ------------------------------------------------------------------------ */ /* Copyright (C) 2003 Texas Instruments, Incorporated. */ /* All Rights Reserved. */ /* ======================================================================== */
#include <stdio.h> #include <stdlib.h> #include <csl.h> #include <csl_timer.h> #include <math.h>
/* ======================================================================== */ /* Include the DSPLIB header file */ /* ======================================================================== */ #include "dsp_fft32x32.h"
/* ======================================================================== */ /* Macro definition */ /* ======================================================================== */ #define PI (3.141592654) #define NN (1024)
/* ======================================================================== */ /* Input and output arrays */ /* ======================================================================== */ #pragma DATA_ALIGN(x, 8) #pragma DATA_ALIGN(xx, 8) #pragma DATA_ALIGN(y, 8) #pragma DATA_ALIGN(w, 8) int x[2*NN]; int w[2*NN]; int xx[2*NN]; int y[2*NN];
/* ======================================================================== */ /* D2I -- Truncate a 'double' to a 'int', with clamping. */ /* ======================================================================== */ static int d2i(double d) { if (d >= 2147483647.0) return (int)0x7FFFFFFF; if (d <= -2147483648.0) return (int)0x80000000; return (int)d; }
/* ======================================================================== */ /* GEN_TWIDDLE -- Generate twiddle factors for fft32x32(). */ /* */ /* USAGE */ /* This routine is called as follows: */ /* */ /* int gen_twiddle_fft32x32(short *w, int n, double scale) */ /* */ /* int *w Pointer to twiddle-factor array */ /* int n Size of FFT */ /* double scale Scale factor to apply to values. */ /* */ /* The routine will generate the twiddle-factors directly into the */ /* array you specify. The array needs to be approximately 2*N */ /* elements long. (The actual size, which is slightly smaller, is */ /* returned by the function.) */ /* ======================================================================== */ int gen_twiddle_fft32x32(int *w, int n, double scale) { int i, j, k, s=0, t;
for (j = 1, k = 0; j < n >> 2; j = j << 2, s++) { for (i = t=0; i < n >> 2; i += j, t++) { w[k + 5] = d2i(scale * cos(6.0 * PI * i / n)); w[k + 4] = d2i(scale * sin(6.0 * PI * i / n));
w[k + 3] = d2i(scale * cos(4.0 * PI * i / n)); w[k + 2] = d2i(scale * sin(4.0 * PI * i / n));
w[k + 1] = d2i(scale * cos(2.0 * PI * i / n)); w[k + 0] = d2i(scale * sin(2.0 * PI * i / n));
k += 6; } }
return k; }
/* ======================================================================== */ /* NAME */ /* main */ /* */ /* RIVISION HISTORY */ /* 30-Jun-2002 Initial revision */ /* 31-Dec-2002 Improved benchmarking */ /* */ /* USAGE */ /* void main (); */ /* This program is to show how to use DSP_fft32x32() */ /* when data are in L2SRAM. */ /* */ /* DESCRIPTION */ /* First, function call overhead for timer functions is measured. */ /* Then, the execution cycles for the target function is measured. */ /* Finally, the timer function call overhead is excluded from the */ /* execution cycles measured. */ /* The cycle count measured will include L1P/D miss overhead as well as */ /* function call overhead. */ /* */ /* ASSUMPTIONS */ /* The benchmarking code assumes C64x, e.g., 1 count = 8 CPU cycles. */ /* */ /* ------------------------------------------------------------------------ */ /* Copyright (c) 2003 Texas Instruments, Incorporated. */ /* All Rights Reserved. */ /* ======================================================================== */
void main(void) { int i; int F1 = 10, F2 = 1140; /* Input frequencies */ int start, stop, overhead, diff; TIMER_Handle hTimer;
/* ==================================================================== */ /* Initialize Chip Support Library */ /* ==================================================================== */ CSL_init(); /* ==================================================================== */ /* Generate Q.31 input data */ /* ==================================================================== */ for(i=0; i<NN; i++) { x[2*i] = xx[2*i] = 2147483647./(2*NN) * ( sin(2*PI*F2*i/NN) + sin(2*PI*F1*i/NN) ); x[2*i+1] = xx[2*i+1] = 0; }
/* ==================================================================== */ /* Generate twiddle factors */ /* ==================================================================== */ gen_twiddle_fft32x32(w, NN, 2147483647.);
/* ==================================================================== */ /* Configure a timer. */ /* ==================================================================== */ hTimer = TIMER_open(TIMER_DEVANY,0); TIMER_configArgs(hTimer, 0x000002C0, 0xFFFFFFFF, 0x00000000); /* ==================================================================== */ /* Compute the overhead of calling the timer. */ /* ==================================================================== */ start = TIMER_getCount(hTimer); /* called twice to avoid L1D miss. */ start = TIMER_getCount(hTimer); stop = TIMER_getCount(hTimer); overhead = stop - start; /* ==================================================================== */ /* Measure the time */ /* ==================================================================== */ start = TIMER_getCount(hTimer); DSP_fft32x32(w, NN, x, y); diff = TIMER_getCount(hTimer) - start - overhead;
/* ==================================================================== */ /* Print the result */ /* ==================================================================== */ printf("Total cycles including L1P/D miss overhead = %d\n", diff*8); printf("Check the result with the Graph menu.\n" "* Input\n" "Start address: xx\n" "Acquisition buffer size: 512\n" "Index increment: 2\n" "Display data size: 512\n" "DSP data type: 32-bit signed integer\n" "* Output\n" "Start address: y\n" "Acquisition buffer size: 1024\n" "Index increment: 1\n" "Display data size: 1024\n" "DSP data type: 32-bit signed integer\n" );
TIMER_close(hTimer); while(1); }
/* ======================================================================== */ /* End of file: fft32x32_main.c */ /* ======================================================================== */ |