Skip to content

Commit cf162f3

Browse files
MihaZupantmds
authored andcommitted
Improve TeddyHelper.RightShift helpers for ARM (dotnet#96928)
1 parent 17b6383 commit cf162f3

File tree

1 file changed

+8
-28
lines changed
  • src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/Helpers

1 file changed

+8
-28
lines changed

src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/Helpers/TeddyHelper.cs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ private static Vector512<byte> Shuffle(Vector512<byte> maskLow, Vector512<byte>
314314

315315
[MethodImpl(MethodImplOptions.AggressiveInlining)]
316316
[CompExactlyDependsOn(typeof(Ssse3))]
317-
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
317+
[CompExactlyDependsOn(typeof(AdvSimd))]
318318
private static Vector128<byte> RightShift1(Vector128<byte> left, Vector128<byte> right)
319319
{
320320
// Given input vectors like
@@ -323,24 +323,14 @@ private static Vector128<byte> RightShift1(Vector128<byte> left, Vector128<byte>
323323
// We want to shift the last element of left (15) to be the first element of the result
324324
// result: [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
325325

326-
if (Ssse3.IsSupported)
327-
{
328-
return Ssse3.AlignRight(right, left, 15);
329-
}
330-
else
331-
{
332-
// We create a temporary 'leftShifted' vector where the 1st element is the 16th element of the input.
333-
// We then use TBX to shuffle all the elements one place to the left.
334-
// 0xFF is used for the first element to replace it with the one from 'leftShifted'.
335-
336-
Vector128<byte> leftShifted = Vector128.Shuffle(left, Vector128.Create(15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0).AsByte());
337-
return AdvSimd.Arm64.VectorTableLookupExtension(leftShifted, right, Vector128.Create(0xFF, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14));
338-
}
326+
return Ssse3.IsSupported
327+
? Ssse3.AlignRight(right, left, 15)
328+
: AdvSimd.ExtractVector128(left, right, 15);
339329
}
340330

341331
[MethodImpl(MethodImplOptions.AggressiveInlining)]
342332
[CompExactlyDependsOn(typeof(Ssse3))]
343-
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
333+
[CompExactlyDependsOn(typeof(AdvSimd))]
344334
private static Vector128<byte> RightShift2(Vector128<byte> left, Vector128<byte> right)
345335
{
346336
// Given input vectors like
@@ -349,19 +339,9 @@ private static Vector128<byte> RightShift2(Vector128<byte> left, Vector128<byte>
349339
// We want to shift the last two elements of left (14, 15) to be the first elements of the result
350340
// result: [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
351341

352-
if (Ssse3.IsSupported)
353-
{
354-
return Ssse3.AlignRight(right, left, 14);
355-
}
356-
else
357-
{
358-
// We create a temporary 'leftShifted' vector where the 1st and 2nd element are the 15th and 16th element of the input.
359-
// We then use TBX to shuffle all the elements two places to the left.
360-
// 0xFF is used for the first two elements to replace them with the ones from 'leftShifted'.
361-
362-
Vector128<byte> leftShifted = Vector128.Shuffle(left, Vector128.Create(14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0).AsByte());
363-
return AdvSimd.Arm64.VectorTableLookupExtension(leftShifted, right, Vector128.Create(0xFF, 0xFF, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13));
364-
}
342+
return Ssse3.IsSupported
343+
? Ssse3.AlignRight(right, left, 14)
344+
: AdvSimd.ExtractVector128(left, right, 14);
365345
}
366346

367347
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)