Skip to content

Implement the firstbithigh HLSL Function #99115

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 · 2 comments · Fixed by #111082
Closed
12 tasks
Tracked by #99235 ...

Implement the firstbithigh HLSL Function #99115

farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #111082
Assignees
Labels
backend:DirectX backend:SPIR-V bot:HLSL clang:codegen IR generation bugs: mangling, exceptions, etc. clang:headers Headers provided by Clang, e.g. for intrinsics 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 firstbithigh clang builtin,
  • Link firstbithigh clang builtin with hlsl_intrinsics.h
  • Add sema checks for firstbithigh to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for firstbithigh to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/firstbithigh.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/firstbithigh-errors.hlsl
  • Create the int_dx_firstbithigh intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_firstbithigh to 34 in DXIL.td
  • Create the firstbithigh.ll and firstbithigh_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_firstbithigh intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the firstbithigh lowering and map it to int_spv_firstbithigh in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/firstbithigh.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
34 FirstbitSHi 6.0 ()

SPIR-V

FindSMsb:

Description:

FindSMsb

Signed-integer most-significant bit, with Value interpreted as a
signed integer.

For positive numbers, the result will be the bit number of the most
significant 1-bit. For negative numbers, the result will be the bit
number of the most significant 0-bit. For a Value of 0 or -1, 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.

This instruction is currently limited to 32-bit width components.

Number Operand 1 Operand 2 Operand 3 Operand 4

74

<id>
Value

Test Case(s)

Example 1

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

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

HLSL:

Gets the location of the first set bit starting from the highest order bit and working downward, per component.

Syntax

int firstbithigh(
  in int value
);

Parameters

value [in]

Type: int

The input value.

Return value

Type: int

The location of the first set bit.

Remarks

For a signed integer, the first significant bit is zero for a negative number.

The following overloaded versions are also available:

int2 firstbithigh(int2 value);
int3 firstbithigh(int3 value);
int4 firstbithigh(int4 value);
uint firstbithigh(uint value);
uint2 firstbithigh(uint2 value);
uint3 firstbithigh(uint3 value);
uint4 firstbithigh(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 moved this to Active in HLSL Support Oct 9, 2024
@damyanp damyanp moved this from Active to Needs Review in HLSL Support Oct 17, 2024
@spall spall closed this as completed in fb90733 Nov 6, 2024
@github-project-automation github-project-automation bot moved this from Needs Review to Closed in HLSL Support Nov 6, 2024
@github-project-automation github-project-automation bot moved this from Needs Review to Closed in HLSL Support Nov 6, 2024
@EugeneZelenko EugeneZelenko added clang:headers Headers provided by Clang, e.g. for intrinsics clang:codegen IR generation bugs: mangling, exceptions, etc. labels Nov 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2024

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)

- [ ] Implement `firstbithigh` clang builtin, - [ ] Link `firstbithigh` clang builtin with `hlsl_intrinsics.h` - [ ] Add sema checks for `firstbithigh` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [ ] Add codegen for `firstbithigh` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/firstbithigh.hlsl` - [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/firstbithigh-errors.hlsl` - [ ] Create the `int_dx_firstbithigh` intrinsic in `IntrinsicsDirectX.td` - [ ] Create the `DXILOpMapping` of `int_dx_firstbithigh` to `34` in `DXIL.td` - [ ] Create the `firstbithigh.ll` and `firstbithigh_errors.ll` tests in `llvm/test/CodeGen/DirectX/` - [ ] Create the `int_spv_firstbithigh` intrinsic in `IntrinsicsSPIRV.td` - [ ] In SPIRVInstructionSelector.cpp create the `firstbithigh` lowering and map it to `int_spv_firstbithigh` in `SPIRVInstructionSelector::selectIntrinsic`. - [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/firstbithigh.ll`

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
34 FirstbitSHi 6.0 ()

SPIR-V

FindSMsb:

Description:

FindSMsb

Signed-integer most-significant bit, with Value interpreted as a
signed integer.

For positive numbers, the result will be the bit number of the most
significant 1-bit. For negative numbers, the result will be the bit
number of the most significant 0-bit. For a Value of 0 or -1, 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.

This instruction is currently limited to 32-bit width components.

<table>
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr>
<th>Number</th>
<th>Operand 1</th>
<th>Operand 2</th>
<th>Operand 3</th>
<th>Operand 4</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>74</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Value</em></p></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

Test Case(s)

Example 1

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

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

HLSL:

Gets the location of the first set bit starting from the highest order bit and working downward, per component.

Syntax

int firstbithigh(
  in int value
);

Parameters

<dl> <dt>

value [in]
</dt> <dd>

Type: int

The input value.

</dd> </dl>

Return value

Type: int

The location of the first set bit.

Remarks

For a signed integer, the first significant bit is zero for a negative number.

The following overloaded versions are also available:

int2 firstbithigh(int2 value);
int3 firstbithigh(int3 value);
int4 firstbithigh(int4 value);
uint firstbithigh(uint value);
uint2 firstbithigh(uint2 value);
uint3 firstbithigh(uint3 value);
uint4 firstbithigh(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

<dl> <dt>

Intrinsic Functions
</dt> <dt>

Shader Model 5
</dt> </dl>

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 clang:codegen IR generation bugs: mangling, exceptions, etc. clang:headers Headers provided by Clang, e.g. for intrinsics HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants