bfind GPU Virtual ISA NVIDIA

bfind Integer Arithmetic Instructions

bfind.type d, a;

Find the bit position of the most significant non-sign bit in a and place the result in d.

Encoding

PTX is a virtual instruction set. It has no single, stable native binary encoding - the compiler lowers this instruction to different native machine code depending on the selected NVIDIA target architecture (compute capability). This page intentionally shows no bit-diagram; see the target/version requirements below for what governs how this instruction compiles.
PTX ISA Version Introduced PTX ISA 2.0
Minimum Target sm_20

Syntax Forms

One mnemonic covers many type / state-space / scope / modifier combinations - each row below is an independently valid form.

Syntax Data Types State Space(s) Modifiers Min. Target Description
bfind.type d, a; sm_20 Find the bit position of the most significant non-sign bit in a and place the result in d. Operand a has the instruction type, and destination d has type.u32. (see the official PTX ISA docs for the full description)

Operands

  • d
    Destination register
  • a
    Source operand

At a Glance

Data Types -

Related AMDGPU Concepts

Find Most-Significant Set Bit ↗
equivalent with restrictions
v_ffbh_i32 (AMDGPU)
v_ffbh_u32 (AMDGPU)

Reference

NVIDIA PTX ISA

Description

Find the bit position of the most significant non-sign bit in a and place the result in d. Operand a has the instruction type, and destination d has type.u32. For unsigned integers, bfind returns the bit position of the most significant 1. For signed integers, bfind returns the bit position of the most significant 0 for negative inputs and the most significant 1 for non-negative inputs. If.shiftamt is specified, bfind returns the shift amount needed to left-shift the found bit into the most-significant bit position. bfind returns 0xffffffff if no non-sign bit is found.

Semantics

msb = (.type==.u32 || .type==.s32) ? 31 : 63; // negate negative signed inputs if ( (.type==.s32 || .type==.s64) && (a & (1<<msb)) ) { a = ~a; } .u32 d = 0xffffffff; for (.s32 i=msb; i>=0; i--) { if (a & (1<<i)) { d = i; break; } } if (.shiftamt && d != 0xffffffff) { d = msb - d; }

Examples

bfind.u32  d, a;
bfind.shiftamt.s64  cnt, X;  // cnt is .u32

Reproduced from NVIDIA's official PTX ISA documentation for technical accuracy.

Sources