commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 21/57: fec: improved fecapi stuff.


From: git
Subject: [Commit-gnuradio] [gnuradio] 21/57: fec: improved fecapi stuff.
Date: Wed, 21 May 2014 03:10:26 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit f8ccc154d7f860d0b9c52c451a2ec7cf0fbc41d9
Author: Nick McCarthy <address@hidden>
Date:   Fri Mar 28 14:54:55 2014 -0700

    fec: improved fecapi stuff.
    
    Fixes for frame lengths, (de)interleave usage, generic conv volk kernel.
---
 gr-fec/lib/cc_decoder_impl.cc                   | 109 ++++++------------
 gr-fec/lib/cc_decoder_impl.h                    |   1 +
 gr-fec/python/fec/capillary_threaded_decoder.py |   2 +-
 gr-fec/python/fec/threaded_encoder.py           |   4 +-
 volk/kernels/volk/volk_8u_x4_conv_k7_r2_8u.h    | 145 +++++++++++++++---------
 5 files changed, 133 insertions(+), 128 deletions(-)

diff --git a/gr-fec/lib/cc_decoder_impl.cc b/gr-fec/lib/cc_decoder_impl.cc
index e09064c..e8d8671 100644
--- a/gr-fec/lib/cc_decoder_impl.cc
+++ b/gr-fec/lib/cc_decoder_impl.cc
@@ -76,33 +76,18 @@ namespace gr {
 
         d_decision_t_size = d_numstates/8; //packed bit array
 
+        d_managed_in_size = 0;
         if(d_tailbiting) {
           d_end_state = &d_end_state_chaining;
           d_veclen = d_framebits + (6 * (d_k - 1));
           d_managed_in = 
(COMPUTETYPE*)volk_malloc(d_veclen*d_rate*sizeof(COMPUTETYPE),
                                                    volk_get_alignment());
-          if(d_managed_in) {
-            printf("allocation failed\n");
-            exit(1);
+          d_managed_in_size = d_veclen * d_rate;
+          if(d_managed_in == NULL) {
+            throw std::runtime_error("bad alloc for d_managed_in!\n");
           }
         }
-        /*
-        else if(d_trunc_intrinsic) {
-          d_end_state = &d_end_state_nonchaining;
-          d_veclen = d_framebits + d_k - 1;
-          if(posix_memalign((void**)&d_managed_in, 16, d_veclen * d_rate * 
sizeof(COMPUTETYPE))){
-            printf("allocation failed\n");
-            exit(1);
-          }
-          int cnt = 0;
-          for(int i = 0; i < d_rate; ++i) {
-            if (d_polys[i] != 1) {
-              cnt++;
-            }
-          }
-          d_partial_rate = cnt;
-        }
-        */
+        
         else if(d_truncated) {
           d_end_state = &d_end_state_chaining;
           d_veclen = d_framebits;
@@ -118,24 +103,30 @@ namespace gr {
           d_veclen = d_framebits + d_k - 1;
         }
 
-        if(posix_memalign((void**)&d_vp->metrics, 16, 2 * d_numstates * 
sizeof(COMPUTETYPE))) {
-          printf("allocation failed\n");
-          exit(1);
+        d_vp->metrics = (COMPUTETYPE*) volk_malloc(2 * sizeof(COMPUTETYPE) * 
d_numstates, volk_get_alignment());
+        if(d_vp->metrics == NULL) {
+          throw std::runtime_error("bad alloc for d_vp->metrics!\n");
         }
 
+        
+
         d_vp->metrics1.t = d_vp->metrics;
         d_vp->metrics2.t = d_vp->metrics + d_numstates;
 
-        if(posix_memalign((void**)&d_vp->decisions, 
16,d_veclen*d_decision_t_size)) {
-          printf("allocation failed\n");
-          exit(1);
+        d_vp->decisions = (DECISIONTYPE*) 
volk_malloc(d_veclen*d_decision_t_size, volk_get_alignment());
+        if(d_vp->decisions == NULL) {
+          throw std::runtime_error("bad alloc for d_vp->decisions!\n");
         }
 
-        if(posix_memalign((void**)&Branchtab, 16, sizeof(COMPUTETYPE) * 
d_numstates/2*rate)) {
-          printf("allocation failed\n");
-          exit(1);
+        
+
+        Branchtab = (COMPUTETYPE*) volk_malloc(sizeof(COMPUTETYPE) * 
d_numstates/2*rate, volk_get_alignment());
+        if(Branchtab == NULL) {
+          throw std::runtime_error("bad alloc for d_vp->decisions!\n");
         }
 
+        
+
         create_viterbi();
 
         if(d_k-1<8) {
@@ -182,17 +173,7 @@ namespace gr {
         if(d_terminated) {
           return d_rate * (d_framebits + d_k - 1);
         }
-        /*
-        else if(d_trunc_intrinsic) {
-          int cnt = 0;
-          for(int i = 0; i < d_rate; ++i) {
-            if (d_polys[i] != 1) {
-              cnt++;
-            }
-          }
-          return (d_rate * (d_framebits)) + (cnt * (d_k - 1));
-        }
-        */
+        
         else {
           return d_rate * d_framebits;
         }
@@ -215,9 +196,7 @@ namespace gr {
         }
       }
 
-      /*const char* cc_decoder_impl::get_output_conversion() {
-        return "unpack";
-        }*/
+      
 
       float
       cc_decoder_impl::get_shift()
@@ -330,7 +309,8 @@ namespace gr {
       int
       cc_decoder_impl::find_endstate()
       {
-        COMPUTETYPE* met = (d_k%2 == 0)? d_vp->new_metrics.t : 
d_vp->old_metrics.t;
+        COMPUTETYPE* met = ((d_k + d_veclen)%2 == 0)? d_vp->new_metrics.t : 
d_vp->old_metrics.t;
+
         COMPUTETYPE min = met[0];
         int state = 0;
         for(int i = 1; i < d_numstates; ++i) {
@@ -338,7 +318,10 @@ namespace gr {
             min = met[i];
             state = i;
           }
+
+          
         }
+        //printf("min %d\n", state);
         return state;
       }
 
@@ -348,11 +331,11 @@ namespace gr {
         DECISIONTYPE *d;
 
         d = d_vp->decisions;
-        //going to have to use nbits for tailbiting?
-        //memset(d,0,d_decision_t_size * (d_framebits+d_k-1));//use volk here?
-        memset(d,0,d_decision_t_size * nbits);//use volk here?
 
-        //d_kernel( d_vp->new_metrics.t, d_vp->old_metrics.t, syms, d, 
d_framebits, d_k - 1, Branchtab);
+        
+        memset(d,0,d_decision_t_size * nbits);
+
+
         d_kernel( d_vp->new_metrics.t, d_vp->old_metrics.t, syms, d, nbits - 
(d_k - 1), d_k -1, Branchtab);
 
         return 0;
@@ -418,6 +401,9 @@ namespace gr {
         d_framebits = framebits;
         if(d_tailbiting) {
           d_veclen = d_framebits + (6 * (d_k - 1));
+          if(d_veclen * d_rate > d_managed_in_size) {
+            throw std::runtime_error("attempt to resize beyond d_managed_in 
buffer size!\n");
+          }
         }
         else if(d_truncated) {
           d_veclen = d_framebits;
@@ -446,30 +432,7 @@ namespace gr {
           init_viterbi_unbiased(d_vp);
         }
 
-        /*
-        else if(d_trunc_intrinsic) {
-          memcpy(d_managed_in, in, d_framebits * d_rate * sizeof(COMPUTETYPE));
-          for(int i = 0; i < (d_k - 1); ++i) {
-            int cnt = 0;
-            for(int j = 0; j < d_rate; ++j) {
-              if(d_polys[j] != 1) {
-
-                d_managed_in[(d_framebits * d_rate) + (i * d_rate) + j] =
-                  in[(d_framebits * d_rate) + (i * d_partial_rate) + cnt++];
-              }
-              else {
-
-                d_managed_in[(d_framebits * d_rate) + (i * d_rate) + j] =
-                  (((*d_end_state) >> (d_k - 2 - i)) & 1) * ((1 << 
(sizeof(COMPUTETYPE) * 8)) - 1);
-              }
-            }
-          }
-          update_viterbi_blk(d_managed_in, d_veclen);
-          d_end_state_chaining = find_endstate();
-          chainback_viterbi(&out[0], d_framebits, *d_end_state, d_veclen - 
d_framebits);
-          init_viterbi(d_vp, *d_start_state);
-        }
-        */
+        
 
         else if(d_truncated) {
           update_viterbi_blk((COMPUTETYPE*)(&in[0]), d_veclen);
@@ -490,7 +453,7 @@ namespace gr {
         else {
           update_viterbi_blk((COMPUTETYPE*)(&in[0]), d_veclen);
           d_end_state_chaining = find_endstate();
-          //printf("es: %d\n", d_end_state_chaining);
+          //printf("es: %d, %d\n", d_end_state_chaining, *d_end_state);
           d_start_state_chaining = chainback_viterbi(&out[0], d_framebits, 
*d_end_state,
                                                      d_veclen - d_framebits);
 
diff --git a/gr-fec/lib/cc_decoder_impl.h b/gr-fec/lib/cc_decoder_impl.h
index 7fe0934..725a27d 100644
--- a/gr-fec/lib/cc_decoder_impl.h
+++ b/gr-fec/lib/cc_decoder_impl.h
@@ -71,6 +71,7 @@ namespace gr {
         std::vector<int> d_polys;
         struct v* d_vp;
         COMPUTETYPE* d_managed_in;
+        unsigned int d_managed_in_size;
         int d_numstates;
         int d_decision_t_size;
         int *d_start_state;
diff --git a/gr-fec/python/fec/capillary_threaded_decoder.py 
b/gr-fec/python/fec/capillary_threaded_decoder.py
index 67c3979..fcfa39e 100644
--- a/gr-fec/python/fec/capillary_threaded_decoder.py
+++ b/gr-fec/python/fec/capillary_threaded_decoder.py
@@ -46,7 +46,7 @@ class capillary_threaded_decoder(gr.hier_block2):
         self.interleaves_0 = []
         for i in range(int(math.log(len(decoder_list_0), 2))):
             for j in range(int(math.pow(2, i))):
-                self.interleaves_0.append(fec.interleave(output_size,
+                self.interleaves_0.append(blocks.interleave(output_size,
                                                          
fec.get_decoder_output_size(decoder_list_0[0])))
 
         rootcount = 0
diff --git a/gr-fec/python/fec/threaded_encoder.py 
b/gr-fec/python/fec/threaded_encoder.py
index b20a07a..6779b04 100644
--- a/gr-fec/python/fec/threaded_encoder.py
+++ b/gr-fec/python/fec/threaded_encoder.py
@@ -32,7 +32,7 @@ class threaded_encoder(gr.hier_block2):
 
         self.encoder_list_0 = encoder_list_0
 
-        self.fec_deinterleave_0 = fec.deinterleave(input_size,
+        self.fec_deinterleave_0 = blocks.deinterleave(input_size,
                                                    
fec.get_encoder_input_size(encoder_list_0[0]))
 
         self.generic_encoders_0 = [];
@@ -40,7 +40,7 @@ class threaded_encoder(gr.hier_block2):
             self.generic_encoders_0.append(fec.encoder(encoder_list_0[i],
                                                        input_size, 
output_size))
 
-        self.fec_interleave_0 = fec.interleave(output_size,
+        self.fec_interleave_0 = blocks.interleave(output_size,
                                                
fec.get_encoder_output_size(encoder_list_0[0]))
 
         for i in range(len(encoder_list_0)):
diff --git a/volk/kernels/volk/volk_8u_x4_conv_k7_r2_8u.h 
b/volk/kernels/volk/volk_8u_x4_conv_k7_r2_8u.h
index db1750e..dfed73b 100644
--- a/volk/kernels/volk/volk_8u_x4_conv_k7_r2_8u.h
+++ b/volk/kernels/volk/volk_8u_x4_conv_k7_r2_8u.h
@@ -2,6 +2,65 @@
 #define INCLUDED_volk_8u_x4_conv_k7_r2_8u_H
 
 
+
+typedef union {
+  unsigned char/*DECISIONTYPE*/ t[64/*NUMSTATES*//8/*DECISIONTYPE_BITSIZE*/];
+  unsigned int w[64/*NUMSTATES*//32];
+  unsigned short s[64/*NUMSTATES*//16];
+  unsigned char c[64/*NUMSTATES*//8];
+} decision_t __attribute__ ((aligned (16)));
+
+static inline void renormalize(unsigned char* X, unsigned char threshold){
+  int NUMSTATES = 64;
+  int i;
+
+    unsigned char min=X[0];
+    //if(min > threshold) {
+    for(i=0;i<NUMSTATES;i++)
+    if (min>X[i])
+      min=X[i];
+    for(i=0;i<NUMSTATES;i++)
+      X[i]-=min;
+    //}
+}
+
+
+
+//helper BFLY for GENERIC version
+static inline void BFLY(int i, int s, unsigned char * syms, unsigned char *Y, 
unsigned char *X, decision_t * d, unsigned char* Branchtab) {
+  int j, decision0, decision1;
+  unsigned char metric,m0,m1,m2,m3;
+
+  int NUMSTATES = 64;
+  int RATE = 2;
+  int METRICSHIFT = 1;
+  int PRECISIONSHIFT = 2;
+
+  
+
+  metric =0;
+  for(j=0;j<RATE;j++)
+    metric += (Branchtab[i+j*NUMSTATES/2] ^ syms[s*RATE+j])>>METRICSHIFT ;
+  metric=metric>>PRECISIONSHIFT;
+
+  unsigned char max = ((RATE*((256 -1)>>METRICSHIFT))>>PRECISIONSHIFT);
+
+  m0 = X[i] + metric;
+  m1 = X[i+NUMSTATES/2] + (max - metric);
+  m2 = X[i] + (max - metric);
+  m3 = X[i+NUMSTATES/2] + metric;
+
+  decision0 = (signed int)(m0-m1) > 0;
+  decision1 = (signed int)(m2-m3) > 0;
+
+  Y[2*i] = decision0 ? m1 : m0;
+  Y[2*i+1] =  decision1 ? m3 : m2;
+
+  d->w[i/(sizeof(unsigned int)*8/2)+s*(sizeof(decision_t)/sizeof(unsigned 
int))] |=
+    (decision0|decision1<<1) << ((2*i)&(sizeof(unsigned int)*8-1));
+}
+
+
 #if LV_HAVE_SSE3
 
 #include <pmmintrin.h>
@@ -12,7 +71,7 @@
 
 static inline void volk_8u_x4_conv_k7_r2_8u_spiral(unsigned char* Y, unsigned 
char* X, unsigned char* syms, unsigned char* dec, unsigned int framebits, 
unsigned int excess, unsigned char* Branchtab) {
   unsigned int i9;
-  for(i9 = 0; i9 < (framebits >> 1) + (excess >> 1); i9++) {
+  for(i9 = 0; i9 < ((framebits + excess) >> 1); i9++) {
     unsigned char a75, a81;
     int a73, a92;
     short int s20, s21, s26, s27;
@@ -261,66 +320,41 @@ static inline void 
volk_8u_x4_conv_k7_r2_8u_spiral(unsigned char* Y, unsigned ch
       ((__m128i  *) X)[3] = _mm_subs_epu8(((__m128i  *) X)[3], m13);
     }
   }
-  /*skip*/
-  return;
-}
-
-#endif /*LV_HAVE_SSE3*/
-
-
-static inline void renormalize(unsigned char* X, unsigned char threshold){
-  int NUMSTATES = 64;
-  int i;
-  if (X[0]>threshold){
-    unsigned char min=X[0];
-    for(i=0;i<NUMSTATES;i++)
-    if (min>X[i])
-      min=X[i];
-    for(i=0;i<NUMSTATES;i++)
-      X[i]-=min;
-      }
-}
-
-typedef union {
-  unsigned char/*DECISIONTYPE*/ t[64/*NUMSTATES*//8/*DECISIONTYPE_BITSIZE*/];
-  unsigned int w[64/*NUMSTATES*//32];
-  unsigned short s[64/*NUMSTATES*//16];
-  unsigned char c[64/*NUMSTATES*//8];
-} decision_t __attribute__ ((aligned (16)));
 
+  renormalize(X, 210);
 
+  /*int ch;
+  for(ch = 0; ch < 64; ch++) {
+    printf("%d,", X[ch]);
+  }
+  printf("\n");*/
 
-//helper BFLY for GENERIC version
-static inline void BFLY(int i, int s, unsigned char * syms, unsigned char *Y, 
unsigned char *X, decision_t * d, unsigned char* Branchtab) {
-  int j, decision0, decision1;
-  unsigned char metric,m0,m1,m2,m3;
+  unsigned int j;
+  for(j=0; j < (framebits + excess) % 2; ++j) {
+    int i;
+    for(i=0;i<64/2;i++){
+      BFLY(i, (((framebits+excess) >> 1) << 1) + j , syms, Y, X, (decision_t 
*)dec, Branchtab);
+    }
+    
 
-  int NUMSTATES = 64;
-  int RATE = 2;
-  int METRICSHIFT = 1;
-  int PRECISIONSHIFT = 2;
+    renormalize(Y, 210);
 
-  metric =0;
-  for(j=0;j<RATE;j++)
-    metric += (Branchtab[i+j*NUMSTATES/2] ^ syms[s*RATE+j])>>METRICSHIFT ;
-  metric=metric>>PRECISIONSHIFT;
+    /*printf("\n");
+    for(ch = 0; ch < 64; ch++) {
+      printf("%d,", Y[ch]);
+    }
+    printf("\n");*/
+    
+  }
+  /*skip*/
+  return;
+}
 
-  unsigned char max = ((RATE*((256 -1)>>METRICSHIFT))>>PRECISIONSHIFT);
+#endif /*LV_HAVE_SSE3*/
 
-  m0 = X[i] + metric;
-  m1 = X[i+NUMSTATES/2] + (max - metric);
-  m2 = X[i] + (max - metric);
-  m3 = X[i+NUMSTATES/2] + metric;
 
-  decision0 = (signed int)(m0-m1) > 0;
-  decision1 = (signed int)(m2-m3) > 0;
 
-  Y[2*i] = decision0 ? m1 : m0;
-  Y[2*i+1] =  decision1 ? m3 : m2;
 
-  d->w[i/(sizeof(unsigned int)*8/2)+s*(sizeof(decision_t)/sizeof(unsigned 
int))] |=
-    (decision0|decision1<<1) << ((2*i)&(sizeof(unsigned int)*8-1));
-}
 
 
 
@@ -330,15 +364,21 @@ static inline void BFLY(int i, int s, unsigned char * 
syms, unsigned char *Y, un
 static inline void volk_8u_x4_conv_k7_r2_8u_generic(unsigned char* Y, unsigned 
char* X, unsigned char* syms, unsigned char* dec, unsigned int framebits, 
unsigned int excess, unsigned char* Branchtab) {
   int nbits = framebits + excess;
   int NUMSTATES = 64;
-  int RENORMALIZE_THRESHOLD = 137;
+  int RENORMALIZE_THRESHOLD = 210;
+
 
   int s,i;
+  
+
+  
   for (s=0;s<nbits;s++){
     void *tmp;
     for(i=0;i<NUMSTATES/2;i++){
       BFLY(i, s, syms, Y, X, (decision_t *)dec, Branchtab);
     }
 
+   
+
     renormalize(Y, RENORMALIZE_THRESHOLD);
 
     ///     Swap pointers to old and new metrics
@@ -347,6 +387,7 @@ static inline void 
volk_8u_x4_conv_k7_r2_8u_generic(unsigned char* Y, unsigned c
     Y = (unsigned char*)tmp;
   }
 
+
   return;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]