xref: /aosp_15_r20/external/webrtc/third_party/crc32c/src/src/crc32c_sse42_check.h (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 #ifndef CRC32C_CRC32C_SSE42_CHECK_H_
6 #define CRC32C_CRC32C_SSE42_CHECK_H_
7 
8 // X86-specific code checking the availability of SSE4.2 instructions.
9 
10 #include <cstddef>
11 #include <cstdint>
12 
13 #include "crc32c/crc32c_config.h"
14 
15 #if HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
16 
17 // If the compiler supports SSE4.2, it definitely supports X86.
18 
19 #if defined(_MSC_VER)
20 #include <intrin.h>
21 
22 namespace crc32c {
23 
CanUseSse42()24 inline bool CanUseSse42() {
25   int cpu_info[4];
26   __cpuid(cpu_info, 1);
27   return (cpu_info[2] & (1 << 20)) != 0;
28 }
29 
30 }  // namespace crc32c
31 
32 #else  // !defined(_MSC_VER)
33 #include <cpuid.h>
34 
35 namespace crc32c {
36 
CanUseSse42()37 inline bool CanUseSse42() {
38   unsigned int eax, ebx, ecx, edx;
39   return __get_cpuid(1, &eax, &ebx, &ecx, &edx) && ((ecx & (1 << 20)) != 0);
40 }
41 
42 }  // namespace crc32c
43 
44 #endif  // defined(_MSC_VER)
45 
46 #endif  // HAVE_SSE42 && (defined(_M_X64) || defined(__x86_64__))
47 
48 #endif  // CRC32C_CRC32C_SSE42_CHECK_H_
49