fix
authorMazet Laurent <laurent.mazet@thalesgroup.com>
Thu, 27 Nov 2025 17:41:53 +0000 (18:41 +0100)
committerMazet Laurent <laurent.mazet@thalesgroup.com>
Thu, 27 Nov 2025 17:41:53 +0000 (18:41 +0100)
Makerule.in
doc/coders.txt
test/benchmark.c [new file with mode: 0644]
test/benckmark.c [deleted file]

index 09f258eedb7ede4042856b8ee01a09ec5cbc48f2..5621f42363a4d50493879863b4f337552a53f537 100644 (file)
@@ -45,7 +45,7 @@ clean-local:
        @$(call removefile,"object file",$(addprefix $(OBJ_BUILD_DIR)/,$(OBJECTS)))
        @$(call removefile,"tmp file",$(TMPFILES))
 
-purge: purge-recursive purge-local
+purge: clean purge-recursive purge-local
 
 purge-local: clean-local
        @$(call removefile,"config file",$(CONFIGS))
index 761970b16c820f943de1e15f71da7fb5406c6680..85edb7abd7e2b3f44df1ff57f1d1d29f3ad5c7a5 100644 (file)
 1       8       6       153     111     165     173     135     135     147     137     40
 1       8       7       275     275     253     371     331     235     313     357     45
 
-## grep -v \^# coders.txt | awk 'NF>0 {printf "l=\"%d", $1; for (i=2;i<NF;i++) printf " %d", $(i); printf "\"; [ $(eval $(echo prog_test 1 $l) | grep \"Nb errors =\" | cut -d\" \" -f 4) != 0 ] && echo $l\n"}'
-## grep -v \^# coders.txt | awk 'NF>0 {printf "%d", $1; for (i=2;i<NF;i++) printf " %d", $(i); printf "\n"}'
\ No newline at end of file
+## grep -v \^# coders.txt | awk 'NF>0 {printf "l=\"%d", $1; for (i=2;i<NF;i++) printf " %d", $(i); printf "\"; [ $(eval $(echo prog_test 0 $l) | grep \"Nb errors =\" | cut -d\" \" -f 4) != 0 ] && echo $l\n"}'
+## grep -v \^# coders.txt | awk 'NF>0 {printf "%d", $1; for (i=2;i<NF;i++) printf " %d", $(i); printf "\n"}'
diff --git a/test/benchmark.c b/test/benchmark.c
new file mode 100644 (file)
index 0000000..32aba0b
--- /dev/null
@@ -0,0 +1,206 @@
+/* -*- C -*- */
+
+/*
+
+Copyright (C) 2003 Laurent Mazet
+
+*/
+
+/* Program test for Viterbi decoding */
+
+/*
+ * This program is a mess. It's used to test all coders in coders.txt and
+ * check memory management
+ */
+
+//#define ONLY_VITERBI
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "trellis.h"
+#include "encoder.h"
+#include "create_trellis.h"
+
+/* Pseudo-random bit sequence */
+void bit_gene (bit * a, int n) {
+  int i;
+  
+  for (i=0; i < n; i++)
+    *(a++) = rand()&1;
+}
+
+int main(int argc, char* argv[]) {
+  /* Coders definition */
+  int nb_unprotected_bits = 0;
+  int nb_inputs;
+  int nb_coded_inputs = 1;
+  int nb_outputs;
+  int nb_coded_outputs = 2;
+  int nb_registers = 2;
+  int *coders;
+  conv_encoder *enc;
+  
+  /* Viterbi parameters */
+  int deepness;
+  int window_dec_size ;
+  int history_size;
+  trellis *tr;
+  
+  /* Data paramaters */
+  int nb_data_bits = 128*8;
+  int nb_uncoded_bits;
+  int nb_coded_bits;
+  int nb_metrics;
+  int nb_packets = 1024;
+
+  /* Various blocks */
+  bit *x;
+  bit *y;
+  metric_t *metrics;
+  int *tmp;
+  bit *xdecod;
+  
+  /* Indexes */
+  int i, j, k, l;
+  int nb_bit_errors;
+  int nb_packet_errors = 0;
+    
+  /* Argument processing */
+  if ((argc > 1) && (argv[1][0] == '-') && (argv[1][1] == 'h')) {
+    printf ("prog_test [#unprotected #inputs #outputs #registers coder_1 coder_2...]\n");
+    exit (1);
+  }
+  if (argc > 1) nb_unprotected_bits = (int) strtol(argv[1], NULL, 10);
+  if (argc > 2) nb_coded_inputs = (int) strtol(argv[2], NULL, 10);
+  if (argc > 3) nb_coded_outputs = (int) strtol(argv[3], NULL, 10);
+  if (argc > 4) nb_registers = (int) strtol(argv[4], NULL, 10);
+
+  coders = (int *) malloc(nb_coded_outputs*sizeof(int));
+  if (argc == 1) { coders[0] = 5; coders[1] = 7; }
+  else if (argc != 5+nb_coded_outputs) {
+    printf ("Wrong number of arguments\n");
+    exit(1);
+  }
+  for (i=0; i<nb_coded_outputs; i++)
+    if (argc > 5+i) coders[i] = (int) strtol(argv[5+i], NULL, 8);
+
+  /* Encoder descriptions */
+  printf ("#S/#I/#O/#R: (%d,%d,%d,%d) [", nb_unprotected_bits,
+          nb_coded_inputs, nb_coded_outputs, nb_registers);
+  for (i=0; i<nb_coded_outputs; i++)
+    printf (" %o", coders[i]);
+  printf (" ]\n");
+  
+  /* Coders definition */
+  nb_inputs = nb_unprotected_bits + nb_coded_inputs;
+  nb_outputs = nb_unprotected_bits + nb_coded_outputs;
+  enc = alloc_conv_encoder (nb_unprotected_bits, nb_coded_inputs,
+                            nb_registers, nb_coded_outputs, coders);
+  
+  /* Data paramaters */
+  nb_uncoded_bits = nb_data_bits + nb_registers;
+  nb_coded_bits = nb_uncoded_bits * nb_outputs;
+  nb_metrics = 1 << nb_outputs;
+  
+  /* Viterbi parameters for a closed trellis */
+  deepness = nb_registers / nb_inputs;
+  window_dec_size = nb_uncoded_bits / nb_inputs - deepness;
+  history_size = deepness + window_dec_size;
+
+  /* Trellis creation */
+  tr = create_trellis_from_conv_encoder (enc, history_size);
+
+  /* Some malloc */
+  x = (bit*) malloc (nb_uncoded_bits*sizeof(bit));
+  y = (bit*) malloc (nb_coded_bits*sizeof(bit));
+  metrics = (metric_t*) malloc (nb_metrics*sizeof(metric_t));
+  tmp = (int*) malloc (window_dec_size*sizeof(int));
+  xdecod = (bit*) malloc (nb_uncoded_bits*sizeof(bit));
+    
+  /* Bit generation */
+  bit_gene (x, nb_data_bits);
+  for (i=nb_data_bits; i<nb_uncoded_bits; i++)
+    x[i] = 0;
+  
+  /* Bit encoding */
+  conv_encoding (y, x, nb_uncoded_bits, enc);
+
+  /* Info */
+  printf ("Send %d packets of %d bits\n", nb_packets, nb_data_bits);
+  
+  /* Loop for benchmark */
+  for (l=0; l<nb_packets; l++) {
+    int nb_dec_symb, ii;
+  
+    /* Viterbi */
+    for (i=0, ii=0; i<nb_uncoded_bits; i+=nb_inputs) {
+      int symbol = 0;
+
+#if !defined(ONLY_VITERBI)       
+      /* Generate symbol */
+      for (k=0; k<nb_outputs; k++)
+        symbol = (symbol << 1) | y[ii++];
+
+      /* Compute distance of received signal to all constellation symbols */
+      for (k=0; k<nb_metrics; k++) {
+        int m = 0, l;
+        int bits = symbol ^ k;
+        
+        for (l=0; (l<nb_outputs) && (bits); l++, bits>>=1)
+          if (bits & 1)
+            m++;
+        
+        metrics[k] = m;
+      }
+#endif      
+      /* acs */
+      tr->acs (tr, metrics);
+      
+      /* Normalize node metrics */
+      /* normalize_node_metrics_trellis (tr, 0); */
+    }
+
+    /* Decoded bits */
+    nb_dec_symb = backtrace_trellis (tr, 0, deepness, window_dec_size, tmp);
+
+    for (j=0; j<nb_dec_symb; j++)
+      for (k=0; k<nb_inputs; k++)
+        xdecod[j*nb_inputs + k] = 
+          ((tmp[j] & (1 << (nb_inputs-k-1))) != 0) ? 1 : 0;
+
+#if !defined(ONLY_VITERBI)       
+    /* Check error */
+    nb_bit_errors = 0;
+    for (i=0; i<nb_data_bits; i++)
+      if (x[i] != xdecod[i])
+        nb_bit_errors++;
+    
+    if (nb_bit_errors) {
+      printf ("Nb bit errors: %d\n", nb_bit_errors);
+      nb_packet_errors++;
+    }
+
+    reset_trellis(tr);
+#endif
+  }
+
+#if !defined(ONLY_VITERBI)       
+  printf ("Nb packet errors: %d\n", nb_packet_errors);
+#endif
+
+  /* Free memory blocks */
+  free_trellis (tr);
+  free_conv_encoder (enc);
+  free (coders);
+  free (x);
+  free (y);
+  free (metrics);
+  free (tmp);
+  free (xdecod);
+
+  printf ("bye\n");
+
+  return 0;
+}
diff --git a/test/benckmark.c b/test/benckmark.c
deleted file mode 100644 (file)
index 32aba0b..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-/* -*- C -*- */
-
-/*
-
-Copyright (C) 2003 Laurent Mazet
-
-*/
-
-/* Program test for Viterbi decoding */
-
-/*
- * This program is a mess. It's used to test all coders in coders.txt and
- * check memory management
- */
-
-//#define ONLY_VITERBI
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "trellis.h"
-#include "encoder.h"
-#include "create_trellis.h"
-
-/* Pseudo-random bit sequence */
-void bit_gene (bit * a, int n) {
-  int i;
-  
-  for (i=0; i < n; i++)
-    *(a++) = rand()&1;
-}
-
-int main(int argc, char* argv[]) {
-  /* Coders definition */
-  int nb_unprotected_bits = 0;
-  int nb_inputs;
-  int nb_coded_inputs = 1;
-  int nb_outputs;
-  int nb_coded_outputs = 2;
-  int nb_registers = 2;
-  int *coders;
-  conv_encoder *enc;
-  
-  /* Viterbi parameters */
-  int deepness;
-  int window_dec_size ;
-  int history_size;
-  trellis *tr;
-  
-  /* Data paramaters */
-  int nb_data_bits = 128*8;
-  int nb_uncoded_bits;
-  int nb_coded_bits;
-  int nb_metrics;
-  int nb_packets = 1024;
-
-  /* Various blocks */
-  bit *x;
-  bit *y;
-  metric_t *metrics;
-  int *tmp;
-  bit *xdecod;
-  
-  /* Indexes */
-  int i, j, k, l;
-  int nb_bit_errors;
-  int nb_packet_errors = 0;
-    
-  /* Argument processing */
-  if ((argc > 1) && (argv[1][0] == '-') && (argv[1][1] == 'h')) {
-    printf ("prog_test [#unprotected #inputs #outputs #registers coder_1 coder_2...]\n");
-    exit (1);
-  }
-  if (argc > 1) nb_unprotected_bits = (int) strtol(argv[1], NULL, 10);
-  if (argc > 2) nb_coded_inputs = (int) strtol(argv[2], NULL, 10);
-  if (argc > 3) nb_coded_outputs = (int) strtol(argv[3], NULL, 10);
-  if (argc > 4) nb_registers = (int) strtol(argv[4], NULL, 10);
-
-  coders = (int *) malloc(nb_coded_outputs*sizeof(int));
-  if (argc == 1) { coders[0] = 5; coders[1] = 7; }
-  else if (argc != 5+nb_coded_outputs) {
-    printf ("Wrong number of arguments\n");
-    exit(1);
-  }
-  for (i=0; i<nb_coded_outputs; i++)
-    if (argc > 5+i) coders[i] = (int) strtol(argv[5+i], NULL, 8);
-
-  /* Encoder descriptions */
-  printf ("#S/#I/#O/#R: (%d,%d,%d,%d) [", nb_unprotected_bits,
-          nb_coded_inputs, nb_coded_outputs, nb_registers);
-  for (i=0; i<nb_coded_outputs; i++)
-    printf (" %o", coders[i]);
-  printf (" ]\n");
-  
-  /* Coders definition */
-  nb_inputs = nb_unprotected_bits + nb_coded_inputs;
-  nb_outputs = nb_unprotected_bits + nb_coded_outputs;
-  enc = alloc_conv_encoder (nb_unprotected_bits, nb_coded_inputs,
-                            nb_registers, nb_coded_outputs, coders);
-  
-  /* Data paramaters */
-  nb_uncoded_bits = nb_data_bits + nb_registers;
-  nb_coded_bits = nb_uncoded_bits * nb_outputs;
-  nb_metrics = 1 << nb_outputs;
-  
-  /* Viterbi parameters for a closed trellis */
-  deepness = nb_registers / nb_inputs;
-  window_dec_size = nb_uncoded_bits / nb_inputs - deepness;
-  history_size = deepness + window_dec_size;
-
-  /* Trellis creation */
-  tr = create_trellis_from_conv_encoder (enc, history_size);
-
-  /* Some malloc */
-  x = (bit*) malloc (nb_uncoded_bits*sizeof(bit));
-  y = (bit*) malloc (nb_coded_bits*sizeof(bit));
-  metrics = (metric_t*) malloc (nb_metrics*sizeof(metric_t));
-  tmp = (int*) malloc (window_dec_size*sizeof(int));
-  xdecod = (bit*) malloc (nb_uncoded_bits*sizeof(bit));
-    
-  /* Bit generation */
-  bit_gene (x, nb_data_bits);
-  for (i=nb_data_bits; i<nb_uncoded_bits; i++)
-    x[i] = 0;
-  
-  /* Bit encoding */
-  conv_encoding (y, x, nb_uncoded_bits, enc);
-
-  /* Info */
-  printf ("Send %d packets of %d bits\n", nb_packets, nb_data_bits);
-  
-  /* Loop for benchmark */
-  for (l=0; l<nb_packets; l++) {
-    int nb_dec_symb, ii;
-  
-    /* Viterbi */
-    for (i=0, ii=0; i<nb_uncoded_bits; i+=nb_inputs) {
-      int symbol = 0;
-
-#if !defined(ONLY_VITERBI)       
-      /* Generate symbol */
-      for (k=0; k<nb_outputs; k++)
-        symbol = (symbol << 1) | y[ii++];
-
-      /* Compute distance of received signal to all constellation symbols */
-      for (k=0; k<nb_metrics; k++) {
-        int m = 0, l;
-        int bits = symbol ^ k;
-        
-        for (l=0; (l<nb_outputs) && (bits); l++, bits>>=1)
-          if (bits & 1)
-            m++;
-        
-        metrics[k] = m;
-      }
-#endif      
-      /* acs */
-      tr->acs (tr, metrics);
-      
-      /* Normalize node metrics */
-      /* normalize_node_metrics_trellis (tr, 0); */
-    }
-
-    /* Decoded bits */
-    nb_dec_symb = backtrace_trellis (tr, 0, deepness, window_dec_size, tmp);
-
-    for (j=0; j<nb_dec_symb; j++)
-      for (k=0; k<nb_inputs; k++)
-        xdecod[j*nb_inputs + k] = 
-          ((tmp[j] & (1 << (nb_inputs-k-1))) != 0) ? 1 : 0;
-
-#if !defined(ONLY_VITERBI)       
-    /* Check error */
-    nb_bit_errors = 0;
-    for (i=0; i<nb_data_bits; i++)
-      if (x[i] != xdecod[i])
-        nb_bit_errors++;
-    
-    if (nb_bit_errors) {
-      printf ("Nb bit errors: %d\n", nb_bit_errors);
-      nb_packet_errors++;
-    }
-
-    reset_trellis(tr);
-#endif
-  }
-
-#if !defined(ONLY_VITERBI)       
-  printf ("Nb packet errors: %d\n", nb_packet_errors);
-#endif
-
-  /* Free memory blocks */
-  free_trellis (tr);
-  free_conv_encoder (enc);
-  free (coders);
-  free (x);
-  free (y);
-  free (metrics);
-  free (tmp);
-  free (xdecod);
-
-  printf ("bye\n");
-
-  return 0;
-}