GNU Radio 3.4.2 C++ API
fft_1d.h
Go to the documentation of this file.
00001 /* --------------------------------------------------------------  */
00002 /* (C)Copyright 2001,2007,                                         */
00003 /* International Business Machines Corporation,                    */
00004 /* Sony Computer Entertainment, Incorporated,                      */
00005 /* Toshiba Corporation,                                            */
00006 /*                                                                 */
00007 /* All Rights Reserved.                                            */
00008 /*                                                                 */
00009 /* Redistribution and use in source and binary forms, with or      */
00010 /* without modification, are permitted provided that the           */
00011 /* following conditions are met:                                   */
00012 /*                                                                 */
00013 /* - Redistributions of source code must retain the above copyright*/
00014 /*   notice, this list of conditions and the following disclaimer. */
00015 /*                                                                 */
00016 /* - Redistributions in binary form must reproduce the above       */
00017 /*   copyright notice, this list of conditions and the following   */
00018 /*   disclaimer in the documentation and/or other materials        */
00019 /*   provided with the distribution.                               */
00020 /*                                                                 */
00021 /* - Neither the name of IBM Corporation nor the names of its      */
00022 /*   contributors may be used to endorse or promote products       */
00023 /*   derived from this software without specific prior written     */
00024 /*   permission.                                                   */
00025 /*                                                                 */
00026 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
00027 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
00028 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
00029 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
00030 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
00031 /* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
00032 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
00033 /* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
00034 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
00035 /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
00036 /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
00037 /* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
00038 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
00039 /* --------------------------------------------------------------  */
00040 /* PROLOG END TAG zYx                                              */
00041 #ifndef _FFT_1D_H_
00042 #define _FFT_1D_H_      1
00043 
00044 #include <spu_intrinsics.h>
00045 
00046 /* BIT_SWAP - swaps up to 16 bits of the integer _i according to the 
00047  *            pattern specified by _pat.
00048  */
00049 #define BIT_SWAP(_i, _pat)        spu_extract(spu_gather(spu_shuffle(spu_maskb(_i), _pat, _pat)), 0)
00050 
00051 
00052 #ifndef MAX_FFT_1D_SIZE
00053 #define MAX_FFT_1D_SIZE 8192
00054 #endif
00055 
00056 #ifndef INV_SQRT_2
00057 #define INV_SQRT_2      0.7071067811865
00058 #endif
00059 
00060 
00061 /* The following macro, FFT_1D_BUTTERFLY, performs a 4 way SIMD basic butterfly 
00062  * operation. The inputs are in parallel arrays (seperate real and imaginary
00063  * vectors). 
00064  * 
00065  *          p --------------------------> P = p + q*Wi
00066  *                        \      /
00067  *                         \    /
00068  *                          \  /
00069  *                           \/
00070  *                           /\
00071  *                          /  \
00072  *                         /    \
00073  *               ____     /      \
00074  *          q --| Wi |-----------------> Q = p - q*Wi
00075  *               ----
00076  */
00077 
00078 #define FFT_1D_BUTTERFLY(_P_re, _P_im, _Q_re, _Q_im, _p_re, _p_im, _q_re, _q_im, _W_re, _W_im) {        \
00079   vector float _qw_re, _qw_im;                                                                          \
00080                                                                                                         \
00081   _qw_re = spu_msub(_q_re, _W_re, spu_mul(_q_im, _W_im));                                               \
00082   _qw_im = spu_madd(_q_re, _W_im, spu_mul(_q_im, _W_re));                                               \
00083   _P_re  = spu_add(_p_re, _qw_re);                                                                      \
00084   _P_im  = spu_add(_p_im, _qw_im);                                                                      \
00085   _Q_re  = spu_sub(_p_re, _qw_re);                                                                      \
00086   _Q_im  = spu_sub(_p_im, _qw_im);                                                                      \
00087 }
00088 
00089 
00090 /* FFT_1D_BUTTERFLY_HI is equivalent to FFT_1D_BUTTERFLY with twiddle factors (W_im, -W_re)
00091  */
00092 #define FFT_1D_BUTTERFLY_HI(_P_re, _P_im, _Q_re, _Q_im, _p_re, _p_im, _q_re, _q_im, _W_re, _W_im) {     \
00093   vector float _qw_re, _qw_im;                                                                          \
00094                                                                                                         \
00095   _qw_re = spu_madd(_q_re, _W_im, spu_mul(_q_im, _W_re));                                               \
00096   _qw_im = spu_msub(_q_im, _W_im, spu_mul(_q_re, _W_re));                                               \
00097   _P_re  = spu_add(_p_re, _qw_re);                                                                      \
00098   _P_im  = spu_add(_p_im, _qw_im);                                                                      \
00099   _Q_re  = spu_sub(_p_re, _qw_re);                                                                      \
00100   _Q_im  = spu_sub(_p_im, _qw_im);                                                                      \
00101 }
00102 
00103 #endif /* _FFT_1D_H_ */