Merged features/mp-sched -r8915:9335 into the trunk. The trunk now
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_fir_fff_altivec.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include <gr_fir_fff_altivec.h>
26 #include <stdlib.h>
27 #include <stdexcept>
28 #include <assert.h>
29 #include <gr_math.h>
30 #include <gr_altivec.h>
31 #include <dotprod_fff_altivec.h>
32
33 gr_fir_fff_altivec::gr_fir_fff_altivec()
34   : gr_fir_fff_generic(),
35     d_naligned_taps(0), d_aligned_taps(0)
36 {
37 }
38
39 gr_fir_fff_altivec::gr_fir_fff_altivec (const std::vector<float> &new_taps)
40   : gr_fir_fff_generic(new_taps),
41     d_naligned_taps(0), d_aligned_taps(0)
42 {
43   set_taps(new_taps);
44 }
45
46 gr_fir_fff_altivec::~gr_fir_fff_altivec()
47 {
48   if (d_aligned_taps){
49     free(d_aligned_taps);
50     d_aligned_taps = 0;
51   }
52 }
53
54 void
55 gr_fir_fff_altivec::set_taps(const std::vector<float> &inew_taps)
56 {
57   gr_fir_fff_generic::set_taps(inew_taps);      // call superclass
58   d_naligned_taps = gr_p2_round_up(ntaps(), FLOATS_PER_VEC);
59
60   if (d_aligned_taps){
61     free(d_aligned_taps);
62     d_aligned_taps = 0;
63   }
64   void *p;
65   int r = posix_memalign(&p,  sizeof(vector float), d_naligned_taps * sizeof(d_aligned_taps[0]));
66   if (r != 0){
67     throw std::bad_alloc();
68   }
69   d_aligned_taps = (float *) p;
70   memcpy(d_aligned_taps, &d_taps[0], ntaps() * sizeof(d_aligned_taps[0]));
71   for (size_t i = ntaps(); i < d_naligned_taps; i++)
72     d_aligned_taps[i] = 0.0;
73 }
74
75
76 float 
77 gr_fir_fff_altivec::filter (const float input[])
78 {
79   if (d_naligned_taps == 0)
80     return 0.0;
81   
82   return dotprod_fff_altivec(input, d_aligned_taps, d_naligned_taps);
83 }