From 5841bf9f3d3cfd2123c9340d4a0f00aa805f61c5 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 12 Sep 2019 18:25:29 -0700 Subject: [PATCH 1/3] Add pseudocode for widening and narrowing operations Clarifies that high lanes are lanes `[0, n/2)` and low 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. --- proposals/simd/SIMD.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/proposals/simd/SIMD.md b/proposals/simd/SIMD.md index 4f9e073f6..980ef00ed 100644 --- a/proposals/simd/SIMD.md +++ b/proposals/simd/SIMD.md @@ -808,6 +808,28 @@ will use unsigned saturation to handle overflow, 0x00 or 0xff for i8x16. Regardless of the whether the operation is signed or unsigned, the input lanes are interpreted as signed integers. +```python +def S.narrow_T_s(a, b): + result = S.New() + for i in range(T.Lanes): + result[i] = S.SignedSaturate(b[i]) + for i in range(T.Lanes): + result[T.Lanes + i] = S.SignedSaturate(a[i]) + return result + +``` + +```python +def S.narrow_T_u(a, b): + result = S.New() + for i in range(T.Lanes): + result[i] = S.UnsignedSaturate(b[i]) + for i in range(T.Lanes): + result[T.Lanes + i] = S.UnsignedSaturate(a[i]) + return result + +``` + ### Integer to integer widening * `i16x8.widen_low_i8x16_s(a: v128) -> v128` * `i16x8.widen_high_i8x16_s(a: v128) -> v128` @@ -820,3 +842,21 @@ are interpreted as signed integers. Converts low or high half of the smaller lane vector to a larger lane vector, sign extended or zero (unsigned) extended. + +```python +def S.widen_low_T(ext, a): + result = S.New() + for i in range(S.Lanes): + result[i] = ext(a[S.Lanes + i]) + +def S.widen_high_T(ext, a): + result = S.New() + for i in range(S.Lanes): + result[i] = ext(a[i]) + +def S.widen_low_T_s(a): + return S.widen_low_T(Sext, a) + +def S.widen_high_T_u(a): + return S.widen_high_T(Zext, a) +``` From e68d2141a7b2785ace98721733f85a7cf45289b2 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Fri, 13 Sep 2019 11:19:20 -0700 Subject: [PATCH 2/3] Switch to "low" meaning [0,n/2) and "high" meaning [n/2,n) --- proposals/simd/SIMD.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/proposals/simd/SIMD.md b/proposals/simd/SIMD.md index 980ef00ed..ca45131e5 100644 --- a/proposals/simd/SIMD.md +++ b/proposals/simd/SIMD.md @@ -812,9 +812,9 @@ are interpreted as signed integers. def S.narrow_T_s(a, b): result = S.New() for i in range(T.Lanes): - result[i] = S.SignedSaturate(b[i]) + result[i] = S.SignedSaturate(a[i]) for i in range(T.Lanes): - result[T.Lanes + i] = S.SignedSaturate(a[i]) + result[T.Lanes + i] = S.SignedSaturate(b[i]) return result ``` @@ -823,9 +823,9 @@ def S.narrow_T_s(a, b): def S.narrow_T_u(a, b): result = S.New() for i in range(T.Lanes): - result[i] = S.UnsignedSaturate(b[i]) + result[i] = S.UnsignedSaturate(a[i]) for i in range(T.Lanes): - result[T.Lanes + i] = S.UnsignedSaturate(a[i]) + result[T.Lanes + i] = S.UnsignedSaturate(b[i]) return result ``` @@ -847,16 +847,22 @@ sign extended or zero (unsigned) extended. def S.widen_low_T(ext, a): result = S.New() for i in range(S.Lanes): - result[i] = ext(a[S.Lanes + i]) + result[i] = ext(a[i]) def S.widen_high_T(ext, a): result = S.New() for i in range(S.Lanes): - result[i] = ext(a[i]) + result[i] = ext(a[S.Lanes + i]) def S.widen_low_T_s(a): return S.widen_low_T(Sext, a) +def S.widen_high_T_s(a): + return S.widen_high_T(Sext, a) + +def S.widen_low_T_u(a): + return S.widen_low_T(Zext, a) + def S.widen_high_T_u(a): return S.widen_high_T(Zext, a) ``` From 5bb3e3acfcf1a8e670920b63ce95115f94365302 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Fri, 13 Sep 2019 11:22:22 -0700 Subject: [PATCH 3/3] Formatting --- proposals/simd/SIMD.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/proposals/simd/SIMD.md b/proposals/simd/SIMD.md index 26345cce3..16277829d 100644 --- a/proposals/simd/SIMD.md +++ b/proposals/simd/SIMD.md @@ -817,9 +817,6 @@ def S.narrow_T_s(a, b): result[T.Lanes + i] = S.SignedSaturate(b[i]) return result -``` - -```python def S.narrow_T_u(a, b): result = S.New() for i in range(T.Lanes): @@ -827,7 +824,6 @@ def S.narrow_T_u(a, b): for i in range(T.Lanes): result[T.Lanes + i] = S.UnsignedSaturate(b[i]) return result - ``` ### Integer to integer widening