Skip to content

Commit e02b8d2

Browse files
committed
Add relaxed min and max
For WebAssembly#33.
1 parent 18c1b1d commit e02b8d2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

proposals/relaxed-simd/Overview.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ def blend(a : v128, b : v128, m: v128, lanes : int):
205205
return result
206206
```
207207

208+
### Relaxed min and max
209+
210+
- `f32x4.min(a: v128, b: v128) -> v128`
211+
- `f32x4.max(a: v128, b: v128) -> v128`
212+
- `f64x2.min(a: v128, b: v128) -> v128`
213+
- `f64x2.max(a: v128, b: v128) -> v128`
214+
215+
Return the lane-wise minimum or maximum of two values. If either values is NaN, or the values are -0.0 and +0.0, the return value is implementation-defined.
216+
217+
```python
218+
def min_or_max(a : v128, b : v128, lanes : int, is_min : bool):
219+
result = []
220+
for i in range(lanes):
221+
if isNaN(a[i]) or isNaN(b[i]):
222+
result[i] = UNDEFINED
223+
elif (a[i] == -0.0 && b[i] == +0.0) or (a[i] == +0.0 && b[i] == -0.0):
224+
result[i] = UNDEFINED
225+
else:
226+
result[i] = is_min ? min(a, b) : max(a, b)
227+
```
228+
208229
## Binary format
209230

210231
All opcodes have the `0xfd` prefix (same as SIMD proposal), which are omitted in the table below.
@@ -224,6 +245,10 @@ All opcodes have the `0xfd` prefix (same as SIMD proposal), which are omitted in
224245
| `i16x8.blend` | 0xb3 |
225246
| `i32x4.blend` | 0xd2 |
226247
| `i64x2.blend` | 0xd3 |
248+
| `f32x4.min` | 0xb4 |
249+
| `f32x4.max` | 0xe2 |
250+
| `f64x2.min` | 0xd4 |
251+
| `f64x2.max` | 0xee |
227252

228253
Note: the opcodes are chosen to fit into the existing opcode space of the SIMD proposal, see [Binary encoding of SIMD](https://github.com/WebAssembly/simd/blob/main/proposals/simd/BinarySIMD.md), or a [table view of the same opcodes](https://github.com/WebAssembly/simd/blob/main/proposals/simd/NewOpcodes.md) for a list of existing opcodes.
229254

0 commit comments

Comments
 (0)