Description
Note The SPIRV Work is completed https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp#L481C3-L482C63
We just need to add the test case.
- Implement
countbits
clang builtin,Linkcountbits
clang builtin withhlsl_intrinsics.h
Add sema checks forcountbits
toCheckHLSLBuiltinFunctionCall
inSemaChecking.cpp
Add codegen forcountbits
toEmitHLSLBuiltinExpr
inCGBuiltin.cpp
Add codegen tests toclang/test/CodeGenHLSL/builtins/countbits.hlsl
Add sema tests toclang/test/SemaHLSL/BuiltIns/countbits-errors.hlsl
Create theDXILOpMapping
ofint_ctpop
to31
inDXIL.td
Create thecountbits.ll
andcountbits_errors.ll
tests inllvm/test/CodeGen/DirectX/
Create SPIR-V backend test case inllvm/test/CodeGen/SPIRV/hlsl-intrinsics/countbits.ll
DirectX
DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
---|---|---|---|
31 | Countbits | 6.0 | () |
SPIR-V
OpBitCount:
Description:
Count the number of set bits in an object.
Results are computed per component.
Result Type must be a scalar or vector of integer type.
The components must be wide enough to hold the unsigned Width of
Base as an unsigned value. That is, no sign bit is needed or counted
when checking for a wide enough result width.
Base must be a scalar or vector of integer type. It must
have the same number of components as Result Type.
The result is the unsigned value that is the number of bits in Base
that are 1.
Word Count | Opcode | Results | Operands | |
---|---|---|---|---|
4 |
205 |
<id> |
<id> |
Test Case(s)
Example 1
//dxc countbits_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export uint4 fn(int4 p1) {
return countbits(p1);
}
HLSL:
Counts the number of bits (per component) set in the input integer.
Syntax
uint countbits(
in uint value
);
Parameters
-
value [in]
-
Type: uint
The input value.
Return value
Type: uint
The number of bits.
Remarks
The following overloaded versions are also available:
uint count_bits(uint value);
uint2 count_bits(uint2 value);
uint3 count_bits(uint3 value);
uint4 count_bits(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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Activity
spall commentedon Sep 5, 2024
looking at this
[HLSL] Implement elementwise popcount (llvm#108121)
6 remaining items