-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime.Intrinsicshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors
Milestone
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.
runtime/src/libraries/System.Private.CoreLib/src/System/Text/Unicode/Utf16Utility.Validation.cs
Lines 133 to 142 in 220437e
if (AdvSimd.IsSupported) | |
{ | |
charIsThreeByteUtf8Encoded = AdvSimd.AddSaturate(utf16Data, vector7800); | |
mask = GetNonAsciiBytes(AdvSimd.Or(charIsNonAscii, charIsThreeByteUtf8Encoded).AsByte(), bitMask128); | |
} | |
else | |
{ | |
charIsThreeByteUtf8Encoded = Sse2.AddSaturate(utf16Data, vector7800); | |
mask = (uint)Sse2.MoveMask(Sse2.Or(charIsNonAscii, charIsThreeByteUtf8Encoded).AsByte()); | |
} |
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.
xoofx and PaulusParssinen
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime.Intrinsicshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors