Replaced the need for code word tables by setting the header/trailer lengths
authorJosh Blum <josh@joshknows.com>
Fri, 18 Dec 2009 01:29:45 +0000 (17:29 -0800)
committerJosh Blum <josh@joshknows.com>
Fri, 18 Dec 2009 02:01:39 +0000 (18:01 -0800)
in the switch body jump table, just like in the unparser switch body.

vrt/lib/Makefile.am
vrt/lib/expanded_header.cc
vrt/lib/expanded_header_cw_tables.h [deleted file]
vrt/lib/expanded_header_parse_switch_body.h
vrt/lib/gen_cw_tables.py [deleted file]
vrt/lib/gen_parse_switch_body.py

index f2fcce0c6677a7382b5a8f4f6fcf251c78466484..303384c6e57dd452134e7322750c75b7a33ea801 100644 (file)
@@ -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
index 64e97ef97fda094d0c522a8050d4f21fab72551f..8b22fb92549f845ab46d60b9a1cc455492d075ea 100644 (file)
@@ -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 (file)
index fbb9c6b..0000000
+++ /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];
-}
-
index 40e575c2c8b8f5fa78a9515320895e2091048945..6bfaf37997f481d653a90a090be3453dfa7244cb 100644 (file)
@@ -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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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:
     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 (executable)
index 803a392..0000000
+++ /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()
index 105fa76a71b902d57c30e40e64780808754c4dbb..d13e490b75b64c2bdc43336a82fccdf697f09c65 100755 (executable)
@@ -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")