1 /* ======================================================================= */
2 /* DSPF_sp_fircirc.c -- Circular 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_fircirc, ".text:optimized");
42 #include "DSPF_sp_fircirc.h"
43 #ifdef __TI_COMPILER_VERSION__
44 #include "c6x.h"
45 #endif
47 #ifdef _LITTLE_ENDIAN
48 void DSPF_sp_fircirc(const float *x, float *h, float *restrict y,
49 int index, int csize, int nh, int ny)
50 {
51 int i, j;
52 /* Circular Buffer block size = ((2^(csize + 1)) / 4) floating point numbers */
53 int mod = (1 << (csize - 1)) - 1;
54 __float2_t x_10, x_21, x_32, x_43, x_54, h_10;
55 __float2_t sum1, sum2, sum3, sum4;
57 _nassert(nh >= 2);
58 _nassert(nh % 2 == 0);
59 _nassert(ny >= 4);
60 _nassert(ny % 4 == 0);
61 _nassert((int) x % 8 == 0);
62 _nassert((int) y % 8 == 0);
63 _nassert((int) h % 8 == 0);
65 #pragma MUST_ITERATE(1,,)
66 for(j = 0; j < ny; j+=4)
67 {
68 sum1 = 0;
69 sum2 = 0;
70 sum3 = 0;
71 sum4 = 0;
73 x_10 = _amem8_f2_const(&x[(j+index) & (mod)]);
74 x_32 = _amem8_f2_const(&x[(j+2+index) & (mod)]);
75 x_21 = _ftof2(_lof2(x_32), _hif2(x_10));
77 /* note: h coeffs given in reverse order: { h[nh-1], h[nh-2], ..., h[0] } */
78 #pragma MUST_ITERATE(1,,)
79 for(i = 0; i < nh; i+=2) {
80 h_10 = _amem8_f2_const(&h[i]);
81 x_54 = _amem8_f2_const(&x[(j+i+4+index) & (mod)]);
82 x_43 = _ftof2(_lof2(x_54), _hif2(x_32));
84 sum1 = _daddsp(sum1, _dmpysp(x_10, h_10));
85 sum2 = _daddsp(sum2, _dmpysp(x_21, h_10));
86 sum3 = _daddsp(sum3, _dmpysp(x_32, h_10));
87 sum4 = _daddsp(sum4, _dmpysp(x_43, h_10));
89 x_10 = x_32;
90 x_21 = x_43;
91 x_32 = x_54;
92 }
93 _amem8_f2(&y[j]) = _ftof2(_hif2(sum2)+_lof2(sum2), _hif2(sum1)+_lof2(sum1));
94 _amem8_f2(&y[j+2]) = _ftof2(_hif2(sum4)+_lof2(sum4), _hif2(sum3)+_lof2(sum3));
95 }
96 }
97 #else
98 void DSPF_sp_fircirc(const float *x, float *h, float *restrict y,
99 int index, int csize, int nh, int ny)
100 {
101 int i, j;
102 /* Circular Buffer block size = ((2^(csize + 1)) / 4) floating point numbers */
103 int mod = (1 << (csize - 1)) - 1;
104 __float2_t x_01, x_12, x_23, x_34, x_45, h_01;
105 __float2_t sum1, sum2, sum3, sum4;
107 _nassert(nh >= 2);
108 _nassert(nh % 2 == 0);
109 _nassert(ny >= 4);
110 _nassert(ny % 4 == 0);
111 _nassert((int) x % 8 == 0);
112 _nassert((int) y % 8 == 0);
113 _nassert((int) h % 8 == 0);
115 #pragma MUST_ITERATE(1,,)
116 for(j = 0; j < ny; j+=4)
117 {
118 sum1 = 0;
119 sum2 = 0;
120 sum3 = 0;
121 sum4 = 0;
123 x_01 = _amem8_f2_const(&x[(j+index) & (mod)]);
124 x_23 = _amem8_f2_const(&x[(j+2+index) & (mod)]);
125 x_12 = _ftof2(_lof2(x_01), _hif2(x_23));
127 /* note: h coeffs given in reverse order: { h[nh-1], h[nh-2], ..., h[0] } */
128 #pragma MUST_ITERATE(1,,)
129 for(i = 0; i < nh; i+=2) {
130 h_01 = _amem8_f2_const(&h[i]);
131 x_45 = _amem8_f2_const(&x[(j+i+4+index) & (mod)]);
132 x_34 = _ftof2(_lof2(x_23), _hif2(x_45));
134 sum1 = _daddsp(sum1, _dmpysp(x_01, h_01));
135 sum2 = _daddsp(sum2, _dmpysp(x_12, h_01));
136 sum3 = _daddsp(sum3, _dmpysp(x_23, h_01));
137 sum4 = _daddsp(sum4, _dmpysp(x_34, h_01));
139 x_01 = x_23;
140 x_12 = x_34;
141 x_23 = x_45;
142 }
143 _amem8_f2(&y[j]) = _ftof2(_hif2(sum1)+_lof2(sum1), _hif2(sum2)+_lof2(sum2));
144 _amem8_f2(&y[j+2]) = _ftof2(_hif2(sum3)+_lof2(sum3), _hif2(sum4)+_lof2(sum4));
145 }
146 }
147 #endif
148 /* ======================================================================= */
149 /* End of file: DSPF_sp_fircirc.c */
150 /* ----------------------------------------------------------------------- */
151 /* Copyright (c) 2011 Texas Instruments, Incorporated. */
152 /* All Rights Reserved. */
153 /* ======================================================================= */