3 * Copyright 2002,2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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 2, or (at your option)
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.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <atsci_sliding_correlator.h>
24 #include <atsci_pnXXX.h>
26 // #define TRY_BACKWARDS
29 * Return the number of 1's in v.
30 * This magic code is explained wonderfully in the AMD Athlon
31 * optimization guide, pg 136.
33 static inline int popcount32 (unsigned long v)
35 unsigned long w = v - ((v >> 1) & 0x55555555);
36 unsigned long x = (w & 0x33333333) + ((w >> 2) & 0x33333333);
37 unsigned long y = (x + (x >> 4)) & 0x0f0f0f0f;
38 unsigned long z = (y * 0x01010101) >> 24;
43 atsci_sliding_correlator::atsci_sliding_correlator ()
45 #if defined(TRY_BACKWARDS)
46 for (int i = 511 - 1; i >= 0; i--)
47 mask.shift_in (atsc_pn511[i]);
49 for (unsigned i = 0; i < 511; i++)
50 mask.shift_in (atsc_pn511[i]);
53 and_mask.shift_in (0);
54 for (int i = 0; i < 511; i++)
55 and_mask.shift_in (1);
59 * we shift in from the top of the register towards the bottom
61 * +-- bits enter here...
64 * block 0 | block 1 | block 2 ... | block N-1
66 * +--> ... and drop out here
70 atsci_sliding_correlator::shift_reg::shift_in (int bit)
72 for (int i = NSRBLOCKS - 1; i > 0; i--)
73 d[i] = ((d[i-1] & 0x1) << (srblock_bitsize - 1)) | (d[i] >> 1);
75 d[0] = (((srblock) bit) << (srblock_bitsize - 1)) | (d[0] >> 1);
79 atsci_sliding_correlator::input_bit (int bit)
83 // can probably get a win by unrolling the loop, if we need to.
85 for (int i = 0; i < NSRBLOCKS; i++)
86 count += popcount32 ((input.d[i] ^ mask.d[i]) & and_mask.d[i]);