Skip to content

[wasm] Add narrow methods to PackedSimd #83084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)