if (sm4 - asm)

Branch based on logical OR result.

if{_z|_nz} src0.select_component




[in] Contains the component on which to test the condition.



The token format contains the offset of the corresponding endif instruction in the Shader as a convenience.

The following example shows how to use this instruction.

                if_z r0.x // if all bits in r0.x are zero
                else // (optional)
                if_nz r1.x // if any bit in r0.x is nonzero
                else // (optional)


  • The source operands (if 4 component vectors) must use a single component selector.
  • The 32-bit register supplied by src0 is tested at a bit level. If any bit is nonzero, if_z will be true. If all bits are zero, if_nz will be true.
  • Flow control blocks can nest up to 64 deep per subroutine (and main). The HLSL compiler will not generate subroutines that exceed this limit. Behavior of control flow instructions beyond 64 levels deep (per subroutine) is undefined.

This instruction applies to the following shader stages:

Vertex ShaderGeometry ShaderPixel Shader


Minimum Shader Model

This function is supported in the following shader models.

Shader ModelSupported
Shader Model 5 yes
Shader Model 4.1 yes
Shader Model 4 yes
Shader Model 3 (DirectX HLSL) no
Shader Model 2 (DirectX HLSL) no
Shader Model 1 (DirectX HLSL) no


Related topics

Shader Model 4 Assembly (DirectX HLSL)