]> git.sesse.net Git - hamming/commitdiff
Drop the lookup table for hamming32; check_zero_bit_detection() seems to be ~25%...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 2 Mar 2006 13:46:57 +0000 (13:46 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 2 Mar 2006 13:46:57 +0000 (13:46 +0000)
hamming32.c

index 24f818c1e55596db2003f02f68812dcce6e7fccf..2d8b882c7fdefeb8b6adb13ced7ce9918a02b150 100644 (file)
@@ -6,8 +6,6 @@
 #define CODE_BITS    (DATA_BITS + PARITY_BITS)
 #define NUM_DATA_WORDS (1 << DATA_BITS)
 
-unsigned char hamming_parity_lookup[256];
-
 /* 
  * Needed since we store all the parity at the end of the word, not at the expected
  * power-of-two bit positions.
@@ -16,14 +14,14 @@ unsigned char permutation_table[CODE_BITS] = {
        0, 5, 4, 31, 3, 30, 29, 28, 2, 27, 26, 25, 24, 23, 22, 21, 1, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6
 };
 
-/* FIXME: check if the lookup table actually helps us any here */
 unsigned find_parity_32(unsigned data)
 {
-       return
-               hamming_parity_lookup[ data        & 0xff] ^
-               hamming_parity_lookup[(data >>  8) & 0xff] ^
-               hamming_parity_lookup[(data >> 16) & 0xff] ^
-               hamming_parity_lookup[ data >> 24        ];
+       data = (data >> 16) ^ data;
+       data = (data >> 8) ^ data;
+       data = (data >> 4) ^ data;
+       data = (data >> 2) ^ data;
+       data = (data >> 1) ^ data;
+       return (data & 1);
 }
 
 unsigned generate_parity(unsigned data)
@@ -43,20 +41,6 @@ unsigned make_codeword(unsigned data)
        return (data << PARITY_BITS) | generate_parity(data);
 }
 
-void generate_lookup()
-{
-       unsigned i;
-
-       printf("Generating lookup table.\n");
-       
-       for (i = 0; i < 256; ++i) {
-               unsigned parity = (i >> 4) ^ i;
-               parity = (parity >> 2) ^ parity;
-               parity = (parity >> 1) ^ parity;
-               hamming_parity_lookup[i] = parity & 1;
-       }
-}
-
 /* can detect all single or double bit errors */
 int has_error(unsigned code)
 {
@@ -179,7 +163,6 @@ void check_double_bit_detection()
 
 int main()
 {
-       generate_lookup();
        check_zero_bit_detection();
        check_single_bit_detection();
        check_double_bit_detection();