<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99185>99185</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `asuint16` HLSL Function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
metabug,
HLSL,
backend:SPIR-V,
bot:HLSL
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
farzonl
</td>
</tr>
</table>
<pre>
- [ ] Implement `asuint16` clang builtin,
- [ ] Link `asuint16` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `asuint16` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `asuint16` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/asuint16.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/asuint16-errors.hlsl`
- [ ] Create the `int_spv_asuint16` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `asuint16` lowering and map it to `int_spv_asuint16` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/asuint16.ll`
## DirectX
There were no DXIL opcodes found for `asuint16`.
## SPIR-V
# [OpBitcast](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpBitcast):
## Description:
Bit pattern-preserving type conversion.
*Result Type* must be an [**OpTypePointer**](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTypePointer), or a
scalar or vector of [*numerical-type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Numerical).
*Operand* must have a type of [**OpTypePointer**](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTypePointer), or a
scalar or vector of [*numerical-type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Numerical). It must be a
different type than *Result Type*.
Before **version 1.5**: If either *Result Type* or *Operand* is a
pointer, the other must be a pointer or an integer scalar.
Starting with **version 1.5**: If either *Result Type* or *Operand* is a
pointer, the other must be a pointer, an integer scalar, or an integer
vector.
If both *Result Type* and the type of *Operand* are pointers, they both
must point into same [storage class](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Storage_Class).
Behavior is undefined if the [storage class](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Storage_Class) of *Result
Type* does not match the one used by the operation that produced the
value of *Operand*.
If *Result Type* has the same number of components as *Operand*, they
must also have the same component width, and results are computed per
component.
If *Result Type* has a different number of components than *Operand*,
the total number of bits in *Result Type* must equal the total number of
bits in *Operand*. Let *L* be the type, either *Result Type* or
*Operand’s* type, that has the larger number of components. Let *S* be
the other type, with the smaller number of components. The number of
components in *L* must be an integer multiple of the number of
components in *S*. The first component (that is, the only or
lowest-numbered component) of *S* maps to the first components of *L*,
and so on, up to the last component of *S* mapping to the last
components of *L*. Within this mapping, any single component of *S*
(mapping to multiple components of *L*) maps its lower-ordered bits to
the lower-numbered components of *L*.
<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>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>4</p></td>
<td class="tableblock halign-left valign-top"><p>124</p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result <id></em></a></p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Operand</em></p></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc asuint16_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export uint16_t4 fn(half4 p1) {
return asuint16(p1);
}
```
## HLSL:
## Syntax
```syntax
uint16_t<> asuint16(numeric16_only<> x);
```
## Type Description
| Name | [**Template Type**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-data-types.md)| [**Component Type**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-data-types.md) | Size |
|-------|--------------------------------------------------------------------|----------------------------------------------------------------------|------|
| *ret* | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-scalar.md), [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-vector.md), or [**matrix**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-matrix.md) | [**uint16_t**](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types) | any |
| *x* | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-scalar.md), [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-vector.md), or [**matrix**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-matrix.md) | [**half**](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types), [**int16_t**](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types), or [**uint16_t**](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types) | any |
## Minimum Shader Model
This function is supported in the following shader models.
|Shader Model | Supported|
|-------------|----------|
|[Shader Model 6.2](https://github.com/microsoft/DirectXShaderCompiler/wiki/Shader-Model-6.2) and higher shader models | yes |
## Shader Stages
## See also
- [**Intrinsic Functions (DirectX HLSL)**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
- **See [HLSL 16-Bit-Scalar-Types](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types)**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl9v4zYS_zTMCyFDpmIlfvCD7cS9AGm3qIO2bwEljS1eKFJHUkncT38YUpKl2Nld3HX_FNhFkJX4Z-Y3vxkOh1S4tWKvABZktiKzmwveuFKbxY6bv7SSF5kuDouIktmKktkNvatqCRUoR0kac9sI5aYpSWOaS672NGuEdEIRtibx8jjrXqinj06gL8KVOKKUVj4K5YxQVuR2UpI0HolaFgW1UHGal5A_WbrT5q1kp7Fljf3_ut_er4KKTaNyJ7RacylxlFA4agsV9yOF2k_yuj6nLtcF7EG9r-q2Em6g6fa1NkcN65_a5k-Jd2CdbSV6cgjbYBthm7Uu4CdQqIOwTcuZJWzTYZkgb-9S9RHJaH8r1sO8G4mNwBht7FnpawPcAXUloFih3KOtnx-H5PRubJm46926_fXut98nrngr805R33WnrDONd9cWJOROG2SP5iOdQ11Sv4ARak-5KmjFa0qFay0-D807_x1dJFmSZGn9Ww-apPHkHAEoJPqdZjx_AlV4rmnOLbQ6pHyuThyJxKNuwjZIbXQM-KFPZcs5_rCEsITeCAO5-zO0PZRggL7gL6XpzZ9391TXGEy4KBpVnInXyUhaQN43oWEf6pVwObeOzG4Iuy6dqy2ywTaEbQzshXXmMHkqjVbaTrTZt5ZEaIqtwRvQKLETUEw7KyelqyRhyVE4m6PQkWVgcyNq9ELoopTEy5VwtObOgVFRbcCCeUYfu0MNNNfqGYwVWk38WP-LsOVvYBvp6MOhBsKWtGqsoxlQrtA-wnDIhxp7f9VCOTCh6cvYO1IzJ2xNtaGcxEubc8kNvj37iKN618JTTQVG5FxGLljwJZD90ikhbD5m70MNhquiZ67kz0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