fns GPU Virtual ISA NVIDIA

fns Integer Arithmetic Instructions

fns.b32 d, mask, base, offset;

Given a 32-bit value mask and an integer value base (between 0 and 31), find the n-th (given by offset) set bit in mask from the base bit, and store the bit position 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 6.0
Minimum Target sm_30

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
fns.b32 d, mask, base, offset; sm_30 Given a 32-bit value mask and an integer value base (between 0 and 31), find the n-th (given by offset) set bit in mask from the base bit, and store the bit position in d. (see the official PTX ISA docs for the full description)

Operands

  • d
    Destination register
  • mask
    Operand
  • base
    Operand
  • offset
    Operand

At a Glance

Data Types -

Reference

NVIDIA PTX ISA

Description

Given a 32-bit value mask and an integer value base (between 0 and 31), find the n-th (given by offset) set bit in mask from the base bit, and store the bit position in d. If not found, store 0xffffffff in d. Operand mask has a 32-bit type. Operand base has.b32,.u32 or.s32 type. Operand offset has.s32 type. Destination d has type.b32. Operand base must be <= 31, otherwise behavior is undefined.

Semantics

d = 0xffffffff; if (offset == 0) { if (mask[base] == 1) { d = base; } } else { pos = base; count = |offset| - 1; inc = (offset > 0) ? 1 : -1; while ((pos >= 0) && (pos < 32)) { if (mask[pos] == 1) { if (count == 0) { d = pos; break; } else { count = count - 1; } } pos = pos + inc; } }

Examples

fns.b32 d, 0xaaaaaaaa, 3, 1;   // d = 3
fns.b32 d, 0xaaaaaaaa, 3, -1;  // d = 3
fns.b32 d, 0xaaaaaaaa, 2, 1;   // d = 3
fns.b32 d, 0xaaaaaaaa, 2, -1;  // d = 1

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

Sources