_bittestandcomplement, _bittestandcomplement64
Visual Studio 2010
Microsoft Specific
Generate the btc instruction, which examines bit b of the address a, returns its current value, and sets the bit to its complement.
unsigned char _bittestandcomplement( long *a, long b ); unsigned char _bittestandcomplement64( __int64 *a, __int64 b );
On the IPF architecture, the btc instruction is not available, so this intrinsic is a custom function that imitates the behavior of btc. This custom function might be slower than a hand-written inline function because it includes overhead, such as handling the case where b is negative, that might be unnecessary in specific cases.
This routine is only available as an intrinsic.
// bittestandcomplement.cpp
// processor: x86, IPF, x64
#include <stdio.h>
#include <intrin.h>
#pragma intrinsic(_bittestandcomplement)
#ifdef _M_AMD64
#pragma intrinsic(_bittestandcomplement64)
#endif
int main()
{
long i = 1;
__int64 i64 = 0x1I64;
unsigned char result;
printf("Initial value: %d\n", i);
printf("Testing bit 1\n");
result = _bittestandcomplement(&i, 1);
printf("Value changed to %d, Result: %d\n", i, result);
#ifdef _M_AMD64
printf("Testing bit 0\n");
result = _bittestandcomplement64(&i64, 0);
printf("Value changed to %I64d, Result: %d\n", i64, result);
#endif
}