mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Reorganize our CRC source files again.
Now that we use CRC-32C in WAL and the control file, the "traditional" and "legacy" CRC-32 variants are not used in any frontend programs anymore. Move the code for those back from src/common to src/backend/utils/hash. Also move the slicing-by-8 implementation (back) to src/port. This is in preparation for next patch that will add another implementation that uses Intel SSE 4.2 instructions to calculate CRC-32C, where available.
This commit is contained in:
49
src/include/port/pg_crc32c.h
Normal file
49
src/include/port/pg_crc32c.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pg_crc32c.h
|
||||
* Routines for computing CRC-32C checksums.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/port/pg_crc32c.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef PG_CRC32C_H
|
||||
#define PG_CRC32C_H
|
||||
|
||||
typedef uint32 pg_crc32c;
|
||||
|
||||
#define INIT_CRC32C(crc) ((crc) = 0xFFFFFFFF)
|
||||
#define EQ_CRC32C(c1, c2) ((c1) == (c2))
|
||||
|
||||
/*
|
||||
* Use slicing-by-8 algorithm.
|
||||
*
|
||||
* On big-endian systems, the intermediate value is kept in reverse byte
|
||||
* order, to avoid byte-swapping during the calculation. FIN_CRC32C reverses
|
||||
* the bytes to the final order.
|
||||
*/
|
||||
#define COMP_CRC32C(crc, data, len) \
|
||||
((crc) = pg_comp_crc32c_sb8((crc), (data), (len)))
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
|
||||
#ifdef HAVE__BUILTIN_BSWAP32
|
||||
#define BSWAP32(x) __builtin_bswap32(x)
|
||||
#else
|
||||
#define BSWAP32(x) (((x << 24) & 0xff000000) | \
|
||||
((x << 8) & 0x00ff0000) | \
|
||||
((x >> 8) & 0x0000ff00) | \
|
||||
((x >> 24) & 0x000000ff))
|
||||
#endif
|
||||
|
||||
#define FIN_CRC32C(crc) ((crc) = BSWAP32(crc) ^ 0xFFFFFFFF)
|
||||
#else
|
||||
#define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF)
|
||||
#endif
|
||||
|
||||
extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len);
|
||||
|
||||
#endif /* PG_CRC32C_H */
|
Reference in New Issue
Block a user