mtd/lib/reed_solomon decode_rs.c, 1.1, 1.2 encode_rs.c, 1.1, 1.2 rslib.c, 1.1, 1.2

gleixner at infradead.org gleixner at infradead.org
Sun Sep 19 08:09:42 EDT 2004


Update of /home/cvs/mtd/lib/reed_solomon
In directory phoenix.infradead.org:/tmp/cvs-serv3423

Modified Files:
	decode_rs.c encode_rs.c rslib.c 
Log Message:
fix the caller provided syndrome case. Fix comments

Index: decode_rs.c
===================================================================
RCS file: /home/cvs/mtd/lib/reed_solomon/decode_rs.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- decode_rs.c	16 Sep 2004 23:58:56 -0000	1.1
+++ decode_rs.c	19 Sep 2004 12:09:40 -0000	1.2
@@ -32,33 +32,34 @@
 	if (PAD < 0 || PAD >= NN)
 		return -ERANGE;
 		
-	/* The caller does not provide the syndrome */
-	if (s == NULL) {
-		/* form the syndromes; i.e., evaluate data(x) at roots of g(x) */
-		for (i = 0; i < NROOTS; i++)
-			syn[i] = (((uint16_t) data[0]) ^ invmsk) & msk;
-
-		for (j = 1; j < len; j++) {
-			for (i = 0; i < NROOTS; i++) {
-				if (syn[i] == 0) {
-					syn[i] = (((uint16_t) data[j]) ^ invmsk) & msk;
-				} else {
-					syn[i] = ((((uint16_t) data[j]) ^ invmsk) & msk) ^ ALPHA_TO[MODNN(INDEX_OF[syn[i]] + (FCR+i)*PRIM)];
-				}
+	/* Deos the caller provide the syndrome ? */
+	if (s != NULL) 
+		goto decode;
+
+	/* form the syndromes; i.e., evaluate data(x) at roots of g(x) */
+	for (i = 0; i < NROOTS; i++)
+		syn[i] = (((uint16_t) data[0]) ^ invmsk) & msk;
+
+	for (j = 1; j < len; j++) {
+		for (i = 0; i < NROOTS; i++) {
+			if (syn[i] == 0) {
+				syn[i] = (((uint16_t) data[j]) ^ invmsk) & msk;
+			} else {
+				syn[i] = ((((uint16_t) data[j]) ^ invmsk) & msk) ^ ALPHA_TO[MODNN(INDEX_OF[syn[i]] + (FCR+i)*PRIM)];
 			}
 		}
+	}
 
-		for (j = 0; j < NROOTS; j++) {
-			for (i = 0; i < NROOTS; i++) {
-				if (syn[i] == 0) {
-					syn[i] = ((uint16_t) par[j]) & msk;
-				} else {
-					syn[i] = (((uint16_t) par[j]) & msk) ^ ALPHA_TO[MODNN(INDEX_OF[syn[i]] + (FCR+i)*PRIM)];
-				}
+	for (j = 0; j < NROOTS; j++) {
+		for (i = 0; i < NROOTS; i++) {
+			if (syn[i] == 0) {
+				syn[i] = ((uint16_t) par[j]) & msk;
+			} else {
+				syn[i] = (((uint16_t) par[j]) & msk) ^ ALPHA_TO[MODNN(INDEX_OF[syn[i]] + (FCR+i)*PRIM)];
 			}
 		}
-		s = syn;
 	}
+	s = syn;
 
 	/* Convert syndromes to index form, checking for nonzero condition */
 	syn_error = 0;
@@ -74,6 +75,8 @@
 		count = 0;
 		goto finish;
 	}
+
+ decode:
 	memset (&lambda[1], 0, NROOTS * sizeof (lambda[0]));
 	lambda[0] = 1;
 

Index: encode_rs.c
===================================================================
RCS file: /home/cvs/mtd/lib/reed_solomon/encode_rs.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- encode_rs.c	16 Sep 2004 23:58:56 -0000	1.1
+++ encode_rs.c	19 Sep 2004 12:09:40 -0000	1.2
@@ -27,8 +27,6 @@
 	if (pad < 0 || pad >= NN)
 		return -ERANGE;
 
-	memset (par, 0, NROOTS * sizeof (uint16_t));
-
 	for (i = 0; i < len; i++) {
 		feedback = INDEX_OF[((((uint16_t) data[i])^invmsk) & msk) ^ par[0]];
 		/* feedback term is non-zero */

Index: rslib.c
===================================================================
RCS file: /home/cvs/mtd/lib/reed_solomon/rslib.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- rslib.c	16 Sep 2004 23:58:56 -0000	1.1
+++ rslib.c	19 Sep 2004 12:09:40 -0000	1.2
@@ -1,5 +1,5 @@
 /* 
- * lib/reed_solomon/lib_rs.c
+ * lib/reed_solomon/rslib.c
  *
  * Overview:
  *   Generic Reed Solomon encoder / decoder library
@@ -198,7 +198,6 @@
 	
 	down (&rslistlock);
 
-#ifdef __KERNEL__	
 	/* Walk through the list and look for a matching entry */
 	list_for_each (tmp, &rslist) {
 		rs = list_entry (tmp, struct rs_control, list);
@@ -216,7 +215,6 @@
 		rs->users++;
 		goto out;
 	}
-#endif
 
 	/* Create a new one */
 	rs = rs_init (symsize, gfpoly, fcr, prim, nroots);
@@ -235,8 +233,8 @@
  *  @rs:	the rs control structure
  *  @data:	data field of a given type
  *  @len:	data length 
- *  @par:	parity data field
- *  @invmsk:	invert data mask
+ *  @par:	parity data field, must be initialized by caller (usually all 0)
+ *  @invmsk:	invert data mask (will be xored on data)
  *
  *  The parity uses a uint16_t data type to enable
  *  symbol size > 8. The calling code must take care of encoding of the
@@ -244,7 +242,6 @@
  */
 int encode_rs8 (struct rs_control *rs, uint8_t *data, int len, uint16_t *par, uint16_t invmsk)
 {
-#define RSINVMSK 0xFF
 #include "encode_rs.c"
 }
 
@@ -258,7 +255,7 @@
  *  @s:		syndrome data field (if NULL, syndrome must be calculated)
  *  @no_eras:	number of erasures
  *  @eras_pos:	position of erasures, can be NULL
- *  @invmsk:	invert data mask
+ *  @invmsk:	invert data mask (will be xored on data, not on parity!)
  *
  *  The syndrome and parity uses a uint16_t data type to enable
  *  symbol size > 8. The calling code must take care of decoding of the
@@ -276,15 +273,13 @@
  *  @rs:	the rs control structure
  *  @data:	data field of a given type
  *  @len:	data length 
- *  @par:	parity data field
- *  @invmsk:	invert data mask
+ *  @par:	parity data field, must be initialized by caller (usually all 0)
+ *  @invmsk:	invert data mask (will be xored on data, not on parity!)
  *
  *  Each field in the data array contains up to symbol size bits of valid data.
  */
 int encode_rs16 (struct rs_control *rs, uint16_t *data, int len, uint16_t *par, uint16_t invmsk)
 {
-#undef RSINVMSK
-#define RSINVMSK 0xFFFF
 #include "encode_rs.c"
 }
 
@@ -298,7 +293,7 @@
  *  @s:		syndrome data field (if NULL, syndrome must be calculated)
  *  @no_eras:	number of erasures
  *  @eras_pos:	position of erasures, can be NULL
- *  @invmsk:	invert data mask
+ *  @invmsk:	invert data mask (will be xored on data, not on parity!) 
  *
  *  Each field in the data array contains up to symbol size bits of valid data.
  */
@@ -314,8 +309,8 @@
  *  @rs:	the rs control structure
  *  @data:	data field of a given type
  *  @len:	data length 
- *  @par:	parity data field
- *  @invmsk:	invert data mask
+ *  @par:	parity data field, must be initialized by caller (usually all 0)
+ *  @invmsk:	invert data mask (will be xored on data)
  *
  *  The parity uses a uint16_t data type due to the fact that
  *  we can't handle symbol size >= 16 bit as the polynominal arrays would 
@@ -337,7 +332,7 @@
  *  @s:		syndrome data field (if NULL, syndrome must be calculated)
  *  @no_eras:	number of erasures
  *  @eras_pos:	position of erasures, can be NULL
- *  @invmsk:	invert data mask
+ *  @invmsk:	invert data mask (will be xored on data, not on parity!)
  *
  *  The syndrome and parity use a uint16_t data type due to the fact that
  *  we can't handle symbol size > 16 as the polynominal arrays would be to 





More information about the linux-mtd-cvs mailing list