GNU Radio Manual and C++ API Reference  3.7.7
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
volk_8u_conv_k7_r2puppet_8u.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014 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
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_volk_8u_conv_k7_r2puppet_8u_H
24 #define INCLUDED_volk_8u_conv_k7_r2puppet_8u_H
25 
26 #include <volk/volk.h>
28 #include <string.h>
29 
30 typedef union {
31  //decision_t is a BIT vector
32  unsigned char* t;
33  unsigned int* w;
34 } p_decision_t;
35 
36 static inline int parity(int x, unsigned char* Partab)
37 {
38  x ^= (x >> 16);
39  x ^= (x >> 8);
40  return Partab[x];
41 }
42 
43 static inline int chainback_viterbi(unsigned char* data,
44  unsigned int nbits,
45  unsigned int endstate,
46  unsigned int tailsize,
47  unsigned char* decisions)
48 {
49  unsigned char* d;
50  int d_ADDSHIFT = 0;
51  int d_numstates = (1 << 6);
52  int d_decision_t_size = d_numstates/8;
53  unsigned int d_k = 7;
54  int d_framebits = nbits;
55  /* ADDSHIFT and SUBSHIFT make sure that the thing returned is a byte. */
56  d = decisions;
57  /* Make room beyond the end of the encoder register so we can
58  * accumulate a full byte of decoded data
59  */
60 
61  endstate = (endstate%d_numstates) << d_ADDSHIFT;
62 
63  /* The store into data[] only needs to be done every 8 bits.
64  * But this avoids a conditional branch, and the writes will
65  * combine in the cache anyway
66  */
67 
68  d += tailsize * d_decision_t_size ; /* Look past tail */
69  int retval;
70  int dif = tailsize - (d_k - 1);
71  //printf("break, %d, %d\n", dif, (nbits+dif)%d_framebits);
72  p_decision_t dec;
73  while(nbits-- > d_framebits - (d_k - 1)) {
74  int k;
75  dec.t = &d[nbits * d_decision_t_size];
76  k = (dec.w[(endstate>>d_ADDSHIFT)/32] >> ((endstate>>d_ADDSHIFT)%32)) & 1;
77 
78  endstate = (endstate >> 1) | (k << (d_k-2+d_ADDSHIFT));
79  //data[((nbits+dif)%nbits)>>3] = endstate>>d_SUBSHIFT;
80  //printf("%d, %d\n", k, (nbits+dif)%d_framebits);
81  data[((nbits+dif)%d_framebits)] = k;
82 
83  retval = endstate;
84  }
85  nbits += 1;
86 
87  while(nbits-- != 0) {
88  int k;
89 
90  dec.t = &d[nbits * d_decision_t_size];
91 
92  k = (dec.w[(endstate>>d_ADDSHIFT)/32] >> ((endstate>>d_ADDSHIFT)%32)) & 1;
93 
94  endstate = (endstate >> 1) | (k << (d_k-2+d_ADDSHIFT));
95  data[((nbits+dif)%d_framebits)] = k;
96  }
97  //printf("%d, %d, %d, %d, %d, %d, %d, %d\n", data[4095],data[4094],data[4093],data[4092],data[4091],data[4090],data[4089],data[4088]);
98 
99 
100  return retval >> d_ADDSHIFT;
101 }
102 
103 
104 #if LV_HAVE_SSE3
105 
106 #include <pmmintrin.h>
107 #include <emmintrin.h>
108 #include <xmmintrin.h>
109 #include <mmintrin.h>
110 #include <stdio.h>
111 
112 
113 
114 
115 
116 static inline void volk_8u_conv_k7_r2puppet_8u_spiral(unsigned char* syms, unsigned char* dec, unsigned int framebits) {
117 
118 
119  static int once = 1;
120  int d_numstates = (1 << 6);
121  int rate = 2;
122  static unsigned char* D;
123  static unsigned char* Y;
124  static unsigned char* X;
125  static unsigned int excess = 6;
126  static unsigned char* Branchtab;
127  static unsigned char Partab[256];
128 
129  int d_polys[2] = {79, 109};
130 
131 
132  if(once) {
133 
134  X = (unsigned char*)volk_malloc(2*d_numstates, volk_get_alignment());
135  Y = X + d_numstates;
136  Branchtab = (unsigned char*)volk_malloc(d_numstates/2*rate, volk_get_alignment());
137  D = (unsigned char*)volk_malloc((d_numstates/8) * (framebits + 6), volk_get_alignment());
138  int state, i;
139  int cnt,ti;
140 
141  /* Initialize parity lookup table */
142  for(i=0;i<256;i++){
143  cnt = 0;
144  ti = i;
145  while(ti){
146  if(ti & 1)
147  cnt++;
148  ti >>= 1;
149  }
150  Partab[i] = cnt & 1;
151  }
152  /* Initialize the branch table */
153  for(state=0;state < d_numstates/2;state++){
154  for(i=0; i<rate; i++){
155  Branchtab[i*d_numstates/2+state] = (d_polys[i] < 0) ^ parity((2*state) & abs(d_polys[i]), Partab) ? 255 : 0;
156  }
157  }
158 
159  once = 0;
160  }
161 
162  //unbias the old_metrics
163  memset(X, 31, d_numstates);
164 
165  volk_8u_x4_conv_k7_r2_8u_spiral(Y, X, syms, D, framebits/2 - excess, excess, Branchtab);
166 
167  unsigned int min = X[0];
168  int i = 0, state = 0;
169  for(i = 0; i < (d_numstates); ++i) {
170  if(X[i] < min) {
171  min = X[i];
172  state = i;
173  }
174  }
175 
176  chainback_viterbi(dec, framebits/2 -excess, state, excess, D);
177 
178  return;
179 }
180 
181 #endif /*LV_HAVE_SSE3*/
182 
183 
184 
185 
186 
187 #if LV_HAVE_GENERIC
188 
189 
190 static inline void volk_8u_conv_k7_r2puppet_8u_generic(unsigned char* syms, unsigned char* dec, unsigned int framebits) {
191 
192 
193 
194  static int once = 1;
195  int d_numstates = (1 << 6);
196  int rate = 2;
197  static unsigned char* Y;
198  static unsigned char* X;
199  static unsigned char* D;
200  static unsigned int excess = 6;
201  static unsigned char* Branchtab;
202  static unsigned char Partab[256];
203 
204  int d_polys[2] = {79, 109};
205 
206 
207  if(once) {
208 
209  X = (unsigned char*)volk_malloc(2*d_numstates, volk_get_alignment());
210  Y = X + d_numstates;
211  Branchtab = (unsigned char*)volk_malloc(d_numstates/2*rate, volk_get_alignment());
212  D = (unsigned char*)volk_malloc((d_numstates/8) * (framebits + 6), volk_get_alignment());
213 
214  int state, i;
215  int cnt,ti;
216 
217  /* Initialize parity lookup table */
218  for(i=0;i<256;i++){
219  cnt = 0;
220  ti = i;
221  while(ti){
222  if(ti & 1)
223  cnt++;
224  ti >>= 1;
225  }
226  Partab[i] = cnt & 1;
227  }
228  /* Initialize the branch table */
229  for(state=0;state < d_numstates/2;state++){
230  for(i=0; i<rate; i++){
231  Branchtab[i*d_numstates/2+state] = (d_polys[i] < 0) ^ parity((2*state) & abs(d_polys[i]), Partab) ? 255 : 0;
232  }
233  }
234 
235  once = 0;
236  }
237 
238 
239 
240 
241  //unbias the old_metrics
242  memset(X, 31, d_numstates);
243 
244  volk_8u_x4_conv_k7_r2_8u_generic(Y, X, syms, D, framebits/2 - excess, excess, Branchtab);
245 
246  unsigned int min = X[0];
247  int i = 0, state = 0;
248  for(i = 0; i < (d_numstates); ++i) {
249  if(X[i] < min) {
250  min = X[i];
251  state = i;
252  }
253  }
254 
255  chainback_viterbi(dec, framebits/2 -excess, state, excess, D);
256 
257  return;
258 
259 
260 }
261 
262 #endif /* LV_HAVE_GENERIC */
263 
264 #endif /*INCLUDED_volk_8u_conv_k7_r2puppet_8u_H*/
unsigned char * t
Definition: volk_8u_conv_k7_r2puppet_8u.h:32
float min(float a, float b)
Definition: volk_8u_conv_k7_r2puppet_8u.h:30
VOLK_API size_t volk_get_alignment(void)
Get the machine alignment in bytes.
static int chainback_viterbi(unsigned char *data, unsigned int nbits, unsigned int endstate, unsigned int tailsize, unsigned char *decisions)
Definition: volk_8u_conv_k7_r2puppet_8u.h:43
__VOLK_DECL_BEGIN VOLK_API void * volk_malloc(size_t size, size_t alignment)
Allocate size bytes of data aligned to alignment.
static int parity(int x, unsigned char *Partab)
Definition: volk_8u_conv_k7_r2puppet_8u.h:36
unsigned int * w
Definition: volk_8u_conv_k7_r2puppet_8u.h:33