Skip to content

Commit

Permalink
Disable load/store vector APIs until Mono adds support for it (#96944)
Browse files Browse the repository at this point in the history
* Revert "[libs] Skip AdvSimdEncode on Mono (#96829)"

This reverts commit 1a76e37.

* Revert "Use multi-reg load/store for EncodeToUtf8 (#95513)"

This reverts commit fdb03ca.

* Wrap load/store vector APIs in '#if false'

* Disable load/store vector tests

* remove the trailing space
  • Loading branch information
kunalspathak authored Jan 16, 2024
1 parent 660cfe0 commit 6dab58f
Show file tree
Hide file tree
Showing 5 changed files with 454 additions and 430 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ public static unsafe OperationStatus EncodeToUtf8(ReadOnlySpan<byte> bytes, Span
goto DoneExit;
}

#if !MONO // https://github.com/dotnet/runtime/issues/93081
end = srcMax - 48;
if (AdvSimd.Arm64.IsSupported && (end >= src))
{
AdvSimdEncode(ref src, ref dest, end, maxSrcLength, destLength, srcBytes, destBytes);

if (src == srcEnd)
goto DoneExit;
}
#endif

end = srcMax - 16;
if ((Ssse3.IsSupported || AdvSimd.Arm64.IsSupported) && BitConverter.IsLittleEndian && (end >= src))
{
Expand Down Expand Up @@ -491,66 +480,6 @@ private static unsafe void Avx2Encode(ref byte* srcBytes, ref byte* destBytes, b
destBytes = dest;
}

#if !MONO // https://github.com/dotnet/runtime/issues/93081
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
private static unsafe void AdvSimdEncode(ref byte* srcBytes, ref byte* destBytes, byte* srcEnd, int sourceLength, int destLength, byte* srcStart, byte* destStart)
{
// C# implementatino of https://github.com/aklomp/base64/blob/3a5add8652076612a8407627a42c768736a4263f/lib/arch/neon64/enc_loop.c
Vector128<byte> str1;
Vector128<byte> str2;
Vector128<byte> str3;
Vector128<byte> res1;
Vector128<byte> res2;
Vector128<byte> res3;
Vector128<byte> res4;
Vector128<byte> tblEnc1 = Vector128.Create("ABCDEFGHIJKLMNOP"u8).AsByte();
Vector128<byte> tblEnc2 = Vector128.Create("QRSTUVWXYZabcdef"u8).AsByte();
Vector128<byte> tblEnc3 = Vector128.Create("ghijklmnopqrstuv"u8).AsByte();
Vector128<byte> tblEnc4 = Vector128.Create("wxyz0123456789+/"u8).AsByte();
byte* src = srcBytes;
byte* dest = destBytes;

// If we have Neon support, pick off 48 bytes at a time for as long as we can.
do
{
// Load 48 bytes and deinterleave:
AssertRead<Vector128<byte>>(src, srcStart, sourceLength);
(str1, str2, str3) = AdvSimd.Arm64.LoadVector128x3AndUnzip(src);

// Divide bits of three input bytes over four output bytes:
res1 = AdvSimd.ShiftRightLogical(str1, 2);
res2 = AdvSimd.ShiftRightLogical(str2, 4);
res3 = AdvSimd.ShiftRightLogical(str3, 6);
res2 = AdvSimd.ShiftLeftAndInsert(res2, str1, 4);
res3 = AdvSimd.ShiftLeftAndInsert(res3, str2, 2);

// Clear top two bits:
res2 &= AdvSimd.DuplicateToVector128((byte)0x3F);
res3 &= AdvSimd.DuplicateToVector128((byte)0x3F);
res4 = str3 & AdvSimd.DuplicateToVector128((byte)0x3F);

// The bits have now been shifted to the right locations;
// translate their values 0..63 to the Base64 alphabet.
// Use a 64-byte table lookup:
res1 = AdvSimd.Arm64.VectorTableLookup((tblEnc1, tblEnc2, tblEnc3, tblEnc4), res1);
res2 = AdvSimd.Arm64.VectorTableLookup((tblEnc1, tblEnc2, tblEnc3, tblEnc4), res2);
res3 = AdvSimd.Arm64.VectorTableLookup((tblEnc1, tblEnc2, tblEnc3, tblEnc4), res3);
res4 = AdvSimd.Arm64.VectorTableLookup((tblEnc1, tblEnc2, tblEnc3, tblEnc4), res4);

// Interleave and store result:
AssertWrite<Vector128<byte>>(dest, destStart, destLength);
AdvSimd.Arm64.StoreVector128x4AndZip(dest, (res1, res2, res3, res4));

src += 48;
dest += 64;
} while (src <= srcEnd);

srcBytes = src;
destBytes = dest;
}
#endif // !MONO

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[CompExactlyDependsOn(typeof(Ssse3))]
[CompExactlyDependsOn(typeof(AdvSimd.Arm64))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,9 @@ internal Arm64() { }
/// </summary>
public static Vector128<ulong> InsertSelectedScalar(Vector128<ulong> result, [ConstantExpected(Max = (byte)(1))] byte resultIndex, Vector128<ulong> value, [ConstantExpected(Max = (byte)(1))] byte valueIndex) { throw new PlatformNotSupportedException(); }

#if false
// Should be disabled until Mono implements these APIs. See https://github.com/dotnet/runtime/issues/93081

/// <summary>
/// A64: LD2 { Vn.16B, Vn+1.16B }[Vm], [Xn]
/// </summary>
Expand Down Expand Up @@ -1699,6 +1702,7 @@ internal Arm64() { }
/// A64: LD4 { Vn.2D, Vn+1.2D, Vn+2.2D, Vn+3.2D }[Vm], [Xn]
/// </summary>
public static unsafe (Vector128<double> Value1, Vector128<double> Value2, Vector128<double> Value3, Vector128<double> Value4) LoadAndInsertScalar((Vector128<double>, Vector128<double>, Vector128<double>, Vector128<double>) values, [ConstantExpected(Max = (byte)(1))] byte index, double* address) { throw new PlatformNotSupportedException(); }
#endif

/// <summary>
/// float64x2_t vld1q_dup_f64 (float64_t const * ptr)
Expand All @@ -1718,6 +1722,9 @@ internal Arm64() { }
/// </summary>
public static unsafe Vector128<ulong> LoadAndReplicateToVector128(ulong* address) { throw new PlatformNotSupportedException(); }

#if false
// Should be disabled until Mono implements these APIs. See https://github.com/dotnet/runtime/issues/93081

/// <summary>
/// A64: LD2R { Vn.16B, Vn+1.16B }, [Xn]
/// </summary>
Expand Down Expand Up @@ -1867,6 +1874,7 @@ internal Arm64() { }
/// A64: LD4R { Vn.2D, Vn+1.2D, Vn+2.2D, Vn+3.2D }, [Xn]
/// </summary>
public static unsafe (Vector128<double> Value1, Vector128<double> Value2, Vector128<double> Value3, Vector128<double> Value4) LoadAndReplicateToVector128x4(double* address) { throw new PlatformNotSupportedException(); }
#endif

/// <summary>
/// A64: LDP Dt1, Dt2, [Xn]
Expand Down Expand Up @@ -2098,6 +2106,9 @@ internal Arm64() { }
/// </summary>
public static unsafe (Vector128<ulong> Value1, Vector128<ulong> Value2) LoadPairVector128NonTemporal(ulong* address) { throw new PlatformNotSupportedException(); }

#if false
// Should be disabled until Mono implements these APIs. See https://github.com/dotnet/runtime/issues/93081

/// <summary>
/// A64: LD2 { Vn.16B, Vn+1.16B }, [Xn]
/// </summary>
Expand Down Expand Up @@ -2397,6 +2408,7 @@ internal Arm64() { }
/// A64: LD1 { Vn.2D, Vn+1.2D, Vn+2.2D, Vn+3.2D }, [Xn]
/// </summary>
public static unsafe (Vector128<double> Value1, Vector128<double> Value2, Vector128<double> Value3, Vector128<double> Value4) LoadVector128x4(double* address) { throw new PlatformNotSupportedException(); }
#endif

/// <summary>
/// float64x2_t vmaxq_f64 (float64x2_t a, float64x2_t b)
Expand Down Expand Up @@ -3776,6 +3788,9 @@ internal Arm64() { }
/// </summary>
public static unsafe void StorePairScalarNonTemporal(uint* address, Vector64<uint> value1, Vector64<uint> value2) { throw new PlatformNotSupportedException(); }

#if false
// Should be disabled until Mono implements these APIs. See https://github.com/dotnet/runtime/issues/93081

/// <summary>
/// void vst2_lane_s8 (int8_t * ptr, int8x16x2_t val, const int lane)
/// A64: ST2 { Vt.16B, Vt+1.16B }[index], [Xn]
Expand Down Expand Up @@ -4246,6 +4261,7 @@ internal Arm64() { }
/// A64: ST1 { Vn.2D, Vn+1.2D, Vn+2.2D, Vn+3.2D }, [Xn]
/// </summary>
public static unsafe void StoreVector128x4(double* address, (Vector128<double> Value1, Vector128<double> Value2, Vector128<double> Value3, Vector128<double> Value4) value) { throw new PlatformNotSupportedException(); }
#endif

/// <summary>
/// float64x2_t vsubq_f64 (float64x2_t a, float64x2_t b)
Expand Down Expand Up @@ -9160,6 +9176,9 @@ internal Arm64() { }
/// </summary>
public static unsafe Vector128<ulong> LoadAndInsertScalar(Vector128<ulong> value, [ConstantExpected(Max = (byte)(1))] byte index, ulong* address) { throw new PlatformNotSupportedException(); }

#if false
// Should be disabled until Mono implements these APIs. See https://github.com/dotnet/runtime/issues/93081

/// <summary>
/// A64: LD2 { Vn.8B, Vn+1.8B }[Vm], [Xn]
/// </summary>
Expand Down Expand Up @@ -9264,6 +9283,7 @@ internal Arm64() { }
/// A64: LD4 { Vn.2S, Vn+1.2S, Vn+2.2S, Vn+3.2S }[Vm], [Xn]
/// </summary>
public static unsafe (Vector64<float> Value1, Vector64<float> Value2, Vector64<float> Value3, Vector64<float> Value4) LoadAndInsertScalar((Vector64<float>, Vector64<float>, Vector64<float>, Vector64<float>) values, [ConstantExpected(Max = (byte)(1))] byte index, float* address) { throw new PlatformNotSupportedException(); }
#endif

/// <summary>
/// uint8x8_t vld1_dup_u8 (uint8_t const * ptr)
Expand Down Expand Up @@ -9363,6 +9383,9 @@ internal Arm64() { }
/// </summary>
public static unsafe Vector128<uint> LoadAndReplicateToVector128(uint* address) { throw new PlatformNotSupportedException(); }

#if false
// Should be disabled until Mono implements these APIs. See https://github.com/dotnet/runtime/issues/93081

/// <summary>
/// A64: LD2R { Vn.8B, Vn+1.8B }, [Xn]
/// </summary>
Expand Down Expand Up @@ -9467,6 +9490,7 @@ internal Arm64() { }
/// A64: LD4R { Vn.2S, Vn+1.2S, Vn+2.2S, Vn+3.2S }, [Xn]
/// </summary>
public static unsafe (Vector64<float> Value1, Vector64<float> Value2, Vector64<float> Value3, Vector64<float> Value4) LoadAndReplicateToVector64x4(float* address) { throw new PlatformNotSupportedException(); }
#endif

/// <summary>
/// uint8x8_t vld1_u8 (uint8_t const * ptr)
Expand Down Expand Up @@ -9608,6 +9632,9 @@ internal Arm64() { }
/// </summary>
public static unsafe Vector128<ulong> LoadVector128(ulong* address) { throw new PlatformNotSupportedException(); }

#if false
// Should be disabled until Mono implements these APIs. See https://github.com/dotnet/runtime/issues/93081

/// <summary>
/// A64: LD2 { Vn.8B, Vn+1.8B }, [Xn]
/// </summary>
Expand Down Expand Up @@ -9817,6 +9844,7 @@ internal Arm64() { }
/// A64: LD1 { Vn.2S, Vn+1.2S, Vn+2.2S, Vn+3.2S }, [Xn]
/// </summary>
public static unsafe (Vector64<float> Value1, Vector64<float> Value2, Vector64<float> Value3, Vector64<float> Value4) LoadVector64x4(float* address) { throw new PlatformNotSupportedException(); }
#endif

/// <summary>
/// uint8x8_t vmax_u8 (uint8x8_t a, uint8x8_t b)
Expand Down Expand Up @@ -15928,6 +15956,9 @@ internal Arm64() { }
/// </summary>
public static unsafe void StoreSelectedScalar(ulong* address, Vector128<ulong> value, [ConstantExpected(Max = (byte)(1))] byte index) { throw new PlatformNotSupportedException(); }

#if false
// Should be disabled until Mono implements these APIs. See https://github.com/dotnet/runtime/issues/93081

/// <summary>
/// A64: ST2 { Vt.8B, Vt+1.8B }[index], [Xn]
/// </summary>
Expand Down Expand Up @@ -16242,6 +16273,7 @@ internal Arm64() { }
/// A64: ST1 { Vn.2S, Vn+1.2S, Vn+2.2S, Vn+3.2S }, [Xn]
/// </summary>
public static unsafe void StoreVector64x4(float* address, (Vector64<float> Value1, Vector64<float> Value2, Vector64<float> Value3, Vector64<float> Value4) value) { throw new PlatformNotSupportedException(); }
#endif

/// <summary>
/// uint8x8_t vsub_u8 (uint8x8_t a, uint8x8_t b)
Expand Down
Loading

0 comments on commit 6dab58f

Please sign in to comment.