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

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

## DirectX

There were no DXIL opcodes found for `dst`.

## SPIR-V

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

## Description:
  
Floating-point multiplication of *Operand 1* and *Operand 2*.  
  
*Result Type* must be a scalar or vector of [*floating-point
type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Floating).  
  
The types of *Operand 1* and *Operand 2* both must be the same as
*Result Type*.  
  
Results are computed per component.

<table style="width:100%;">
<colgroup>
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>5</p></td>
<td class="tableblock halign-left valign-top"><p>133</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>Operand 1</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Operand 2</em></p></td>
</tr>
</tbody>
</table>



## Test Case(s)

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

export float4 fn(float4 p1, float4 p2) {
    return dst(p1, p2);
}
```
## HLSL:

Calculates a distance vector.

## Syntax

``` syntax
fVector dst(
  in fVector src0,
  in fVector src1
);
```

## Parameters

<dl> <dt>

*src0* \[in\]
</dt> <dd>

Type: **[fVector](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-vector.md)**

The first vector.

</dd> <dt>

*src1* \[in\]
</dt> <dd>

Type: **[fVector](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-vector.md)**

The second vector.

</dd> </dl>

## Return value

Type: **[fVector](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-vector.md)**

The computed distance vector.

## Remarks

This intrinsic function provides the same functionality as the Vertex Shader instruction [dst](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dst---vs.md).

## See also

<dl> <dt>

[Intrinsic Functions](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="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