<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99095>99095</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `cross` 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 `cross` clang builtin,
- [ ] Link `cross` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `cross` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `cross` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/cross.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/cross-errors.hlsl`
- [ ] Create the `int_spv_cross` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `cross` lowering and map it to `int_spv_cross` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/cross.ll`
## DirectX
There were no DXIL opcodes found for `cross`.
## SPIR-V
# Cross:
## Description:
**Cross**
Result is the cross product of *x* and *y*, i.e., the resulting
components are, in order:
*x*\[1\] \* *y*\[2\] - *y*\[1\] \* *x*\[2\]
*x*\[2\] \* *y*\[0\] - *y*\[2\] \* *x*\[0\]
*x*\[0\] \* *y*\[1\] - *y*\[0\] \* *x*\[1\]
All the operands must be vectors of 3 components of a floating-point
type.
*Result Type* and the type of all operands must be the same type.
<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>68</p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>x</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>y</em></p></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc cross_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float3 fn(float3 p1, float3 p2) {
return cross(p1, p2);
}
```
## HLSL:
Returns the cross product of two floating-point, 3D vectors.
| *ret* cross(*x*, *y*) |
|-----------------------|
## Parameters
| Item | Description |
|--------------------------------------------------------|---------------------------------------------------------|
| <span id="x"></span><span id="X"></span>*x*<br/> | \[in\] The first floating-point, 3D vector.<br/> |
| <span id="y"></span><span id="Y"></span>*y*<br/> | \[in\] The second floating-point, 3D vector.<br/> |
## Return Value
The cross product of the *x* parameter and the *y* parameter.
## 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* | [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md) | [**float**](/windows/desktop/WinProg/windows-data-types) | 3 |
| *y* | [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md) | [**float**](/windows/desktop/WinProg/windows-data-types) | 3 |
| *ret* | [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md) | [**float**](/windows/desktop/WinProg/windows-data-types) | 3 |
## Minimum Shader Model
This function is supported in the following shader models.
| Shader Model | Supported |
|------------------------------------------------------------------------------------|-----------------------|
| [Shader Model 2 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm2.md) and higher shader models | yes |
| [Shader Model 1 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm1.md) | vs\_1\_1 and ps\_1\_4 |
## 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/eJzsWV9v4zgO_zTKC-HAkZt_D3lInclegZndwbSYm3sqFFuJdZUlQ5LbZD_9gZLtxE2aKW4OuC6wQRBbIsUfRVIk7TBrxU5xviDjWzJeDVjtCm0WW2b-1EoONjo_LCIg41sg4xXclZXkJVcOyCTOjLaWTGLIJFM72NRCOqEITUm8PC75LNTT29zwIlyB5EJa-SiUM0JZkdlhQSZxT84yz8HykkFW8OzJwlabnlincZgi8R-f7z_fBvnrWmVOaJUyKZFLKOS65yXznELthllVXcLKdM53XL2B86kU7gTm074yR_Hpb830z2Q7bp1tJHqzELrGOULXqc75b1whBqHrxlqW0LVXZIjmetNCV8TizhuZXse7o8yIG6PNZdGp4cxxcAVHmUK5R1s9P3Y26fzWGOCu8-P917tv34cufy3wToEn3SnrTO1ddM8lz5w2aDTIeoAdkNQv3Ai1A6ZyKFkFIFyz0QtKeVe_gUKSJUmW1o86dckkHl7aNwqJvsOGZU9c5d6-kDHLGwwpn8szz6GxEZvQNVo0OsZ250TZ2Bm_NCE0gZUwPHM_wtxDwQ2HF_xRGlY_7j6DrjB0MPhrlb8OzWFPVNC5m4LUcyXLPh63mREVGqYhUfwGXn8LQOLw843bWjoQ1nvFg0JldF5nDvQWCF3ukR89Q-jy4JenIIZ8iFdcY7wE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