adcintrin.h (5565B) - Raw
1 /*===---- adcintrin.h - ADC 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 __ADCINTRIN_H 11 #define __ADCINTRIN_H 12 13 #if !defined(__i386__) && !defined(__x86_64__) 14 #error "This header is only meant to be used on x86 and x64 architecture" 15 #endif 16 17 /* Define the default attributes for the functions in this file. */ 18 #if defined(__cplusplus) && (__cplusplus >= 201103L) 19 #define __DEFAULT_FN_ATTRS \ 20 __attribute__((__always_inline__, __nodebug__)) constexpr 21 #else 22 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) 23 #endif 24 25 /* Use C++ inline semantics in C++, GNU inline for C mode. */ 26 #if defined(__cplusplus) 27 #define __INLINE __inline 28 #else 29 #define __INLINE static __inline 30 #endif 31 32 #if defined(__cplusplus) 33 extern "C" { 34 #endif 35 36 /// Adds unsigned 32-bit integers \a __x and \a __y, plus 0 or 1 as indicated 37 /// by the carry flag \a __cf. Stores the unsigned 32-bit sum in the memory 38 /// at \a __p, and returns the 8-bit carry-out (carry flag). 39 /// 40 /// \code{.operation} 41 /// temp := (__cf == 0) ? 0 : 1 42 /// Store32(__p, __x + __y + temp) 43 /// result := CF 44 /// \endcode 45 /// 46 /// \headerfile <immintrin.h> 47 /// 48 /// This intrinsic corresponds to the \c ADC instruction. 49 /// 50 /// \param __cf 51 /// The 8-bit unsigned carry flag; any non-zero value indicates carry. 52 /// \param __x 53 /// A 32-bit unsigned addend. 54 /// \param __y 55 /// A 32-bit unsigned addend. 56 /// \param __p 57 /// Pointer to memory for storing the sum. 58 /// \returns The 8-bit unsigned carry-out value. 59 __INLINE unsigned char __DEFAULT_FN_ATTRS _addcarry_u32(unsigned char __cf, 60 unsigned int __x, 61 unsigned int __y, 62 unsigned int *__p) { 63 return __builtin_ia32_addcarryx_u32(__cf, __x, __y, __p); 64 } 65 66 /// Adds unsigned 32-bit integer \a __y to 0 or 1 as indicated by the carry 67 /// flag \a __cf, and subtracts the result from unsigned 32-bit integer 68 /// \a __x. Stores the unsigned 32-bit difference in the memory at \a __p, 69 /// and returns the 8-bit carry-out (carry or overflow flag). 70 /// 71 /// \code{.operation} 72 /// temp := (__cf == 0) ? 0 : 1 73 /// Store32(__p, __x - (__y + temp)) 74 /// result := CF 75 /// \endcode 76 /// 77 /// \headerfile <immintrin.h> 78 /// 79 /// This intrinsic corresponds to the \c SBB instruction. 80 /// 81 /// \param __cf 82 /// The 8-bit unsigned carry flag; any non-zero value indicates carry. 83 /// \param __x 84 /// The 32-bit unsigned minuend. 85 /// \param __y 86 /// The 32-bit unsigned subtrahend. 87 /// \param __p 88 /// Pointer to memory for storing the difference. 89 /// \returns The 8-bit unsigned carry-out value. 90 __INLINE unsigned char __DEFAULT_FN_ATTRS _subborrow_u32(unsigned char __cf, 91 unsigned int __x, 92 unsigned int __y, 93 unsigned int *__p) { 94 return __builtin_ia32_subborrow_u32(__cf, __x, __y, __p); 95 } 96 97 #ifdef __x86_64__ 98 /// Adds unsigned 64-bit integers \a __x and \a __y, plus 0 or 1 as indicated 99 /// by the carry flag \a __cf. Stores the unsigned 64-bit sum in the memory 100 /// at \a __p, and returns the 8-bit carry-out (carry flag). 101 /// 102 /// \code{.operation} 103 /// temp := (__cf == 0) ? 0 : 1 104 /// Store64(__p, __x + __y + temp) 105 /// result := CF 106 /// \endcode 107 /// 108 /// \headerfile <immintrin.h> 109 /// 110 /// This intrinsic corresponds to the \c ADC instruction. 111 /// 112 /// \param __cf 113 /// The 8-bit unsigned carry flag; any non-zero value indicates carry. 114 /// \param __x 115 /// A 64-bit unsigned addend. 116 /// \param __y 117 /// A 64-bit unsigned addend. 118 /// \param __p 119 /// Pointer to memory for storing the sum. 120 /// \returns The 8-bit unsigned carry-out value. 121 __INLINE unsigned char __DEFAULT_FN_ATTRS 122 _addcarry_u64(unsigned char __cf, unsigned long long __x, 123 unsigned long long __y, unsigned long long *__p) { 124 return __builtin_ia32_addcarryx_u64(__cf, __x, __y, __p); 125 } 126 127 /// Adds unsigned 64-bit integer \a __y to 0 or 1 as indicated by the carry 128 /// flag \a __cf, and subtracts the result from unsigned 64-bit integer 129 /// \a __x. Stores the unsigned 64-bit difference in the memory at \a __p, 130 /// and returns the 8-bit carry-out (carry or overflow flag). 131 /// 132 /// \code{.operation} 133 /// temp := (__cf == 0) ? 0 : 1 134 /// Store64(__p, __x - (__y + temp)) 135 /// result := CF 136 /// \endcode 137 /// 138 /// \headerfile <immintrin.h> 139 /// 140 /// This intrinsic corresponds to the \c ADC instruction. 141 /// 142 /// \param __cf 143 /// The 8-bit unsigned carry flag; any non-zero value indicates carry. 144 /// \param __x 145 /// The 64-bit unsigned minuend. 146 /// \param __y 147 /// The 64-bit unsigned subtrahend. 148 /// \param __p 149 /// Pointer to memory for storing the difference. 150 /// \returns The 8-bit unsigned carry-out value. 151 __INLINE unsigned char __DEFAULT_FN_ATTRS 152 _subborrow_u64(unsigned char __cf, unsigned long long __x, 153 unsigned long long __y, unsigned long long *__p) { 154 return __builtin_ia32_subborrow_u64(__cf, __x, __y, __p); 155 } 156 #endif 157 158 #if defined(__cplusplus) 159 } 160 #endif 161 162 #undef __INLINE 163 #undef __DEFAULT_FN_ATTRS 164 165 #endif /* __ADCINTRIN_H */