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