_bittestandreset、_bittestandreset64
[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 Blank topics are included as placeholders.]
Microsoft 固有の仕様 →
アドレスを返します a ビット b 現在の値をチェックしビットを 0 にリセットする btr 命令を生成します。
unsigned char _bittestandreset(
long *a,
long b
);
unsigned char _bittestandreset64(
__int64 *a,
__int64 b
);
パラメーター
[入力、出力] a
チェックするメモリへのポインター。[入力] b
テストするビット位置。
戻り値
指定した位置のビット。
必要条件
組み込み |
アーキテクチャ |
---|---|
_bittestandreset |
x86IPFx64 |
_bittestandreset64 |
はx64 |
ヘッダー ファイル <intrin.h>
解説
はアーキテクチャではbtr 命令は使用できないためこの組み込みでは btr の動作をシミュレートするカスタム関数です。 この関数はカスタム オーバーヘッドが含まれているため特定の場合は不要である可能性もある b が負の値である場合の処理など手書きのインライン関数より遅い場合があります。
このルーチンは組み込みとしてのみ使用できます。
使用例
// bittestandreset.cpp
// processor: x86, IPF, x64
#include <stdio.h>
#include <limits.h>
#include <intrin.h>
#pragma intrinsic(_bittestandreset)
// Check the sign bit and reset to 0 (taking the absolute value)
// Returns 0 if the number is positive or zero
// Returns 1 if the number is negative
unsigned char absolute_value(long* p)
{
const int SIGN_BIT = 31;
return _bittestandreset(p, SIGN_BIT);
}
int main()
{
long i = -112;
unsigned char result;
// Check the sign bit and reset to 0 (taking the absolute value)
result = absolute_value(&i);
if (result == 1)
printf_s("The number was negative.\n");
}