1 /* Utility routines for FEC support 2 * Copyright 2004, Phil Karn, KA9Q 3 */ 4 5 #include <stdio.h> 6 #include "fec.h" 7 8 unsigned char Partab[256]; 9 int P_init; 10 11 /* Create 256-entry odd-parity lookup table 12 * Needed only on non-ia32 machines 13 */ 14 void partab_init(void){ 15 int i,cnt,ti; 16 17 /* Initialize parity lookup table */ 18 for(i=0;i<256;i++){ 19 cnt = 0; 20 ti = i; 21 while(ti){ 22 if(ti & 1) 23 cnt++; 24 ti >>= 1; 25 } 26 Partab[i] = cnt & 1; 27 } 28 P_init=1; 29 } 30 31 /* Lookup table giving count of 1 bits for integers 0-255 */ 32 int Bitcnt[] = { 33 0, 1, 1, 2, 1, 2, 2, 3, 34 1, 2, 2, 3, 2, 3, 3, 4, 35 1, 2, 2, 3, 2, 3, 3, 4, 36 2, 3, 3, 4, 3, 4, 4, 5, 37 1, 2, 2, 3, 2, 3, 3, 4, 38 2, 3, 3, 4, 3, 4, 4, 5, 39 2, 3, 3, 4, 3, 4, 4, 5, 40 3, 4, 4, 5, 4, 5, 5, 6, 41 1, 2, 2, 3, 2, 3, 3, 4, 42 2, 3, 3, 4, 3, 4, 4, 5, 43 2, 3, 3, 4, 3, 4, 4, 5, 44 3, 4, 4, 5, 4, 5, 5, 6, 45 2, 3, 3, 4, 3, 4, 4, 5, 46 3, 4, 4, 5, 4, 5, 5, 6, 47 3, 4, 4, 5, 4, 5, 5, 6, 48 4, 5, 5, 6, 5, 6, 6, 7, 49 1, 2, 2, 3, 2, 3, 3, 4, 50 2, 3, 3, 4, 3, 4, 4, 5, 51 2, 3, 3, 4, 3, 4, 4, 5, 52 3, 4, 4, 5, 4, 5, 5, 6, 53 2, 3, 3, 4, 3, 4, 4, 5, 54 3, 4, 4, 5, 4, 5, 5, 6, 55 3, 4, 4, 5, 4, 5, 5, 6, 56 4, 5, 5, 6, 5, 6, 6, 7, 57 2, 3, 3, 4, 3, 4, 4, 5, 58 3, 4, 4, 5, 4, 5, 5, 6, 59 3, 4, 4, 5, 4, 5, 5, 6, 60 4, 5, 5, 6, 5, 6, 6, 7, 61 3, 4, 4, 5, 4, 5, 5, 6, 62 4, 5, 5, 6, 5, 6, 6, 7, 63 4, 5, 5, 6, 5, 6, 6, 7, 64 5, 6, 6, 7, 6, 7, 7, 8, 65 }; 66 67