Skip to content

Implement the firstbitlow HLSL Function #99116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
12 tasks
Tracked by #99235 ...
farzonl opened this issue Jul 16, 2024 · 3 comments · Fixed by #116858
Closed
12 tasks
Tracked by #99235 ...

Implement the firstbitlow HLSL Function #99116

farzonl opened this issue Jul 16, 2024 · 3 comments · Fixed by #116858
Assignees
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • 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

@farzonl farzonl added backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Jul 16, 2024
@spall
Copy link
Contributor

spall commented Sep 11, 2024

looking at this

@damyanp damyanp assigned spall and unassigned spall Sep 11, 2024
@damyanp
Copy link
Contributor

damyanp commented Sep 11, 2024

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

@bob80905 bob80905 self-assigned this Sep 23, 2024
@damyanp damyanp moved this to Active in HLSL Support Oct 9, 2024
@damyanp damyanp moved this from Active to Ready in HLSL Support Oct 10, 2024
@V-FEXrt
Copy link
Contributor

V-FEXrt commented Nov 13, 2024

@spall I can take this on if you want to assign it to me :)

@spall spall moved this from Ready to Active in HLSL Support Nov 14, 2024
@damyanp damyanp moved this from Active to Needs Review in HLSL Support Dec 10, 2024
@github-project-automation github-project-automation bot moved this from Needs Review to Closed in HLSL Support Jan 15, 2025
github-actions bot pushed a commit to arm/arm-toolchain that referenced this issue Jan 15, 2025

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
Closes llvm/llvm-project#99116

Implements `firstbitlow` by extracting common functionality from
`firstbithigh` into a shared function while also fixing a bug for an edge
case where `u64x3` and larger vectors will attempt to create vectors
larger than the SPRIV max of 4.
---------

Co-authored-by: Steven Perron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

5 participants