From 7ad344802d7f2865832ac37ab032365a5fbeaab9 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 2 Mar 2006 13:46:57 +0000 Subject: [PATCH] Drop the lookup table for hamming32; check_zero_bit_detection() seems to be ~25% faster without it... --- hamming32.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/hamming32.c b/hamming32.c index 24f818c..2d8b882 100644 --- a/hamming32.c +++ b/hamming32.c @@ -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(); -- 2.39.2