Re: [PATCH] add slice by 8 algorithm to crc32.c

From: George Spelvin
Date: Mon Aug 08 2011 - 08:55:08 EST


> -#define LE_TABLE_SIZE (1 << CRC_LE_BITS)
> -#define BE_TABLE_SIZE (1 << CRC_BE_BITS)
> +#if CRC_LE_BITS > 8
> +# define LE_TABLE_SIZE 256
> +#else
> +# define LE_TABLE_SIZE (1 << CRC_LE_BITS)
> +#endif
> +#if CRC_BE_BITS > 8
> +# define BE_TABLE_SIZE 256
> +#else
> +# define BE_TABLE_SIZE (1 << CRC_BE_BITS)
> +#endif
>
> -static uint32_t crc32table_le[4][LE_TABLE_SIZE];
> -static uint32_t crc32table_be[4][BE_TABLE_SIZE];
> +#define LE_TABLE_ROWS ((CRC_LE_BITS - 1)/8 + 1)
> +#define BE_TABLE_ROWS ((CRC_BE_BITS - 1)/8 + 1)
> +
> +static uint32_t crc32table_le[LE_TABLE_ROWS][LE_TABLE_SIZE];
> +static uint32_t crc32table_be[BE_TABLE_ROWS][BE_TABLE_SIZE];

Minor cleanup suggestion: The two different ways of computing
xE_TABLE_SIZE and xE_TABLE_ROWS is a bit confusing.

May I recommend choosing one of the following:

#if CRC_LE_BITS > 8
# define LE_TABLE_ROWS (CRC_LE_BITS/8)
# define LE_TABLE_SIZE 256
#else
# define LE_TABLE_ROWS 1
# define LE_TABLE_SIZE (1 << CRC_LE_BITS)
#endif

or

#define LE_TABLE_ROWS ((CRC_LE_BITS - 1)/8 + 1)
#define LE_TABLE_SIZE (1 << ((CRC_LE_BITS - 1)%8 + 1))

Either one makes the relationship between the two clearer.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/