<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99184>99184</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `asint16` 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 `asint16` clang builtin,
- [ ] Link `asint16` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `asint16` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `asint16` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/asint16.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/asint16-errors.hlsl`
- [ ] Create the `int_spv_asint16` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `asint16` lowering and map it to `int_spv_asint16` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/asint16.ll`
## DirectX
There were no DXIL opcodes found for `asint16`.
## 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 asint16_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export int16_t4 fn(half4 p1) {
return asint16(p1);
}
```
## HLSL:
## Syntax
```syntax
int16_t<> asint16(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) | [**int16_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_zTMCyFDpmwnfvCD7cS9AGm3qBdt3wJKGlm8UKSOpJK4n_4wpCRLsbO7uOt2t0AXQVbin5nf_GY4HFLh1oqDAliR-YbMb69440ptVgU3f2glr1KdH1cRJfMNJfNbel_VEipQjpJFzK1Qbrogi5hmkqsDTRshnVCEbUm8Pk16EOrpU-Ppi3AlDiillY9COSOUFZmdlGQRjySt85xaqDjNSsieLC20eSPYaWzYYve_HvYPm6Bh16jMCa22XEocJRSO2kPF_UihDpOsri9py3QOB1DvarqrhBsounutzUnB9oe2-XPSHVhnW4meGsJ22EbYbqtz-AEU6iBs1zJmCdu1UCZI2rs8fUIwWt9K9Sjvh1IjMEYbe1H41gB3QF0JKFUo92jr58cBM70HWxrue4_uf77_5deJy9-KvFfUd90r60zjXbUHCZnTBqmj2UjlQJXUL2CEOlCuclrxmlLhWnMvAvNuf0cTSdYkWVv_1kMmi3hyyXoUEv1KU549gco9zzTjFlodUj5XZz5E0lE3YTvkNTpF-sCdsuUbf1hCWEJvhYHM_R7aPpZggL7gL6Xp7e_3D1TXGEa4GBqVnwfqZCQs4O6b0KwP9Ua4jFtH5reE3ZTO1Ra5YDvCdgYOwjpznDyVRittJ9ocWjsiNMTW4OE3ShQC8mln46R0lSQsOQlnSxQ6MgxsZkSNPghdlJJ4vRGO1tw5MCqqDVgwz-hgd6yBZlo9g7FCq4kf638Rtv4FbCMd_XisgbA1rRrraAqUK7SPMBzyocben7VQDkxo-jr2jtQsCdtSbSgn8dpmXHKDb88-3qguWniqqcCIjMvIBQu-BrKfOiWELcfsfajBcJX3zJX8GSgPjPcY_6HwLYX37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