Merged r11397:11413 from balister/arm-configure into trunk. Trunk passes distcheck.
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_fir_fff_armv7_a.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008,2009 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
26 #include <gr_fir_fff_armv7_a.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdexcept>
30 #include <assert.h>
31 #include <gr_math.h>
32 #include <dotprod_fff_armv7_a.h>
33
34 #define FLOATS_PER_VEC 8
35
36 gr_fir_fff_armv7_a::gr_fir_fff_armv7_a()
37   : gr_fir_fff_generic(),
38     d_naligned_taps(0), d_aligned_taps(0)
39 {
40 }
41
42 gr_fir_fff_armv7_a::gr_fir_fff_armv7_a (const std::vector<float> &new_taps)
43   : gr_fir_fff_generic(new_taps),
44     d_naligned_taps(0), d_aligned_taps(0)
45 {
46   set_taps(new_taps);
47 }
48
49 gr_fir_fff_armv7_a::~gr_fir_fff_armv7_a()
50 {
51   if (d_aligned_taps){
52     free(d_aligned_taps);
53     d_aligned_taps = 0;
54   }
55 }
56
57 void
58 gr_fir_fff_armv7_a::set_taps(const std::vector<float> &inew_taps)
59 {
60   gr_fir_fff_generic::set_taps(inew_taps);      // call superclass
61   d_naligned_taps = gr_p2_round_up(ntaps(), FLOATS_PER_VEC);
62
63   if (d_aligned_taps){
64     free(d_aligned_taps);
65     d_aligned_taps = 0;
66   }
67   void *p;
68   int r = posix_memalign(&p,  sizeof(float), d_naligned_taps * sizeof(d_aligned_taps[0]));
69   if (r != 0){
70     throw std::bad_alloc();
71   }
72   d_aligned_taps = (float *) p;
73   memcpy(d_aligned_taps, &d_taps[0], ntaps() * sizeof(d_aligned_taps[0]));
74   for (size_t i = ntaps(); i < d_naligned_taps; i++)
75     d_aligned_taps[i] = 0.0;
76 }
77
78
79 float 
80 gr_fir_fff_armv7_a::filter (const float input[])
81 {
82   if (d_naligned_taps == 0)
83     return 0.0;
84   
85   return dotprod_fff_armv7_a(input, d_aligned_taps, d_naligned_taps);
86 }