Skip to content

Commit

Permalink
[wasm] Add narrow methods to PackedSimd (#83084)
Browse files Browse the repository at this point in the history
* [wasm] Add narrow methods to PackedSimd

Add them as internal as the approved API contains wrong methods for
these. #53730 (comment)

This will allow faster implementation of IndexOfAnyValues for wasm.
#82789 (comment)

* Fix build
  • Loading branch information
radekdoulik committed Mar 7, 2023
1 parent 0f1866e commit f3b8427
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,11 @@ public abstract class PackedSimd
public static Vector128<double> CompareNotEqual(Vector128<double> left, Vector128<double> right) { throw new PlatformNotSupportedException(); }
public static Vector128<nint> CompareNotEqual(Vector128<nint> left, Vector128<nint> right) { throw new PlatformNotSupportedException(); }
public static Vector128<nuint> CompareNotEqual(Vector128<nuint> left, Vector128<nuint> right) { throw new PlatformNotSupportedException(); }

internal static Vector128<sbyte> ConvertNarrowingSignedSaturate(Vector128<short> lower, Vector128<short> upper) { throw new PlatformNotSupportedException(); }
internal static Vector128<short> ConvertNarrowingSignedSaturate(Vector128<int> lower, Vector128<int> upper) { throw new PlatformNotSupportedException(); }

internal static Vector128<byte> ConvertNarrowingUnsignedSaturate(Vector128<short> lower, Vector128<short> upper) { throw new PlatformNotSupportedException(); }
internal static Vector128<ushort> ConvertNarrowingUnsignedSaturate(Vector128<int> lower, Vector128<int> upper) { throw new PlatformNotSupportedException(); }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -665,5 +665,29 @@ public abstract class PackedSimd
/// </summary>
[Intrinsic]
public static Vector128<nuint> CompareNotEqual(Vector128<nuint> left, Vector128<nuint> right) => CompareNotEqual(left, right);

/// <summary>
/// i8x16.narrow_i16x8_s
/// </summary>
[Intrinsic]
internal static Vector128<sbyte> ConvertNarrowingSignedSaturate(Vector128<short> lower, Vector128<short> upper) => ConvertNarrowingSignedSaturate(lower, upper);

/// <summary>
/// i16x8.narrow_i32x4_s
/// </summary>
[Intrinsic]
internal static Vector128<short> ConvertNarrowingSignedSaturate(Vector128<int> lower, Vector128<int> upper) => ConvertNarrowingSignedSaturate(lower, upper);

/// <summary>
/// i8x16.narrow_i16x8_u
/// </summary>
[Intrinsic]
internal static Vector128<byte> ConvertNarrowingUnsignedSaturate(Vector128<short> lower, Vector128<short> upper) => ConvertNarrowingUnsignedSaturate(lower, upper);

/// <summary>
/// i16x8.narrow_i32x4_u
/// </summary>
[Intrinsic]
internal static Vector128<ushort> ConvertNarrowingUnsignedSaturate(Vector128<int> lower, Vector128<int> upper) => ConvertNarrowingUnsignedSaturate(lower, upper);
}
}
32 changes: 32 additions & 0 deletions src/mono/mono/mini/simd-intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -4613,6 +4613,8 @@ static SimdIntrinsic packedsimd_methods [] = {
{SN_Bitmask},
{SN_CompareEqual},
{SN_CompareNotEqual},
{SN_ConvertNarrowingSignedSaturate},
{SN_ConvertNarrowingUnsignedSaturate},
{SN_Dot},
{SN_ExtractLane},
{SN_Multiply},
Expand Down Expand Up @@ -4708,6 +4710,36 @@ emit_wasm_supported_intrinsics (
return emit_simd_ins_for_sig (cfg, klass, type_enum_is_float (arg0_type) ? OP_XCOMPARE_FP : OP_XCOMPARE, CMP_EQ, arg0_type, fsig, args);
case SN_CompareNotEqual:
return emit_simd_ins_for_sig (cfg, klass, type_enum_is_float (arg0_type) ? OP_XCOMPARE_FP : OP_XCOMPARE, CMP_NE, arg0_type, fsig, args);
case SN_ConvertNarrowingSignedSaturate: {
int intrins = -1;
switch (arg0_type) {
case MONO_TYPE_I2:
intrins = INTRINS_WASM_NARROW_SIGNED_V16;
break;
case MONO_TYPE_I4:
intrins = INTRINS_WASM_NARROW_SIGNED_V8;
break;
}
if (intrins != -1)
return emit_simd_ins_for_sig (cfg, klass, OP_XOP_X_X_X, intrins, arg0_type, fsig, args);

return NULL;
}
case SN_ConvertNarrowingUnsignedSaturate: {
int intrins = -1;
switch (arg0_type) {
case MONO_TYPE_I2:
intrins = INTRINS_WASM_NARROW_UNSIGNED_V16;
break;
case MONO_TYPE_I4:
intrins = INTRINS_WASM_NARROW_UNSIGNED_V8;
break;
}
if (intrins != -1)
return emit_simd_ins_for_sig (cfg, klass, OP_XOP_X_X_X, intrins, arg0_type, fsig, args);

return NULL;
}
case SN_ExtractLane: {
int extract_op = type_to_xextract_op (arg0_type);
return emit_simd_ins_for_sig (cfg, klass, extract_op, -1, arg0_type, fsig, args);
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/simd-methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,5 @@ METHOD(Splat)
METHOD(ExtractLane)
METHOD(ReplaceLane)
METHOD(Swizzle)
METHOD(ConvertNarrowingSignedSaturate)
METHOD(ConvertNarrowingUnsignedSaturate)

0 comments on commit f3b8427

Please sign in to comment.