Path: blob/master/tools/android-sdk/renderscript/clang-include/bmiintrin.h
496 views
/*===---- bmiintrin.h - BMI intrinsics -------------------------------------===1*2* Permission is hereby granted, free of charge, to any person obtaining a copy3* of this software and associated documentation files (the "Software"), to deal4* in the Software without restriction, including without limitation the rights5* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell6* copies of the Software, and to permit persons to whom the Software is7* furnished to do so, subject to the following conditions:8*9* The above copyright notice and this permission notice shall be included in10* all copies or substantial portions of the Software.11*12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,17* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN18* THE SOFTWARE.19*20*===-----------------------------------------------------------------------===21*/2223#if !defined __X86INTRIN_H && !defined __IMMINTRIN_H24#error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead."25#endif2627#ifndef __BMIINTRIN_H28#define __BMIINTRIN_H2930/// \brief Counts the number of trailing zero bits in the operand.31///32/// \headerfile <x86intrin.h>33///34/// \code35/// unsigned short _tzcnt_u16(unsigned short a);36/// \endcode37///38/// This intrinsic corresponds to the \c TZCNT instruction.39///40/// \param a41/// An unsigned 16-bit integer whose trailing zeros are to be counted.42/// \returns An unsigned 16-bit integer containing the number of trailing zero43/// bits in the operand.44#define _tzcnt_u16(a) (__tzcnt_u16((a)))4546/// \brief Performs a bitwise AND of the second operand with the one's47/// complement of the first operand.48///49/// \headerfile <x86intrin.h>50///51/// \code52/// unsigned int _andn_u32(unsigned int a, unsigned int b);53/// \endcode54///55/// This intrinsic corresponds to the \c ANDN instruction.56///57/// \param a58/// An unsigned integer containing one of the operands.59/// \param b60/// An unsigned integer containing one of the operands.61/// \returns An unsigned integer containing the bitwise AND of the second62/// operand with the one's complement of the first operand.63#define _andn_u32(a, b) (__andn_u32((a), (b)))6465/* _bextr_u32 != __bextr_u32 */66/// \brief Clears all bits in the source except for the least significant bit67/// containing a value of 1 and returns the result.68///69/// \headerfile <x86intrin.h>70///71/// \code72/// unsigned int _blsi_u32(unsigned int a);73/// \endcode74///75/// This intrinsic corresponds to the \c BLSI instruction.76///77/// \param a78/// An unsigned integer whose bits are to be cleared.79/// \returns An unsigned integer containing the result of clearing the bits from80/// the source operand.81#define _blsi_u32(a) (__blsi_u32((a)))8283/// \brief Creates a mask whose bits are set to 1, using bit 0 up to and84/// including the least siginificant bit that is set to 1 in the source85/// operand and returns the result.86///87/// \headerfile <x86intrin.h>88///89/// \code90/// unsigned int _blsmsk_u32(unsigned int a);91/// \endcode92///93/// This intrinsic corresponds to the \c BLSMSK instruction.94///95/// \param a96/// An unsigned integer used to create the mask.97/// \returns An unsigned integer containing the newly created mask.98#define _blsmsk_u32(a) (__blsmsk_u32((a)))99100/// \brief Clears the least siginificant bit that is set to 1 in the source101/// operand and returns the result.102///103/// \headerfile <x86intrin.h>104///105/// \code106/// unsigned int _blsr_u32(unsigned int a);107/// \endcode108///109/// This intrinsic corresponds to the \c BLSR instruction.110///111/// \param a112/// An unsigned integer containing the operand to be cleared.113/// \returns An unsigned integer containing the result of clearing the source114/// operand.115#define _blsr_u32(a) (__blsr_u32((a)))116117/// \brief Counts the number of trailing zero bits in the operand.118///119/// \headerfile <x86intrin.h>120///121/// \code122/// unsigned int _tzcnt_u32(unsigned int a);123/// \endcode124///125/// This intrinsic corresponds to the \c TZCNT instruction.126///127/// \param a128/// An unsigned 32-bit integer whose trailing zeros are to be counted.129/// \returns An unsigned 32-bit integer containing the number of trailing zero130/// bits in the operand.131#define _tzcnt_u32(a) (__tzcnt_u32((a)))132133/* Define the default attributes for the functions in this file. */134#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("bmi")))135136/* Allow using the tzcnt intrinsics even for non-BMI targets. Since the TZCNT137instruction behaves as BSF on non-BMI targets, there is code that expects138to use it as a potentially faster version of BSF. */139#define __RELAXED_FN_ATTRS __attribute__((__always_inline__, __nodebug__))140141/// \brief Counts the number of trailing zero bits in the operand.142///143/// \headerfile <x86intrin.h>144///145/// This intrinsic corresponds to the \c TZCNT instruction.146///147/// \param __X148/// An unsigned 16-bit integer whose trailing zeros are to be counted.149/// \returns An unsigned 16-bit integer containing the number of trailing zero150/// bits in the operand.151static __inline__ unsigned short __RELAXED_FN_ATTRS152__tzcnt_u16(unsigned short __X)153{154return __X ? __builtin_ctzs(__X) : 16;155}156157/// \brief Performs a bitwise AND of the second operand with the one's158/// complement of the first operand.159///160/// \headerfile <x86intrin.h>161///162/// This intrinsic corresponds to the \c ANDN instruction.163///164/// \param __X165/// An unsigned integer containing one of the operands.166/// \param __Y167/// An unsigned integer containing one of the operands.168/// \returns An unsigned integer containing the bitwise AND of the second169/// operand with the one's complement of the first operand.170static __inline__ unsigned int __DEFAULT_FN_ATTRS171__andn_u32(unsigned int __X, unsigned int __Y)172{173return ~__X & __Y;174}175176/* AMD-specified, double-leading-underscore version of BEXTR */177/// \brief Extracts the specified bits from the first operand and returns them178/// in the least significant bits of the result.179///180/// \headerfile <x86intrin.h>181///182/// This intrinsic corresponds to the \c BEXTR instruction.183///184/// \param __X185/// An unsigned integer whose bits are to be extracted.186/// \param __Y187/// An unsigned integer used to specify which bits are extracted. Bits [7:0]188/// specify the index of the least significant bit. Bits [15:8] specify the189/// number of bits to be extracted.190/// \returns An unsigned integer whose least significant bits contain the191/// extracted bits.192static __inline__ unsigned int __DEFAULT_FN_ATTRS193__bextr_u32(unsigned int __X, unsigned int __Y)194{195return __builtin_ia32_bextr_u32(__X, __Y);196}197198/* Intel-specified, single-leading-underscore version of BEXTR */199/// \brief Extracts the specified bits from the first operand and returns them200/// in the least significant bits of the result.201///202/// \headerfile <x86intrin.h>203///204/// This intrinsic corresponds to the \c BEXTR instruction.205///206/// \param __X207/// An unsigned integer whose bits are to be extracted.208/// \param __Y209/// An unsigned integer used to specify the index of the least significant210/// bit for the bits to be extracted. Bits [7:0] specify the index.211/// \param __Z212/// An unsigned integer used to specify the number of bits to be extracted.213/// Bits [7:0] specify the number of bits.214/// \returns An unsigned integer whose least significant bits contain the215/// extracted bits.216static __inline__ unsigned int __DEFAULT_FN_ATTRS217_bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)218{219return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));220}221222/// \brief Clears all bits in the source except for the least significant bit223/// containing a value of 1 and returns the result.224///225/// \headerfile <x86intrin.h>226///227/// This intrinsic corresponds to the \c BLSI instruction.228///229/// \param __X230/// An unsigned integer whose bits are to be cleared.231/// \returns An unsigned integer containing the result of clearing the bits from232/// the source operand.233static __inline__ unsigned int __DEFAULT_FN_ATTRS234__blsi_u32(unsigned int __X)235{236return __X & -__X;237}238239/// \brief Creates a mask whose bits are set to 1, using bit 0 up to and240/// including the least siginificant bit that is set to 1 in the source241/// operand and returns the result.242///243/// \headerfile <x86intrin.h>244///245/// This intrinsic corresponds to the \c BLSMSK instruction.246///247/// \param __X248/// An unsigned integer used to create the mask.249/// \returns An unsigned integer containing the newly created mask.250static __inline__ unsigned int __DEFAULT_FN_ATTRS251__blsmsk_u32(unsigned int __X)252{253return __X ^ (__X - 1);254}255256/// \brief Clears the least siginificant bit that is set to 1 in the source257/// operand and returns the result.258///259/// \headerfile <x86intrin.h>260///261/// This intrinsic corresponds to the \c BLSR instruction.262///263/// \param __X264/// An unsigned integer containing the operand to be cleared.265/// \returns An unsigned integer containing the result of clearing the source266/// operand.267static __inline__ unsigned int __DEFAULT_FN_ATTRS268__blsr_u32(unsigned int __X)269{270return __X & (__X - 1);271}272273/// \brief Counts the number of trailing zero bits in the operand.274///275/// \headerfile <x86intrin.h>276///277/// This intrinsic corresponds to the \c TZCNT instruction.278///279/// \param __X280/// An unsigned 32-bit integer whose trailing zeros are to be counted.281/// \returns An unsigned 32-bit integer containing the number of trailing zero282/// bits in the operand.283static __inline__ unsigned int __RELAXED_FN_ATTRS284__tzcnt_u32(unsigned int __X)285{286return __X ? __builtin_ctz(__X) : 32;287}288289/// \brief Counts the number of trailing zero bits in the operand.290///291/// \headerfile <x86intrin.h>292///293/// This intrinsic corresponds to the \c TZCNT instruction.294///295/// \param __X296/// An unsigned 32-bit integer whose trailing zeros are to be counted.297/// \returns An 32-bit integer containing the number of trailing zero298/// bits in the operand.299static __inline__ int __RELAXED_FN_ATTRS300_mm_tzcnt_32(unsigned int __X)301{302return __X ? __builtin_ctz(__X) : 32;303}304305#ifdef __x86_64__306307/// \brief Performs a bitwise AND of the second operand with the one's308/// complement of the first operand.309///310/// \headerfile <x86intrin.h>311///312/// \code313/// unsigned long long _andn_u64 (unsigned long long a, unsigned long long b);314/// \endcode315///316/// This intrinsic corresponds to the \c ANDN instruction.317///318/// \param a319/// An unsigned 64-bit integer containing one of the operands.320/// \param b321/// An unsigned 64-bit integer containing one of the operands.322/// \returns An unsigned 64-bit integer containing the bitwise AND of the second323/// operand with the one's complement of the first operand.324#define _andn_u64(a, b) (__andn_u64((a), (b)))325326/* _bextr_u64 != __bextr_u64 */327/// \brief Clears all bits in the source except for the least significant bit328/// containing a value of 1 and returns the result.329///330/// \headerfile <x86intrin.h>331///332/// \code333/// unsigned long long _blsi_u64(unsigned long long a);334/// \endcode335///336/// This intrinsic corresponds to the \c BLSI instruction.337///338/// \param a339/// An unsigned 64-bit integer whose bits are to be cleared.340/// \returns An unsigned 64-bit integer containing the result of clearing the341/// bits from the source operand.342#define _blsi_u64(a) (__blsi_u64((a)))343344/// \brief Creates a mask whose bits are set to 1, using bit 0 up to and345/// including the least siginificant bit that is set to 1 in the source346/// operand and returns the result.347///348/// \headerfile <x86intrin.h>349///350/// \code351/// unsigned long long _blsmsk_u64(unsigned long long a);352/// \endcode353///354/// This intrinsic corresponds to the \c BLSMSK instruction.355///356/// \param a357/// An unsigned 64-bit integer used to create the mask.358/// \returns A unsigned 64-bit integer containing the newly created mask.359#define _blsmsk_u64(a) (__blsmsk_u64((a)))360361/// \brief Clears the least siginificant bit that is set to 1 in the source362/// operand and returns the result.363///364/// \headerfile <x86intrin.h>365///366/// \code367/// unsigned long long _blsr_u64(unsigned long long a);368/// \endcode369///370/// This intrinsic corresponds to the \c BLSR instruction.371///372/// \param a373/// An unsigned 64-bit integer containing the operand to be cleared.374/// \returns An unsigned 64-bit integer containing the result of clearing the375/// source operand.376#define _blsr_u64(a) (__blsr_u64((a)))377378/// \brief Counts the number of trailing zero bits in the operand.379///380/// \headerfile <x86intrin.h>381///382/// \code383/// unsigned long long _tzcnt_u64(unsigned long long a);384/// \endcode385///386/// This intrinsic corresponds to the \c TZCNT instruction.387///388/// \param a389/// An unsigned 64-bit integer whose trailing zeros are to be counted.390/// \returns An unsigned 64-bit integer containing the number of trailing zero391/// bits in the operand.392#define _tzcnt_u64(a) (__tzcnt_u64((a)))393394/// \brief Performs a bitwise AND of the second operand with the one's395/// complement of the first operand.396///397/// \headerfile <x86intrin.h>398///399/// This intrinsic corresponds to the \c ANDN instruction.400///401/// \param __X402/// An unsigned 64-bit integer containing one of the operands.403/// \param __Y404/// An unsigned 64-bit integer containing one of the operands.405/// \returns An unsigned 64-bit integer containing the bitwise AND of the second406/// operand with the one's complement of the first operand.407static __inline__ unsigned long long __DEFAULT_FN_ATTRS408__andn_u64 (unsigned long long __X, unsigned long long __Y)409{410return ~__X & __Y;411}412413/* AMD-specified, double-leading-underscore version of BEXTR */414/// \brief Extracts the specified bits from the first operand and returns them415/// in the least significant bits of the result.416///417/// \headerfile <x86intrin.h>418///419/// This intrinsic corresponds to the \c BEXTR instruction.420///421/// \param __X422/// An unsigned 64-bit integer whose bits are to be extracted.423/// \param __Y424/// An unsigned 64-bit integer used to specify which bits are extracted. Bits425/// [7:0] specify the index of the least significant bit. Bits [15:8] specify426/// the number of bits to be extracted.427/// \returns An unsigned 64-bit integer whose least significant bits contain the428/// extracted bits.429static __inline__ unsigned long long __DEFAULT_FN_ATTRS430__bextr_u64(unsigned long long __X, unsigned long long __Y)431{432return __builtin_ia32_bextr_u64(__X, __Y);433}434435/* Intel-specified, single-leading-underscore version of BEXTR */436/// \brief Extracts the specified bits from the first operand and returns them437/// in the least significant bits of the result.438///439/// \headerfile <x86intrin.h>440///441/// This intrinsic corresponds to the \c BEXTR instruction.442///443/// \param __X444/// An unsigned 64-bit integer whose bits are to be extracted.445/// \param __Y446/// An unsigned integer used to specify the index of the least significant447/// bit for the bits to be extracted. Bits [7:0] specify the index.448/// \param __Z449/// An unsigned integer used to specify the number of bits to be extracted.450/// Bits [7:0] specify the number of bits.451/// \returns An unsigned 64-bit integer whose least significant bits contain the452/// extracted bits.453static __inline__ unsigned long long __DEFAULT_FN_ATTRS454_bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z)455{456return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));457}458459/// \brief Clears all bits in the source except for the least significant bit460/// containing a value of 1 and returns the result.461///462/// \headerfile <x86intrin.h>463///464/// This intrinsic corresponds to the \c BLSI instruction.465///466/// \param __X467/// An unsigned 64-bit integer whose bits are to be cleared.468/// \returns An unsigned 64-bit integer containing the result of clearing the469/// bits from the source operand.470static __inline__ unsigned long long __DEFAULT_FN_ATTRS471__blsi_u64(unsigned long long __X)472{473return __X & -__X;474}475476/// \brief Creates a mask whose bits are set to 1, using bit 0 up to and477/// including the least siginificant bit that is set to 1 in the source478/// operand and returns the result.479///480/// \headerfile <x86intrin.h>481///482/// This intrinsic corresponds to the \c BLSMSK instruction.483///484/// \param __X485/// An unsigned 64-bit integer used to create the mask.486/// \returns A unsigned 64-bit integer containing the newly created mask.487static __inline__ unsigned long long __DEFAULT_FN_ATTRS488__blsmsk_u64(unsigned long long __X)489{490return __X ^ (__X - 1);491}492493/// \brief Clears the least siginificant bit that is set to 1 in the source494/// operand and returns the result.495///496/// \headerfile <x86intrin.h>497///498/// This intrinsic corresponds to the \c BLSR instruction.499///500/// \param __X501/// An unsigned 64-bit integer containing the operand to be cleared.502/// \returns An unsigned 64-bit integer containing the result of clearing the503/// source operand.504static __inline__ unsigned long long __DEFAULT_FN_ATTRS505__blsr_u64(unsigned long long __X)506{507return __X & (__X - 1);508}509510/// \brief Counts the number of trailing zero bits in the operand.511///512/// \headerfile <x86intrin.h>513///514/// This intrinsic corresponds to the \c TZCNT instruction.515///516/// \param __X517/// An unsigned 64-bit integer whose trailing zeros are to be counted.518/// \returns An unsigned 64-bit integer containing the number of trailing zero519/// bits in the operand.520static __inline__ unsigned long long __RELAXED_FN_ATTRS521__tzcnt_u64(unsigned long long __X)522{523return __X ? __builtin_ctzll(__X) : 64;524}525526/// \brief Counts the number of trailing zero bits in the operand.527///528/// \headerfile <x86intrin.h>529///530/// This intrinsic corresponds to the \c TZCNT instruction.531///532/// \param __X533/// An unsigned 64-bit integer whose trailing zeros are to be counted.534/// \returns An 64-bit integer containing the number of trailing zero535/// bits in the operand.536static __inline__ long long __RELAXED_FN_ATTRS537_mm_tzcnt_64(unsigned long long __X)538{539return __X ? __builtin_ctzll(__X) : 64;540}541542#endif /* __x86_64__ */543544#undef __DEFAULT_FN_ATTRS545#undef __RELAXED_FN_ATTRS546547#endif /* __BMIINTRIN_H */548549550