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

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

## DirectX

There were no DXIL opcodes found for `asint`.

## SPIR-V

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

## Description:
  
Construct a new [*composite*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#CompositeType) object from a set of
constituent objects.  
  
*Result Type* must be a [*composite*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#CompositeType) type, whose
top-level members/elements/components/columns have the same type as the
types of the operands, with one exception. The exception is that for
constructing a vector, the operands may also be vectors with the same
component type as the *Result Type* component type. If constructing a
vector, the total number of components in all the operands must equal
the number of components in *Result Type*.  
  
*Constituents* become members of a structure, or elements of an array,
or components of a vector, or columns of a matrix. There must be exactly
one *Constituent* for each top-level member/element/component/column of
the result, with one exception. The exception is that for constructing a
vector, a contiguous subset of the scalars consumed can be represented
by a vector operand instead. The *Constituents* must appear in the order
needed by the definition of the type of the result. If constructing a
vector, there must be at least two *Constituent* operands.

<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>3 + variable</p></td>
<td class="tableblock halign-left valign-top"><p>80</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;,
&lt;id&gt;, …​</em><br />
<em>Constituents</em></p></td>
</tr>
</tbody>
</table>



## Test Case(s)

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

export int4 fn(float p1) {
    return asint(p1);
}
```
 ### Example 2
```hlsl
//dxc asint_1_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export int4 fn(uint p1) {
    return asint(p1);
}
```
 ### Example 3
```hlsl
//dxc asint_2_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export int4 fn(int p1) {
    return asint(p1);
}
```
## HLSL:

Interprets the bit pattern of *x* as an integer.



| ret asint(*x*) |
|----------------|



 

## Parameters



| Item                                                   | Description                        |
|--------------------------------------------------------|------------------------------------|
| <span id="x"></span><span id="X"></span>*x*<br/> | \[in\] The input value.<br/> |



 

## Return Value

The input interpreted as an integer.

## Type Description



| Name  | [**Template Type**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)                                                  | [**Component Type**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)                  | Size                           |
|-------|----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|--------------------------------|
| *x*   | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md), **vector**, or **matrix** | [**float**](/windows/desktop/WinProg/windows-data-types), [**uint**](/windows/desktop/WinProg/windows-data-types) | any                            |
| *ret* | same as input *x*                                                                                              | [**int**](/windows/desktop/WinProg/windows-data-types)                                           | same dimension(s) as input *x* |



 

## 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       |
| [Shader Model 3 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm3.md)           | no        |
| [Shader Model 2 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm2.md)           | no        |
| [Shader Model 1 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm1.md)           | no        |



 

## See also

<dl> <dt>

[**Intrinsic Functions (DirectX HLSL)**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWVtv47YS_jXMy8CGTNlO8uAHR1n3BNieFs2i7duCksYWG4rUIakk7q8_GFKSrcTJpnvBboUgFm8z31w4nKGEc3KnEVdsccUW12ei9ZWxq62wfxutznJT7lcTYIsrYItruKkbh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