<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99157>99157</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `step` 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 `step` clang builtin,
- [ ] Link `step` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `step` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `step` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/step.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/step-errors.hlsl`
- [ ] Create the `int_spv_step` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `step` lowering and map it to `int_spv_step` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/step.ll`
## DirectX
There were no DXIL opcodes found for `step`.
## SPIR-V
# Step:
## Description:
**Step**
Result is 0.0 if *x* \< *edge*; otherwise result is 1.0.
The operands must all be a scalar or vector whose component type is
floating-point.
*Result Type* and the type of all operands must be the same 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>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>48</p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>edge</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>x</em></p></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc step_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float4 fn(float4 p1, float4 p2) {
return step(p1, p2);
}
```
## HLSL:
Compares two values, returning 0 or 1 based on which value is greater.
| *ret* step(*y*, *x*) |
|----------------------|
## Parameters
| Item | Description |
|--------------------------------------------------------|---------------------------------------------------------------|
| <span id="y"></span><span id="Y"></span>*y*<br/> | \[in\] The first floating-point value to compare.<br/> |
| <span id="x"></span><span id="X"></span>*x*<br/> | \[in\] The second floating-point value to compare.<br/> |
## Return Value
1 if the *x* parameter is greater than or equal to the *y* parameter; otherwise, 0.
## Remarks
This function uses the following formula: (*x* >= *y*) ? 1 : 0. The function returns either 0 or 1 depending on whether the *x* parameter is greater than the *y* parameter. To compute a smooth interpolation between 0 and 1, use the [**smoothstep**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-smoothstep.md) HLSL intrinsic function.
## 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 |
|-------|----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|--------------------------------|
| *y* | [**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) | any |
| *x* | same as input *y* | [**float**](/windows/desktop/WinProg/windows-data-types) | same dimension(s) as input *y* |
| *ret* | same as input *y* | [**float**](/windows/desktop/WinProg/windows-data-types) | same dimension(s) as input *y* |
## 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) | yes (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/eJzUGV1T4zjy14iXrqRsmSTwkIfgkD2qZnenBmpu7olS7E6sQ5Z8kkxgf_1VS3YSQ4bhdupuuVQqWOpWf3_JCOfkViPO2eSKTZZnovWVsfONsH8Yrc7Wpnyej4BNroBNlnBTNwpr1B7YNHEeGzZNoFBCb2HdSuWlZjxnyeJw4pPUD99Fhp30FUEr5dS91N5K7WThxhWbJgMyi7IEh7WAosLiwcHG2GOq3tAqJ9jfPt1-uorkV60uvDQ6F0oRltSEdYu1CJhSb8dF05xiVZgSt6hPs7mupT_icv3U2AP1_Jdu-0ekPTrvOorBKIyvaI_xVW5K_AU18WB81dnKMb4iOcZkq--a5w2qpHdHMoh4syc5QmuNdScp5xaFR_AVEkmp_b1rHu97g-xd1ml_s3fh7eebL1_HvnxJ70ZDAN1o520b3HOLCgtvLFkMigG_no8yO7RSb0HoEmrRAEjfaflapODk7_Bg2YJlCxdWe2HZNBmfUpqIjL7CWhQPqMtgWyiEw46HUo_1K6eRoYk34ysy5-gQ1L3_VGdj-vKM8QyW0mLhv8W9uwotwo5-tIHlt5tPYBoKGgr6VpcvYnI8oBQl3m_BLSFliyE3dIWVDVmlA3H6BtTwBMCS-PMFXas8SAfJOAG5AcYXT4TBJjnLclpiuUU6ll2B8RXanXQIdn8uHSfjA727CsE0aIUuHdSt8yC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