<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99112>99112</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `f16tof32` HLSL Function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
metabug,
backend:DirectX,
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 `f16tof32` clang builtin,
- [ ] Link `f16tof32` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `f16tof32` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `f16tof32` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/f16tof32.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/f16tof32-errors.hlsl`
- [ ] Create the `int_dx_f16tof32` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_f16tof32` to `131` in `DXIL.td`
- [ ] Create the `f16tof32.ll` and `f16tof32_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_f16tof32` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `f16tof32` lowering and map it to `int_spv_f16tof32` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/f16tof32.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 131 | LegacyF16ToF32 | 6.0 | () |
## SPIR-V
# UnpackHalf2x16:
## Description:
**UnpackHalf2x16**
Result is the two-component floating-point vector with components
obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit
values, interpreting those values as 16-bit floating-point numbers
according to the OpenGL Specification, and converting them to 32-bit
floating-point values. Subnormal numbers are either preserved or flushed
to zero, consistently within an implemenation.
The first component of the vector is obtained from the 16
least-significant bits of *v*; the second component is obtained from the
16 most-significant bits of *v*.
The *v* operand must be a scalar with 32-bit integer type.
*Result Type* must be a vector of 2 components whose type is 32-bit
floating point.
<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>62</p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>v</em></p></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc f16tof32_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float4 fn(uint4 p1) {
return f16tof32(p1);
}
```
## HLSL:
Converts the float16 stored in the low-half of the uint to a float.
## Syntax
``` syntax
float f16tof32(
in uint value
);
```
## Parameters
<dl> <dt>
*value* \[in\]
</dt> <dd>
Type: **uint**
The input value.
</dd> </dl>
## Return value
Type: **float**
The converted value.
## Remarks
The following overloaded versions are also available:
``` syntax
float2 f16tof32(uint2 value);
float3 f16tof32(uint3 value);
float4 f16tof32(uint4 value);
```
### Minimum Shader Model
This function is supported in the following shader models.
| Shader Model | Supported |
|---------------------------------------------------------------------|-----------|
| [Shader Model 4](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm4.md) and higher shader models | yes |
Although this function is available in [Shader Model 4](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm4.md) and higher shader models, because it is emulated in 4.0 and 4.1, it is less perfomant on these shader models than it is on [Shader Model 5](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/d3d11-graphics-reference-sm5.md).
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](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
</dt> <dt>
[Shader Model 5](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/d3d11-graphics-reference-sm5.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUGF1v27r11zAvhAyJst34wQ-OE7cB0tui6Yr7FlDSkcWFIgWScpL764dDyvpwXHe7G7bdwIjEw8Pz_SVya8VeAazJ4oYsbq946ypt1iU3f2glrzJdvK0jShY3lCxu6X3dSKhBOUqWcZksnS5TRpYxzSVXe5q1QjqhCNuSeDOcehDq-eIB-iJchRiVtPJJKGeEsiK3s4os4wmpTVFQCzWneQX5s6WlNqeUnUbIFvc_PTw-3AQWu1blTmi15VIillCI9Qg195hC7Wd505xjl-sC9qB-zuquFm7E6e61MQOH7ccO_CvyDqyzHUVvHMJ2CCNst9UFfASFPAjbdTazhO2OsszQbj811QXKqH9H1ot5PyEbgTHa2LPUtwa4A-oqQLJCuafi9Wlsm96LnSHue6_eCgO5-33mistEb3-_f_jSfOZNI9QeSeryJ7ycpriTpMlgeDx9mcXYm7MQFVwVY-hTZ4CwGewYqEt5qN85iLBdpxthu18bzDaHf9Jij1_vv_04o8y9on7rXllnWh_fjyAhd9pguNF8wnPMS-oXMELtvcY1bygVrguR86L5bPkJL5JuSLqxftULTZbx7JwBkEj0g2Y8fwZVeKPSnFv4hWE9b8J2GIvRUCHGSSC7IMUfSwlL6dEbAfZhSzEo6JcGc46O1r_xOqwfK16AoZ91AXIMeHR8DxYhHaFo-KO_WL8HRCNCSZr4_QfY8_xtlyy_613KPGg5i_2TsGvCVsczvXLBkD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