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