VK1ET : Changes to fixBitErrors()

1) Reduce complexity of fixBitErrors()
2) Inline flipBits()
3) Remove validation checks that can never occur.
This commit is contained in:
Malcolm Robb 2013-05-21 13:40:07 +01:00
parent 0a0ba165db
commit 542b94dedb

View file

@ -1328,10 +1328,10 @@ void modesInitErrorInfo() {
} }
*/ */
} }
//
/* Flip a bit, but make sure that the DF field (first 5 bits) // Flip a bit, but make sure that the DF field (first 5 bits)
* is never changed // is never changed
*/ /*
int flipBit(unsigned char *msg, int nbits, int bit) { int flipBit(unsigned char *msg, int nbits, int bit) {
int bytepos, mask; int bytepos, mask;
if ((bit < 0) || (bit >= nbits)) { if ((bit < 0) || (bit >= nbits)) {
@ -1345,12 +1345,12 @@ int flipBit(unsigned char *msg, int nbits, int bit) {
msg[bytepos] ^= mask; msg[bytepos] ^= mask;
return 1; return 1;
} }
/* Search syndrome in table and, if an entry is found, flip the necessary
* bits. Make sure the indices fit into the array, and for 2-bit errors,
* are different.
* Return number of fixed bits.
*/ */
// Search syndrome in table and, if an entry is found, flip the necessary
// bits. Make sure the indices fit into the array, and for 2-bit errors,
// are different.
// Return number of fixed bits.
//
int fixBitErrors(unsigned char *msg, int bits) { int fixBitErrors(unsigned char *msg, int bits) {
struct errorinfo *pei; struct errorinfo *pei;
struct errorinfo ei; struct errorinfo ei;
@ -1361,34 +1361,25 @@ int fixBitErrors(unsigned char *msg, int bits) {
pei = bsearch(&ei, bitErrorTable, NERRORINFO, pei = bsearch(&ei, bitErrorTable, NERRORINFO,
sizeof(struct errorinfo), cmpErrorInfo); sizeof(struct errorinfo), cmpErrorInfo);
if (pei == NULL) { if (pei == NULL) {
/* Nothing found */ return 0; // No syndrome found
}
res = 0;
offset = MODES_LONG_MSG_BITS-bits;
bitpos0 = pei->pos0 - offset;
if ((bitpos0 < 0) || (bitpos0 >= bits)) {
return 0; return 0;
} }
offset = MODES_LONG_MSG_BITS-bits; msg[(bitpos0 >> 3)] ^= (1 << (7 - (bitpos0 & 7)));
bitpos0 = pei->pos0; res++;
bitpos1 = pei->pos1; if (pei->pos1 >= 0) { /* two-bit error pattern */
res = 0; bitpos1 = pei->pos1 - offset;
if (bitpos1 >= 0) { /* two-bit error pattern */ if ((bitpos1 < 0) || (bitpos1 >= bits)) {
bitpos0 -= offset; return 0;
bitpos1 -= offset;
if ((bitpos0 < 0) || (bitpos0 >= bits) ||
(bitpos1 < 0) || (bitpos1 >= bits)) {
return res;
} }
res +=flipBit(msg, bits, bitpos0); msg[(bitpos1 >> 3)] ^= (1 << (7 - (bitpos1 & 7)));
if (bitpos0 != bitpos1) { res++;
res += flipBit(msg, bits, bitpos1);
return res;
} }
return res; return res;
} else {
bitpos0 -= offset;
if ((bitpos0 < 0) || (bitpos0 >= bits)) {
return res;
}
res += flipBit(msg, bits, bitpos0);
return res;
}
} }
/* Code for testing the timing: run all possible 1- and 2-bit error /* Code for testing the timing: run all possible 1- and 2-bit error