Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit e7c2002

Browse files
authored
Shorten saturating instructions to sat (#341)
Also update the test generation script, and regenerate all test files. Adressess #332 (not closing so other tools can also use it to track their rename progress).
1 parent 163e122 commit e7c2002

13 files changed

+1335
-1335
lines changed

interpreter/binary/decode.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ let simd_prefix s =
315315
| 0x65l -> i8x16_narrow_i16x8_s
316316
| 0x66l -> i8x16_narrow_i16x8_u
317317
| 0x6el -> i8x16_add
318-
| 0x6fl -> i8x16_add_saturate_s
319-
| 0x70l -> i8x16_add_saturate_u
318+
| 0x6fl -> i8x16_add_sat_s
319+
| 0x70l -> i8x16_add_sat_u
320320
| 0x71l -> i8x16_sub
321-
| 0x72l -> i8x16_sub_saturate_s
322-
| 0x73l -> i8x16_sub_saturate_u
321+
| 0x72l -> i8x16_sub_sat_s
322+
| 0x73l -> i8x16_sub_sat_u
323323
| 0x76l -> i8x16_min_s
324324
| 0x77l -> i8x16_min_u
325325
| 0x78l -> i8x16_max_s
@@ -340,11 +340,11 @@ let simd_prefix s =
340340
| 0x8cl -> i16x8_shr_s
341341
| 0x8dl -> i16x8_shr_u
342342
| 0x8el -> i16x8_add
343-
| 0x8fl -> i16x8_add_saturate_s
344-
| 0x90l -> i16x8_add_saturate_u
343+
| 0x8fl -> i16x8_add_sat_s
344+
| 0x90l -> i16x8_add_sat_u
345345
| 0x91l -> i16x8_sub
346-
| 0x92l -> i16x8_sub_saturate_s
347-
| 0x93l -> i16x8_sub_saturate_u
346+
| 0x92l -> i16x8_sub_sat_s
347+
| 0x93l -> i16x8_sub_sat_u
348348
| 0x95l -> i16x8_mul
349349
| 0x96l -> i16x8_min_s
350350
| 0x97l -> i16x8_min_u

interpreter/syntax/operators.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ let i8x16_shl = SimdShift V128Op.(I8x16 Shl)
278278
let i8x16_shr_s = SimdShift V128Op.(I8x16 ShrS)
279279
let i8x16_shr_u = SimdShift V128Op.(I8x16 ShrU)
280280
let i8x16_add = Binary (V128 (V128Op.I8x16 V128Op.Add))
281-
let i8x16_add_saturate_s = Binary (V128 V128Op.(I8x16 AddSatS))
282-
let i8x16_add_saturate_u = Binary (V128 V128Op.(I8x16 AddSatU))
281+
let i8x16_add_sat_s = Binary (V128 V128Op.(I8x16 AddSatS))
282+
let i8x16_add_sat_u = Binary (V128 V128Op.(I8x16 AddSatU))
283283
let i8x16_sub = Binary (V128 (V128Op.I8x16 V128Op.Sub))
284-
let i8x16_sub_saturate_s = Binary (V128 V128Op.(I8x16 SubSatS))
285-
let i8x16_sub_saturate_u = Binary (V128 V128Op.(I8x16 SubSatU))
284+
let i8x16_sub_sat_s = Binary (V128 V128Op.(I8x16 SubSatS))
285+
let i8x16_sub_sat_u = Binary (V128 V128Op.(I8x16 SubSatU))
286286
let i8x16_abs = Unary (V128 (V128Op.I8x16 V128Op.Abs))
287287
let i8x16_min_s = Binary (V128 (V128Op.I8x16 V128Op.MinS))
288288
let i8x16_min_u = Binary (V128 (V128Op.I8x16 V128Op.MinU))
@@ -314,11 +314,11 @@ let i16x8_shl = SimdShift V128Op.(I16x8 Shl)
314314
let i16x8_shr_s = SimdShift V128Op.(I16x8 ShrS)
315315
let i16x8_shr_u = SimdShift V128Op.(I16x8 ShrU)
316316
let i16x8_add = Binary (V128 (V128Op.I16x8 V128Op.Add))
317-
let i16x8_add_saturate_s = Binary (V128 V128Op.(I16x8 AddSatS))
318-
let i16x8_add_saturate_u = Binary (V128 V128Op.(I16x8 AddSatU))
317+
let i16x8_add_sat_s = Binary (V128 V128Op.(I16x8 AddSatS))
318+
let i16x8_add_sat_u = Binary (V128 V128Op.(I16x8 AddSatU))
319319
let i16x8_sub = Binary (V128 (V128Op.I16x8 V128Op.Sub))
320-
let i16x8_sub_saturate_s = Binary (V128 V128Op.(I16x8 SubSatS))
321-
let i16x8_sub_saturate_u = Binary (V128 V128Op.(I16x8 SubSatU))
320+
let i16x8_sub_sat_s = Binary (V128 V128Op.(I16x8 SubSatS))
321+
let i16x8_sub_sat_u = Binary (V128 V128Op.(I16x8 SubSatU))
322322
let i16x8_mul = Binary (V128 (V128Op.I16x8 V128Op.Mul))
323323
let i16x8_abs = Unary (V128 (V128Op.I16x8 V128Op.Abs))
324324
let i16x8_min_s = Binary (V128 (V128Op.I16x8 V128Op.MinS))

interpreter/text/arrange.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ struct
266266
| I8x16 NarrowS -> "i8x16.narrow_i16x8_s"
267267
| I8x16 NarrowU -> "i8x16.narrow_i16x8_u"
268268
| I8x16 Add -> "i8x16.add"
269-
| I8x16 AddSatS -> "i8x16.add_saturate_s"
270-
| I8x16 AddSatU -> "i8x16.add_saturate_u"
269+
| I8x16 AddSatS -> "i8x16.add_sat_s"
270+
| I8x16 AddSatU -> "i8x16.add_sat_u"
271271
| I8x16 Sub -> "i8x16.sub"
272-
| I8x16 SubSatS -> "i8x16.sub_saturate_s"
273-
| I8x16 SubSatU -> "i8x16.sub_saturate_u"
272+
| I8x16 SubSatS -> "i8x16.sub_sat_s"
273+
| I8x16 SubSatU -> "i8x16.sub_sat_u"
274274
| I8x16 MinS -> "i8x16.min_s"
275275
| I8x16 MinU -> "i8x16.min_u"
276276
| I8x16 MaxS -> "i8x16.max_s"
@@ -279,11 +279,11 @@ struct
279279
| I16x8 NarrowS -> "i16x8.narrow_i32x4_s"
280280
| I16x8 NarrowU -> "i16x8.narrow_i32x4_u"
281281
| I16x8 Add -> "i16x8.add"
282-
| I16x8 AddSatS -> "i16x8.add_saturate_s"
283-
| I16x8 AddSatU -> "i16x8.add_saturate_u"
282+
| I16x8 AddSatS -> "i16x8.add_sat_s"
283+
| I16x8 AddSatU -> "i16x8.add_sat_u"
284284
| I16x8 Sub -> "i16x8.sub"
285-
| I16x8 SubSatS -> "i16x8.sub_saturate_s"
286-
| I16x8 SubSatU -> "i16x8.sub_saturate_u"
285+
| I16x8 SubSatS -> "i16x8.sub_sat_s"
286+
| I16x8 SubSatU -> "i16x8.sub_sat_u"
287287
| I16x8 Mul -> "i16x8.mul"
288288
| I16x8 MinS -> "i16x8.min_s"
289289
| I16x8 MinU -> "i16x8.min_u"

interpreter/text/lexer.mll

+8-8
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,14 @@ rule token = parse
550550
| "i32x4.widen_high_i16x8_"(sign as s)
551551
{ UNARY (ext s i32x4_widen_high_i16x8_s i32x4_widen_high_i16x8_u) }
552552

553-
| "i8x16.add_saturate_"(sign as s)
554-
{ BINARY (ext s i8x16_add_saturate_s i8x16_add_saturate_u) }
555-
| "i8x16.sub_saturate_"(sign as s)
556-
{ BINARY (ext s i8x16_sub_saturate_s i8x16_sub_saturate_u) }
557-
| "i16x8.add_saturate_"(sign as s)
558-
{ BINARY (ext s i16x8_add_saturate_s i16x8_add_saturate_u) }
559-
| "i16x8.sub_saturate_"(sign as s)
560-
{ BINARY (ext s i16x8_sub_saturate_s i16x8_sub_saturate_u) }
553+
| "i8x16.add_sat_"(sign as s)
554+
{ BINARY (ext s i8x16_add_sat_s i8x16_add_sat_u) }
555+
| "i8x16.sub_sat_"(sign as s)
556+
{ BINARY (ext s i8x16_sub_sat_s i8x16_sub_sat_u) }
557+
| "i16x8.add_sat_"(sign as s)
558+
{ BINARY (ext s i16x8_add_sat_s i16x8_add_sat_u) }
559+
| "i16x8.sub_sat_"(sign as s)
560+
{ BINARY (ext s i16x8_sub_sat_s i16x8_sub_sat_u) }
561561

562562
| (simd_shape as s) { SIMD_SHAPE (simd_shape s) }
563563

proposals/simd/BinarySIMD.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ For example, `ImmLaneIdx16` is a byte with values in the range 0-15 (inclusive).
126126
| `i8x16.shr_s` | `0x6c`| - |
127127
| `i8x16.shr_u` | `0x6d`| - |
128128
| `i8x16.add` | `0x6e`| - |
129-
| `i8x16.add_saturate_s` | `0x6f`| - |
130-
| `i8x16.add_saturate_u` | `0x70`| - |
129+
| `i8x16.add_sat_s` | `0x6f`| - |
130+
| `i8x16.add_sat_u` | `0x70`| - |
131131
| `i8x16.sub` | `0x71`| - |
132-
| `i8x16.sub_saturate_s` | `0x72`| - |
133-
| `i8x16.sub_saturate_u` | `0x73`| - |
132+
| `i8x16.sub_sat_s` | `0x72`| - |
133+
| `i8x16.sub_sat_u` | `0x73`| - |
134134
| `i8x16.min_s` | `0x76`| - |
135135
| `i8x16.min_u` | `0x77`| - |
136136
| `i8x16.max_s` | `0x78`| - |
@@ -151,11 +151,11 @@ For example, `ImmLaneIdx16` is a byte with values in the range 0-15 (inclusive).
151151
| `i16x8.shr_s` | `0x8c`| - |
152152
| `i16x8.shr_u` | `0x8d`| - |
153153
| `i16x8.add` | `0x8e`| - |
154-
| `i16x8.add_saturate_s` | `0x8f`| - |
155-
| `i16x8.add_saturate_u` | `0x90`| - |
154+
| `i16x8.add_sat_s` | `0x8f`| - |
155+
| `i16x8.add_sat_u` | `0x90`| - |
156156
| `i16x8.sub` | `0x91`| - |
157-
| `i16x8.sub_saturate_s` | `0x92`| - |
158-
| `i16x8.sub_saturate_u` | `0x93`| - |
157+
| `i16x8.sub_sat_s` | `0x92`| - |
158+
| `i16x8.sub_sat_u` | `0x93`| - |
159159
| `i16x8.mul` | `0x95`| - |
160160
| `i16x8.min_s` | `0x96`| - |
161161
| `i16x8.min_u` | `0x97`| - |

proposals/simd/ImplementationStatus.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@
9494
| `i8x16.shr_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
9595
| `i8x16.shr_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
9696
| `i8x16.add` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
97-
| `i8x16.add_saturate_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
98-
| `i8x16.add_saturate_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
97+
| `i8x16.add_sat_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
98+
| `i8x16.add_sat_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
9999
| `i8x16.sub` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
100-
| `i8x16.sub_saturate_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
101-
| `i8x16.sub_saturate_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
100+
| `i8x16.sub_sat_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
101+
| `i8x16.sub_sat_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
102102
| `i8x16.min_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
103103
| `i8x16.min_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
104104
| `i8x16.max_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
@@ -119,11 +119,11 @@
119119
| `i16x8.shr_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
120120
| `i16x8.shr_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
121121
| `i16x8.add` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
122-
| `i16x8.add_saturate_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
123-
| `i16x8.add_saturate_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
122+
| `i16x8.add_sat_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
123+
| `i16x8.add_sat_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
124124
| `i16x8.sub` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
125-
| `i16x8.sub_saturate_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
126-
| `i16x8.sub_saturate_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
125+
| `i16x8.sub_sat_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
126+
| `i16x8.sub_sat_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
127127
| `i16x8.mul` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
128128
| `i16x8.min_s` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |
129129
| `i16x8.min_u` | `-msimd128` | :heavy_check_mark: | | | :heavy_check_mark: |

proposals/simd/NewOpcodes.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@
9393
| i8x16.shr_s | 0x6c | i16x8.shr_s | 0x8c | i32x4.shr_s | 0xac | i64x2.shr_s | 0xcc |
9494
| i8x16.shr_u | 0x6d | i16x8.shr_u | 0x8d | i32x4.shr_u | 0xad | i64x2.shr_u | 0xcd |
9595
| i8x16.add | 0x6e | i16x8.add | 0x8e | i32x4.add | 0xae | i64x2.add | 0xce |
96-
| i8x16.add_saturate_s | 0x6f | i16x8.add_saturate_s | 0x8f | ---- add_sat ---- | 0xaf | ---- | 0xcf |
97-
| i8x16.add_saturate_u | 0x70 | i16x8.add_saturate_u | 0x90 | ---- add_sat ---- | 0xb0 | ---- | 0xd0 |
96+
| i8x16.add_sat_s | 0x6f | i16x8.add_sat_s | 0x8f | ---- add_sat ---- | 0xaf | ---- | 0xcf |
97+
| i8x16.add_sat_u | 0x70 | i16x8.add_sat_u | 0x90 | ---- add_sat ---- | 0xb0 | ---- | 0xd0 |
9898
| i8x16.sub | 0x71 | i16x8.sub | 0x91 | i32x4.sub | 0xb1 | i64x2.sub | 0xd1 |
99-
| i8x16.sub_saturate_s | 0x72 | i16x8.sub_saturate_s | 0x92 | ---- sub_sat ---- | 0xb2 | ---- | 0xd2 |
100-
| i8x16.sub_saturate_u | 0x73 | i16x8.sub_saturate_u | 0x93 | ---- sub_sat ---- | 0xb3 | ---- | 0xd3 |
99+
| i8x16.sub_sat_s | 0x72 | i16x8.sub_sat_s | 0x92 | ---- sub_sat ---- | 0xb2 | ---- | 0xd2 |
100+
| i8x16.sub_sat_u | 0x73 | i16x8.sub_sat_u | 0x93 | ---- sub_sat ---- | 0xb3 | ---- | 0xd3 |
101101
| ---- dot ---- | 0x74 | ---- dot ---- | 0x94 | ---- dot ---- | 0xb4 | ---- | 0xd4 |
102102
| ---- mul ---- | 0x75 | i16x8.mul | 0x95 | i32x4.mul | 0xb5 | i64x2.mul | 0xd5 |
103103
| i8x16.min_s | 0x76 | i16x8.min_s | 0x96 | i32x4.min_s | 0xb6 | ---- | 0xd6 |

proposals/simd/SIMD.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -433,40 +433,40 @@ def S.UnsignedSaturate(x):
433433
```
434434

435435
### Saturating integer addition
436-
* `i8x16.add_saturate_s(a: v128, b: v128) -> v128`
437-
* `i8x16.add_saturate_u(a: v128, b: v128) -> v128`
438-
* `i16x8.add_saturate_s(a: v128, b: v128) -> v128`
439-
* `i16x8.add_saturate_u(a: v128, b: v128) -> v128`
436+
* `i8x16.add_sat_s(a: v128, b: v128) -> v128`
437+
* `i8x16.add_sat_u(a: v128, b: v128) -> v128`
438+
* `i16x8.add_sat_s(a: v128, b: v128) -> v128`
439+
* `i16x8.add_sat_u(a: v128, b: v128) -> v128`
440440

441441
Lane-wise saturating addition:
442442

443443
```python
444-
def S.add_saturate_s(a, b):
444+
def S.add_sat_s(a, b):
445445
def addsat(x, y):
446446
return S.SignedSaturate(x + y)
447447
return S.lanewise_binary(addsat, S.AsSigned(a), S.AsSigned(b))
448448

449-
def S.add_saturate_u(a, b):
449+
def S.add_sat_u(a, b):
450450
def addsat(x, y):
451451
return S.UnsignedSaturate(x + y)
452452
return S.lanewise_binary(addsat, S.AsUnsigned(a), S.AsUnsigned(b))
453453
```
454454

455455
### Saturating integer subtraction
456-
* `i8x16.sub_saturate_s(a: v128, b: v128) -> v128`
457-
* `i8x16.sub_saturate_u(a: v128, b: v128) -> v128`
458-
* `i16x8.sub_saturate_s(a: v128, b: v128) -> v128`
459-
* `i16x8.sub_saturate_u(a: v128, b: v128) -> v128`
456+
* `i8x16.sub_sat_s(a: v128, b: v128) -> v128`
457+
* `i8x16.sub_sat_u(a: v128, b: v128) -> v128`
458+
* `i16x8.sub_sat_s(a: v128, b: v128) -> v128`
459+
* `i16x8.sub_sat_u(a: v128, b: v128) -> v128`
460460

461461
Lane-wise saturating subtraction:
462462

463463
```python
464-
def S.sub_saturate_s(a, b):
464+
def S.sub_sat_s(a, b):
465465
def subsat(x, y):
466466
return S.SignedSaturate(x - y)
467467
return S.lanewise_binary(subsat, S.AsSigned(a), S.AsSigned(b))
468468

469-
def S.sub_saturate_u(a, b):
469+
def S.sub_sat_u(a, b):
470470
def subsat(x, y):
471471
return S.UnsignedSaturate(x - y)
472472
return S.lanewise_binary(subsat, S.AsUnsigned(a), S.AsUnsigned(b))

test/core/simd/meta/simd_integer_op.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class ArithmeticOp:
1212
may be required for the operations.
1313
The following operators are covered:
1414
add, sub, mul, neg,
15-
add_saturate_s, add_saturate_u,
16-
sub_saturate_s, sub_saturate_u,
15+
add_sat_s, add_sat_u,
16+
sub_sat_s, sub_sat_u,
1717
min_s, min_u, max_s, max_u, avgr_u, abs
1818
"""
1919
def __init__(self, op: str):
@@ -45,7 +45,7 @@ def _saturate(self, operand1: int, operand2: int, lane: LaneValue) -> int:
4545
"""Get the result of saturating arithmetic operation on 2 operands.
4646
The operands can be both signed or unsigned. The following ops
4747
are covered:
48-
add_saturate_s, sub_saturate_s, add_saturate_u, sub_saturate_u,
48+
add_sat_s, sub_sat_s, add_sat_u, sub_sat_u,
4949
5050
Saturating arithmetic can make sure:
5151
When the operation result is less than the minimum, return the minimum.
@@ -56,7 +56,7 @@ def _saturate(self, operand1: int, operand2: int, lane: LaneValue) -> int:
5656
:param lane: the LaneValue instance of a lane in v128
5757
:return: the result of the saturating arithmetic operation
5858
"""
59-
if self.op.endswith('saturate_s'):
59+
if self.op.endswith('sat_s'):
6060
if operand1 > lane.max:
6161
operand1 -= lane.mod
6262
if operand2 > lane.max:
@@ -72,7 +72,7 @@ def _saturate(self, operand1: int, operand2: int, lane: LaneValue) -> int:
7272
if value < lane.min:
7373
return lane.min
7474

75-
if self.op.endswith('saturate_u'):
75+
if self.op.endswith('sat_u'):
7676
if operand1 < 0:
7777
operand1 += lane.mod
7878
if operand2 < 0:
@@ -127,8 +127,8 @@ def binary_op(self, operand1, operand2, lane):
127127
128128
Supported ops:
129129
add, sub, mul,
130-
add_saturate_s, add_saturate_u,
131-
sub_saturate_s, sub_saturate_u,
130+
add_sat_s, add_sat_u,
131+
sub_sat_s, sub_sat_u,
132132
min_s, min_u, max_s, max_u, avgr_u
133133
134134
:param operand1: the operand 1, integer or literal string in hex or decimal format
@@ -155,7 +155,7 @@ def binary_op(self, operand1, operand2, lane):
155155
value = v1 - v2
156156
elif self.op == 'mul':
157157
value = v1 * v2
158-
elif 'saturate' in self.op:
158+
elif 'sat' in self.op:
159159
value = self._saturate(v1, v2, lane)
160160
if self.op.endswith('_u'):
161161
result_signed = False

0 commit comments

Comments
 (0)