<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/99222>99222</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Implement the `unpack_s8s16` 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 `unpack_s8s16` clang builtin,
- [ ] Link `unpack_s8s16` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `unpack_s8s16` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `unpack_s8s16` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/unpack_s8s16.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/unpack_s8s16-errors.hlsl`
- [ ] Create the `int_dx_unpack_s8s16` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_unpack_s8s16` to  `219` in `DXIL.td`
- [ ] Create the  `unpack_s8s16.ll` and `unpack_s8s16_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_unpack_s8s16` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `unpack_s8s16` lowering and map  it to `int_spv_unpack_s8s16` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_s8s16.ll`

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 219 | Unpack4x8 | 6.6 | () |

## SPIR-V

# [OpSConvert](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpSConvert):

## Description:
  
Convert signed width. This is either a truncate or a sign extend.  
  
*Result Type* must be a scalar or vector of [*integer
type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer). 
  
*Signed Value* must be a scalar or vector of [*integer type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer).
It must have the same number of components as *Result Type*. The
component width must not equal the component width in *Result Type*.  
  
Results are computed per component.

<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>114</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result &lt;id&gt;</em></a></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Signed Value</em></p></td>
</tr>
</tbody>
</table>



## Test Case(s)

 
 ### Example 1
```hlsl
//dxc unpack_s8s16_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export int16_t4 fn(int8_t4_packed p1) {
 return unpack_s8s16(p1);
}
```
## HLSL:

## Syntax


```syntax
int16_t<4> unpack_s8s16(p32i8 pk);
```


## 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* | [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-vector.md) | [**int16_t**](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types) | 4 |
| *pk* | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-scalar.md) | [**int8_t4_packed**](../WinProg/windows-data-types) | 1 |

## Minimum Shader Model

This function is supported in the following shader models.
|Shader Model | Supported|
|-------------|----------|
|[Shader Model 6.6](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_ShaderModel6_6) 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 [Unpack Intrinsics](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_Pack_Unpack_Intrinsics#unpack-intrinsics)**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWF9z4ygS_zTkhZJKQrbGfvCD48R7rpq5mVrPze6bCwsscUGgA5Q_--mvGmRLsp1k9272bjblik3TdDe_buhuqLWiVJwv0PQWTe9uaOsqbRYHan7TSt7sNXtZRBhNbzGa3uFN3Uhec-UwypNWNbR42NmZTXOUJ7iQVJV43wrphEJkhZJlv_KjUA_vLsJPwlXAVUkrd0I5I5QVhY0rlCcjcUvGsOU1xUXFiweLD9pck-40UFfA87eP24-3Qc26VYUTWq2olMAlFHBteU09p1BlXDTNNZWFZrzk6m1197VwA233z43ptax-6sjvqXDcOttJ9CAhsgYaIuuVZvwnrkAHIusOO4vIemhPDBi-Ctsb0gGHTrQ3dXMhOuLGaGOvalgZTh3HruIgWii3Y8-7c5xOnu1A2Zw8fScML9yvsWNvC777dfPxc_OJNo1QJYjUhzf0OY1hlqTz3hEg4W015x6OQ7RQxc5ndh0ggSFgG7RI-VhfOA6RdbdPRNbvA2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