Commit c1211838 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Lift some crc magic constants

Summary: [Folly] Lift some crc magic constants in `folly/hash/detail/Crc32CombineDetail.cpp`.

Differential Revision: D9934404

fbshipit-source-id: e2508a22e300e22f2265383a0a111df53d2738c5
parent c23e38c1
...@@ -117,13 +117,16 @@ static uint32_t gf_multiply_crc32_hw(uint64_t, uint64_t, uint32_t) { ...@@ -117,13 +117,16 @@ static uint32_t gf_multiply_crc32_hw(uint64_t, uint64_t, uint32_t) {
#endif #endif
static constexpr uint32_t crc32c_m = 0x82f63b78;
static constexpr uint32_t crc32_m = 0xedb88320;
/* /*
* Pre-calculated powers tables for crc32c and crc32. * Pre-calculated powers tables for crc32c and crc32.
*/ */
static constexpr std::array<uint32_t, 62> const crc32c_powers = static constexpr std::array<uint32_t, 62> const crc32c_powers =
gf_powers_make<0x82f63b78>{}(make_index_sequence<62>{}); gf_powers_make<crc32c_m>{}(make_index_sequence<62>{});
static constexpr std::array<uint32_t, 62> const crc32_powers = static constexpr std::array<uint32_t, 62> const crc32_powers =
gf_powers_make<0xedb88320>{}(make_index_sequence<62>{}); gf_powers_make<crc32_m>{}(make_index_sequence<62>{});
template <typename F> template <typename F>
static uint32_t crc32_append_zeroes( static uint32_t crc32_append_zeroes(
...@@ -157,26 +160,25 @@ namespace detail { ...@@ -157,26 +160,25 @@ namespace detail {
uint32_t crc32_combine_sw(uint32_t crc1, uint32_t crc2, size_t crc2len) { uint32_t crc32_combine_sw(uint32_t crc1, uint32_t crc2, size_t crc2len) {
return crc2 ^ return crc2 ^
crc32_append_zeroes( crc32_append_zeroes(gf_multiply_sw, crc1, crc2len, crc32_m, crc32_powers);
gf_multiply_sw, crc1, crc2len, 0xEDB88320, crc32_powers);
} }
uint32_t crc32_combine_hw(uint32_t crc1, uint32_t crc2, size_t crc2len) { uint32_t crc32_combine_hw(uint32_t crc1, uint32_t crc2, size_t crc2len) {
return crc2 ^ return crc2 ^
crc32_append_zeroes( crc32_append_zeroes(
gf_multiply_crc32_hw, crc1, crc2len, 0xEDB88320, crc32_powers); gf_multiply_crc32_hw, crc1, crc2len, crc32_m, crc32_powers);
} }
uint32_t crc32c_combine_sw(uint32_t crc1, uint32_t crc2, size_t crc2len) { uint32_t crc32c_combine_sw(uint32_t crc1, uint32_t crc2, size_t crc2len) {
return crc2 ^ return crc2 ^
crc32_append_zeroes( crc32_append_zeroes(
gf_multiply_sw, crc1, crc2len, 0x82F63B78, crc32c_powers); gf_multiply_sw, crc1, crc2len, crc32c_m, crc32c_powers);
} }
uint32_t crc32c_combine_hw(uint32_t crc1, uint32_t crc2, size_t crc2len) { uint32_t crc32c_combine_hw(uint32_t crc1, uint32_t crc2, size_t crc2len) {
return crc2 ^ return crc2 ^
crc32_append_zeroes( crc32_append_zeroes(
gf_multiply_crc32c_hw, crc1, crc2len, 0x82F63B78, crc32c_powers); gf_multiply_crc32c_hw, crc1, crc2len, crc32c_m, crc32c_powers);
} }
} // namespace detail } // namespace detail
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment