Coverage Report

Created: 2026-08-18 18:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/index/snii/encoding/crc32c.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <crc32c/crc32c.h>
21
22
#include <cstddef>
23
#include <cstdint>
24
25
#include "storage/index/snii/common/slice.h"
26
27
namespace doris::snii {
28
29
// CRC32C (Castagnoli, polynomial 0x1EDC6F41). Used to checksum the tail of each
30
// format block. Thin inline adapter over Doris's bundled Google crc32c thirdparty
31
// (crc32c::Extend / crc32c::Crc32c). That library computes the same canonical
32
// CRC32C (same reflected polynomial, same standard pre/post inversion), so every
33
// on-disk checksum stays byte-identical to the previous in-tree slice-by-8 /
34
// SSE4.2 implementation -- this is an implementation swap, not a format change.
35
// The leading :: keeps the crc32c namespace distinct from crc32c() below.
36
5.60k
inline uint32_t crc32c_extend(uint32_t crc, Slice data) {
37
5.60k
    return ::crc32c::Extend(crc, data.data(), data.size());
38
5.60k
}
39
40
206k
inline uint32_t crc32c(Slice data) {
41
206k
    return ::crc32c::Crc32c(data.data(), data.size());
42
206k
}
43
44
#ifdef BE_TEST
45
// T21 test seam. The production crc32c()/crc32c_extend() above delegate to the
46
// bundled Google crc32c thirdparty (see commit d0416bb4129), which already runs a
47
// runtime-dispatched, hardware-accelerated and interleaved CRC32C -- so T21's
48
// "hardware interleaved CRC" goal is already met (and exceeded: that library adds
49
// a PCLMULQDQ fold a hand-rolled 3-way _mm_crc32_u64 lacks). Rather than regress
50
// that reuse, the reference sub-paths below let unit tests prove, byte-for-byte
51
// across all sizes/alignments, that the production path equals the canonical
52
// CRC32C and that the hardware path is engaged:
53
//   * crc32c_slice8_extend    -- portable software slice-by-8 (always available);
54
//   * crc32c_hw_serial_extend -- serial SSE4.2 _mm_crc32 hardware path;
55
//   * crc32c_hw3_extend       -- 3-way interleaved SSE4.2 hardware path with a
56
//                                GF(2) shift-combine and a 1024-byte fall-back to
57
//                                the serial path (the algorithm T21 specifies).
58
// hw_serial/hw3 fall back to slice8 when SSE4.2 is absent. Each *_extend applies
59
// the standard ~crc pre/post inversion, so *_extend(0, d) == crc32c(d). The whole
60
// seam plus its static slice-by-8 table and startup CPUID probe are compiled out
61
// of release builds by this BE_TEST gate, so production carries no extra code.
62
// Pure functions with no shared mutable state (CONCURRENCY: N/A).
63
namespace detail {
64
uint32_t crc32c_slice8_extend(uint32_t crc, Slice data);
65
uint32_t crc32c_hw_serial_extend(uint32_t crc, Slice data);
66
uint32_t crc32c_hw3_extend(uint32_t crc, Slice data);
67
size_t crc32c_interleave_threshold();
68
bool crc32c_has_hw();
69
} // namespace detail
70
#endif // BE_TEST
71
72
} // namespace doris::snii