Closed
Description
Background and motivation
I hit lack of these crossplatform helpers when I was doing "parse hex" work in #82521 - ended up with local functions. These APIs seem to present in SSE/AVX and AdvSimd and can be easily exposed as cross-platform helpers. Some places in BCL might benefit from this too, e.g.
API Proposal
namespace System.Numerics;
public static class Vector
{
+ public static Vector<T> AddSaturate<T> (Vector<T> left, Vector<T> right) where T : struct;
+ public static Vector<T> SubtractSaturate<T>(Vector<T> left, Vector<T> right) where T : struct;
}
namespace System.Runtime.Intrinsics;
public static class Vector64
{
+ public static Vector64<T> AddSaturate<T> (Vector64<T> left, Vector64<T> right) where T : struct;
+ public static Vector64<T> SubtractSaturate<T>(Vector64<T> left, Vector64<T> right) where T : struct;
}
public static class Vector128
{
+ public static Vector128<T> AddSaturate<T> (Vector128<T> left, Vector128<T> right) where T : struct;
+ public static Vector128<T> SubtractSaturate<T>(Vector128<T> left, Vector128<T> right) where T : struct;
}
public static class Vector256
{
+ public static Vector256<T> AddSaturate<T> (Vector256<T> left, Vector256<T> right) where T : struct;
+ public static Vector256<T> SubtractSaturate<T>(Vector256<T> left, Vector256<T> right) where T : struct;
}
public static class Vector512
{
+ public static Vector512<T> AddSaturate<T> (Vector512<T> left, Vector512<T> right) where T : struct;
+ public static Vector512<T> SubtractSaturate<T>(Vector512<T> left, Vector512<T> right) where T : struct;
}
NOTE: SSE and AVX only accelerate byte
, sbyte
, short
and ushort
. AdvSimd supports more types.