166 lines · c
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-exception6 *7 *===-----------------------------------------------------------------------===8 */9 10#ifndef __ADCINTRIN_H11#define __ADCINTRIN_H12 13#if !defined(__i386__) && !defined(__x86_64__)14#error "This header is only meant to be used on x86 and x64 architecture"15#endif16 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__)) constexpr21#else22#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))23#endif24 25/* Use C++ inline semantics in C++, GNU inline for C mode. */26#if defined(__cplusplus)27#define __INLINE __inline28#else29#define __INLINE static __inline30#endif31 32#if defined(__cplusplus)33extern "C" {34#endif35 36/// Adds unsigned 32-bit integers \a __x and \a __y, plus 0 or 1 as indicated37/// by the carry flag \a __cf. Stores the unsigned 32-bit sum in the memory38/// at \a __p, and returns the 8-bit carry-out (carry flag).39///40/// \code{.operation}41/// temp := (__cf == 0) ? 0 : 142/// Store32(__p, __x + __y + temp)43/// result := CF44/// \endcode45///46/// \headerfile <immintrin.h>47///48/// This intrinsic corresponds to the \c ADC instruction.49///50/// \param __cf51/// The 8-bit unsigned carry flag; any non-zero value indicates carry.52/// \param __x53/// A 32-bit unsigned addend.54/// \param __y55/// A 32-bit unsigned addend.56/// \param __p57/// 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 carry67/// flag \a __cf, and subtracts the result from unsigned 32-bit integer68/// \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 : 173/// Store32(__p, __x - (__y + temp))74/// result := CF75/// \endcode76///77/// \headerfile <immintrin.h>78///79/// This intrinsic corresponds to the \c SBB instruction.80///81/// \param __cf82/// The 8-bit unsigned carry flag; any non-zero value indicates carry.83/// \param __x84/// The 32-bit unsigned minuend.85/// \param __y86/// The 32-bit unsigned subtrahend.87/// \param __p88/// 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 indicated99/// by the carry flag \a __cf. Stores the unsigned 64-bit sum in the memory100/// at \a __p, and returns the 8-bit carry-out (carry flag).101///102/// \code{.operation}103/// temp := (__cf == 0) ? 0 : 1104/// Store64(__p, __x + __y + temp)105/// result := CF106/// \endcode107///108/// \headerfile <immintrin.h>109///110/// This intrinsic corresponds to the \c ADC instruction.111///112/// \param __cf113/// The 8-bit unsigned carry flag; any non-zero value indicates carry.114/// \param __x115/// A 64-bit unsigned addend.116/// \param __y117/// A 64-bit unsigned addend.118/// \param __p119/// Pointer to memory for storing the sum.120/// \returns The 8-bit unsigned carry-out value.121__INLINE unsigned char __DEFAULT_FN_ATTRS122_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 carry128/// flag \a __cf, and subtracts the result from unsigned 64-bit integer129/// \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 : 1134/// Store64(__p, __x - (__y + temp))135/// result := CF136/// \endcode137///138/// \headerfile <immintrin.h>139///140/// This intrinsic corresponds to the \c ADC instruction.141///142/// \param __cf143/// The 8-bit unsigned carry flag; any non-zero value indicates carry.144/// \param __x145/// The 64-bit unsigned minuend.146/// \param __y147/// The 64-bit unsigned subtrahend.148/// \param __p149/// Pointer to memory for storing the difference.150/// \returns The 8-bit unsigned carry-out value.151__INLINE unsigned char __DEFAULT_FN_ATTRS152_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#endif157 158#if defined(__cplusplus)159}160#endif161 162#undef __INLINE163#undef __DEFAULT_FN_ATTRS164 165#endif /* __ADCINTRIN_H */166