Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:15

0001 // Copyright 2022 The Abseil Authors.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //      https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 // Unless required by applicable law or agreed to in writing, software
0010 // distributed under the License is distributed on an "AS IS" BASIS,
0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 // See the License for the specific language governing permissions and
0013 // limitations under the License.
0014 
0015 #ifndef ABSL_CRC_INTERNAL_CRC32C_INLINE_H_
0016 #define ABSL_CRC_INTERNAL_CRC32C_INLINE_H_
0017 
0018 #include <cstdint>
0019 
0020 #include "absl/base/config.h"
0021 #include "absl/base/internal/endian.h"
0022 #include "absl/crc/internal/crc32_x86_arm_combined_simd.h"
0023 
0024 namespace absl {
0025 ABSL_NAMESPACE_BEGIN
0026 namespace crc_internal {
0027 
0028 // CRC32C implementation optimized for small inputs.
0029 // Either computes crc and return true, or if there is
0030 // no hardware support does nothing and returns false.
0031 inline bool ExtendCrc32cInline(uint32_t* crc, const char* p, size_t n) {
0032 #if defined(ABSL_CRC_INTERNAL_HAVE_ARM_SIMD) || \
0033     defined(ABSL_CRC_INTERNAL_HAVE_X86_SIMD)
0034   constexpr uint32_t kCrc32Xor = 0xffffffffU;
0035   *crc ^= kCrc32Xor;
0036   if (n & 1) {
0037     *crc = CRC32_u8(*crc, static_cast<uint8_t>(*p));
0038     n--;
0039     p++;
0040   }
0041   if (n & 2) {
0042     *crc = CRC32_u16(*crc, absl::little_endian::Load16(p));
0043     n -= 2;
0044     p += 2;
0045   }
0046   if (n & 4) {
0047     *crc = CRC32_u32(*crc, absl::little_endian::Load32(p));
0048     n -= 4;
0049     p += 4;
0050   }
0051   while (n) {
0052     *crc = CRC32_u64(*crc, absl::little_endian::Load64(p));
0053     n -= 8;
0054     p += 8;
0055   }
0056   *crc ^= kCrc32Xor;
0057   return true;
0058 #else
0059   // No hardware support, signal the need to fallback.
0060   static_cast<void>(crc);
0061   static_cast<void>(p);
0062   static_cast<void>(n);
0063   return false;
0064 #endif  // defined(ABSL_CRC_INTERNAL_HAVE_ARM_SIMD) ||
0065         // defined(ABSL_CRC_INTERNAL_HAVE_X86_SIMD)
0066 }
0067 
0068 }  // namespace crc_internal
0069 ABSL_NAMESPACE_END
0070 }  // namespace absl
0071 
0072 #endif  // ABSL_CRC_INTERNAL_CRC32C_INLINE_H_