xref: /aosp_15_r20/external/webrtc/third_party/crc32c/src/src/crc32c.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 // Copyright 2017 The CRC32C Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. See the AUTHORS file for names of contributors.
4 
5 #include "crc32c/crc32c.h"
6 
7 #include <cstddef>
8 #include <cstdint>
9 
10 #include "./crc32c_arm64.h"
11 #include "./crc32c_arm64_check.h"
12 #include "./crc32c_internal.h"
13 #include "./crc32c_sse42.h"
14 #include "./crc32c_sse42_check.h"
15 
16 namespace crc32c {
17 
Extend(uint32_t crc,const uint8_t * data,size_t count)18 uint32_t Extend(uint32_t crc, const uint8_t* data, size_t count) {
19 #if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
20   static bool can_use_sse42 = CanUseSse42();
21   if (can_use_sse42) return ExtendSse42(crc, data, count);
22 #elif HAVE_ARM64_CRC32C
23   static bool can_use_arm64_crc32 = CanUseArm64Crc32();
24   if (can_use_arm64_crc32) return ExtendArm64(crc, data, count);
25 #endif  // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
26 
27   return ExtendPortable(crc, data, count);
28 }
29 
crc32c_extend(uint32_t crc,const uint8_t * data,size_t count)30 extern "C" uint32_t crc32c_extend(uint32_t crc, const uint8_t* data,
31                                   size_t count) {
32   return crc32c::Extend(crc, data, count);
33 }
34 
crc32c_value(const uint8_t * data,size_t count)35 extern "C" uint32_t crc32c_value(const uint8_t* data, size_t count) {
36   return crc32c::Crc32c(data, count);
37 }
38 
39 }  // namespace crc32c
40