1 /* Reed-Solomon encoder
2  * Copyright 2002, Phil Karn, KA9Q
3  * May be used under the terms of the GNU General Public License (GPL)
4  */
5 #include <string.h>
6 
7 #ifdef FIXED
8 #include "fixed.h"
9 #elif defined(BIGSYM)
10 #include "int.h"
11 #else
12 #include "char.h"
13 #endif
14 
ENCODE_RS(void * p,DTYPE * data,DTYPE * bb)15 void ENCODE_RS(
16 #ifndef FIXED
17     void* p,
18 #endif
19     DTYPE* data,
20     DTYPE* bb)
21 {
22 #ifndef FIXED
23     struct rs* rs = (struct rs*)p;
24 #endif
25     unsigned int i, j;
26     DTYPE feedback;
27 
28     memset(bb, 0, NROOTS * sizeof(DTYPE));
29 
30     for (i = 0; i < NN - NROOTS; i++) {
31         feedback = INDEX_OF[data[i] ^ bb[0]];
32         if (feedback != A0) { /* feedback term is non-zero */
33 #ifdef UNNORMALIZED
34             /* This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
35              * always be for the polynomials constructed by init_rs()
36              */
37             feedback = MODNN(NN - GENPOLY[NROOTS] + feedback);
38 #endif
39             for (j = 1; j < NROOTS; j++)
40 #ifdef FIXED
41                 bb[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS - j])];
42 #elif defined(BIGSYM)
43                 // Same as above; keeping as a separate line in case these change.
44                 bb[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS - j])];
45 #else
46                 bb[j] ^= ALPHA_TO[rs->modnn_table[feedback + GENPOLY[NROOTS - j]]];
47 #endif
48         }
49         /* Shift */
50         memmove(&bb[0], &bb[1], sizeof(DTYPE) * (NROOTS - 1));
51         if (feedback != A0)
52 #ifdef FIXED
53             bb[NROOTS - 1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
54 #elif defined(BIGSYM)
55             // Same as above; keeping as a separate line in case these change.
56             bb[NROOTS - 1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
57 #else
58             bb[NROOTS - 1] = ALPHA_TO[rs->modnn_table[feedback + GENPOLY[0]]];
59 #endif
60         else
61             bb[NROOTS - 1] = 0;
62     }
63 }
64