-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
countbitsclang builtin, - Link
countbitsclang builtin withhlsl_intrinsics.h - Add sema checks for
countbitstoCheckHLSLBuiltinFunctionCallinSemaChecking.cpp - Add codegen for
countbitstoEmitHLSLBuiltinExprinCGBuiltin.cpp - Add codegen tests to
clang/test/CodeGenHLSL/builtins/countbits.hlsl - Add sema tests to
clang/test/SemaHLSL/BuiltIns/countbits-errors.hlsl - Create the
DXILOpMappingofint_ctpopto31inDXIL.td - Create the
countbits.llandcountbits_errors.lltests inllvm/test/CodeGen/DirectX/ - Create SPIR-V backend test case in
llvm/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