1*638691a0SAndroid Build Coastguard Worker /* Stuff common to all the general-purpose Reed-Solomon codecs 2*638691a0SAndroid Build Coastguard Worker * Copyright 2004 Phil Karn, KA9Q 3*638691a0SAndroid Build Coastguard Worker * May be used under the terms of the GNU Lesser General Public License (LGPL) 4*638691a0SAndroid Build Coastguard Worker */ 5*638691a0SAndroid Build Coastguard Worker 6*638691a0SAndroid Build Coastguard Worker /* Reed-Solomon codec control block */ 7*638691a0SAndroid Build Coastguard Worker struct rs { 8*638691a0SAndroid Build Coastguard Worker int mm; /* Bits per symbol */ 9*638691a0SAndroid Build Coastguard Worker int nn; /* Symbols per block (= (1<<mm)-1) */ 10*638691a0SAndroid Build Coastguard Worker data_t *alpha_to; /* log lookup table */ 11*638691a0SAndroid Build Coastguard Worker data_t *index_of; /* Antilog lookup table */ 12*638691a0SAndroid Build Coastguard Worker data_t *genpoly; /* Generator polynomial */ 13*638691a0SAndroid Build Coastguard Worker int nroots; /* Number of generator roots = number of parity symbols */ 14*638691a0SAndroid Build Coastguard Worker int fcr; /* First consecutive root, index form */ 15*638691a0SAndroid Build Coastguard Worker int prim; /* Primitive element, index form */ 16*638691a0SAndroid Build Coastguard Worker int iprim; /* prim-th root of 1, index form */ 17*638691a0SAndroid Build Coastguard Worker int pad; /* Padding bytes in shortened block */ 18*638691a0SAndroid Build Coastguard Worker }; 19*638691a0SAndroid Build Coastguard Worker modnn(struct rs * rs,int x)20*638691a0SAndroid Build Coastguard Workerstatic inline int modnn(struct rs *rs,int x){ 21*638691a0SAndroid Build Coastguard Worker while (x >= rs->nn) { 22*638691a0SAndroid Build Coastguard Worker x -= rs->nn; 23*638691a0SAndroid Build Coastguard Worker x = (x >> rs->mm) + (x & rs->nn); 24*638691a0SAndroid Build Coastguard Worker } 25*638691a0SAndroid Build Coastguard Worker return x; 26*638691a0SAndroid Build Coastguard Worker } 27