File indexing completed on 2025-01-18 09:27:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef ABSL_CRC_INTERNAL_CRC_MEMCPY_H_
0016 #define ABSL_CRC_INTERNAL_CRC_MEMCPY_H_
0017
0018 #include <cstddef>
0019 #include <memory>
0020
0021 #include "absl/base/config.h"
0022 #include "absl/crc/crc32c.h"
0023 #include "absl/crc/internal/crc32_x86_arm_combined_simd.h"
0024
0025
0026
0027
0028 #if defined(ABSL_CRC_INTERNAL_HAVE_X86_SIMD)
0029 #define ABSL_INTERNAL_HAVE_X86_64_ACCELERATED_CRC_MEMCPY_ENGINE 1
0030 #elif defined(ABSL_CRC_INTERNAL_HAVE_ARM_SIMD)
0031 #define ABSL_INTERNAL_HAVE_ARM_ACCELERATED_CRC_MEMCPY_ENGINE 1
0032 #endif
0033
0034 namespace absl {
0035 ABSL_NAMESPACE_BEGIN
0036 namespace crc_internal {
0037
0038 class CrcMemcpyEngine {
0039 public:
0040 virtual ~CrcMemcpyEngine() = default;
0041
0042 virtual crc32c_t Compute(void* __restrict dst, const void* __restrict src,
0043 std::size_t length, crc32c_t initial_crc) const = 0;
0044
0045 protected:
0046 CrcMemcpyEngine() = default;
0047 };
0048
0049 class CrcMemcpy {
0050 public:
0051 static crc32c_t CrcAndCopy(void* __restrict dst, const void* __restrict src,
0052 std::size_t length,
0053 crc32c_t initial_crc = crc32c_t{0},
0054 bool non_temporal = false) {
0055 static const ArchSpecificEngines engines = GetArchSpecificEngines();
0056 auto* engine = non_temporal ? engines.non_temporal : engines.temporal;
0057 return engine->Compute(dst, src, length, initial_crc);
0058 }
0059
0060
0061 static std::unique_ptr<CrcMemcpyEngine> GetTestEngine(int vector,
0062 int integer);
0063
0064 private:
0065 struct ArchSpecificEngines {
0066 CrcMemcpyEngine* temporal;
0067 CrcMemcpyEngine* non_temporal;
0068 };
0069
0070 static ArchSpecificEngines GetArchSpecificEngines();
0071 };
0072
0073
0074 class FallbackCrcMemcpyEngine : public CrcMemcpyEngine {
0075 public:
0076 FallbackCrcMemcpyEngine() = default;
0077 FallbackCrcMemcpyEngine(const FallbackCrcMemcpyEngine&) = delete;
0078 FallbackCrcMemcpyEngine operator=(const FallbackCrcMemcpyEngine&) = delete;
0079
0080 crc32c_t Compute(void* __restrict dst, const void* __restrict src,
0081 std::size_t length, crc32c_t initial_crc) const override;
0082 };
0083
0084
0085 class CrcNonTemporalMemcpyEngine : public CrcMemcpyEngine {
0086 public:
0087 CrcNonTemporalMemcpyEngine() = default;
0088 CrcNonTemporalMemcpyEngine(const CrcNonTemporalMemcpyEngine&) = delete;
0089 CrcNonTemporalMemcpyEngine operator=(const CrcNonTemporalMemcpyEngine&) =
0090 delete;
0091
0092 crc32c_t Compute(void* __restrict dst, const void* __restrict src,
0093 std::size_t length, crc32c_t initial_crc) const override;
0094 };
0095
0096
0097 class CrcNonTemporalMemcpyAVXEngine : public CrcMemcpyEngine {
0098 public:
0099 CrcNonTemporalMemcpyAVXEngine() = default;
0100 CrcNonTemporalMemcpyAVXEngine(const CrcNonTemporalMemcpyAVXEngine&) = delete;
0101 CrcNonTemporalMemcpyAVXEngine operator=(
0102 const CrcNonTemporalMemcpyAVXEngine&) = delete;
0103
0104 crc32c_t Compute(void* __restrict dst, const void* __restrict src,
0105 std::size_t length, crc32c_t initial_crc) const override;
0106 };
0107
0108
0109
0110
0111 inline crc32c_t Crc32CAndCopy(void* __restrict dst, const void* __restrict src,
0112 std::size_t length,
0113 crc32c_t initial_crc = crc32c_t{0},
0114 bool non_temporal = false) {
0115 return CrcMemcpy::CrcAndCopy(dst, src, length, initial_crc, non_temporal);
0116 }
0117
0118 }
0119 ABSL_NAMESPACE_END
0120 }
0121
0122 #endif