1 //===-- scudo_crc32.cpp -----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// CRC32 function leveraging hardware specific instructions. This has to be
11 /// kept separated to restrict the use of compiler specific flags to this file.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "sanitizer_common/sanitizer_internal_defs.h"
16 
17 // Hardware CRC32 is supported at compilation via the following:
18 // - for i386 & x86_64: -msse4.2
19 // - for ARM & AArch64: -march=armv8-a+crc or -mcrc
20 // An additional check must be performed at runtime as well to make sure the
21 // emitted instructions are valid on the target host.
22 
23 #if defined(__SSE4_2__) || defined(__ARM_FEATURE_CRC32)
24 # ifdef __SSE4_2__
25 #  include <smmintrin.h>
26 #  define CRC32_INTRINSIC FIRST_32_SECOND_64(_mm_crc32_u32, _mm_crc32_u64)
27 # endif
28 # ifdef __ARM_FEATURE_CRC32
29 #  include <arm_acle.h>
30 #  define CRC32_INTRINSIC FIRST_32_SECOND_64(__crc32cw, __crc32cd)
31 # endif
32 #endif  // defined(__SSE4_2__) || defined(__ARM_FEATURE_CRC32)
33 
34 namespace __scudo {
35 
36 #if defined(__SSE4_2__) || defined(__ARM_FEATURE_CRC32)
37 u32 computeHardwareCRC32(u32 Crc, uptr Data) {
38   return CRC32_INTRINSIC(Crc, Data);
39 }
40 #endif  // defined(__SSE4_2__) || defined(__ARM_FEATURE_CRC32)
41 
42 }  // namespace __scudo
43