Coverage Report

Created: 2026-07-25 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/abseil-cpp/absl/crc/internal/crc_memcpy_fallback.cc
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
#include <cstdint>
16
#include <memory>
17
18
#include "absl/base/config.h"
19
#include "absl/crc/crc32c.h"
20
#include "absl/crc/internal/crc_memcpy.h"
21
22
namespace absl {
23
ABSL_NAMESPACE_BEGIN
24
namespace crc_internal {
25
26
absl::crc32c_t FallbackCrcMemcpyEngine::Compute(void* __restrict dst,
27
                                                const void* __restrict src,
28
                                                std::size_t length,
29
0
                                                crc32c_t initial_crc) const {
30
0
  constexpr size_t kBlockSize = 8192;
31
0
  absl::crc32c_t crc = initial_crc;
32
33
0
  const char* src_bytes = reinterpret_cast<const char*>(src);
34
0
  char* dst_bytes = reinterpret_cast<char*>(dst);
35
36
  // Copy + CRC loop - run 8k chunks until we are out of full chunks.  CRC
37
  // then copy was found to be slightly more efficient in our test cases.
38
0
  std::size_t offset = 0;
39
0
  for (; offset + kBlockSize < length; offset += kBlockSize) {
40
0
    crc = absl::ExtendCrc32c(crc,
41
0
                             absl::string_view(src_bytes + offset, kBlockSize));
42
0
    memcpy(dst_bytes + offset, src_bytes + offset, kBlockSize);
43
0
  }
44
45
  // Save some work if length is 0.
46
0
  if (offset < length) {
47
0
    std::size_t final_copy_size = length - offset;
48
0
    crc = absl::ExtendCrc32c(
49
0
        crc, absl::string_view(src_bytes + offset, final_copy_size));
50
0
    memcpy(dst_bytes + offset, src_bytes + offset, final_copy_size);
51
0
  }
52
53
0
  return crc;
54
0
}
55
56
// Compile the following only if we don't have
57
#if !defined(ABSL_INTERNAL_HAVE_X86_64_ACCELERATED_CRC_MEMCPY_ENGINE) && \
58
    !defined(ABSL_INTERNAL_HAVE_ARM_ACCELERATED_CRC_MEMCPY_ENGINE)
59
60
0
CrcMemcpy::ArchSpecificEngines CrcMemcpy::GetArchSpecificEngines() {
61
0
  CrcMemcpy::ArchSpecificEngines engines;
62
0
  engines.temporal = new FallbackCrcMemcpyEngine();
63
0
  engines.non_temporal = new FallbackCrcMemcpyEngine();
64
0
  return engines;
65
0
}
66
67
std::unique_ptr<CrcMemcpyEngine> CrcMemcpy::GetTestEngine(int /*vector*/,
68
0
                                                          int /*integer*/) {
69
0
  return std::make_unique<FallbackCrcMemcpyEngine>();
70
0
}
71
72
#endif  // !ABSL_INTERNAL_HAVE_X86_64_ACCELERATED_CRC_MEMCPY_ENGINE &&
73
        // !ABSL_INTERNAL_HAVE_ARM_ACCELERATED_CRC_MEMCPY_ENGINE
74
75
}  // namespace crc_internal
76
ABSL_NAMESPACE_END
77
}  // namespace absl