[ep-processor-libraries/dsplib.git] / ti / dsplib / src / DSPF_sp_fir_gen / c674 / DSPF_sp_fir_gen.c
1 /* ======================================================================= */
2 /* DSPF_sp_fir_gen.c -- FIR Filter */
3 /* Optimized C Implementation (w/ Intrinsics) */
4 /* */
5 /* Rev 0.0.1 */
6 /* */
7 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ */
8 /* */
9 /* */
10 /* Redistribution and use in source and binary forms, with or without */
11 /* modification, are permitted provided that the following conditions */
12 /* are met: */
13 /* */
14 /* Redistributions of source code must retain the above copyright */
15 /* notice, this list of conditions and the following disclaimer. */
16 /* */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in the */
19 /* documentation and/or other materials provided with the */
20 /* distribution. */
21 /* */
22 /* Neither the name of Texas Instruments Incorporated nor the names of */
23 /* its contributors may be used to endorse or promote products derived */
24 /* from this software without specific prior written permission. */
25 /* */
26 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
27 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
28 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
29 /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
30 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
31 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
32 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
33 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
34 /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
35 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
36 /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
37 /* */
38 /* ======================================================================= */
40 #pragma CODE_SECTION(DSPF_sp_fir_gen, ".text:optimized");
42 #include "DSPF_sp_fir_gen.h"
43 #ifdef __TI_COMPILER_VERSION__
44 #include "c6x.h"
45 #endif
47 void DSPF_sp_fir_gen(const float * restrict x,
48 const float * restrict h,
49 float * restrict y,
50 int nh,
51 int ny)
52 {
53 int i, j = 0, k = 0, l = 0, nhm4 = nh - 4;
54 __float2_t x1x0, h1h0;
55 __float2_t x3x2, h3h2;
56 __float2_t x5x4;
57 float sum1=0,sum2=0,sum3=0,sum4=0;
58 float term1, term2, term3, term4, x1, x0, h1, h0;
59 float term5, term6, term7, term8, x2,x3,h2,h3;
60 float term9, term10, term11, term12, term13, term14, term15, term16, x4,x5;
62 _nassert(nh >= 4);
63 _nassert(nh % 4 == 0);
64 _nassert(ny >= 4);
65 _nassert(ny % 4 == 0);
67 #pragma MUST_ITERATE(4,,)
68 for (i = 0; i < (nh * ny) >> 2; i += 4)
69 {
70 //term1 = x[j++] * h[l];
71 //term3 = x[j] * h[l++];
72 //term2 = x[j++] * h[l];
73 //term4 = x[j] * h[l++];
74 x1x0 = _amem8_f2((void *)(x + j));
75 h1h0 = _amem8_f2((void *)(h + l));
77 x3x2 = _amem8_f2((void *)(x + j + 2));
78 h3h2 = _amem8_f2((void *)(h + l + 2));
80 x5x4 = _amem8_f2((void *)(x + j + 4));
81 j += 4;
82 l += 4;
83 x0 = _lof2(x1x0);
84 x1 = _hif2(x1x0);
85 h0 = _lof2(h1h0);
86 h1 = _hif2(h1h0);
88 x2 = _lof2(x3x2);
89 x3 = _hif2(x3x2);
90 h2 = _lof2(h3h2);
91 h3 = _hif2(h3h2);
93 x4 = _lof2(x5x4);
94 x5 = _hif2(x5x4);
96 term1 = x0 * h0;
97 term5 = x1 * h0;
98 term2 = x1 * h1;
99 term6 = x2 * h1;
101 term3 = x2 * h2;
102 term7 = x3 * h2;
103 term4 = x3 * h3;
104 term8 = x4 * h3;
106 term9 = x2 * h0;
107 term13= x3 * h0;
108 term10= x3 * h1;
109 term14= x4 * h1;
111 term11= x4 * h2;
112 term15= x5 * h2;
113 term12= x5 * h3;
114 term16= x[j+2]*h3;
116 sum1 += term1 + term2 + term3 + term4;
117 sum2 += term5 + term6 + term7 + term8;
118 sum3 += term9 + term10+ term11+term12;
119 sum4 += term13+ term14+ term15+term16;
121 if (l >= nh)
122 {
123 _amem8_f2((void *)(y + k )) = _ftof2(sum2, sum1);
124 _amem8_f2((void *)(y + k + 2)) = _ftof2(sum4, sum3);
125 k += 4;
126 j -= nhm4;
127 l = 0;
128 sum1 = 0;
129 sum2 = 0;
130 sum3 = 0;
131 sum4 = 0;
133 }
134 }
135 }
137 /* ======================================================================= */
138 /* End of file: DSPF_sp_fir_gen.c */
139 /* ----------------------------------------------------------------------- */
140 /* Copyright (c) 2011 Texas Instruments, Incorporated. */
141 /* All Rights Reserved. */
142 /* ======================================================================= */