From: Hans Kristian Rosbach Date: Mon, 25 May 2015 21:03:25 +0000 (+0200) Subject: Style cleanup for adler/crc code X-Git-Tag: 1.9.9-b1~803^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9b63c782f7f7ed44ce1e332a17e137796e8b2d1;p=thirdparty%2Fzlib-ng.git Style cleanup for adler/crc code --- diff --git a/adler32.c b/adler32.c index 7cded1d25..f2dd922f0 100644 --- a/adler32.c +++ b/adler32.c @@ -7,17 +7,17 @@ #include "zutil.h" -static uint32_t adler32_combine_ (uint32_t adler1, uint32_t adler2, z_off64_t len2); +static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2); #define BASE 65521 /* largest prime smaller than 65536 */ #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ -#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} -#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); -#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); -#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); -#define DO16(buf) DO8(buf,0); DO8(buf,8); +#define DO1(buf, i) {adler += (buf)[i]; sum2 += adler;} +#define DO2(buf, i) DO1(buf, i); DO1(buf, i+1); +#define DO4(buf, i) DO2(buf, i); DO2(buf, i+2); +#define DO8(buf, i) DO4(buf, i); DO4(buf, i+4); +#define DO16(buf) DO8(buf, 0); DO8(buf, 8); /* use NO_DIVIDE if your processor does not do division in hardware -- try it both ways to see which is faster */ @@ -60,8 +60,7 @@ static uint32_t adler32_combine_ (uint32_t adler1, uint32_t adler2, z_off64_t le #endif /* ========================================================================= */ -uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uInt len) -{ +uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uInt len) { uint32_t sum2; unsigned n; @@ -109,7 +108,7 @@ uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uInt len) DO16(buf); /* 16 sums unrolled */ buf += 16; #else - DO8(buf,0); /* 8 sums unrolled */ + DO8(buf, 0); /* 8 sums unrolled */ buf += 8; #endif } while (--n); @@ -144,8 +143,7 @@ uint32_t ZEXPORT adler32(uint32_t adler, const unsigned char *buf, uInt len) } /* ========================================================================= */ -static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2) -{ +static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len2) { uint32_t sum1; uint32_t sum2; unsigned rem; @@ -170,12 +168,10 @@ static uint32_t adler32_combine_(uint32_t adler1, uint32_t adler2, z_off64_t len } /* ========================================================================= */ -uint32_t ZEXPORT adler32_combine(uint32_t adler1, uint32_t adler2, z_off_t len2) -{ +uint32_t ZEXPORT adler32_combine(uint32_t adler1, uint32_t adler2, z_off_t len2) { return adler32_combine_(adler1, adler2, len2); } -uint32_t ZEXPORT adler32_combine64(uint32_t adler1, uint32_t adler2, z_off64_t len2) -{ +uint32_t ZEXPORT adler32_combine64(uint32_t adler1, uint32_t adler2, z_off64_t len2) { return adler32_combine_(adler1, adler2, len2); } diff --git a/crc32.c b/crc32.c index da7a8dfc4..34343b2b0 100644 --- a/crc32.c +++ b/crc32.c @@ -45,24 +45,23 @@ #include "deflate.h" #if BYTE_ORDER == LITTLE_ENDIAN -static uint32_t crc32_little (uint32_t, const unsigned char *, unsigned); +static uint32_t crc32_little(uint32_t, const unsigned char *, unsigned); #elif BYTE_ORDER == BIG_ENDIAN -static uint32_t crc32_big (uint32_t, const unsigned char *, unsigned); +static uint32_t crc32_big(uint32_t, const unsigned char *, unsigned); #endif /* Local functions for crc concatenation */ -static uint32_t gf2_matrix_times (uint32_t *mat, uint32_t vec); -static void gf2_matrix_square (uint32_t *square, uint32_t *mat); -static uint32_t crc32_combine_ (uint32_t crc1, uint32_t crc2, z_off64_t len2); +static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec); +static void gf2_matrix_square(uint32_t *square, uint32_t *mat); +static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2); #ifdef DYNAMIC_CRC_TABLE - static volatile int crc_table_empty = 1; static uint32_t crc_table[8][256]; -static void make_crc_table (void); +static void make_crc_table(void); #ifdef MAKECRCH - static void write_table (FILE *, const uint32_t *); +static void write_table(FILE *, const uint32_t *); #endif /* MAKECRCH */ /* Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: @@ -90,14 +89,13 @@ static void make_crc_table (void); allow for word-at-a-time CRC calculation for both big-endian and little- endian machines, where a word is four bytes. */ -static void make_crc_table() -{ +static void make_crc_table() { uint32_t c; int n, k; uint32_t poly; /* polynomial exclusive-or pattern */ /* terms of polynomial defining this crc (except x^32): */ static volatile int first = 1; /* flag to limit concurrent making */ - static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; + static const unsigned char p[] = {0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26}; /* See if another task is already doing this (not thread-safe, but better than nothing -- significantly reduces duration of vulnerability in @@ -131,11 +129,10 @@ static void make_crc_table() } crc_table_empty = 0; - } - else { /* not first */ + } else { /* not first */ /* wait for the other guy to finish (not efficient, but rare) */ while (crc_table_empty) - ; + {} } #ifdef MAKECRCH @@ -161,8 +158,7 @@ static void make_crc_table() } #ifdef MAKECRCH -static void write_table(FILE *out, const uint32_t *table) -{ +static void write_table(FILE *out, const uint32_t *table) { int n; for (n = 0; n < 256; n++) @@ -182,8 +178,7 @@ static void write_table(FILE *out, const uint32_t *table) /* ========================================================================= * This function can be used by asm versions of crc32() */ -const uint32_t * ZEXPORT get_crc_table(void) -{ +const uint32_t * ZEXPORT get_crc_table(void) { #ifdef DYNAMIC_CRC_TABLE if (crc_table_empty) make_crc_table(); @@ -197,8 +192,7 @@ const uint32_t * ZEXPORT get_crc_table(void) #define DO4 DO1; DO1; DO1; DO1 /* ========================================================================= */ -uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uInt len) -{ +uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uInt len) { if (buf == Z_NULL) return 0; #ifdef DYNAMIC_CRC_TABLE @@ -242,8 +236,7 @@ uint32_t ZEXPORT crc32(uint32_t crc, const unsigned char *buf, uInt len) #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 /* ========================================================================= */ -static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, unsigned len) -{ +static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, unsigned len) { register uint32_t c; register const uint32_t *buf4; @@ -285,8 +278,7 @@ static uint32_t crc32_little(uint32_t crc, const unsigned char *buf, unsigned le #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 /* ========================================================================= */ -static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, unsigned len) -{ +static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, unsigned len) { register uint32_t c; register const uint32_t *buf4; @@ -326,8 +318,7 @@ static uint32_t crc32_big(uint32_t crc, const unsigned char *buf, unsigned len) #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ /* ========================================================================= */ -static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec) -{ +static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec) { uint32_t sum; sum = 0; @@ -341,8 +332,7 @@ static uint32_t gf2_matrix_times(uint32_t *mat, uint32_t vec) } /* ========================================================================= */ -static void gf2_matrix_square(uint32_t *square, uint32_t *mat) -{ +static void gf2_matrix_square(uint32_t *square, uint32_t *mat) { int n; for (n = 0; n < GF2_DIM; n++) @@ -350,8 +340,7 @@ static void gf2_matrix_square(uint32_t *square, uint32_t *mat) } /* ========================================================================= */ -static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) -{ +static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) { int n; uint32_t row; uint32_t even[GF2_DIM]; /* even-power-of-two zeros operator */ @@ -403,13 +392,11 @@ static uint32_t crc32_combine_(uint32_t crc1, uint32_t crc2, z_off64_t len2) } /* ========================================================================= */ -uint32_t ZEXPORT crc32_combine(uint32_t crc1, uint32_t crc2, z_off_t len2) -{ +uint32_t ZEXPORT crc32_combine(uint32_t crc1, uint32_t crc2, z_off_t len2) { return crc32_combine_(crc1, crc2, len2); } -uint32_t ZEXPORT crc32_combine64(uint32_t crc1, uint32_t crc2, z_off64_t len2) -{ +uint32_t ZEXPORT crc32_combine64(uint32_t crc1, uint32_t crc2, z_off64_t len2) { return crc32_combine_(crc1, crc2, len2); } @@ -418,12 +405,11 @@ uint32_t ZEXPORT crc32_combine64(uint32_t crc1, uint32_t crc2, z_off64_t len2) #include "arch/x86/x86.h" extern void ZLIB_INTERNAL crc_fold_init(deflate_state *const s); extern void ZLIB_INTERNAL crc_fold_copy(deflate_state *const s, - unsigned char *dst, const unsigned char *src, long len); + unsigned char *dst, const unsigned char *src, long len); extern uint32_t ZLIB_INTERNAL crc_fold_512to32(deflate_state *const s); #endif -ZLIB_INTERNAL void crc_reset(deflate_state *const s) -{ +ZLIB_INTERNAL void crc_reset(deflate_state *const s) { #ifdef X86_PCLMULQDQ_CRC if (x86_cpu_has_pclmulqdq) { crc_fold_init(s); @@ -433,16 +419,14 @@ ZLIB_INTERNAL void crc_reset(deflate_state *const s) s->strm->adler = crc32(0L, Z_NULL, 0); } -ZLIB_INTERNAL void crc_finalize(deflate_state *const s) -{ +ZLIB_INTERNAL void crc_finalize(deflate_state *const s) { #ifdef X86_PCLMULQDQ_CRC if (x86_cpu_has_pclmulqdq) s->strm->adler = crc_fold_512to32(s); #endif } -ZLIB_INTERNAL void copy_with_crc(z_stream *strm, unsigned char *dst, long size) -{ +ZLIB_INTERNAL void copy_with_crc(z_stream *strm, unsigned char *dst, long size) { #ifdef X86_PCLMULQDQ_CRC if (x86_cpu_has_pclmulqdq) { crc_fold_copy(strm->state, dst, strm->next_in, size); diff --git a/crc32.h b/crc32.h index a56e50b62..d194d10b5 100644 --- a/crc32.h +++ b/crc32.h @@ -1,3 +1,6 @@ +#ifndef CRC32_H_ +#define CRC32_H_ + /* crc32.h -- tables for rapid CRC calculation * Generated automatically by crc32.c */ @@ -437,3 +440,5 @@ static const uint32_t crc_table[8][256] = 0xf10605de } }; + +#endif /* CRC32_H_ */