Closed
Description
Background and motivation
I find it a quite common case when I have to use a verbose Unsafe.As
before Vector128.LoadUnsafe
. E.g. char
-> ushort
since we can't use char
as T for vectors:
Vector128<ushort> vec = Vector128.LoadUnsafe<ushort>(ref Unsafe.As<char, ushort>(ref searchSpace));
Another example is #66889 (comment):
Vector128.LoadUnsafe<byte>(ref Unsafe.As<Guid, byte>(ref Unsafe.AsRef(in left)))
API Proposal
namespace System.Runtime.Intrinsics
{
public static class Vector64
{
public static Vector64<T> LoadUnsafe<T>(ref T source)
where T : struct
public static Vector64<T> LoadUnsafe<T>(ref T source, nuint elementOffset)
where T : struct
+ public static Vector64<TTo> LoadUnsafe<TFrom, TTo>(ref TFromT source)
+ where TTo : struct
+ where TFrom : struct
+ public static Vector64<TTo> LoadUnsafe<TFrom, TTo>(ref TFrom source, nuint elementOffset)
+ where TTo : struct
+ where TFrom : struct
}
public static class Vector128
{
public static Vector128<T> LoadUnsafe<T>(ref T source)
where T : struct
public static Vector128<T> LoadUnsafe<T>(ref T source, nuint elementOffset)
where T : struct
+ public static Vector128<TTo> LoadUnsafe<TFrom, TTo>(ref TFromT source)
+ where TTo : struct
+ where TFrom : struct
+ public static Vector128<TTo> LoadUnsafe<TFrom, TTo>(ref TFrom source, nuint elementOffset)
+ where TTo : struct
+ where TFrom : struct
}
public static class Vector256
{
public static Vector256<T> LoadUnsafe<T>(ref T source)
where T : struct
public static Vector256<T> LoadUnsafe<T>(ref T source, nuint elementOffset)
where T : struct
+ public static Vector256<TTo> LoadUnsafe<TFrom, TTo>(ref TFromT source)
+ where TTo : struct
+ where TFrom : struct
+ public static Vector256<TTo> LoadUnsafe<TFrom, TTo>(ref TFrom source, nuint elementOffset)
+ where TTo : struct
+ where TFrom : struct
}
}
API Usage
For the example above ^:
Vector128<ushort> vec = Vector128.LoadUnsafe<char, ushort>(ref searchSpace);
Alternative Designs
No response
Risks
No response