Skip to content
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 @@ -11,13 +11,6 @@ public static partial class Vector
/// <param name="value">The plane to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector4" />.</returns>
[Intrinsic]
public static Vector4 AsVector4(this Plane value)
{
#if MONO
return Unsafe.As<Plane, Vector4>(ref value);
#else
return Unsafe.BitCast<Plane, Vector4>(value);
#endif
}
public static Vector4 AsVector4(this Plane value) => Unsafe.BitCast<Plane, Vector4>(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ public static partial class Vector
/// <param name="value">The quaternion to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Quaternion" />.</returns>
[Intrinsic]
public static Vector4 AsVector4(this Quaternion value)
{
#if MONO
return Unsafe.As<Quaternion, Vector4>(ref value);
#else
return Unsafe.BitCast<Quaternion, Vector4>(value);
#endif
}
public static Vector4 AsVector4(this Quaternion value) => Unsafe.BitCast<Quaternion, Vector4>(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ public static Vector<TTo> As<TFrom, TTo>(this Vector<TFrom> vector)
ThrowHelper.ThrowForUnsupportedNumericsVectorBaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedNumericsVectorBaseType<TTo>();

#if MONO
return Unsafe.As<Vector<TFrom>, Vector<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector<TFrom>, Vector<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector{T}" /> as a new <see langword="Vector&lt;Byte&gt;" />.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,12 @@ public static unsafe partial class Vector
/// <summary>Reinterprets a <see cref="Vector4" /> as a new <see cref="Plane" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Plane" />.</returns>
public static Plane AsPlane(this Vector4 value)
{
#if MONO
return Unsafe.As<Vector4, Plane>(ref value);
#else
return Unsafe.BitCast<Vector4, Plane>(value);
#endif
}
public static Plane AsPlane(this Vector4 value) => Unsafe.BitCast<Vector4, Plane>(value);

/// <summary>Reinterprets a <see cref="Vector4" /> as a new <see cref="Quaternion" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Quaternion" />.</returns>
public static Quaternion AsQuaternion(this Vector4 value)
{
#if MONO
return Unsafe.As<Vector4, Quaternion>(ref value);
#else
return Unsafe.BitCast<Vector4, Quaternion>(value);
#endif
}
public static Quaternion AsQuaternion(this Vector4 value) => Unsafe.BitCast<Vector4, Quaternion>(value);

/// <summary>Reinterprets a <see cref="Vector4" /> as a new <see cref="Vector2" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,25 @@ public static partial class Vector128
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Plane" />.</returns>
[Intrinsic]
public static Plane AsPlane(this Vector128<float> value)
{
#if MONO
return Unsafe.As<Vector128<float>, Plane>(ref value);
#else
return Unsafe.BitCast<Vector128<float>, Plane>(value);
#endif
}
public static Plane AsPlane(this Vector128<float> value) => Unsafe.BitCast<Vector128<float>, Plane>(value);

/// <summary>Reinterprets a <see langword="Vector128&lt;Single&gt;" /> as a new <see cref="Quaternion" />.</summary>
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Quaternion" />.</returns>
[Intrinsic]
public static Quaternion AsQuaternion(this Vector128<float> value)
{
#if MONO
return Unsafe.As<Vector128<float>, Quaternion>(ref value);
#else
return Unsafe.BitCast<Vector128<float>, Quaternion>(value);
#endif
}
public static Quaternion AsQuaternion(this Vector128<float> value) => Unsafe.BitCast<Vector128<float>, Quaternion>(value);

/// <summary>Reinterprets a <see cref="Plane" /> as a new <see langword="Vector128&lt;Single&gt;" />.</summary>
/// <param name="value">The plane to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see langword="Vector128&lt;Single&gt;" />.</returns>
[Intrinsic]
public static Vector128<float> AsVector128(this Plane value)
{
#if MONO
return Unsafe.As<Plane, Vector128<float>>(ref value);
#else
return Unsafe.BitCast<Plane, Vector128<float>>(value);
#endif
}
public static Vector128<float> AsVector128(this Plane value) => Unsafe.BitCast<Plane, Vector128<float>>(value);

/// <summary>Reinterprets a <see cref="Quaternion" /> as a new <see langword="Vector128&lt;Single&gt;" />.</summary>
/// <param name="value">The quaternion to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see langword="Vector128&lt;Single&gt;" />.</returns>
[Intrinsic]
public static Vector128<float> AsVector128(this Quaternion value)
{
#if MONO
return Unsafe.As<Quaternion, Vector128<float>>(ref value);
#else
return Unsafe.BitCast<Quaternion, Vector128<float>>(value);
#endif
}
public static Vector128<float> AsVector128(this Quaternion value) => Unsafe.BitCast<Quaternion, Vector128<float>>(value);

/// <summary>Reinterprets a <see langword="Vector2" /> as a new <see cref="Vector128&lt;Single&gt;" /> with the new elements zeroed.</summary>
/// <param name="value">The vector to reinterpret.</param>
Expand All @@ -117,14 +89,7 @@ public static Vector128<float> AsVector128(this Quaternion value)
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see langword="Vector128&lt;Single&gt;" />.</returns>
[Intrinsic]
public static Vector128<float> AsVector128(this Vector4 value)
{
#if MONO
return Unsafe.As<Vector4, Vector128<float>>(ref value);
#else
return Unsafe.BitCast<Vector4, Vector128<float>>(value);
#endif
}
public static Vector128<float> AsVector128(this Vector4 value) => Unsafe.BitCast<Vector4, Vector128<float>>(value);

/// <summary>Reinterprets a <see cref="Vector{T}" /> as a new <see cref="Vector128{T}" />.</summary>
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
Expand Down Expand Up @@ -196,14 +161,7 @@ public static Vector3 AsVector3(this Vector128<float> value)
/// <param name="value">The vector to reinterpret.</param>
/// <returns><paramref name="value" /> reinterpreted as a new <see cref="Vector4" />.</returns>
[Intrinsic]
public static Vector4 AsVector4(this Vector128<float> value)
{
#if MONO
return Unsafe.As<Vector128<float>, Vector4>(ref value);
#else
return Unsafe.BitCast<Vector128<float>, Vector4>(value);
#endif
}
public static Vector4 AsVector4(this Vector128<float> value) => Unsafe.BitCast<Vector128<float>, Vector4>(value);

/// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see cref="Vector{T}" />.</summary>
/// <typeparam name="T">The type of the elements in the vector.</typeparam>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ public static Vector128<TTo> As<TFrom, TTo>(this Vector128<TFrom> vector)
ThrowHelper.ThrowForUnsupportedIntrinsicsVector128BaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedIntrinsicsVector128BaseType<TTo>();

#if MONO
return Unsafe.As<Vector128<TFrom>, Vector128<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector128<TFrom>, Vector128<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector128{T}" /> as a new <see langword="Vector128&lt;Byte&gt;" />.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ public static Vector256<TTo> As<TFrom, TTo>(this Vector256<TFrom> vector)
ThrowHelper.ThrowForUnsupportedIntrinsicsVector256BaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedIntrinsicsVector256BaseType<TTo>();

#if MONO
return Unsafe.As<Vector256<TFrom>, Vector256<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector256<TFrom>, Vector256<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector256{T}" /> as a new <see langword="Vector256&lt;Byte&gt;" />.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,7 @@ public static Vector512<TTo> As<TFrom, TTo>(this Vector512<TFrom> vector)
ThrowHelper.ThrowForUnsupportedIntrinsicsVector512BaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedIntrinsicsVector512BaseType<TTo>();

#if MONO
return Unsafe.As<Vector512<TFrom>, Vector512<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector512<TFrom>, Vector512<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector512{T}" /> as a new <see langword="Vector512&lt;Byte&gt;" />.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,7 @@ public static Vector64<TTo> As<TFrom, TTo>(this Vector64<TFrom> vector)
ThrowHelper.ThrowForUnsupportedIntrinsicsVector64BaseType<TFrom>();
ThrowHelper.ThrowForUnsupportedIntrinsicsVector64BaseType<TTo>();

#if MONO
return Unsafe.As<Vector64<TFrom>, Vector64<TTo>>(ref vector);
#else
return Unsafe.BitCast<Vector64<TFrom>, Vector64<TTo>>(vector);
#endif
}

/// <summary>Reinterprets a <see cref="Vector64{T}" /> as a new <see langword="Vector64&lt;Byte&gt;" />.</summary>
Expand Down
76 changes: 76 additions & 0 deletions src/mono/mono/mini/interp/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,16 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
return TRUE;
}
}
} else if (in_corlib && !strcmp (klass_name_space, "System") && (!strcmp (klass_name, "BitConverter"))) {
if (!strcmp (tm, "DoubleToInt64Bits") || !strcmp (tm, "DoubleToUInt64Bits")) {
*op = MINT_MOV_8;
} else if (!strcmp (tm, "Int32BitsToSingle") || !strcmp (tm, "UInt32BitsToSingle")) {
*op = MINT_MOV_4;
} else if (!strcmp (tm, "Int64BitsToDouble") || !strcmp (tm, "UInt64BitsToDouble")) {
*op = MINT_MOV_8;
} else if (!strcmp (tm, "SingleToInt32Bits") || !strcmp (tm, "SingleToUInt32Bits")) {
*op = MINT_MOV_4;
}
} else if (in_corlib && !strcmp (klass_name_space, "System.Runtime.CompilerServices") && !strcmp (klass_name, "Unsafe")) {
if (!strcmp (tm, "AddByteOffset"))
#if SIZEOF_VOID_P == 4
Expand All @@ -2156,6 +2166,72 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
return TRUE;
} else if (!strcmp (tm, "AreSame")) {
*op = MINT_CEQ_P;
} else if (!strcmp (tm, "BitCast")) {
MonoGenericContext *ctx = mono_method_get_context (target_method);
g_assert (ctx);
g_assert (ctx->method_inst);
g_assert (ctx->method_inst->type_argc == 2);
g_assert (csignature->param_count == 1);

// We explicitly do not handle gsharedvt as it is meant as a slow fallback strategy
// instead we fallback to the managed implementation which will do the right things

MonoType *tfrom = ctx->method_inst->type_argv [0];
MonoType *tto = ctx->method_inst->type_argv [1];
tfrom = mini_get_underlying_type (tfrom);
tto = mini_get_underlying_type (tto);

// The underlying API always throws for reference type inputs, so we
// fallback to the managed implementation to let that handling occur

if (MONO_TYPE_IS_REFERENCE (tfrom) || MONO_TYPE_IS_REFERENCE (tto)) {
return FALSE;
}

MonoClass *tto_klass = mono_class_from_mono_type_internal (tto);

// The same applies for when the type sizes do not match, as this will always throw
// and so its not an expected case and we can fallback to the managed implementation

int tfrom_align, tto_align;
gint32 size = mono_type_size (tfrom, &tfrom_align);
if (size != mono_type_size (tto, &tto_align)) {
return FALSE;
}
g_assert (size < G_MAXUINT16);

// We have several different move opcodes to handle the data depending on the
// source and target types, so detect and optimize the most common ones falling
// back to what is effectively `ReadUnaligned<TTo>(ref As<TFrom, byte>(ref source))`
// for anything that can't be special cased as potentially zero-cost move.

if (m_class_is_enumtype (tto_klass)) {
tto = mono_class_enum_basetype_internal (tto_klass);
}

int mov_op = interp_get_mov_for_type (mono_mint_type (tto), TRUE);

if (mov_op == MINT_MOV_VT ) {
if (size <= 4) {
*op = MINT_MOV_4;
} else if (size <= 8) {
*op = MINT_MOV_8;
} else {
td->sp--;
interp_add_ins (td, MINT_MOV_VT);
interp_ins_set_sreg (td->last_ins, td->sp [0].var);
push_type_vt (td, tto_klass, size);
interp_ins_set_dreg (td->last_ins, td->sp [-1].var);
td->last_ins->data [0] = GINT32_TO_UINT16 (size);
td->ip += 5;
return TRUE;
}
} else {
if (size < 4)
return FALSE;

*op = mov_op;
}
} else if (!strcmp (tm, "ByteOffset")) {
#if SIZEOF_VOID_P == 4
interp_add_ins (td, MINT_SUB_I4);
Expand Down
5 changes: 5 additions & 0 deletions src/mono/mono/mini/intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,11 @@ MONO_RESTORE_WARNING
}
} else if (mini_class_is_simd (cfg, tfrom_klass) && mini_class_is_simd (cfg, tto_klass)) {
#if TARGET_SIZEOF_VOID_P == 8 || defined(TARGET_WASM)
#if defined(TARGET_WIN32) && defined(TARGET_AMD64)
if (!COMPILE_LLVM (cfg))
// FIXME: Fix the register allocation for SIMD on Windows x64
return NULL;
#endif
opcode = OP_XCAST;
tto_stack = STACK_VTYPE;
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Collections.Generic;
using Xunit;

[assembly:ActiveIssue("https://github.com/dotnet/runtime/issues/54122", TestPlatforms.Browser)]

namespace JIT.HardwareIntrinsics.General._Vector128_1
{
public static partial class Program
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Collections.Generic;
using Xunit;

[assembly:ActiveIssue("https://github.com/dotnet/runtime/issues/54122", TestPlatforms.Browser)]

namespace JIT.HardwareIntrinsics.General._Vector256_1
{
public static partial class Program
Expand Down
10 changes: 0 additions & 10 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2725,16 +2725,6 @@
<Issue>https://github.com/dotnet/runtime/issues/54867</Issue>
</ExcludeList>

<ExcludeList Include = "$(XunitTestBinBase)/JIT/HardwareIntrinsics/General/Vector512_1/**">
<Issue>https://github.com/dotnet/runtime/issues/54122</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/HardwareIntrinsics/General/Vector256_1/**">
<Issue>https://github.com/dotnet/runtime/issues/54122</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/HardwareIntrinsics/General/Vector128_1/**">
<Issue>https://github.com/dotnet/runtime/issues/54122</Issue>
</ExcludeList>

<ExcludeList Include = "$(XunitTestBinBase)/baseservices/invalid_operations/**">
<Issue>Function mismatch</Issue>
</ExcludeList>
Expand Down
Loading