commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 94/148: Replaced the need for code word tab


From: git
Subject: [Commit-gnuradio] [gnuradio] 94/148: Replaced the need for code word tables by setting the header/trailer lengths in the switch body jump table, just like in the unparser switch body.
Date: Mon, 15 Aug 2016 00:47:28 +0000 (UTC)

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

nwest pushed a commit to annotated tag old_usrp_devel_udp
in repository gnuradio.

commit 5f8d21ca7a147d6634dfdab1d335405a59dc6b34
Author: Josh Blum <address@hidden>
Date:   Thu Dec 17 17:29:45 2009 -0800

    Replaced the need for code word tables by setting the header/trailer lengths
    in the switch body jump table, just like in the unparser switch body.
---
 vrt/lib/Makefile.am                         |  2 -
 vrt/lib/expanded_header.cc                  | 22 ++++-----
 vrt/lib/expanded_header_cw_tables.h         | 14 ------
 vrt/lib/expanded_header_parse_switch_body.h | 64 ++++++++++++++++++++++++++
 vrt/lib/gen_cw_tables.py                    | 69 -----------------------------
 vrt/lib/gen_parse_switch_body.py            | 11 +++--
 6 files changed, 83 insertions(+), 99 deletions(-)

diff --git a/vrt/lib/Makefile.am b/vrt/lib/Makefile.am
index f2fcce0..303384c 100644
--- a/vrt/lib/Makefile.am
+++ b/vrt/lib/Makefile.am
@@ -41,12 +41,10 @@ libvrt_la_LIBADD =
 # Private headers not needed for above the API development
 noinst_HEADERS = \
        data_handler.h \
-       expanded_header_cw_tables.h \
        expanded_header_parse_switch_body.h \
        expanded_header_unparse_switch_body.h \
        socket_rx_buffer.h
 
 EXTRA_DIST = \
-       gen_cw_tables.py \
        gen_parse_switch_body.py \
        gen_unparse_switch_body.py
diff --git a/vrt/lib/expanded_header.cc b/vrt/lib/expanded_header.cc
index 64e97ef..8b22fb9 100644
--- a/vrt/lib/expanded_header.cc
+++ b/vrt/lib/expanded_header.cc
@@ -57,8 +57,6 @@ namespace vrt {
   static const int HAS_FRACTIONAL_SECS = 1 << 3;
   static const int HAS_TRAILER         = 1 << 4;
 
-#include "expanded_header_cw_tables.h"
-
   static int
   compute_codeword(const expanded_header &h)
   {
@@ -94,6 +92,8 @@ namespace vrt {
                        const uint32_t **payload,       // out
                        size_t *n32_bit_words_payload)  // out
   {
+    size_t n32_bit_words_header = 0;
+    size_t n32_bit_words_trailer = 0;
     size_t len = n32_bit_words_packet;
     const uint32_t *p = packet;
 
@@ -115,19 +115,19 @@ namespace vrt {
     len = h->pkt_size();       // valid length of packet
 
     int cw = compute_codeword(*h);
-    if (cw_header_len(cw) + cw_trailer_len(cw) > len)
-      return false;            // negative payload len
-
-    *payload = p + cw_header_len(cw);
-    *n32_bit_words_payload = len - (cw_header_len(cw) + cw_trailer_len(cw));
-
-    // printf("parse: hdr = 0x%08x, cw = 0x%02x, cw_header_len(cw) = %d, 
cw_trailer_len(cw) = %d\n",
-    //   h->header, cw, cw_header_len(cw), cw_trailer_len(cw));
-
     switch (cw & 0x1f){
 #include "expanded_header_parse_switch_body.h"
     }
 
+    if (n32_bit_words_header + n32_bit_words_trailer > len)
+      return false;            // negative payload len
+
+    *payload = p + n32_bit_words_header;
+    *n32_bit_words_payload = len - (n32_bit_words_header + 
n32_bit_words_trailer);
+
+    // printf("parse: hdr = 0x%08x, cw = 0x%02x, n32_bit_words_header = %d, 
n32_bit_words_trailer = %d\n",
+    //   h->header, cw, n32_bit_words_header, n32_bit_words_trailer);
+
     return true;
   }
 
diff --git a/vrt/lib/expanded_header_cw_tables.h 
b/vrt/lib/expanded_header_cw_tables.h
deleted file mode 100644
index fbb9c6b..0000000
--- a/vrt/lib/expanded_header_cw_tables.h
+++ /dev/null
@@ -1,14 +0,0 @@
-inline static size_t cw_header_len(int cw){
-  static const size_t s_cw_header_len[32] = {
-    1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 1, 2, 3, 4, 2, 3, 4, 5, 3, 
4, 5, 6, 4, 5, 6, 7, 
-  };
-  return s_cw_header_len[cw];
-}
-
-inline static size_t cw_trailer_len(int cw){
-  static const size_t s_cw_trailer_len[32] = {
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 
-  };
-  return s_cw_trailer_len[cw];
-}
-
diff --git a/vrt/lib/expanded_header_parse_switch_body.h 
b/vrt/lib/expanded_header_parse_switch_body.h
index 40e575c..6bfaf37 100644
--- a/vrt/lib/expanded_header_parse_switch_body.h
+++ b/vrt/lib/expanded_header_parse_switch_body.h
@@ -3,7 +3,9 @@
     h->class_id = 0;
     h->integer_secs = 0;
     h->fractional_secs = 0;
+    n32_bit_words_header = 1;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 1:
@@ -11,7 +13,9 @@
     h->class_id = 0;
     h->integer_secs = 0;
     h->fractional_secs = 0;
+    n32_bit_words_header = 2;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 2:
@@ -19,7 +23,9 @@
     h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
     h->integer_secs = 0;
     h->fractional_secs = 0;
+    n32_bit_words_header = 3;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 3:
@@ -27,7 +33,9 @@
     h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
     h->integer_secs = 0;
     h->fractional_secs = 0;
+    n32_bit_words_header = 4;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 4:
@@ -35,7 +43,9 @@
     h->class_id = 0;
     h->integer_secs = ntohl(p[1]);
     h->fractional_secs = 0;
+    n32_bit_words_header = 2;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 5:
@@ -43,7 +53,9 @@
     h->class_id = 0;
     h->integer_secs = ntohl(p[2]);
     h->fractional_secs = 0;
+    n32_bit_words_header = 3;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 6:
@@ -51,7 +63,9 @@
     h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
     h->integer_secs = ntohl(p[3]);
     h->fractional_secs = 0;
+    n32_bit_words_header = 4;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 7:
@@ -59,7 +73,9 @@
     h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
     h->integer_secs = ntohl(p[4]);
     h->fractional_secs = 0;
+    n32_bit_words_header = 5;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 8:
@@ -67,7 +83,9 @@
     h->class_id = 0;
     h->integer_secs = 0;
     h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    n32_bit_words_header = 3;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 9:
@@ -75,7 +93,9 @@
     h->class_id = 0;
     h->integer_secs = 0;
     h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    n32_bit_words_header = 4;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 10:
@@ -83,7 +103,9 @@
     h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
     h->integer_secs = 0;
     h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+    n32_bit_words_header = 5;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 11:
@@ -91,7 +113,9 @@
     h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
     h->integer_secs = 0;
     h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+    n32_bit_words_header = 6;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 12:
@@ -99,7 +123,9 @@
     h->class_id = 0;
     h->integer_secs = ntohl(p[1]);
     h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    n32_bit_words_header = 4;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 13:
@@ -107,7 +133,9 @@
     h->class_id = 0;
     h->integer_secs = ntohl(p[2]);
     h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+    n32_bit_words_header = 5;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 14:
@@ -115,7 +143,9 @@
     h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
     h->integer_secs = ntohl(p[3]);
     h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+    n32_bit_words_header = 6;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 15:
@@ -123,7 +153,9 @@
     h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
     h->integer_secs = ntohl(p[4]);
     h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]);
+    n32_bit_words_header = 7;
     h->trailer = 0;
+    n32_bit_words_trailer = 0;
     break;
 
   case 16:
@@ -131,7 +163,9 @@
     h->class_id = 0;
     h->integer_secs = 0;
     h->fractional_secs = 0;
+    n32_bit_words_header = 1;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 17:
@@ -139,7 +173,9 @@
     h->class_id = 0;
     h->integer_secs = 0;
     h->fractional_secs = 0;
+    n32_bit_words_header = 2;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 18:
@@ -147,7 +183,9 @@
     h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
     h->integer_secs = 0;
     h->fractional_secs = 0;
+    n32_bit_words_header = 3;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 19:
@@ -155,7 +193,9 @@
     h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
     h->integer_secs = 0;
     h->fractional_secs = 0;
+    n32_bit_words_header = 4;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 20:
@@ -163,7 +203,9 @@
     h->class_id = 0;
     h->integer_secs = ntohl(p[1]);
     h->fractional_secs = 0;
+    n32_bit_words_header = 2;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 21:
@@ -171,7 +213,9 @@
     h->class_id = 0;
     h->integer_secs = ntohl(p[2]);
     h->fractional_secs = 0;
+    n32_bit_words_header = 3;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 22:
@@ -179,7 +223,9 @@
     h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
     h->integer_secs = ntohl(p[3]);
     h->fractional_secs = 0;
+    n32_bit_words_header = 4;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 23:
@@ -187,7 +233,9 @@
     h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
     h->integer_secs = ntohl(p[4]);
     h->fractional_secs = 0;
+    n32_bit_words_header = 5;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 24:
@@ -195,7 +243,9 @@
     h->class_id = 0;
     h->integer_secs = 0;
     h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+    n32_bit_words_header = 3;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 25:
@@ -203,7 +253,9 @@
     h->class_id = 0;
     h->integer_secs = 0;
     h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    n32_bit_words_header = 4;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 26:
@@ -211,7 +263,9 @@
     h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
     h->integer_secs = 0;
     h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+    n32_bit_words_header = 5;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 27:
@@ -219,7 +273,9 @@
     h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
     h->integer_secs = 0;
     h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+    n32_bit_words_header = 6;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 28:
@@ -227,7 +283,9 @@
     h->class_id = 0;
     h->integer_secs = ntohl(p[1]);
     h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+    n32_bit_words_header = 4;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 29:
@@ -235,7 +293,9 @@
     h->class_id = 0;
     h->integer_secs = ntohl(p[2]);
     h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+    n32_bit_words_header = 5;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 30:
@@ -243,7 +303,9 @@
     h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
     h->integer_secs = ntohl(p[3]);
     h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+    n32_bit_words_header = 6;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
   case 31:
@@ -251,6 +313,8 @@
     h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
     h->integer_secs = ntohl(p[4]);
     h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]);
+    n32_bit_words_header = 7;
     h->trailer = ntohl(p[len-1]);
+    n32_bit_words_trailer = 1;
     break;
 
diff --git a/vrt/lib/gen_cw_tables.py b/vrt/lib/gen_cw_tables.py
deleted file mode 100755
index 803a392..0000000
--- a/vrt/lib/gen_cw_tables.py
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2009 Free Software Foundation, Inc.
-# 
-# This file is part of GNU Radio
-# 
-# GNU Radio is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-# 
-# GNU Radio is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-# 
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-
-import sys
-
-# dispatch codeword bits
-HAS_STREAM_ID       = 1 << 0;
-HAS_CLASS_ID        = 1 << 1;
-HAS_INTEGER_SECS    = 1 << 2;
-HAS_FRACTIONAL_SECS = 1 << 3;
-HAS_TRAILER         = 1 << 4;
-
-def main():
-    f = sys.stdout
-    header_len  = 32 * [0]
-    trailer_len = 32 * [0]
-
-    for cw in range(32):
-        t = 0
-        if cw & HAS_TRAILER:         t += 1
-        trailer_len[cw] = t
-
-        t = 1
-        if cw & HAS_STREAM_ID:       t += 1
-        if cw & HAS_CLASS_ID:        t += 2
-        if cw & HAS_INTEGER_SECS:    t += 1
-        if cw & HAS_FRACTIONAL_SECS: t += 2
-        header_len[cw] = t
-
-    write_table(f, "cw_header_len", header_len)
-    write_table(f, "cw_trailer_len", trailer_len)
-    
-def write_table(f, name, table):
-    f.write("inline static size_t ")
-    f.write(name)
-    f.write("(int cw){\n")
-
-    f.write("  static const size_t s_")
-    f.write(name)
-    f.write("[32] = {\n    ")
-    for t in table:
-        f.write("%d, " % (t,))
-    f.write("\n  };\n")
-
-    f.write("  return s_")
-    f.write(name)
-    f.write("[cw];\n}\n\n")
-
-
-if __name__ == '__main__':
-    main()
diff --git a/vrt/lib/gen_parse_switch_body.py b/vrt/lib/gen_parse_switch_body.py
index 105fa76..d13e490 100755
--- a/vrt/lib/gen_parse_switch_body.py
+++ b/vrt/lib/gen_parse_switch_body.py
@@ -48,13 +48,17 @@ def do_case(f, cw):
             f.write("h->%s = 0;\n" % (name,))
             return 0
 
+    def dolength(index):
+        f.write("    n32_bit_words_header = %d;\n"%index)
+
     def dotrailer(name, mask):
-        f.write("    ")
         if cw & mask:
-            f.write("h->%s = ntohl(p[len-1]);\n" % (name,))
+            f.write("    h->%s = ntohl(p[len-1]);\n" % (name,))
+            f.write("    n32_bit_words_trailer = 1;\n")
             return 1
         else:
-            f.write("h->%s = 0;\n" % (name,))
+            f.write("    h->%s = 0;\n" % (name,))
+            f.write("    n32_bit_words_trailer = 0;\n")
             return 0
         
     f.write("  case %d:\n" % (cw,))
@@ -64,6 +68,7 @@ def do_case(f, cw):
     index += do64("class_id",  HAS_CLASS_ID,  index)
     index += do32("integer_secs", HAS_INTEGER_SECS, index)
     index += do64("fractional_secs", HAS_FRACTIONAL_SECS, index)
+    dolength(index)
     dotrailer("trailer", HAS_TRAILER)
     
     f.write("    break;\n\n")



reply via email to

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