Coverage Report

Created: 2026-09-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/abseil-cpp/absl/crc/internal/crc32c_inline.h
Line
Count
Source
1
// Copyright 2022 The Abseil Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef ABSL_CRC_INTERNAL_CRC32C_INLINE_H_
16
#define ABSL_CRC_INTERNAL_CRC32C_INLINE_H_
17
18
#include <cstddef>
19
#include <cstdint>
20
21
#include "absl/base/config.h"
22
#include "absl/base/internal/endian.h"
23
#include "absl/crc/internal/crc32_x86_arm_combined_simd.h"
24
25
namespace absl {
26
ABSL_NAMESPACE_BEGIN
27
namespace crc_internal {
28
29
// CRC32C implementation optimized for small inputs.
30
// Either computes crc and return true, or if there is
31
// no hardware support does nothing and returns false.
32
0
inline bool ExtendCrc32cInline(uint32_t* crc, const char* p, size_t n) {
33
0
#if defined(ABSL_CRC_INTERNAL_HAVE_ARM_SIMD) || \
34
0
    defined(ABSL_CRC_INTERNAL_HAVE_X86_SIMD)
35
0
  constexpr uint32_t kCrc32Xor = 0xffffffffU;
36
0
  *crc ^= kCrc32Xor;
37
0
  if (n & 1) {
38
0
    *crc = CRC32_u8(*crc, static_cast<uint8_t>(*p));
39
0
    n--;
40
0
    p++;
41
0
  }
42
0
  if (n & 2) {
43
0
    *crc = CRC32_u16(*crc, absl::little_endian::Load16(p));
44
0
    n -= 2;
45
0
    p += 2;
46
0
  }
47
0
  if (n & 4) {
48
0
    *crc = CRC32_u32(*crc, absl::little_endian::Load32(p));
49
0
    n -= 4;
50
0
    p += 4;
51
0
  }
52
0
  while (n) {
53
0
    *crc = CRC32_u64(*crc, absl::little_endian::Load64(p));
54
0
    n -= 8;
55
0
    p += 8;
56
0
  }
57
0
  *crc ^= kCrc32Xor;
58
0
  return true;
59
0
#else
60
0
  // No hardware support, signal the need to fallback.
61
0
  static_cast<void>(crc);
62
0
  static_cast<void>(p);
63
0
  static_cast<void>(n);
64
0
  return false;
65
0
#endif  // defined(ABSL_CRC_INTERNAL_HAVE_ARM_SIMD) ||
66
0
        // defined(ABSL_CRC_INTERNAL_HAVE_X86_SIMD)
67
0
}
68
69
}  // namespace crc_internal
70
ABSL_NAMESPACE_END
71
}  // namespace absl
72
73
#endif  // ABSL_CRC_INTERNAL_CRC32C_INLINE_H_