Skip to content

Implement the firstbitlow HLSL Function #99116

Closed
@farzonl

Description

@farzonl
  • Implement firstbitlow clang builtin,
    Link firstbitlow clang builtin with hlsl_intrinsics.h
    Add sema checks for firstbitlow to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
    Add codegen for firstbitlow to EmitHLSLBuiltinExpr in CGBuiltin.cpp
    Add codegen tests to clang/test/CodeGenHLSL/builtins/firstbitlow.hlsl
    Add sema tests to clang/test/SemaHLSL/BuiltIns/firstbitlow-errors.hlsl
    Create the int_dx_firstbitlow intrinsic in IntrinsicsDirectX.td
    Create the DXILOpMapping of int_dx_firstbitlow to 32 in DXIL.td
    Create the firstbitlow.ll and firstbitlow_errors.ll tests in llvm/test/CodeGen/DirectX/
    Create the int_spv_firstbitlow intrinsic in IntrinsicsSPIRV.td
    In SPIRVInstructionSelector.cpp create the firstbitlow lowering and map it to int_spv_firstbitlow in SPIRVInstructionSelector::selectIntrinsic.
    Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/firstbitlow.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
32 FirstbitLo 6.0 ()

SPIR-V

FindILsb:

Description:

FindILsb

Integer least-significant bit.

Results in the bit number of the least-significant 1-bit in the binary
representation of Value. If Value is 0, the result is -1.

Result Type and the type of Value must both be integer scalar or
integer vector types. Result Type and operand types must have the same
number of components with the same component width. Results are computed
per component.

Number Operand 1 Operand 2 Operand 3 Operand 4

73

<id>
Value

Test Case(s)

Example 1

//dxc firstbitlow_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export uint4 fn(int4 p1) {
    return firstbitlow(p1);
}

HLSL:

Returns the location of the first set bit starting from the lowest order bit and working upward, per component.

Syntax

int firstbitlow(
  in int value
);

Parameters

value [in]

Type: int

The input value.

Return value

Type: int

The location of the first set bit.

Remarks

The following overloaded versions are also available:

uint2 firstbitlow(uint2 value);
uint3 firstbitlow(uint3 value);
uint4 firstbitlow(uint4 value);

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 5 and higher shader models yes

 

This function is supported in the following types of shaders:

Vertex Hull Domain Geometry Pixel Compute
x x x x x x

 

See also

Intrinsic Functions

Shader Model 5

Activity

spall

spall commented on Sep 11, 2024

@spall
Contributor

looking at this

assigned and unassigned on Sep 11, 2024
damyanp

damyanp commented on Sep 11, 2024

@damyanp
Contributor

As discussed with @spall - keeping this around as a good starter issue.

self-assigned this
on Sep 23, 2024
moved this to Active in HLSL Supporton Oct 9, 2024
moved this from Active to Ready in HLSL Supporton Oct 10, 2024

15 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Closed

Milestone

No milestone

Development

Participants

@spall@farzonl@V-FEXrt@damyanp@bob80905

Issue actions

    Implement the `firstbitlow` HLSL Function · Issue #99116 · llvm/llvm-project