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

Commit fb7b68b

Browse files
authored
Add pseudocode for widening and narrowing operations (#105)
Clarifies that low lanes are lanes [0, n/2) and high lanes are [n/2, n) and that the order of arguments to the narrowing ops are (low, high). This matches the current implementation in V8.
1 parent ed7767b commit fb7b68b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

proposals/simd/SIMD.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,24 @@ will use unsigned saturation to handle overflow, 0x00 or 0xff for i8x16.
808808
Regardless of the whether the operation is signed or unsigned, the input lanes
809809
are interpreted as signed integers.
810810

811+
```python
812+
def S.narrow_T_s(a, b):
813+
result = S.New()
814+
for i in range(T.Lanes):
815+
result[i] = S.SignedSaturate(a[i])
816+
for i in range(T.Lanes):
817+
result[T.Lanes + i] = S.SignedSaturate(b[i])
818+
return result
819+
820+
def S.narrow_T_u(a, b):
821+
result = S.New()
822+
for i in range(T.Lanes):
823+
result[i] = S.UnsignedSaturate(a[i])
824+
for i in range(T.Lanes):
825+
result[T.Lanes + i] = S.UnsignedSaturate(b[i])
826+
return result
827+
```
828+
811829
### Integer to integer widening
812830
* `i16x8.widen_low_i8x16_s(a: v128) -> v128`
813831
* `i16x8.widen_high_i8x16_s(a: v128) -> v128`
@@ -820,3 +838,27 @@ are interpreted as signed integers.
820838

821839
Converts low or high half of the smaller lane vector to a larger lane vector,
822840
sign extended or zero (unsigned) extended.
841+
842+
```python
843+
def S.widen_low_T(ext, a):
844+
result = S.New()
845+
for i in range(S.Lanes):
846+
result[i] = ext(a[i])
847+
848+
def S.widen_high_T(ext, a):
849+
result = S.New()
850+
for i in range(S.Lanes):
851+
result[i] = ext(a[S.Lanes + i])
852+
853+
def S.widen_low_T_s(a):
854+
return S.widen_low_T(Sext, a)
855+
856+
def S.widen_high_T_s(a):
857+
return S.widen_high_T(Sext, a)
858+
859+
def S.widen_low_T_u(a):
860+
return S.widen_low_T(Zext, a)
861+
862+
def S.widen_high_T_u(a):
863+
return S.widen_high_T(Zext, a)
864+
```

0 commit comments

Comments
 (0)