clang 23.0.0git
crc32intrin.h
Go to the documentation of this file.
1/*===---- crc32intrin.h - SSE4.2 Accumulate CRC32 intrinsics ---------------===
2 *
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 *
7 *===-----------------------------------------------------------------------===
8 */
9
10#ifndef __CRC32INTRIN_H
11#define __CRC32INTRIN_H
12
13/// We only declare crc32 as a constexpr if we are compiling C++ code
14#if defined(__cplusplus) && (__cplusplus >= 201103L)
15#define __DEFAULT_FN_ATTRS \
16 __attribute__((__always_inline__, __nodebug__, __target__("crc32"))) constexpr
17#else
18#define __DEFAULT_FN_ATTRS \
19 __attribute__((__always_inline__, __nodebug__, __target__("crc32")))
20#endif
21
22/// Adds the unsigned integer operand to the CRC-32C checksum of the
23/// unsigned char operand.
24///
25/// \headerfile <x86intrin.h>
26///
27/// This intrinsic corresponds to the <c> CRC32B </c> instruction.
28///
29/// \param __C
30/// An unsigned integer operand to add to the CRC-32C checksum of operand
31/// \a __D.
32/// \param __D
33/// An unsigned 8-bit integer operand used to compute the CRC-32C checksum.
34/// \returns The result of adding operand \a __C to the CRC-32C checksum of
35/// operand \a __D.
36static __inline__ unsigned int __DEFAULT_FN_ATTRS
37_mm_crc32_u8(unsigned int __C, unsigned char __D) {
38 return __builtin_ia32_crc32qi(__C, __D);
39}
40
41/// Adds the unsigned integer operand to the CRC-32C checksum of the
42/// unsigned short operand.
43///
44/// \headerfile <x86intrin.h>
45///
46/// This intrinsic corresponds to the <c> CRC32W </c> instruction.
47///
48/// \param __C
49/// An unsigned integer operand to add to the CRC-32C checksum of operand
50/// \a __D.
51/// \param __D
52/// An unsigned 16-bit integer operand used to compute the CRC-32C checksum.
53/// \returns The result of adding operand \a __C to the CRC-32C checksum of
54/// operand \a __D.
55static __inline__ unsigned int __DEFAULT_FN_ATTRS
56_mm_crc32_u16(unsigned int __C, unsigned short __D) {
57 return __builtin_ia32_crc32hi(__C, __D);
58}
59
60/// Adds the first unsigned integer operand to the CRC-32C checksum of
61/// the second unsigned integer operand.
62///
63/// \headerfile <x86intrin.h>
64///
65/// This intrinsic corresponds to the <c> CRC32L </c> instruction.
66///
67/// \param __C
68/// An unsigned integer operand to add to the CRC-32C checksum of operand
69/// \a __D.
70/// \param __D
71/// An unsigned 32-bit integer operand used to compute the CRC-32C checksum.
72/// \returns The result of adding operand \a __C to the CRC-32C checksum of
73/// operand \a __D.
74static __inline__ unsigned int __DEFAULT_FN_ATTRS
75_mm_crc32_u32(unsigned int __C, unsigned int __D) {
76 return __builtin_ia32_crc32si(__C, __D);
77}
78
79#ifdef __x86_64__
80/// Adds the unsigned integer operand to the CRC-32C checksum of the
81/// unsigned 64-bit integer operand.
82///
83/// \headerfile <x86intrin.h>
84///
85/// This intrinsic corresponds to the <c> CRC32Q </c> instruction.
86///
87/// \param __C
88/// An unsigned integer operand to add to the CRC-32C checksum of operand
89/// \a __D.
90/// \param __D
91/// An unsigned 64-bit integer operand used to compute the CRC-32C checksum.
92/// \returns The result of adding operand \a __C to the CRC-32C checksum of
93/// operand \a __D.
94static __inline__ unsigned long long __DEFAULT_FN_ATTRS
95_mm_crc32_u64(unsigned long long __C, unsigned long long __D) {
96 return __builtin_ia32_crc32di(__C, __D);
97}
98#endif /* __x86_64__ */
99
100#undef __DEFAULT_FN_ATTRS
101
102#endif /* __CRC32INTRIN_H */
#define __DEFAULT_FN_ATTRS
static __inline__ unsigned int __DEFAULT_FN_ATTRS _mm_crc32_u8(unsigned int __C, unsigned char __D)
Adds the unsigned integer operand to the CRC-32C checksum of the unsigned char operand.
Definition crc32intrin.h:37
static __inline__ unsigned int __DEFAULT_FN_ATTRS _mm_crc32_u32(unsigned int __C, unsigned int __D)
Adds the first unsigned integer operand to the CRC-32C checksum of the second unsigned integer operan...
Definition crc32intrin.h:75
static __inline__ unsigned int __DEFAULT_FN_ATTRS _mm_crc32_u16(unsigned int __C, unsigned short __D)
Adds the unsigned integer operand to the CRC-32C checksum of the unsigned short operand.
Definition crc32intrin.h:56
static __inline__ void short __D
Definition immintrin.h:342