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

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

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 162 | Dot2AddHalf | 6.4 | () |

## SPIR-V

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

## Description:
  
Dot product of *Vector 1* and *Vector 2*.  
  
*Result Type* must be a [*floating-point type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Floating) scalar.  
  
*Vector 1* and *Vector 2* must be vectors of the same type, and their
component type must be *Result Type*.

<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>148</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>Vector 1</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Vector 2</em></p></td>
</tr>
</tbody>
</table>



## Test Case(s)

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

export float fn(half2 p1, half2 p2, float p3) {
    return dot2add(p1, p2, p3);
}
```
## HLSL:

## Syntax


```syntax
float dot2add(float16_t<2> a, float16_t<2> b, float c);
```


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

## Minimum Shader Model

This function is supported in the following shader models.
|Shader Model | Supported|
|-------------|----------|
|[Shader Model 6.4](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/hlsl-shader-model-6-4-features-for-direct3d-12.md) 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 [Single Precision Floating Point 2-Element Dot-Product and Accumulate](../direct3dhlsl/hlsl-shader-model-6-4-features-for-direct3d-12.md#signed-integer-dot-product-of-4-elements-and-accumulate)**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWUtv4zgS_jX0haAgUbZiH3xw7HgmQPd2MA565hZQIi1xQ5ECSeUxv35BUi93nAe2Z9C92AmCxCwWi1VfFcVPZWIMLyVja7C4BIvdjLS2Unp9JPpPJcUsV_R5jSBYXEKw2MHruhGsZtJCkMVUWUwoBVkMC0FkCfOWC8slwFsQb8ZFn7i8f0sfPnJbOYVKGHHHpdVcGl6YqAJZfGJpQyk0rCawqFhxb-BR6W8MW-UEWzf966fDp8uww76VheVKbokQTotLp3Vg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