* Removing the InsertVector128 and ExtractVector128 overloads that take an address from S.P.Corelib
* Removing the ExtractStore and InsertLoad tests.
* Fixing the PacketTracer test to use the appropriate Extract/InsertVector128 overloads
* Removing the JIT support for the Extract/InsertVector128 overloads that take an address.
public static Vector128<double> ExtractVector128(Vector256<double> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(byte* address, Vector256<byte> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(sbyte* address, Vector256<sbyte> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(short* address, Vector256<short> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(ushort* address, Vector256<ushort> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(int* address, Vector256<int> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(uint* address, Vector256<uint> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(long* address, Vector256<long> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(ulong* address, Vector256<ulong> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128 _mm256_extractf128_ps (__m256 a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(float* address, Vector256<float> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128d _mm256_extractf128_pd (__m256d a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(double* address, Vector256<double> value, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
/// __m256 _mm256_floor_ps (__m256 a)
/// VROUNDPS ymm, ymm/m256, imm8(9)
/// </summary>
public static Vector256<double> InsertVector128(Vector256<double> value, Vector128<double> data, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<sbyte> InsertVector128(Vector256<sbyte> value, sbyte* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<byte> InsertVector128(Vector256<byte> value, byte* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<short> InsertVector128(Vector256<short> value, short* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<ushort> InsertVector128(Vector256<ushort> value, ushort* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<int> InsertVector128(Vector256<int> value, int* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<uint> InsertVector128(Vector256<uint> value, uint* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<long> InsertVector128(Vector256<long> value, long* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<ulong> InsertVector128(Vector256<ulong> value, ulong* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256 _mm256_insertf128_ps (__m256 a, __m128 b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<float> InsertVector128(Vector256<float> value, float* address, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256d _mm256_insertf128_pd (__m256d a, __m128d b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<double> InsertVector128(Vector256<double> value, double* address, byte index) { throw new PlatformNotSupportedException(); }
-
- /// <summary>
/// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
/// VMOVDQU ymm, m256
/// </summary>
public static Vector128<double> ExtractVector128(Vector256<double> value, byte index) => ExtractVector128(value, index);
/// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(byte* address, Vector256<byte> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(sbyte* address, Vector256<sbyte> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(short* address, Vector256<short> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(ushort* address, Vector256<ushort> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(int* address, Vector256<int> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(uint* address, Vector256<uint> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(long* address, Vector256<long> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128i _mm256_extractf128_si256 (__m256i a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(ulong* address, Vector256<ulong> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128 _mm256_extractf128_ps (__m256 a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(float* address, Vector256<float> value, byte index) => ExtractVector128(address, value, index);
- /// <summary>
- /// __m128d _mm256_extractf128_pd (__m256d a, const int imm8)
- /// VEXTRACTF128 m128, ymm, imm8
- /// </summary>
- public static unsafe void ExtractVector128(double* address, Vector256<double> value, byte index) => ExtractVector128(address, value, index);
-
- /// <summary>
/// __m256 _mm256_floor_ps (__m256 a)
/// VROUNDPS ymm, ymm/m256, imm8(9)
/// </summary>
public static Vector256<double> InsertVector128(Vector256<double> value, Vector128<double> data, byte index) => InsertVector128(value, data, index);
/// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<sbyte> InsertVector128(Vector256<sbyte> value, sbyte* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<byte> InsertVector128(Vector256<byte> value, byte* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<short> InsertVector128(Vector256<short> value, short* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<ushort> InsertVector128(Vector256<ushort> value, ushort* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<int> InsertVector128(Vector256<int> value, int* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<uint> InsertVector128(Vector256<uint> value, uint* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<long> InsertVector128(Vector256<long> value, long* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256i _mm256_insertf128_si256 (__m256i a, __m128i b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<ulong> InsertVector128(Vector256<ulong> value, ulong* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256 _mm256_insertf128_ps (__m256 a, __m128 b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<float> InsertVector128(Vector256<float> value, float* address, byte index) => InsertVector128(value, address, index);
- /// <summary>
- /// __m256d _mm256_insertf128_pd (__m256d a, __m128d b, int imm8)
- /// VINSERTF128 ymm, ymm, m128, imm8
- /// </summary>
- public static unsafe Vector256<double> InsertVector128(Vector256<double> value, double* address, byte index) => InsertVector128(value, address, index);
-
- /// <summary>
/// __m256i _mm256_loadu_si256 (__m256i const * mem_addr)
/// VMOVDQU ymm, m256
/// </summary>
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<sbyte> ExtractVector128(Vector256<sbyte> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(sbyte* address, Vector256<sbyte> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<byte> ExtractVector128(Vector256<byte> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(byte* address, Vector256<byte> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<short> ExtractVector128(Vector256<short> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(short* address, Vector256<short> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<ushort> ExtractVector128(Vector256<ushort> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(ushort* address, Vector256<ushort> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<int> ExtractVector128(Vector256<int> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(int* address, Vector256<int> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<uint> ExtractVector128(Vector256<uint> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(uint* address, Vector256<uint> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<long> ExtractVector128(Vector256<long> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(long* address, Vector256<long> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<ulong> ExtractVector128(Vector256<ulong> value, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(ulong* address, Vector256<ulong> value, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m128i _mm_i32gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<sbyte> InsertVector128(Vector256<sbyte> value, Vector128<sbyte> data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xm128, imm8
- /// </summary>
- public new static unsafe Vector256<sbyte> InsertVector128(Vector256<sbyte> value, sbyte* address, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<byte> InsertVector128(Vector256<byte> value, Vector128<byte> data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<byte> InsertVector128(Vector256<byte> value, byte* address, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<short> InsertVector128(Vector256<short> value, Vector128<short> data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<short> InsertVector128(Vector256<short> value, short* address, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<ushort> InsertVector128(Vector256<ushort> value, Vector128<ushort> data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<ushort> InsertVector128(Vector256<ushort> value, ushort* address, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<int> InsertVector128(Vector256<int> value, Vector128<int> data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<int> InsertVector128(Vector256<int> value, int* address, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<uint> InsertVector128(Vector256<uint> value, Vector128<uint> data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<uint> InsertVector128(Vector256<uint> value, uint* address, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<long> InsertVector128(Vector256<long> value, Vector128<long> data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<long> InsertVector128(Vector256<long> value, long* address, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<ulong> InsertVector128(Vector256<ulong> value, Vector128<ulong> data, byte index) { throw new PlatformNotSupportedException(); }
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<ulong> InsertVector128(Vector256<ulong> value, ulong* address, byte index) { throw new PlatformNotSupportedException(); }
/// <summary>
/// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(sbyte* address, Vector256<sbyte> value, byte index) => ExtractVector128(address, value, index);
-
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<byte> ExtractVector128(Vector256<byte> value, byte index) => ExtractVector128(value, index);
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(byte* address, Vector256<byte> value, byte index) => ExtractVector128(address, value, index);
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<short> ExtractVector128(Vector256<short> value, byte index) => ExtractVector128(value, index);
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(short* address, Vector256<short> value, byte index) => ExtractVector128(address, value, index);
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<ushort> ExtractVector128(Vector256<ushort> value, byte index) => ExtractVector128(value, index);
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(ushort* address, Vector256<ushort> value, byte index) => ExtractVector128(address, value, index);
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<int> ExtractVector128(Vector256<int> value, byte index) => ExtractVector128(value, index);
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(int* address, Vector256<int> value, byte index) => ExtractVector128(address, value, index);
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<uint> ExtractVector128(Vector256<uint> value, byte index) => ExtractVector128(value, index);
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(uint* address, Vector256<uint> value, byte index) => ExtractVector128(address, value, index);
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<long> ExtractVector128(Vector256<long> value, byte index) => ExtractVector128(value, index);
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(long* address, Vector256<long> value, byte index) => ExtractVector128(address, value, index);
/// <summary>
/// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
/// VEXTRACTI128 xmm, ymm, imm8
/// </summary>
public new static Vector128<ulong> ExtractVector128(Vector256<ulong> value, byte index) => ExtractVector128(value, index);
- /// <summary>
- /// __m128i _mm256_extracti128_si256 (__m256i a, const int imm8)
- /// VEXTRACTI128 m128, ymm, imm8
- /// </summary>
- public new static unsafe void ExtractVector128(ulong* address, Vector256<ulong> value, byte index) => ExtractVector128(address, value, index);
/// <summary>
/// __m128i _mm_i32gather_epi32 (int const* base_addr, __m128i vindex, const int scale)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<sbyte> InsertVector128(Vector256<sbyte> value, Vector128<sbyte> data, byte index) => InsertVector128(value, data, index);
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, xm128, imm8
- /// </summary>
- public new static unsafe Vector256<sbyte> InsertVector128(Vector256<sbyte> value, sbyte* address, byte index) => InsertVector128(value, address, index);
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<byte> InsertVector128(Vector256<byte> value, Vector128<byte> data, byte index) => InsertVector128(value, data, index);
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<byte> InsertVector128(Vector256<byte> value, byte* address, byte index) => InsertVector128(value, address, index);
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<short> InsertVector128(Vector256<short> value, Vector128<short> data, byte index) => InsertVector128(value, data, index);
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<short> InsertVector128(Vector256<short> value, short* address, byte index) => InsertVector128(value, address, index);
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<ushort> InsertVector128(Vector256<ushort> value, Vector128<ushort> data, byte index) => InsertVector128(value, data, index);
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<ushort> InsertVector128(Vector256<ushort> value, ushort* address, byte index) => InsertVector128(value, address, index);
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<int> InsertVector128(Vector256<int> value, Vector128<int> data, byte index) => InsertVector128(value, data, index);
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<int> InsertVector128(Vector256<int> value, int* address, byte index) => InsertVector128(value, address, index);
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<uint> InsertVector128(Vector256<uint> value, Vector128<uint> data, byte index) => InsertVector128(value, data, index);
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<uint> InsertVector128(Vector256<uint> value, uint* address, byte index) => InsertVector128(value, address, index);
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<long> InsertVector128(Vector256<long> value, Vector128<long> data, byte index) => InsertVector128(value, data, index);
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<long> InsertVector128(Vector256<long> value, long* address, byte index) => InsertVector128(value, address, index);
/// <summary>
/// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
/// VINSERTI128 ymm, ymm, xmm, imm8
/// </summary>
public new static Vector256<ulong> InsertVector128(Vector256<ulong> value, Vector128<ulong> data, byte index) => InsertVector128(value, data, index);
- /// <summary>
- /// __m256i _mm256_inserti128_si256 (__m256i a, __m128i b, const int imm8)
- /// VINSERTI128 ymm, ymm, m128, imm8
- /// </summary>
- public new static unsafe Vector256<ulong> InsertVector128(Vector256<ulong> value, ulong* address, byte index) => InsertVector128(value, address, index);
/// <summary>
/// __m256i _mm256_stream_load_si256 (__m256i const* mem_addr)
}
else if (HWIntrinsicInfo::MaybeMemoryLoad(gtHWIntrinsicId))
{
- // Some AVX intrinsic (without HW_Category_MemoryLoad) also have MemoryLoad semantics
+ // Some intrinsics (without HW_Category_MemoryLoad) also have MemoryLoad semantics
+
if (category == HW_Category_SIMDScalar)
{
// Avx2.BroadcastScalarToVector128/256 have vector and pointer overloads both, e.g.,
{
return false;
}
- else // We have 3 or more operands/args
+ else if (HWIntrinsicInfo::isAVX2GatherIntrinsic(gtHWIntrinsicId))
{
- // All the Avx2.Gather* are "load" instructions
- if (HWIntrinsicInfo::isAVX2GatherIntrinsic(gtHWIntrinsicId))
- {
- return true;
- }
-
- GenTreeArgList* argList = gtOp.gtOp1->AsArgList();
-
- // Avx/Avx2.InsertVector128 have vector and pointer overloads both, e.g.,
- // Vector256<sbyte> InsertVector128(Vector256<sbyte> value, Vector128<sbyte> data, byte index)
- // Vector256<sbyte> InsertVector128(Vector256<sbyte> value, sbyte* address, byte index)
- // So, we need to check the second argument's type is memory-reference (TYP_I_IMPL) or not
- if ((gtHWIntrinsicId == NI_AVX_InsertVector128 || gtHWIntrinsicId == NI_AVX2_InsertVector128) &&
- (argList->Rest()->Current()->TypeGet() == TYP_I_IMPL)) // Is the type of the second arg TYP_I_IMPL?
- {
- // This is Avx/Avx2.InsertVector128
- return true;
- }
+ return true;
}
}
}
else if (HWIntrinsicInfo::MaybeMemoryStore(gtHWIntrinsicId) &&
(category == HW_Category_IMM || category == HW_Category_Scalar))
{
- // Some AVX intrinsic (without HW_Category_MemoryStore) also have MemoryStore semantics
+ // Some intrinsics (without HW_Category_MemoryStore) also have MemoryStore semantics
- // Avx/Avx2.InsertVector128 have vector and pointer overloads both, e.g.,
- // Vector128<sbyte> ExtractVector128(Vector256<sbyte> value, byte index)
- // void ExtractVector128(sbyte* address, Vector256<sbyte> value, byte index)
// Bmi2/Bmi2.X64.MultiplyNoFlags may return the lower half result by a out argument
// unsafe ulong MultiplyNoFlags(ulong left, ulong right, ulong* low)
//
{
switch (gtHWIntrinsicId)
{
- case NI_AVX_ExtractVector128:
- case NI_AVX2_ExtractVector128:
case NI_BMI2_MultiplyNoFlags:
case NI_BMI2_X64_MultiplyNoFlags:
return true;
break;
}
- case NI_AVX_ExtractVector128:
- case NI_AVX_InsertVector128:
- case NI_AVX2_ExtractVector128:
- case NI_AVX2_InsertVector128:
- {
- GenTree* lastOp = nullptr;
- if (numArgs == 2)
- {
- assert(intrinsicId == NI_AVX_ExtractVector128 || NI_AVX_ExtractVector128);
- op2Reg = op2->gtRegNum;
- lastOp = op2;
- }
- else
- {
- assert(numArgs == 3);
- assert(op1->OperIsList());
- assert(op1->gtGetOp2()->OperIsList());
- assert(op1->gtGetOp2()->gtGetOp2()->OperIsList());
-
- GenTreeArgList* argList = op1->AsArgList();
- op1 = argList->Current();
- genConsumeRegs(op1);
- op1Reg = op1->gtRegNum;
-
- argList = argList->Rest();
- op2 = argList->Current();
- genConsumeRegs(op2);
- op2Reg = op2->gtRegNum;
-
- argList = argList->Rest();
- lastOp = argList->Current();
- genConsumeRegs(lastOp);
- }
-
- regNumber op3Reg = lastOp->gtRegNum;
-
- auto emitSwCase = [&](int8_t i) {
- if (numArgs == 3)
- {
- if (intrinsicId == NI_AVX_ExtractVector128 || intrinsicId == NI_AVX2_ExtractVector128)
- {
- emit->emitIns_AR_R_I(ins, attr, op1Reg, 0, op2Reg, i);
- }
- else if (op2->TypeGet() == TYP_I_IMPL)
- {
- emit->emitIns_SIMD_R_R_AR_I(ins, attr, targetReg, op1Reg, op2Reg, i);
- }
- else
- {
- assert(op2->TypeGet() == TYP_SIMD16);
- emit->emitIns_SIMD_R_R_R_I(ins, attr, targetReg, op1Reg, op2Reg, i);
- }
- }
- else
- {
- assert(numArgs == 2);
- assert(intrinsicId == NI_AVX_ExtractVector128 || intrinsicId == NI_AVX2_ExtractVector128);
- emit->emitIns_SIMD_R_R_I(ins, attr, targetReg, op1Reg, i);
- }
- };
-
- if (lastOp->IsCnsIntOrI())
- {
- ssize_t ival = lastOp->AsIntCon()->IconValue();
- assert((ival >= 0) && (ival <= 255));
- emitSwCase((int8_t)ival);
- }
- else
- {
- // We emit a fallback case for the scenario when the imm-op is not a constant. This should
- // normally happen when the intrinsic is called indirectly, such as via Reflection. However, it
- // can also occur if the consumer calls it directly and just doesn't pass a constant value.
- regNumber baseReg = node->ExtractTempReg();
- regNumber offsReg = node->GetSingleTempReg();
- genHWIntrinsicJumpTableFallback(intrinsicId, op3Reg, baseReg, offsReg, emitSwCase);
- }
- break;
- }
-
default:
unreached();
break;
HARDWARE_INTRINSIC(AVX_DotProduct, "DotProduct", AVX, -1, 32, 3, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_dpps, INS_invalid}, HW_Category_IMM, HW_Flag_FullRangeIMM)
HARDWARE_INTRINSIC(AVX_DuplicateEvenIndexed, "DuplicateEvenIndexed", AVX, -1, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_movsldup, INS_movddup}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
HARDWARE_INTRINSIC(AVX_DuplicateOddIndexed, "DuplicateOddIndexed", AVX, -1, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_movshdup, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
-HARDWARE_INTRINSIC(AVX_ExtractVector128, "ExtractVector128", AVX, -1, 32, -1, {INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128}, HW_Category_IMM, HW_Flag_MaybeMemoryStore|HW_Flag_SpecialImport|HW_Flag_SpecialCodeGen|HW_Flag_FullRangeIMM)
+HARDWARE_INTRINSIC(AVX_ExtractVector128, "ExtractVector128", AVX, -1, 32, 2, {INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128, INS_vextractf128}, HW_Category_IMM, HW_Flag_FullRangeIMM)
HARDWARE_INTRINSIC(AVX_Floor, "Floor", AVX, 9, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_roundps, INS_roundpd}, HW_Category_SimpleSIMD, HW_Flag_NoRMWSemantics)
HARDWARE_INTRINSIC(AVX_HorizontalAdd, "HorizontalAdd", AVX, -1, 32, 2, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_haddps, INS_haddpd}, HW_Category_SimpleSIMD, HW_Flag_NoFlag)
HARDWARE_INTRINSIC(AVX_HorizontalSubtract, "HorizontalSubtract", AVX, -1, 32, 2, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_hsubps, INS_hsubpd}, HW_Category_SimpleSIMD, HW_Flag_NoFlag)
-HARDWARE_INTRINSIC(AVX_InsertVector128, "InsertVector128", AVX, -1, 32, 3, {INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128}, HW_Category_IMM, HW_Flag_MaybeMemoryLoad|HW_Flag_FullRangeIMM|HW_Flag_SpecialCodeGen)
+HARDWARE_INTRINSIC(AVX_InsertVector128, "InsertVector128", AVX, -1, 32, 3, {INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128, INS_vinsertf128}, HW_Category_IMM, HW_Flag_FullRangeIMM)
HARDWARE_INTRINSIC(AVX_LoadAlignedVector256, "LoadAlignedVector256", AVX, -1, 32, 1, {INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movdqa, INS_movaps, INS_movapd}, HW_Category_MemoryLoad, HW_Flag_NoContainment|HW_Flag_NoRMWSemantics)
HARDWARE_INTRINSIC(AVX_LoadDquVector256, "LoadDquVector256", AVX, -1, 32, 1, {INS_lddqu, INS_lddqu, INS_lddqu, INS_lddqu, INS_lddqu, INS_lddqu, INS_lddqu, INS_lddqu, INS_invalid, INS_invalid}, HW_Category_MemoryLoad, HW_Flag_NoContainment|HW_Flag_NoRMWSemantics)
HARDWARE_INTRINSIC(AVX_LoadVector256, "LoadVector256", AVX, -1, 32, 1, {INS_movdqu, INS_movdqu, INS_movdqu, INS_movdqu, INS_movdqu, INS_movdqu, INS_movdqu, INS_movdqu, INS_movups, INS_movupd}, HW_Category_MemoryLoad, HW_Flag_NoContainment|HW_Flag_NoRMWSemantics)
HARDWARE_INTRINSIC(AVX2_BroadcastVector128ToVector256, "BroadcastVector128ToVector256", AVX2, -1, 32, 1, {INS_vbroadcasti128, INS_vbroadcasti128, INS_vbroadcasti128, INS_vbroadcasti128, INS_vbroadcasti128, INS_vbroadcasti128, INS_vbroadcasti128, INS_vbroadcasti128, INS_invalid, INS_invalid}, HW_Category_MemoryLoad, HW_Flag_NoContainment)
HARDWARE_INTRINSIC(AVX2_CompareEqual, "CompareEqual", AVX2, -1, 32, 2, {INS_pcmpeqb, INS_pcmpeqb, INS_pcmpeqw, INS_pcmpeqw, INS_pcmpeqd, INS_pcmpeqd, INS_pcmpeqq, INS_pcmpeqq, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_Commutative)
HARDWARE_INTRINSIC(AVX2_CompareGreaterThan, "CompareGreaterThan", AVX2, -1, 32, 2, {INS_pcmpgtb, INS_invalid, INS_pcmpgtw, INS_invalid, INS_pcmpgtd, INS_invalid, INS_pcmpgtq, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_NoFlag)
-HARDWARE_INTRINSIC(AVX2_ExtractVector128, "ExtractVector128", AVX2, -1, 32, -1, {INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_invalid, INS_invalid}, HW_Category_IMM, HW_Flag_MaybeMemoryStore|HW_Flag_SpecialImport|HW_Flag_SpecialCodeGen|HW_Flag_FullRangeIMM)
+HARDWARE_INTRINSIC(AVX2_ExtractVector128, "ExtractVector128", AVX2, -1, 32, 2, {INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_vextracti128, INS_invalid, INS_invalid}, HW_Category_IMM, HW_Flag_FullRangeIMM)
HARDWARE_INTRINSIC(AVX2_ConvertToInt32, "ConvertToInt32", AVX2, -1, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_mov_xmm2i, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SIMDScalar, HW_Flag_BaseTypeFromFirstArg|HW_Flag_SpecialCodeGen|HW_Flag_NoRMWSemantics)
HARDWARE_INTRINSIC(AVX2_ConvertToUInt32, "ConvertToUInt32", AVX2, -1, 32, 1, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_mov_xmm2i, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SIMDScalar, HW_Flag_BaseTypeFromFirstArg|HW_Flag_SpecialCodeGen|HW_Flag_NoRMWSemantics)
HARDWARE_INTRINSIC(AVX2_ConvertToVector256Int16, "ConvertToVector256Int16", AVX2, -1, 32, 1, {INS_pmovsxbw, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_BaseTypeFromFirstArg)
HARDWARE_INTRINSIC(AVX2_ConvertToVector256UInt32, "ConvertToVector256UInt32", AVX2, -1, 32, 1, {INS_invalid, INS_pmovzxbd, INS_invalid, INS_pmovzxwd, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_BaseTypeFromFirstArg)
HARDWARE_INTRINSIC(AVX2_ConvertToVector256Int64, "ConvertToVector256Int64", AVX2, -1, 32, 1, {INS_pmovsxbq, INS_invalid, INS_pmovsxwq, INS_invalid, INS_pmovsxdq, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_BaseTypeFromFirstArg)
HARDWARE_INTRINSIC(AVX2_ConvertToVector256UInt64, "ConvertToVector256UInt64", AVX2, -1, 32, 1, {INS_invalid, INS_pmovzxbq, INS_invalid, INS_pmovzxwq, INS_invalid, INS_pmovzxdq, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_BaseTypeFromFirstArg)
-HARDWARE_INTRINSIC(AVX2_GatherVector128, "GatherVector128", AVX2, -1, 16, 3, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_vpgatherdd, INS_vpgatherdd, INS_vpgatherdq, INS_vpgatherdq, INS_vgatherdps, INS_vgatherdpd}, HW_Category_IMM, HW_Flag_MaybeMemoryLoad|HW_Flag_SpecialCodeGen|HW_Flag_NoContainment)
+HARDWARE_INTRINSIC(AVX2_GatherVector128, "GatherVector128", AVX2, -1, 16, 3, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_vpgatherdd, INS_vpgatherdd, INS_vpgatherdq, INS_vpgatherdq, INS_vgatherdps, INS_vgatherdpd}, HW_Category_IMM, HW_Flag_SpecialCodeGen|HW_Flag_NoContainment)
HARDWARE_INTRINSIC(AVX2_GatherVector256, "GatherVector256", AVX2, -1, 32, 3, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_vpgatherdd, INS_vpgatherdd, INS_vpgatherdq, INS_vpgatherdq, INS_vgatherdps, INS_vgatherdpd}, HW_Category_IMM, HW_Flag_MaybeMemoryLoad|HW_Flag_SpecialCodeGen|HW_Flag_NoContainment)
HARDWARE_INTRINSIC(AVX2_GatherMaskVector128, "GatherMaskVector128", AVX2, -1, 16, 5, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_vpgatherdd, INS_vpgatherdd, INS_vpgatherdq, INS_vpgatherdq, INS_vgatherdps, INS_vgatherdpd}, HW_Category_IMM, HW_Flag_MaybeMemoryLoad|HW_Flag_SpecialCodeGen|HW_Flag_SpecialImport|HW_Flag_NoContainment)
HARDWARE_INTRINSIC(AVX2_GatherMaskVector256, "GatherMaskVector256", AVX2, -1, 32, 5, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_vpgatherdd, INS_vpgatherdd, INS_vpgatherdq, INS_vpgatherdq, INS_vgatherdps, INS_vgatherdpd}, HW_Category_IMM, HW_Flag_MaybeMemoryLoad|HW_Flag_SpecialCodeGen|HW_Flag_SpecialImport|HW_Flag_NoContainment)
HARDWARE_INTRINSIC(AVX2_HorizontalAddSaturate, "HorizontalAddSaturate", AVX2, -1, 32, 2, {INS_invalid, INS_invalid, INS_phaddsw, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_NoFlag)
HARDWARE_INTRINSIC(AVX2_HorizontalSubtract, "HorizontalSubtract", AVX2, -1, 32, 2, {INS_invalid, INS_invalid, INS_phsubw, INS_invalid, INS_phsubd, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_NoFlag)
HARDWARE_INTRINSIC(AVX2_HorizontalSubtractSaturate, "HorizontalSubtractSaturate", AVX2, -1, 32, 2, {INS_invalid, INS_invalid, INS_phsubsw, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_invalid}, HW_Category_SimpleSIMD, HW_Flag_NoFlag)
-HARDWARE_INTRINSIC(AVX2_InsertVector128, "InsertVector128", AVX2, -1, 32, 3, {INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_invalid, INS_invalid}, HW_Category_IMM, HW_Flag_MaybeMemoryLoad|HW_Flag_FullRangeIMM|HW_Flag_SpecialCodeGen)
+HARDWARE_INTRINSIC(AVX2_InsertVector128, "InsertVector128", AVX2, -1, 32, 3, {INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_vinserti128, INS_invalid, INS_invalid}, HW_Category_IMM, HW_Flag_FullRangeIMM)
HARDWARE_INTRINSIC(AVX2_LoadAlignedVector256NonTemporal, "LoadAlignedVector256NonTemporal", AVX2, -1, 32, 1, {INS_movntdqa, INS_movntdqa, INS_movntdqa, INS_movntdqa, INS_movntdqa, INS_movntdqa, INS_movntdqa, INS_movntdqa, INS_invalid, INS_invalid}, HW_Category_MemoryLoad, HW_Flag_NoContainment)
HARDWARE_INTRINSIC(AVX2_MaskLoad, "MaskLoad", AVX2, -1, 0, 2, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_vpmaskmovd, INS_vpmaskmovd, INS_vpmaskmovq, INS_vpmaskmovq, INS_invalid, INS_invalid}, HW_Category_MemoryLoad, HW_Flag_NoContainment|HW_Flag_UnfixedSIMDSize)
HARDWARE_INTRINSIC(AVX2_MaskStore, "MaskStore", AVX2, -1, 0, 3, {INS_invalid, INS_invalid, INS_invalid, INS_invalid, INS_vpmaskmovd, INS_vpmaskmovd, INS_vpmaskmovq, INS_vpmaskmovq, INS_invalid, INS_invalid}, HW_Category_MemoryStore, HW_Flag_NoContainment|HW_Flag_UnfixedSIMDSize|HW_Flag_BaseTypeFromSecondArg)
switch (intrinsic)
{
- case NI_AVX_ExtractVector128:
- case NI_AVX2_ExtractVector128:
- {
- GenTree* lastOp = impPopStack().val;
- assert(lastOp->IsCnsIntOrI() || mustExpand);
- GenTree* vectorOp = impSIMDPopStack(TYP_SIMD32);
- if (sig->numArgs == 2)
- {
- baseType = getBaseTypeOfSIMDType(sig->retTypeSigClass);
- retNode = gtNewSimdHWIntrinsicNode(TYP_SIMD16, vectorOp, lastOp, intrinsic, baseType, 32);
- }
- else
- {
- assert(sig->numArgs == 3);
- op1 = impPopStack().val;
- CORINFO_ARG_LIST_HANDLE secondArg = info.compCompHnd->getArgNext(sig->args);
- CORINFO_CLASS_HANDLE secondArgClass = info.compCompHnd->getArgClass(sig, secondArg);
- baseType = getBaseTypeOfSIMDType(secondArgClass);
- retNode = gtNewSimdHWIntrinsicNode(TYP_VOID, op1, vectorOp, lastOp, intrinsic, baseType, 32);
- }
- break;
- }
-
case NI_AVX2_PermuteVar8x32:
{
baseType = getBaseTypeOfSIMDType(sig->retTypeSigClass);
<Compile Include="ExtractVector128.UInt64.1.cs" />
<Compile Include="ExtractVector128.Single.1.cs" />
<Compile Include="ExtractVector128.Double.1.cs" />
- <Compile Include="ExtractVector128.Byte.1.Store.cs" />
- <Compile Include="ExtractVector128.SByte.1.Store.cs" />
- <Compile Include="ExtractVector128.Int16.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt16.1.Store.cs" />
- <Compile Include="ExtractVector128.Int32.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt32.1.Store.cs" />
- <Compile Include="ExtractVector128.Int64.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt64.1.Store.cs" />
- <Compile Include="ExtractVector128.Single.1.Store.cs" />
- <Compile Include="ExtractVector128.Double.1.Store.cs" />
<Compile Include="InsertVector128.Byte.1.cs" />
<Compile Include="InsertVector128.SByte.1.cs" />
<Compile Include="InsertVector128.Int16.1.cs" />
<Compile Include="InsertVector128.UInt64.1.cs" />
<Compile Include="InsertVector128.Single.1.cs" />
<Compile Include="InsertVector128.Double.1.cs" />
- <Compile Include="InsertVector128.Byte.1.Load.cs" />
- <Compile Include="InsertVector128.SByte.1.Load.cs" />
- <Compile Include="InsertVector128.Int16.1.Load.cs" />
- <Compile Include="InsertVector128.UInt16.1.Load.cs" />
- <Compile Include="InsertVector128.Int32.1.Load.cs" />
- <Compile Include="InsertVector128.UInt32.1.Load.cs" />
- <Compile Include="InsertVector128.Int64.1.Load.cs" />
- <Compile Include="InsertVector128.UInt64.1.Load.cs" />
- <Compile Include="InsertVector128.Single.1.Load.cs" />
- <Compile Include="InsertVector128.Double.1.Load.cs" />
<Compile Include="Floor.Double.cs" />
<Compile Include="Floor.Single.cs" />
<Compile Include="LoadVector256.Byte.cs" />
<Compile Include="ExtractVector128.UInt64.1.cs" />
<Compile Include="ExtractVector128.Single.1.cs" />
<Compile Include="ExtractVector128.Double.1.cs" />
- <Compile Include="ExtractVector128.Byte.1.Store.cs" />
- <Compile Include="ExtractVector128.SByte.1.Store.cs" />
- <Compile Include="ExtractVector128.Int16.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt16.1.Store.cs" />
- <Compile Include="ExtractVector128.Int32.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt32.1.Store.cs" />
- <Compile Include="ExtractVector128.Int64.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt64.1.Store.cs" />
- <Compile Include="ExtractVector128.Single.1.Store.cs" />
- <Compile Include="ExtractVector128.Double.1.Store.cs" />
<Compile Include="InsertVector128.Byte.1.cs" />
<Compile Include="InsertVector128.SByte.1.cs" />
<Compile Include="InsertVector128.Int16.1.cs" />
<Compile Include="InsertVector128.UInt64.1.cs" />
<Compile Include="InsertVector128.Single.1.cs" />
<Compile Include="InsertVector128.Double.1.cs" />
- <Compile Include="InsertVector128.Byte.1.Load.cs" />
- <Compile Include="InsertVector128.SByte.1.Load.cs" />
- <Compile Include="InsertVector128.Int16.1.Load.cs" />
- <Compile Include="InsertVector128.UInt16.1.Load.cs" />
- <Compile Include="InsertVector128.Int32.1.Load.cs" />
- <Compile Include="InsertVector128.UInt32.1.Load.cs" />
- <Compile Include="InsertVector128.Int64.1.Load.cs" />
- <Compile Include="InsertVector128.UInt64.1.Load.cs" />
- <Compile Include="InsertVector128.Single.1.Load.cs" />
- <Compile Include="InsertVector128.Double.1.Load.cs" />
<Compile Include="Floor.Double.cs" />
<Compile Include="Floor.Single.cs" />
<Compile Include="LoadVector256.Byte.cs" />
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Byte1Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Byte1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Byte1
- {
- private struct TestStruct
- {
- public Vector256<Byte> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref testStruct._fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Byte1 testClass)
- {
- Avx.ExtractVector128((Byte*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Byte>>() / sizeof(Byte);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Byte>>() / sizeof(Byte);
-
- private static Byte[] _data = new Byte[Op1ElementCount];
-
- private static Vector256<Byte> _clsVar;
-
- private Vector256<Byte> _fld;
-
- private SimpleUnaryOpTest__DataTable<Byte, Byte> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Byte1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref _clsVar), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- }
-
- public ExtractStoreTest__ExtractVector128Byte1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref _fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Byte, Byte>(_data, new Byte[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (Byte*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Byte>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (Byte*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Byte*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (Byte*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Byte*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Byte*), typeof(Vector256<Byte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Byte*)),
- Unsafe.Read<Vector256<Byte>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Byte*), typeof(Vector256<Byte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Byte*)),
- Avx.LoadVector256((Byte*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Byte*), typeof(Vector256<Byte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Byte*)),
- Avx.LoadAlignedVector256((Byte*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (Byte*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Byte>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((Byte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Byte*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Byte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Byte*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Byte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Byte1();
- Avx.ExtractVector128((Byte*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((Byte*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((Byte*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Byte> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray = new Byte[Op1ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray = new Byte[Op1ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Byte[] firstOp, Byte[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[16])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 16]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<Byte>(Vector256<Byte><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Double1Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Double1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Double1
- {
- private struct TestStruct
- {
- public Vector256<Double> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref testStruct._fld), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Double1 testClass)
- {
- Avx.ExtractVector128((Double*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Double>>() / sizeof(Double);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double);
-
- private static Double[] _data = new Double[Op1ElementCount];
-
- private static Vector256<Double> _clsVar;
-
- private Vector256<Double> _fld;
-
- private SimpleUnaryOpTest__DataTable<Double, Double> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Double1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _clsVar), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
- }
-
- public ExtractStoreTest__ExtractVector128Double1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _fld), ref Unsafe.As<Double, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetDouble(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Double, Double>(_data, new Double[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (Double*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Double>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (Double*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Double*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (Double*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Double*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Double*), typeof(Vector256<Double>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Double*)),
- Unsafe.Read<Vector256<Double>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Double*), typeof(Vector256<Double>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Double*)),
- Avx.LoadVector256((Double*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Double*), typeof(Vector256<Double>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Double*)),
- Avx.LoadAlignedVector256((Double*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (Double*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Double>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((Double*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Double*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Double*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Double*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Double*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Double1();
- Avx.ExtractVector128((Double*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((Double*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((Double*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Double> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Double[] inArray = new Double[Op1ElementCount];
- Double[] outArray = new Double[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Double>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Double[] inArray = new Double[Op1ElementCount];
- Double[] outArray = new Double[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Double>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Double>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Double[] firstOp, Double[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(firstOp[2]))
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(firstOp[i + 2])))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<Double>(Vector256<Double><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Int161Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Int161();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Int161
- {
- private struct TestStruct
- {
- public Vector256<Int16> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref testStruct._fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Int161 testClass)
- {
- Avx.ExtractVector128((Int16*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int16>>() / sizeof(Int16);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16);
-
- private static Int16[] _data = new Int16[Op1ElementCount];
-
- private static Vector256<Int16> _clsVar;
-
- private Vector256<Int16> _fld;
-
- private SimpleUnaryOpTest__DataTable<Int16, Int16> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Int161()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref _clsVar), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- }
-
- public ExtractStoreTest__ExtractVector128Int161()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref _fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Int16, Int16>(_data, new Int16[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (Int16*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Int16>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (Int16*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Int16*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (Int16*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Int16*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int16*), typeof(Vector256<Int16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int16*)),
- Unsafe.Read<Vector256<Int16>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int16*), typeof(Vector256<Int16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int16*)),
- Avx.LoadVector256((Int16*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int16*), typeof(Vector256<Int16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int16*)),
- Avx.LoadAlignedVector256((Int16*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (Int16*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Int16>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((Int16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Int16*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Int16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Int16*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Int16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Int161();
- Avx.ExtractVector128((Int16*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((Int16*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((Int16*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int16> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray = new Int16[Op1ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray = new Int16[Op1ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[8])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 8]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<Int16>(Vector256<Int16><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Int321Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Int321();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Int321
- {
- private struct TestStruct
- {
- public Vector256<Int32> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref testStruct._fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Int321 testClass)
- {
- Avx.ExtractVector128((Int32*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int32>>() / sizeof(Int32);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32);
-
- private static Int32[] _data = new Int32[Op1ElementCount];
-
- private static Vector256<Int32> _clsVar;
-
- private Vector256<Int32> _fld;
-
- private SimpleUnaryOpTest__DataTable<Int32, Int32> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Int321()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref _clsVar), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- }
-
- public ExtractStoreTest__ExtractVector128Int321()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref _fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Int32, Int32>(_data, new Int32[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (Int32*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Int32>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (Int32*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Int32*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (Int32*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Int32*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int32*), typeof(Vector256<Int32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int32*)),
- Unsafe.Read<Vector256<Int32>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int32*), typeof(Vector256<Int32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int32*)),
- Avx.LoadVector256((Int32*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int32*), typeof(Vector256<Int32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int32*)),
- Avx.LoadAlignedVector256((Int32*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (Int32*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Int32>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((Int32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Int32*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Int32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Int32*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Int32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Int321();
- Avx.ExtractVector128((Int32*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((Int32*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((Int32*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int32> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray = new Int32[Op1ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray = new Int32[Op1ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Int32[] firstOp, Int32[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[4])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 4]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<Int32>(Vector256<Int32><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Int641Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Int641();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Int641
- {
- private struct TestStruct
- {
- public Vector256<Int64> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref testStruct._fld), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Int641 testClass)
- {
- Avx.ExtractVector128((Int64*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int64>>() / sizeof(Int64);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int64>>() / sizeof(Int64);
-
- private static Int64[] _data = new Int64[Op1ElementCount];
-
- private static Vector256<Int64> _clsVar;
-
- private Vector256<Int64> _fld;
-
- private SimpleUnaryOpTest__DataTable<Int64, Int64> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Int641()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref _clsVar), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- }
-
- public ExtractStoreTest__ExtractVector128Int641()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref _fld), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Int64, Int64>(_data, new Int64[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (Int64*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Int64>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (Int64*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Int64*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (Int64*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Int64*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int64*), typeof(Vector256<Int64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int64*)),
- Unsafe.Read<Vector256<Int64>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int64*), typeof(Vector256<Int64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int64*)),
- Avx.LoadVector256((Int64*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Int64*), typeof(Vector256<Int64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int64*)),
- Avx.LoadAlignedVector256((Int64*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (Int64*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Int64>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((Int64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Int64*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Int64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Int64*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Int64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Int641();
- Avx.ExtractVector128((Int64*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((Int64*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((Int64*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int64> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray = new Int64[Op1ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray = new Int64[Op1ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Int64[] firstOp, Int64[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[2])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 2]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<Int64>(Vector256<Int64><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128SByte1Store()
- {
- var test = new ExtractStoreTest__ExtractVector128SByte1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128SByte1
- {
- private struct TestStruct
- {
- public Vector256<SByte> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref testStruct._fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128SByte1 testClass)
- {
- Avx.ExtractVector128((SByte*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<SByte>>() / sizeof(SByte);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<SByte>>() / sizeof(SByte);
-
- private static SByte[] _data = new SByte[Op1ElementCount];
-
- private static Vector256<SByte> _clsVar;
-
- private Vector256<SByte> _fld;
-
- private SimpleUnaryOpTest__DataTable<SByte, SByte> _dataTable;
-
- static ExtractStoreTest__ExtractVector128SByte1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref _clsVar), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- }
-
- public ExtractStoreTest__ExtractVector128SByte1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref _fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<SByte, SByte>(_data, new SByte[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (SByte*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<SByte>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (SByte*)_dataTable.outArrayPtr,
- Avx.LoadVector256((SByte*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (SByte*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((SByte*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(SByte*), typeof(Vector256<SByte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(SByte*)),
- Unsafe.Read<Vector256<SByte>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(SByte*), typeof(Vector256<SByte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(SByte*)),
- Avx.LoadVector256((SByte*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(SByte*), typeof(Vector256<SByte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(SByte*)),
- Avx.LoadAlignedVector256((SByte*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (SByte*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<SByte>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((SByte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((SByte*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((SByte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((SByte*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((SByte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128SByte1();
- Avx.ExtractVector128((SByte*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((SByte*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((SByte*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<SByte> firstOp, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray = new SByte[Op1ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray = new SByte[Op1ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(SByte[] firstOp, SByte[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[16])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 16]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<SByte>(Vector256<SByte><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Single1Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Single1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Single1
- {
- private struct TestStruct
- {
- public Vector256<Single> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref testStruct._fld), ref Unsafe.As<Single, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Single1 testClass)
- {
- Avx.ExtractVector128((Single*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Single>>() / sizeof(Single);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Single>>() / sizeof(Single);
-
- private static Single[] _data = new Single[Op1ElementCount];
-
- private static Vector256<Single> _clsVar;
-
- private Vector256<Single> _fld;
-
- private SimpleUnaryOpTest__DataTable<Single, Single> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Single1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _clsVar), ref Unsafe.As<Single, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
- }
-
- public ExtractStoreTest__ExtractVector128Single1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _fld), ref Unsafe.As<Single, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSingle(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Single, Single>(_data, new Single[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (Single*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Single>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (Single*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Single*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (Single*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Single*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Single*), typeof(Vector256<Single>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Single*)),
- Unsafe.Read<Vector256<Single>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Single*), typeof(Vector256<Single>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Single*)),
- Avx.LoadVector256((Single*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(Single*), typeof(Vector256<Single>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Single*)),
- Avx.LoadAlignedVector256((Single*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (Single*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Single>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((Single*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Single*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Single*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Single*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((Single*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Single1();
- Avx.ExtractVector128((Single*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((Single*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((Single*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Single> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Single[] inArray = new Single[Op1ElementCount];
- Single[] outArray = new Single[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Single, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Single>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Single[] inArray = new Single[Op1ElementCount];
- Single[] outArray = new Single[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Single>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Single>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Single[] firstOp, Single[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(firstOp[4]))
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(firstOp[i + 4])))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<Single>(Vector256<Single><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128UInt161Store()
- {
- var test = new ExtractStoreTest__ExtractVector128UInt161();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128UInt161
- {
- private struct TestStruct
- {
- public Vector256<UInt16> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref testStruct._fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128UInt161 testClass)
- {
- Avx.ExtractVector128((UInt16*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt16>>() / sizeof(UInt16);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16);
-
- private static UInt16[] _data = new UInt16[Op1ElementCount];
-
- private static Vector256<UInt16> _clsVar;
-
- private Vector256<UInt16> _fld;
-
- private SimpleUnaryOpTest__DataTable<UInt16, UInt16> _dataTable;
-
- static ExtractStoreTest__ExtractVector128UInt161()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref _clsVar), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- }
-
- public ExtractStoreTest__ExtractVector128UInt161()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref _fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<UInt16, UInt16>(_data, new UInt16[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (UInt16*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<UInt16>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (UInt16*)_dataTable.outArrayPtr,
- Avx.LoadVector256((UInt16*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (UInt16*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt16*), typeof(Vector256<UInt16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt16*)),
- Unsafe.Read<Vector256<UInt16>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt16*), typeof(Vector256<UInt16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt16*)),
- Avx.LoadVector256((UInt16*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt16*), typeof(Vector256<UInt16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt16*)),
- Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (UInt16*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<UInt16>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((UInt16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((UInt16*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((UInt16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((UInt16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128UInt161();
- Avx.ExtractVector128((UInt16*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((UInt16*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((UInt16*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt16> firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray = new UInt16[Op1ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray = new UInt16[Op1ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[8])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 8]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<UInt16>(Vector256<UInt16><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128UInt321Store()
- {
- var test = new ExtractStoreTest__ExtractVector128UInt321();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128UInt321
- {
- private struct TestStruct
- {
- public Vector256<UInt32> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref testStruct._fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128UInt321 testClass)
- {
- Avx.ExtractVector128((UInt32*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt32>>() / sizeof(UInt32);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32);
-
- private static UInt32[] _data = new UInt32[Op1ElementCount];
-
- private static Vector256<UInt32> _clsVar;
-
- private Vector256<UInt32> _fld;
-
- private SimpleUnaryOpTest__DataTable<UInt32, UInt32> _dataTable;
-
- static ExtractStoreTest__ExtractVector128UInt321()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref _clsVar), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- }
-
- public ExtractStoreTest__ExtractVector128UInt321()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref _fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<UInt32, UInt32>(_data, new UInt32[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (UInt32*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<UInt32>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (UInt32*)_dataTable.outArrayPtr,
- Avx.LoadVector256((UInt32*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (UInt32*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt32*), typeof(Vector256<UInt32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt32*)),
- Unsafe.Read<Vector256<UInt32>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt32*), typeof(Vector256<UInt32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt32*)),
- Avx.LoadVector256((UInt32*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt32*), typeof(Vector256<UInt32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt32*)),
- Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (UInt32*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<UInt32>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((UInt32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((UInt32*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((UInt32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((UInt32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128UInt321();
- Avx.ExtractVector128((UInt32*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((UInt32*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((UInt32*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt32> firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray = new UInt32[Op1ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray = new UInt32[Op1ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(UInt32[] firstOp, UInt32[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[4])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 4]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<UInt32>(Vector256<UInt32><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128UInt641Store()
- {
- var test = new ExtractStoreTest__ExtractVector128UInt641();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128UInt641
- {
- private struct TestStruct
- {
- public Vector256<UInt64> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref testStruct._fld), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128UInt641 testClass)
- {
- Avx.ExtractVector128((UInt64*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt64>>() / sizeof(UInt64);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt64>>() / sizeof(UInt64);
-
- private static UInt64[] _data = new UInt64[Op1ElementCount];
-
- private static Vector256<UInt64> _clsVar;
-
- private Vector256<UInt64> _fld;
-
- private SimpleUnaryOpTest__DataTable<UInt64, UInt64> _dataTable;
-
- static ExtractStoreTest__ExtractVector128UInt641()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _clsVar), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- }
-
- public ExtractStoreTest__ExtractVector128UInt641()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _fld), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<UInt64, UInt64>(_data, new UInt64[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx.ExtractVector128(
- (UInt64*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx.ExtractVector128(
- (UInt64*)_dataTable.outArrayPtr,
- Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx.ExtractVector128(
- (UInt64*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt64*), typeof(Vector256<UInt64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt64*)),
- Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt64*), typeof(Vector256<UInt64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt64*)),
- Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx).GetMethod(nameof(Avx.ExtractVector128), new Type[] { typeof(UInt64*), typeof(Vector256<UInt64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt64*)),
- Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx.ExtractVector128(
- (UInt64*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr);
- Avx.ExtractVector128((UInt64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((UInt64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr));
- Avx.ExtractVector128((UInt64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128UInt641();
- Avx.ExtractVector128((UInt64*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx.ExtractVector128((UInt64*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx.ExtractVector128((UInt64*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt64> firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray = new UInt64[Op1ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray = new UInt64[Op1ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(UInt64[] firstOp, UInt64[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[2])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 2]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.ExtractVector128)}<UInt64>(Vector256<UInt64><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Byte1Load()
- {
- var test = new InsertLoadTest__InsertVector128Byte1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Byte1
- {
- private struct TestStruct
- {
- public Vector256<Byte> _fld1;
- public Vector128<Byte> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref testStruct._fld1), ref Unsafe.As<Byte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref testStruct._fld2), ref Unsafe.As<Byte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Byte1 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (Byte*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Byte*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Byte>>() / sizeof(Byte);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Byte>>() / sizeof(Byte);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Byte>>() / sizeof(Byte);
-
- private static Byte[] _data1 = new Byte[Op1ElementCount];
- private static Byte[] _data2 = new Byte[Op2ElementCount];
-
- private static Vector256<Byte> _clsVar1;
- private static Vector128<Byte> _clsVar2;
-
- private Vector256<Byte> _fld1;
- private Vector128<Byte> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Byte, Byte, Byte> _dataTable;
-
- static InsertLoadTest__InsertVector128Byte1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref _clsVar1), ref Unsafe.As<Byte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref _clsVar2), ref Unsafe.As<Byte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>());
- }
-
- public InsertLoadTest__InsertVector128Byte1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref _fld1), ref Unsafe.As<Byte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref _fld2), ref Unsafe.As<Byte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Byte, Byte, Byte>(_data1, _data2, new Byte[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<Byte>>(_dataTable.inArray1Ptr),
- (Byte*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((Byte*)(_dataTable.inArray1Ptr)),
- (Byte*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((Byte*)(_dataTable.inArray1Ptr)),
- (Byte*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Byte>), typeof(Byte*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Byte>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Byte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Byte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Byte>), typeof(Byte*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Byte*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Byte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Byte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Byte>), typeof(Byte*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Byte*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Byte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Byte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (Byte*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Byte*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Byte>>(_dataTable.inArray1Ptr);
- var right = (Byte*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Byte*)(_dataTable.inArray1Ptr));
- var right = (Byte*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Byte*)(_dataTable.inArray1Ptr));
- var right = (Byte*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Byte1();
- var result = Avx.InsertVector128(test._fld1, (Byte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Byte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (Byte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Byte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (Byte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Byte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Byte> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray1 = new Byte[Op1ElementCount];
- Byte[] inArray2 = new Byte[Op2ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Byte, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Byte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Byte>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray1 = new Byte[Op1ElementCount];
- Byte[] inArray2 = new Byte[Op2ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Byte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Byte>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Byte[] left, Byte[] right, Byte[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 15 ? result[i] != right[i - 16] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<Byte>(Vector256<Byte>, Vector128<Byte>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Double1Load()
- {
- var test = new InsertLoadTest__InsertVector128Double1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Double1
- {
- private struct TestStruct
- {
- public Vector256<Double> _fld1;
- public Vector128<Double> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref testStruct._fld1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref testStruct._fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Double1 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (Double*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Double*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Double>>() / sizeof(Double);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Double>>() / sizeof(Double);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Double>>() / sizeof(Double);
-
- private static Double[] _data1 = new Double[Op1ElementCount];
- private static Double[] _data2 = new Double[Op2ElementCount];
-
- private static Vector256<Double> _clsVar1;
- private static Vector128<Double> _clsVar2;
-
- private Vector256<Double> _fld1;
- private Vector128<Double> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Double, Double, Double> _dataTable;
-
- static InsertLoadTest__InsertVector128Double1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _clsVar1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _clsVar2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>());
- }
-
- public InsertLoadTest__InsertVector128Double1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Double>, byte>(ref _fld1), ref Unsafe.As<Double, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Double>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Double>, byte>(ref _fld2), ref Unsafe.As<Double, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Double>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetDouble(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetDouble(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Double, Double, Double>(_data1, _data2, new Double[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<Double>>(_dataTable.inArray1Ptr),
- (Double*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((Double*)(_dataTable.inArray1Ptr)),
- (Double*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((Double*)(_dataTable.inArray1Ptr)),
- (Double*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Double>), typeof(Double*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Double>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Double*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Double>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Double>), typeof(Double*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Double*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Double*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Double>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Double>), typeof(Double*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Double*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Double*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Double>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (Double*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Double*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Double>>(_dataTable.inArray1Ptr);
- var right = (Double*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Double*)(_dataTable.inArray1Ptr));
- var right = (Double*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Double*)(_dataTable.inArray1Ptr));
- var right = (Double*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Double1();
- var result = Avx.InsertVector128(test._fld1, (Double*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Double*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (Double*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Double*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (Double*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Double*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Double> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Double[] inArray1 = new Double[Op1ElementCount];
- Double[] inArray2 = new Double[Op2ElementCount];
- Double[] outArray = new Double[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Double>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Double>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Double[] inArray1 = new Double[Op1ElementCount];
- Double[] inArray2 = new Double[Op2ElementCount];
- Double[] outArray = new Double[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Double>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Double>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Double, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Double>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Double[] left, Double[] right, Double[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(left[0]))
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 1 ? BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(right[i - 2]) : BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(left[i])))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<Double>(Vector256<Double>, Vector128<Double>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Int161Load()
- {
- var test = new InsertLoadTest__InsertVector128Int161();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Int161
- {
- private struct TestStruct
- {
- public Vector256<Int16> _fld1;
- public Vector128<Int16> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref testStruct._fld1), ref Unsafe.As<Int16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref testStruct._fld2), ref Unsafe.As<Int16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Int161 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (Int16*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Int16*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int16>>() / sizeof(Int16);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Int16>>() / sizeof(Int16);
-
- private static Int16[] _data1 = new Int16[Op1ElementCount];
- private static Int16[] _data2 = new Int16[Op2ElementCount];
-
- private static Vector256<Int16> _clsVar1;
- private static Vector128<Int16> _clsVar2;
-
- private Vector256<Int16> _fld1;
- private Vector128<Int16> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Int16, Int16, Int16> _dataTable;
-
- static InsertLoadTest__InsertVector128Int161()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref _clsVar1), ref Unsafe.As<Int16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _clsVar2), ref Unsafe.As<Int16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>());
- }
-
- public InsertLoadTest__InsertVector128Int161()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref _fld1), ref Unsafe.As<Int16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _fld2), ref Unsafe.As<Int16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Int16, Int16, Int16>(_data1, _data2, new Int16[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<Int16>>(_dataTable.inArray1Ptr),
- (Int16*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((Int16*)(_dataTable.inArray1Ptr)),
- (Int16*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((Int16*)(_dataTable.inArray1Ptr)),
- (Int16*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int16>), typeof(Int16*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Int16>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int16>), typeof(Int16*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Int16*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int16>), typeof(Int16*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Int16*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (Int16*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Int16*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Int16>>(_dataTable.inArray1Ptr);
- var right = (Int16*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Int16*)(_dataTable.inArray1Ptr));
- var right = (Int16*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Int16*)(_dataTable.inArray1Ptr));
- var right = (Int16*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Int161();
- var result = Avx.InsertVector128(test._fld1, (Int16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (Int16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Int16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (Int16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int16> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray1 = new Int16[Op1ElementCount];
- Int16[] inArray2 = new Int16[Op2ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int16>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray1 = new Int16[Op1ElementCount];
- Int16[] inArray2 = new Int16[Op2ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int16>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Int16[] left, Int16[] right, Int16[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 7 ? result[i] != right[i - 8] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<Int16>(Vector256<Int16>, Vector128<Int16>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Int321Load()
- {
- var test = new InsertLoadTest__InsertVector128Int321();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Int321
- {
- private struct TestStruct
- {
- public Vector256<Int32> _fld1;
- public Vector128<Int32> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref testStruct._fld1), ref Unsafe.As<Int32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref testStruct._fld2), ref Unsafe.As<Int32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Int321 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (Int32*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Int32*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int32>>() / sizeof(Int32);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Int32>>() / sizeof(Int32);
-
- private static Int32[] _data1 = new Int32[Op1ElementCount];
- private static Int32[] _data2 = new Int32[Op2ElementCount];
-
- private static Vector256<Int32> _clsVar1;
- private static Vector128<Int32> _clsVar2;
-
- private Vector256<Int32> _fld1;
- private Vector128<Int32> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Int32, Int32, Int32> _dataTable;
-
- static InsertLoadTest__InsertVector128Int321()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref _clsVar1), ref Unsafe.As<Int32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _clsVar2), ref Unsafe.As<Int32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>());
- }
-
- public InsertLoadTest__InsertVector128Int321()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref _fld1), ref Unsafe.As<Int32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _fld2), ref Unsafe.As<Int32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Int32, Int32, Int32>(_data1, _data2, new Int32[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<Int32>>(_dataTable.inArray1Ptr),
- (Int32*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((Int32*)(_dataTable.inArray1Ptr)),
- (Int32*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((Int32*)(_dataTable.inArray1Ptr)),
- (Int32*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int32>), typeof(Int32*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Int32>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int32>), typeof(Int32*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Int32*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int32>), typeof(Int32*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Int32*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (Int32*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Int32*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Int32>>(_dataTable.inArray1Ptr);
- var right = (Int32*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Int32*)(_dataTable.inArray1Ptr));
- var right = (Int32*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Int32*)(_dataTable.inArray1Ptr));
- var right = (Int32*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Int321();
- var result = Avx.InsertVector128(test._fld1, (Int32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (Int32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Int32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (Int32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int32> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray1 = new Int32[Op1ElementCount];
- Int32[] inArray2 = new Int32[Op2ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int32>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray1 = new Int32[Op1ElementCount];
- Int32[] inArray2 = new Int32[Op2ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int32>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Int32[] left, Int32[] right, Int32[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 3 ? result[i] != right[i - 4] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<Int32>(Vector256<Int32>, Vector128<Int32>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Int641Load()
- {
- var test = new InsertLoadTest__InsertVector128Int641();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Int641
- {
- private struct TestStruct
- {
- public Vector256<Int64> _fld1;
- public Vector128<Int64> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref testStruct._fld1), ref Unsafe.As<Int64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int64>, byte>(ref testStruct._fld2), ref Unsafe.As<Int64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Int641 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (Int64*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Int64*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int64>>() / sizeof(Int64);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Int64>>() / sizeof(Int64);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Int64>>() / sizeof(Int64);
-
- private static Int64[] _data1 = new Int64[Op1ElementCount];
- private static Int64[] _data2 = new Int64[Op2ElementCount];
-
- private static Vector256<Int64> _clsVar1;
- private static Vector128<Int64> _clsVar2;
-
- private Vector256<Int64> _fld1;
- private Vector128<Int64> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Int64, Int64, Int64> _dataTable;
-
- static InsertLoadTest__InsertVector128Int641()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref _clsVar1), ref Unsafe.As<Int64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int64>, byte>(ref _clsVar2), ref Unsafe.As<Int64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int64>>());
- }
-
- public InsertLoadTest__InsertVector128Int641()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref _fld1), ref Unsafe.As<Int64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int64>, byte>(ref _fld2), ref Unsafe.As<Int64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Int64, Int64, Int64>(_data1, _data2, new Int64[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<Int64>>(_dataTable.inArray1Ptr),
- (Int64*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((Int64*)(_dataTable.inArray1Ptr)),
- (Int64*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((Int64*)(_dataTable.inArray1Ptr)),
- (Int64*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int64>), typeof(Int64*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Int64>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int64>), typeof(Int64*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Int64*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Int64>), typeof(Int64*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Int64*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (Int64*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Int64*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Int64>>(_dataTable.inArray1Ptr);
- var right = (Int64*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Int64*)(_dataTable.inArray1Ptr));
- var right = (Int64*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Int64*)(_dataTable.inArray1Ptr));
- var right = (Int64*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Int641();
- var result = Avx.InsertVector128(test._fld1, (Int64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (Int64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Int64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (Int64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int64> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray1 = new Int64[Op1ElementCount];
- Int64[] inArray2 = new Int64[Op2ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int64, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int64>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray1 = new Int64[Op1ElementCount];
- Int64[] inArray2 = new Int64[Op2ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int64>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Int64[] left, Int64[] right, Int64[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 1 ? result[i] != right[i - 2] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<Int64>(Vector256<Int64>, Vector128<Int64>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128SByte1Load()
- {
- var test = new InsertLoadTest__InsertVector128SByte1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128SByte1
- {
- private struct TestStruct
- {
- public Vector256<SByte> _fld1;
- public Vector128<SByte> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref testStruct._fld1), ref Unsafe.As<SByte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref testStruct._fld2), ref Unsafe.As<SByte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128SByte1 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (SByte*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (SByte*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<SByte>>() / sizeof(SByte);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<SByte>>() / sizeof(SByte);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<SByte>>() / sizeof(SByte);
-
- private static SByte[] _data1 = new SByte[Op1ElementCount];
- private static SByte[] _data2 = new SByte[Op2ElementCount];
-
- private static Vector256<SByte> _clsVar1;
- private static Vector128<SByte> _clsVar2;
-
- private Vector256<SByte> _fld1;
- private Vector128<SByte> _fld2;
-
- private SimpleBinaryOpTest__DataTable<SByte, SByte, SByte> _dataTable;
-
- static InsertLoadTest__InsertVector128SByte1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref _clsVar1), ref Unsafe.As<SByte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref _clsVar2), ref Unsafe.As<SByte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>());
- }
-
- public InsertLoadTest__InsertVector128SByte1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref _fld1), ref Unsafe.As<SByte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref _fld2), ref Unsafe.As<SByte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<SByte, SByte, SByte>(_data1, _data2, new SByte[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<SByte>>(_dataTable.inArray1Ptr),
- (SByte*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((SByte*)(_dataTable.inArray1Ptr)),
- (SByte*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((SByte*)(_dataTable.inArray1Ptr)),
- (SByte*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<SByte>), typeof(SByte*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<SByte>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(SByte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<SByte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<SByte>), typeof(SByte*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((SByte*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(SByte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<SByte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<SByte>), typeof(SByte*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((SByte*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(SByte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<SByte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (SByte*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (SByte*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<SByte>>(_dataTable.inArray1Ptr);
- var right = (SByte*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((SByte*)(_dataTable.inArray1Ptr));
- var right = (SByte*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((SByte*)(_dataTable.inArray1Ptr));
- var right = (SByte*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128SByte1();
- var result = Avx.InsertVector128(test._fld1, (SByte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (SByte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (SByte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (SByte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (SByte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (SByte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<SByte> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray1 = new SByte[Op1ElementCount];
- SByte[] inArray2 = new SByte[Op2ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<SByte, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<SByte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<SByte>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray1 = new SByte[Op1ElementCount];
- SByte[] inArray2 = new SByte[Op2ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<SByte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<SByte>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(SByte[] left, SByte[] right, SByte[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 15 ? result[i] != right[i - 16] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<SByte>(Vector256<SByte>, Vector128<SByte>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Single1Load()
- {
- var test = new InsertLoadTest__InsertVector128Single1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Single1
- {
- private struct TestStruct
- {
- public Vector256<Single> _fld1;
- public Vector128<Single> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref testStruct._fld1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref testStruct._fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Single1 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (Single*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Single*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Single>>() / sizeof(Single);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Single>>() / sizeof(Single);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Single>>() / sizeof(Single);
-
- private static Single[] _data1 = new Single[Op1ElementCount];
- private static Single[] _data2 = new Single[Op2ElementCount];
-
- private static Vector256<Single> _clsVar1;
- private static Vector128<Single> _clsVar2;
-
- private Vector256<Single> _fld1;
- private Vector128<Single> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Single, Single, Single> _dataTable;
-
- static InsertLoadTest__InsertVector128Single1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _clsVar1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _clsVar2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
- }
-
- public InsertLoadTest__InsertVector128Single1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Single>, byte>(ref _fld1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Single>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSingle(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSingle(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Single, Single, Single>(_data1, _data2, new Single[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<Single>>(_dataTable.inArray1Ptr),
- (Single*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((Single*)(_dataTable.inArray1Ptr)),
- (Single*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((Single*)(_dataTable.inArray1Ptr)),
- (Single*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Single>), typeof(Single*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Single>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Single*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Single>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Single>), typeof(Single*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Single*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Single*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Single>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<Single>), typeof(Single*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Single*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Single*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Single>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (Single*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Single*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Single>>(_dataTable.inArray1Ptr);
- var right = (Single*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Single*)(_dataTable.inArray1Ptr));
- var right = (Single*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Single*)(_dataTable.inArray1Ptr));
- var right = (Single*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Single1();
- var result = Avx.InsertVector128(test._fld1, (Single*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Single*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (Single*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Single*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (Single*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Single*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Single> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Single[] inArray1 = new Single[Op1ElementCount];
- Single[] inArray2 = new Single[Op2ElementCount];
- Single[] outArray = new Single[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Single>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Single>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Single[] inArray1 = new Single[Op1ElementCount];
- Single[] inArray2 = new Single[Op2ElementCount];
- Single[] outArray = new Single[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Single>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Single>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Single>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Single[] left, Single[] right, Single[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(left[0]))
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 3 ? BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(right[i - 4]) : BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i])))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<Single>(Vector256<Single>, Vector128<Single>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128UInt161Load()
- {
- var test = new InsertLoadTest__InsertVector128UInt161();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128UInt161
- {
- private struct TestStruct
- {
- public Vector256<UInt16> _fld1;
- public Vector128<UInt16> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref testStruct._fld1), ref Unsafe.As<UInt16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref testStruct._fld2), ref Unsafe.As<UInt16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128UInt161 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (UInt16*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (UInt16*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt16>>() / sizeof(UInt16);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<UInt16>>() / sizeof(UInt16);
-
- private static UInt16[] _data1 = new UInt16[Op1ElementCount];
- private static UInt16[] _data2 = new UInt16[Op2ElementCount];
-
- private static Vector256<UInt16> _clsVar1;
- private static Vector128<UInt16> _clsVar2;
-
- private Vector256<UInt16> _fld1;
- private Vector128<UInt16> _fld2;
-
- private SimpleBinaryOpTest__DataTable<UInt16, UInt16, UInt16> _dataTable;
-
- static InsertLoadTest__InsertVector128UInt161()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref _clsVar1), ref Unsafe.As<UInt16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _clsVar2), ref Unsafe.As<UInt16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
- }
-
- public InsertLoadTest__InsertVector128UInt161()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref _fld1), ref Unsafe.As<UInt16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _fld2), ref Unsafe.As<UInt16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<UInt16, UInt16, UInt16>(_data1, _data2, new UInt16[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<UInt16>>(_dataTable.inArray1Ptr),
- (UInt16*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((UInt16*)(_dataTable.inArray1Ptr)),
- (UInt16*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArray1Ptr)),
- (UInt16*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt16>), typeof(UInt16*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<UInt16>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt16>), typeof(UInt16*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((UInt16*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt16>), typeof(UInt16*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (UInt16*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (UInt16*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<UInt16>>(_dataTable.inArray1Ptr);
- var right = (UInt16*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((UInt16*)(_dataTable.inArray1Ptr));
- var right = (UInt16*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArray1Ptr));
- var right = (UInt16*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128UInt161();
- var result = Avx.InsertVector128(test._fld1, (UInt16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (UInt16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (UInt16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (UInt16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt16> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray1 = new UInt16[Op1ElementCount];
- UInt16[] inArray2 = new UInt16[Op2ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray1 = new UInt16[Op1ElementCount];
- UInt16[] inArray2 = new UInt16[Op2ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(UInt16[] left, UInt16[] right, UInt16[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 7 ? result[i] != right[i - 8] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<UInt16>(Vector256<UInt16>, Vector128<UInt16>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128UInt321Load()
- {
- var test = new InsertLoadTest__InsertVector128UInt321();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128UInt321
- {
- private struct TestStruct
- {
- public Vector256<UInt32> _fld1;
- public Vector128<UInt32> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref testStruct._fld1), ref Unsafe.As<UInt32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref testStruct._fld2), ref Unsafe.As<UInt32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128UInt321 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (UInt32*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (UInt32*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt32>>() / sizeof(UInt32);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<UInt32>>() / sizeof(UInt32);
-
- private static UInt32[] _data1 = new UInt32[Op1ElementCount];
- private static UInt32[] _data2 = new UInt32[Op2ElementCount];
-
- private static Vector256<UInt32> _clsVar1;
- private static Vector128<UInt32> _clsVar2;
-
- private Vector256<UInt32> _fld1;
- private Vector128<UInt32> _fld2;
-
- private SimpleBinaryOpTest__DataTable<UInt32, UInt32, UInt32> _dataTable;
-
- static InsertLoadTest__InsertVector128UInt321()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref _clsVar1), ref Unsafe.As<UInt32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref _clsVar2), ref Unsafe.As<UInt32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
- }
-
- public InsertLoadTest__InsertVector128UInt321()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref _fld1), ref Unsafe.As<UInt32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref _fld2), ref Unsafe.As<UInt32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<UInt32, UInt32, UInt32>(_data1, _data2, new UInt32[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<UInt32>>(_dataTable.inArray1Ptr),
- (UInt32*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((UInt32*)(_dataTable.inArray1Ptr)),
- (UInt32*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArray1Ptr)),
- (UInt32*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt32>), typeof(UInt32*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<UInt32>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt32>), typeof(UInt32*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((UInt32*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt32>), typeof(UInt32*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (UInt32*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (UInt32*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<UInt32>>(_dataTable.inArray1Ptr);
- var right = (UInt32*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((UInt32*)(_dataTable.inArray1Ptr));
- var right = (UInt32*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArray1Ptr));
- var right = (UInt32*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128UInt321();
- var result = Avx.InsertVector128(test._fld1, (UInt32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (UInt32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (UInt32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (UInt32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt32> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray1 = new UInt32[Op1ElementCount];
- UInt32[] inArray2 = new UInt32[Op2ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray1 = new UInt32[Op1ElementCount];
- UInt32[] inArray2 = new UInt32[Op2ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(UInt32[] left, UInt32[] right, UInt32[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 3 ? result[i] != right[i - 4] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<UInt32>(Vector256<UInt32>, Vector128<UInt32>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128UInt641Load()
- {
- var test = new InsertLoadTest__InsertVector128UInt641();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128UInt641
- {
- private struct TestStruct
- {
- public Vector256<UInt64> _fld1;
- public Vector128<UInt64> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref testStruct._fld1), ref Unsafe.As<UInt64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt64>, byte>(ref testStruct._fld2), ref Unsafe.As<UInt64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128UInt641 testClass)
- {
- var result = Avx.InsertVector128(_fld1, (UInt64*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (UInt64*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt64>>() / sizeof(UInt64);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<UInt64>>() / sizeof(UInt64);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<UInt64>>() / sizeof(UInt64);
-
- private static UInt64[] _data1 = new UInt64[Op1ElementCount];
- private static UInt64[] _data2 = new UInt64[Op2ElementCount];
-
- private static Vector256<UInt64> _clsVar1;
- private static Vector128<UInt64> _clsVar2;
-
- private Vector256<UInt64> _fld1;
- private Vector128<UInt64> _fld2;
-
- private SimpleBinaryOpTest__DataTable<UInt64, UInt64, UInt64> _dataTable;
-
- static InsertLoadTest__InsertVector128UInt641()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _clsVar1), ref Unsafe.As<UInt64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt64>, byte>(ref _clsVar2), ref Unsafe.As<UInt64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
- }
-
- public InsertLoadTest__InsertVector128UInt641()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _fld1), ref Unsafe.As<UInt64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt64>, byte>(ref _fld2), ref Unsafe.As<UInt64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<UInt64, UInt64, UInt64>(_data1, _data2, new UInt64[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx.InsertVector128(
- Unsafe.Read<Vector256<UInt64>>(_dataTable.inArray1Ptr),
- (UInt64*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx.InsertVector128(
- Avx.LoadVector256((UInt64*)(_dataTable.inArray1Ptr)),
- (UInt64*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx.InsertVector128(
- Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArray1Ptr)),
- (UInt64*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt64>), typeof(UInt64*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<UInt64>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt64>), typeof(UInt64*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((UInt64*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx).GetMethod(nameof(Avx.InsertVector128), new Type[] { typeof(Vector256<UInt64>), typeof(UInt64*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx.InsertVector128(
- _clsVar1,
- (UInt64*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (UInt64*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<UInt64>>(_dataTable.inArray1Ptr);
- var right = (UInt64*)_dataTable.inArray2Ptr;
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((UInt64*)(_dataTable.inArray1Ptr));
- var right = (UInt64*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArray1Ptr));
- var right = (UInt64*)(_dataTable.inArray2Ptr);
- var result = Avx.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128UInt641();
- var result = Avx.InsertVector128(test._fld1, (UInt64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx.InsertVector128(_fld1, (UInt64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (UInt64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx.InsertVector128(test._fld1, (UInt64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt64> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray1 = new UInt64[Op1ElementCount];
- UInt64[] inArray2 = new UInt64[Op2ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray1 = new UInt64[Op1ElementCount];
- UInt64[] inArray2 = new UInt64[Op2ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(UInt64[] left, UInt64[] right, UInt64[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 1 ? result[i] != right[i - 2] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx)}.{nameof(Avx.InsertVector128)}<UInt64>(Vector256<UInt64>, Vector128<UInt64>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
["ExtractVector128.UInt32.1"] = ExtractVector128UInt321,
["ExtractVector128.Int64.1"] = ExtractVector128Int641,
["ExtractVector128.UInt64.1"] = ExtractVector128UInt641,
- ["ExtractVector128.Byte.1.Store"] = ExtractVector128Byte1Store,
- ["ExtractVector128.SByte.1.Store"] = ExtractVector128SByte1Store,
- ["ExtractVector128.Int16.1.Store"] = ExtractVector128Int161Store,
- ["ExtractVector128.UInt16.1.Store"] = ExtractVector128UInt161Store,
- ["ExtractVector128.Int32.1.Store"] = ExtractVector128Int321Store,
- ["ExtractVector128.UInt32.1.Store"] = ExtractVector128UInt321Store,
- ["ExtractVector128.Int64.1.Store"] = ExtractVector128Int641Store,
- ["ExtractVector128.UInt64.1.Store"] = ExtractVector128UInt641Store,
- ["ExtractVector128.Single.1.Store"] = ExtractVector128Single1Store,
- ["ExtractVector128.Double.1.Store"] = ExtractVector128Double1Store,
["InsertVector128.Byte.1"] = InsertVector128Byte1,
["InsertVector128.SByte.1"] = InsertVector128SByte1,
["InsertVector128.Int16.1"] = InsertVector128Int161,
["InsertVector128.UInt64.1"] = InsertVector128UInt641,
["InsertVector128.Single.1"] = InsertVector128Single1,
["InsertVector128.Double.1"] = InsertVector128Double1,
- ["InsertVector128.Byte.1.Load"] = InsertVector128Byte1Load,
- ["InsertVector128.SByte.1.Load"] = InsertVector128SByte1Load,
- ["InsertVector128.Int16.1.Load"] = InsertVector128Int161Load,
- ["InsertVector128.UInt16.1.Load"] = InsertVector128UInt161Load,
- ["InsertVector128.Int32.1.Load"] = InsertVector128Int321Load,
- ["InsertVector128.UInt32.1.Load"] = InsertVector128UInt321Load,
- ["InsertVector128.Int64.1.Load"] = InsertVector128Int641Load,
- ["InsertVector128.UInt64.1.Load"] = InsertVector128UInt641Load,
- ["InsertVector128.Single.1.Load"] = InsertVector128Single1Load,
- ["InsertVector128.Double.1.Load"] = InsertVector128Double1Load,
["Floor.Double"] = FloorDouble,
["Floor.Single"] = FloorSingle,
["LoadVector256.Single"] = LoadVector256Single,
<Compile Include="ExtractVector128.UInt32.1.cs" />
<Compile Include="ExtractVector128.Int64.1.cs" />
<Compile Include="ExtractVector128.UInt64.1.cs" />
- <Compile Include="ExtractVector128.Byte.1.Store.cs" />
- <Compile Include="ExtractVector128.SByte.1.Store.cs" />
- <Compile Include="ExtractVector128.Int16.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt16.1.Store.cs" />
- <Compile Include="ExtractVector128.Int32.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt32.1.Store.cs" />
- <Compile Include="ExtractVector128.Int64.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt64.1.Store.cs" />
<Compile Include="InsertVector128.Byte.1.cs" />
<Compile Include="InsertVector128.SByte.1.cs" />
<Compile Include="InsertVector128.Int16.1.cs" />
<Compile Include="InsertVector128.UInt32.1.cs" />
<Compile Include="InsertVector128.Int64.1.cs" />
<Compile Include="InsertVector128.UInt64.1.cs" />
- <Compile Include="InsertVector128.Byte.1.Load.cs" />
- <Compile Include="InsertVector128.SByte.1.Load.cs" />
- <Compile Include="InsertVector128.Int16.1.Load.cs" />
- <Compile Include="InsertVector128.UInt16.1.Load.cs" />
- <Compile Include="InsertVector128.Int32.1.Load.cs" />
- <Compile Include="InsertVector128.UInt32.1.Load.cs" />
- <Compile Include="InsertVector128.Int64.1.Load.cs" />
- <Compile Include="InsertVector128.UInt64.1.Load.cs" />
<Compile Include="MaskLoad.Int32.cs" />
<Compile Include="MaskLoad.UInt32.cs" />
<Compile Include="MaskLoad.Int64.cs" />
<Compile Include="ExtractVector128.UInt32.1.cs" />
<Compile Include="ExtractVector128.Int64.1.cs" />
<Compile Include="ExtractVector128.UInt64.1.cs" />
- <Compile Include="ExtractVector128.Byte.1.Store.cs" />
- <Compile Include="ExtractVector128.SByte.1.Store.cs" />
- <Compile Include="ExtractVector128.Int16.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt16.1.Store.cs" />
- <Compile Include="ExtractVector128.Int32.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt32.1.Store.cs" />
- <Compile Include="ExtractVector128.Int64.1.Store.cs" />
- <Compile Include="ExtractVector128.UInt64.1.Store.cs" />
<Compile Include="InsertVector128.Byte.1.cs" />
<Compile Include="InsertVector128.SByte.1.cs" />
<Compile Include="InsertVector128.Int16.1.cs" />
<Compile Include="InsertVector128.UInt32.1.cs" />
<Compile Include="InsertVector128.Int64.1.cs" />
<Compile Include="InsertVector128.UInt64.1.cs" />
- <Compile Include="InsertVector128.Byte.1.Load.cs" />
- <Compile Include="InsertVector128.SByte.1.Load.cs" />
- <Compile Include="InsertVector128.Int16.1.Load.cs" />
- <Compile Include="InsertVector128.UInt16.1.Load.cs" />
- <Compile Include="InsertVector128.Int32.1.Load.cs" />
- <Compile Include="InsertVector128.UInt32.1.Load.cs" />
- <Compile Include="InsertVector128.Int64.1.Load.cs" />
- <Compile Include="InsertVector128.UInt64.1.Load.cs" />
<Compile Include="MaskLoad.Int32.cs" />
<Compile Include="MaskLoad.UInt32.cs" />
<Compile Include="MaskLoad.Int64.cs" />
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Byte1Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Byte1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Byte1
- {
- private struct TestStruct
- {
- public Vector256<Byte> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref testStruct._fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Byte1 testClass)
- {
- Avx2.ExtractVector128((Byte*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Byte>>() / sizeof(Byte);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Byte>>() / sizeof(Byte);
-
- private static Byte[] _data = new Byte[Op1ElementCount];
-
- private static Vector256<Byte> _clsVar;
-
- private Vector256<Byte> _fld;
-
- private SimpleUnaryOpTest__DataTable<Byte, Byte> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Byte1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref _clsVar), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- }
-
- public ExtractStoreTest__ExtractVector128Byte1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref _fld), ref Unsafe.As<Byte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetByte(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Byte, Byte>(_data, new Byte[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx2.ExtractVector128(
- (Byte*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Byte>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx2.ExtractVector128(
- (Byte*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Byte*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx2.ExtractVector128(
- (Byte*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Byte*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Byte*), typeof(Vector256<Byte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Byte*)),
- Unsafe.Read<Vector256<Byte>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Byte*), typeof(Vector256<Byte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Byte*)),
- Avx.LoadVector256((Byte*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Byte*), typeof(Vector256<Byte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Byte*)),
- Avx.LoadAlignedVector256((Byte*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx2.ExtractVector128(
- (Byte*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Byte>>(_dataTable.inArrayPtr);
- Avx2.ExtractVector128((Byte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Byte*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((Byte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Byte*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((Byte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Byte1();
- Avx2.ExtractVector128((Byte*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx2.ExtractVector128((Byte*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx2.ExtractVector128((Byte*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Byte> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray = new Byte[Op1ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray = new Byte[Op1ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Byte[] firstOp, Byte[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[16])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 16]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.ExtractVector128)}<Byte>(Vector256<Byte><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Int161Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Int161();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Int161
- {
- private struct TestStruct
- {
- public Vector256<Int16> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref testStruct._fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Int161 testClass)
- {
- Avx2.ExtractVector128((Int16*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int16>>() / sizeof(Int16);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16);
-
- private static Int16[] _data = new Int16[Op1ElementCount];
-
- private static Vector256<Int16> _clsVar;
-
- private Vector256<Int16> _fld;
-
- private SimpleUnaryOpTest__DataTable<Int16, Int16> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Int161()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref _clsVar), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- }
-
- public ExtractStoreTest__ExtractVector128Int161()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref _fld), ref Unsafe.As<Int16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt16(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Int16, Int16>(_data, new Int16[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx2.ExtractVector128(
- (Int16*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Int16>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx2.ExtractVector128(
- (Int16*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Int16*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx2.ExtractVector128(
- (Int16*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Int16*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int16*), typeof(Vector256<Int16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int16*)),
- Unsafe.Read<Vector256<Int16>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int16*), typeof(Vector256<Int16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int16*)),
- Avx.LoadVector256((Int16*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int16*), typeof(Vector256<Int16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int16*)),
- Avx.LoadAlignedVector256((Int16*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx2.ExtractVector128(
- (Int16*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Int16>>(_dataTable.inArrayPtr);
- Avx2.ExtractVector128((Int16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Int16*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((Int16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Int16*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((Int16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Int161();
- Avx2.ExtractVector128((Int16*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx2.ExtractVector128((Int16*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx2.ExtractVector128((Int16*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int16> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray = new Int16[Op1ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray = new Int16[Op1ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Int16[] firstOp, Int16[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[8])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 8]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.ExtractVector128)}<Int16>(Vector256<Int16><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Int321Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Int321();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Int321
- {
- private struct TestStruct
- {
- public Vector256<Int32> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref testStruct._fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Int321 testClass)
- {
- Avx2.ExtractVector128((Int32*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int32>>() / sizeof(Int32);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32);
-
- private static Int32[] _data = new Int32[Op1ElementCount];
-
- private static Vector256<Int32> _clsVar;
-
- private Vector256<Int32> _fld;
-
- private SimpleUnaryOpTest__DataTable<Int32, Int32> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Int321()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref _clsVar), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- }
-
- public ExtractStoreTest__ExtractVector128Int321()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref _fld), ref Unsafe.As<Int32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt32(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Int32, Int32>(_data, new Int32[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx2.ExtractVector128(
- (Int32*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Int32>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx2.ExtractVector128(
- (Int32*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Int32*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx2.ExtractVector128(
- (Int32*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Int32*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int32*), typeof(Vector256<Int32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int32*)),
- Unsafe.Read<Vector256<Int32>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int32*), typeof(Vector256<Int32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int32*)),
- Avx.LoadVector256((Int32*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int32*), typeof(Vector256<Int32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int32*)),
- Avx.LoadAlignedVector256((Int32*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx2.ExtractVector128(
- (Int32*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Int32>>(_dataTable.inArrayPtr);
- Avx2.ExtractVector128((Int32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Int32*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((Int32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Int32*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((Int32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Int321();
- Avx2.ExtractVector128((Int32*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx2.ExtractVector128((Int32*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx2.ExtractVector128((Int32*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int32> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray = new Int32[Op1ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray = new Int32[Op1ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Int32[] firstOp, Int32[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[4])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 4]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.ExtractVector128)}<Int32>(Vector256<Int32><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128Int641Store()
- {
- var test = new ExtractStoreTest__ExtractVector128Int641();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128Int641
- {
- private struct TestStruct
- {
- public Vector256<Int64> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref testStruct._fld), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128Int641 testClass)
- {
- Avx2.ExtractVector128((Int64*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int64>>() / sizeof(Int64);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<Int64>>() / sizeof(Int64);
-
- private static Int64[] _data = new Int64[Op1ElementCount];
-
- private static Vector256<Int64> _clsVar;
-
- private Vector256<Int64> _fld;
-
- private SimpleUnaryOpTest__DataTable<Int64, Int64> _dataTable;
-
- static ExtractStoreTest__ExtractVector128Int641()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref _clsVar), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- }
-
- public ExtractStoreTest__ExtractVector128Int641()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref _fld), ref Unsafe.As<Int64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetInt64(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<Int64, Int64>(_data, new Int64[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx2.ExtractVector128(
- (Int64*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<Int64>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx2.ExtractVector128(
- (Int64*)_dataTable.outArrayPtr,
- Avx.LoadVector256((Int64*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx2.ExtractVector128(
- (Int64*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((Int64*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int64*), typeof(Vector256<Int64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int64*)),
- Unsafe.Read<Vector256<Int64>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int64*), typeof(Vector256<Int64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int64*)),
- Avx.LoadVector256((Int64*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(Int64*), typeof(Vector256<Int64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(Int64*)),
- Avx.LoadAlignedVector256((Int64*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx2.ExtractVector128(
- (Int64*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<Int64>>(_dataTable.inArrayPtr);
- Avx2.ExtractVector128((Int64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((Int64*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((Int64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((Int64*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((Int64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128Int641();
- Avx2.ExtractVector128((Int64*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx2.ExtractVector128((Int64*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx2.ExtractVector128((Int64*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int64> firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray = new Int64[Op1ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray = new Int64[Op1ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(Int64[] firstOp, Int64[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[2])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 2]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.ExtractVector128)}<Int64>(Vector256<Int64><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128SByte1Store()
- {
- var test = new ExtractStoreTest__ExtractVector128SByte1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128SByte1
- {
- private struct TestStruct
- {
- public Vector256<SByte> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref testStruct._fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128SByte1 testClass)
- {
- Avx2.ExtractVector128((SByte*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<SByte>>() / sizeof(SByte);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<SByte>>() / sizeof(SByte);
-
- private static SByte[] _data = new SByte[Op1ElementCount];
-
- private static Vector256<SByte> _clsVar;
-
- private Vector256<SByte> _fld;
-
- private SimpleUnaryOpTest__DataTable<SByte, SByte> _dataTable;
-
- static ExtractStoreTest__ExtractVector128SByte1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref _clsVar), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- }
-
- public ExtractStoreTest__ExtractVector128SByte1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref _fld), ref Unsafe.As<SByte, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetSByte(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<SByte, SByte>(_data, new SByte[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx2.ExtractVector128(
- (SByte*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<SByte>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx2.ExtractVector128(
- (SByte*)_dataTable.outArrayPtr,
- Avx.LoadVector256((SByte*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx2.ExtractVector128(
- (SByte*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((SByte*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(SByte*), typeof(Vector256<SByte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(SByte*)),
- Unsafe.Read<Vector256<SByte>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(SByte*), typeof(Vector256<SByte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(SByte*)),
- Avx.LoadVector256((SByte*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(SByte*), typeof(Vector256<SByte>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(SByte*)),
- Avx.LoadAlignedVector256((SByte*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx2.ExtractVector128(
- (SByte*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<SByte>>(_dataTable.inArrayPtr);
- Avx2.ExtractVector128((SByte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((SByte*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((SByte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((SByte*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((SByte*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128SByte1();
- Avx2.ExtractVector128((SByte*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx2.ExtractVector128((SByte*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx2.ExtractVector128((SByte*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<SByte> firstOp, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray = new SByte[Op1ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray = new SByte[Op1ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(SByte[] firstOp, SByte[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[16])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 16]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.ExtractVector128)}<SByte>(Vector256<SByte><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128UInt161Store()
- {
- var test = new ExtractStoreTest__ExtractVector128UInt161();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128UInt161
- {
- private struct TestStruct
- {
- public Vector256<UInt16> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref testStruct._fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128UInt161 testClass)
- {
- Avx2.ExtractVector128((UInt16*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt16>>() / sizeof(UInt16);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16);
-
- private static UInt16[] _data = new UInt16[Op1ElementCount];
-
- private static Vector256<UInt16> _clsVar;
-
- private Vector256<UInt16> _fld;
-
- private SimpleUnaryOpTest__DataTable<UInt16, UInt16> _dataTable;
-
- static ExtractStoreTest__ExtractVector128UInt161()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref _clsVar), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- }
-
- public ExtractStoreTest__ExtractVector128UInt161()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref _fld), ref Unsafe.As<UInt16, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt16(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<UInt16, UInt16>(_data, new UInt16[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx2.ExtractVector128(
- (UInt16*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<UInt16>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx2.ExtractVector128(
- (UInt16*)_dataTable.outArrayPtr,
- Avx.LoadVector256((UInt16*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx2.ExtractVector128(
- (UInt16*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt16*), typeof(Vector256<UInt16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt16*)),
- Unsafe.Read<Vector256<UInt16>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt16*), typeof(Vector256<UInt16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt16*)),
- Avx.LoadVector256((UInt16*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt16*), typeof(Vector256<UInt16>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt16*)),
- Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx2.ExtractVector128(
- (UInt16*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<UInt16>>(_dataTable.inArrayPtr);
- Avx2.ExtractVector128((UInt16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((UInt16*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((UInt16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((UInt16*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128UInt161();
- Avx2.ExtractVector128((UInt16*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx2.ExtractVector128((UInt16*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx2.ExtractVector128((UInt16*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt16> firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray = new UInt16[Op1ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray = new UInt16[Op1ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(UInt16[] firstOp, UInt16[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[8])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 8]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.ExtractVector128)}<UInt16>(Vector256<UInt16><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128UInt321Store()
- {
- var test = new ExtractStoreTest__ExtractVector128UInt321();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128UInt321
- {
- private struct TestStruct
- {
- public Vector256<UInt32> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref testStruct._fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128UInt321 testClass)
- {
- Avx2.ExtractVector128((UInt32*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt32>>() / sizeof(UInt32);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32);
-
- private static UInt32[] _data = new UInt32[Op1ElementCount];
-
- private static Vector256<UInt32> _clsVar;
-
- private Vector256<UInt32> _fld;
-
- private SimpleUnaryOpTest__DataTable<UInt32, UInt32> _dataTable;
-
- static ExtractStoreTest__ExtractVector128UInt321()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref _clsVar), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- }
-
- public ExtractStoreTest__ExtractVector128UInt321()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref _fld), ref Unsafe.As<UInt32, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt32(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<UInt32, UInt32>(_data, new UInt32[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx2.ExtractVector128(
- (UInt32*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<UInt32>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx2.ExtractVector128(
- (UInt32*)_dataTable.outArrayPtr,
- Avx.LoadVector256((UInt32*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx2.ExtractVector128(
- (UInt32*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt32*), typeof(Vector256<UInt32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt32*)),
- Unsafe.Read<Vector256<UInt32>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt32*), typeof(Vector256<UInt32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt32*)),
- Avx.LoadVector256((UInt32*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt32*), typeof(Vector256<UInt32>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt32*)),
- Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx2.ExtractVector128(
- (UInt32*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<UInt32>>(_dataTable.inArrayPtr);
- Avx2.ExtractVector128((UInt32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((UInt32*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((UInt32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((UInt32*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128UInt321();
- Avx2.ExtractVector128((UInt32*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx2.ExtractVector128((UInt32*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx2.ExtractVector128((UInt32*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt32> firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray = new UInt32[Op1ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray = new UInt32[Op1ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(UInt32[] firstOp, UInt32[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[4])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 4]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.ExtractVector128)}<UInt32>(Vector256<UInt32><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void ExtractVector128UInt641Store()
- {
- var test = new ExtractStoreTest__ExtractVector128UInt641();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__ExtractVector128UInt641
- {
- private struct TestStruct
- {
- public Vector256<UInt64> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref testStruct._fld), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__ExtractVector128UInt641 testClass)
- {
- Avx2.ExtractVector128((UInt64*)testClass._dataTable.outArrayPtr, _fld, 1);
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt64>>() / sizeof(UInt64);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector128<UInt64>>() / sizeof(UInt64);
-
- private static UInt64[] _data = new UInt64[Op1ElementCount];
-
- private static Vector256<UInt64> _clsVar;
-
- private Vector256<UInt64> _fld;
-
- private SimpleUnaryOpTest__DataTable<UInt64, UInt64> _dataTable;
-
- static ExtractStoreTest__ExtractVector128UInt641()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _clsVar), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- }
-
- public ExtractStoreTest__ExtractVector128UInt641()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _fld), ref Unsafe.As<UInt64, byte>(ref _data[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = TestLibrary.Generator.GetUInt64(); }
- _dataTable = new SimpleUnaryOpTest__DataTable<UInt64, UInt64>(_data, new UInt64[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- Avx2.ExtractVector128(
- (UInt64*)_dataTable.outArrayPtr,
- Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- Avx2.ExtractVector128(
- (UInt64*)_dataTable.outArrayPtr,
- Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- Avx2.ExtractVector128(
- (UInt64*)_dataTable.outArrayPtr,
- Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr)),
- 1
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt64*), typeof(Vector256<UInt64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt64*)),
- Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt64*), typeof(Vector256<UInt64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt64*)),
- Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof(Avx2).GetMethod(nameof(Avx2.ExtractVector128), new Type[] { typeof(UInt64*), typeof(Vector256<UInt64>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof(UInt64*)),
- Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr)),
- (byte)1
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- Avx2.ExtractVector128(
- (UInt64*)_dataTable.outArrayPtr,
- _clsVar,
- 1
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr);
- Avx2.ExtractVector128((UInt64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((UInt64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr));
- Avx2.ExtractVector128((UInt64*)_dataTable.outArrayPtr, firstOp, 1);
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__ExtractVector128UInt641();
- Avx2.ExtractVector128((UInt64*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- Avx2.ExtractVector128((UInt64*)_dataTable.outArrayPtr, _fld, 1);
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- Avx2.ExtractVector128((UInt64*)_dataTable.outArrayPtr, test._fld, 1);
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt64> firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray = new UInt64[Op1ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray = new UInt64[Op1ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(UInt64[] firstOp, UInt64[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != firstOp[2])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((result[i] != firstOp[i + 2]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.ExtractVector128)}<UInt64>(Vector256<UInt64><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Byte1Load()
- {
- var test = new InsertLoadTest__InsertVector128Byte1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Byte1
- {
- private struct TestStruct
- {
- public Vector256<Byte> _fld1;
- public Vector128<Byte> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref testStruct._fld1), ref Unsafe.As<Byte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref testStruct._fld2), ref Unsafe.As<Byte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Byte1 testClass)
- {
- var result = Avx2.InsertVector128(_fld1, (Byte*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Byte*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Byte>>() / sizeof(Byte);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Byte>>() / sizeof(Byte);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Byte>>() / sizeof(Byte);
-
- private static Byte[] _data1 = new Byte[Op1ElementCount];
- private static Byte[] _data2 = new Byte[Op2ElementCount];
-
- private static Vector256<Byte> _clsVar1;
- private static Vector128<Byte> _clsVar2;
-
- private Vector256<Byte> _fld1;
- private Vector128<Byte> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Byte, Byte, Byte> _dataTable;
-
- static InsertLoadTest__InsertVector128Byte1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref _clsVar1), ref Unsafe.As<Byte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref _clsVar2), ref Unsafe.As<Byte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>());
- }
-
- public InsertLoadTest__InsertVector128Byte1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Byte>, byte>(ref _fld1), ref Unsafe.As<Byte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Byte>, byte>(ref _fld2), ref Unsafe.As<Byte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Byte>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetByte(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetByte(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Byte, Byte, Byte>(_data1, _data2, new Byte[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx2.InsertVector128(
- Unsafe.Read<Vector256<Byte>>(_dataTable.inArray1Ptr),
- (Byte*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx2.InsertVector128(
- Avx.LoadVector256((Byte*)(_dataTable.inArray1Ptr)),
- (Byte*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx2.InsertVector128(
- Avx.LoadAlignedVector256((Byte*)(_dataTable.inArray1Ptr)),
- (Byte*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Byte>), typeof(Byte*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Byte>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Byte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Byte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Byte>), typeof(Byte*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Byte*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Byte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Byte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Byte>), typeof(Byte*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Byte*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Byte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Byte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx2.InsertVector128(
- _clsVar1,
- (Byte*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Byte*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Byte>>(_dataTable.inArray1Ptr);
- var right = (Byte*)_dataTable.inArray2Ptr;
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Byte*)(_dataTable.inArray1Ptr));
- var right = (Byte*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Byte*)(_dataTable.inArray1Ptr));
- var right = (Byte*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Byte1();
- var result = Avx2.InsertVector128(test._fld1, (Byte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Byte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx2.InsertVector128(_fld1, (Byte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Byte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx2.InsertVector128(test._fld1, (Byte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Byte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Byte> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray1 = new Byte[Op1ElementCount];
- Byte[] inArray2 = new Byte[Op2ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Byte, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Byte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Byte>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Byte[] inArray1 = new Byte[Op1ElementCount];
- Byte[] inArray2 = new Byte[Op2ElementCount];
- Byte[] outArray = new Byte[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Byte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Byte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Byte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Byte>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Byte[] left, Byte[] right, Byte[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 15 ? result[i] != right[i - 16] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.InsertVector128)}<Byte>(Vector256<Byte>, Vector128<Byte>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Int161Load()
- {
- var test = new InsertLoadTest__InsertVector128Int161();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Int161
- {
- private struct TestStruct
- {
- public Vector256<Int16> _fld1;
- public Vector128<Int16> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref testStruct._fld1), ref Unsafe.As<Int16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref testStruct._fld2), ref Unsafe.As<Int16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Int161 testClass)
- {
- var result = Avx2.InsertVector128(_fld1, (Int16*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Int16*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int16>>() / sizeof(Int16);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Int16>>() / sizeof(Int16);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Int16>>() / sizeof(Int16);
-
- private static Int16[] _data1 = new Int16[Op1ElementCount];
- private static Int16[] _data2 = new Int16[Op2ElementCount];
-
- private static Vector256<Int16> _clsVar1;
- private static Vector128<Int16> _clsVar2;
-
- private Vector256<Int16> _fld1;
- private Vector128<Int16> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Int16, Int16, Int16> _dataTable;
-
- static InsertLoadTest__InsertVector128Int161()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref _clsVar1), ref Unsafe.As<Int16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _clsVar2), ref Unsafe.As<Int16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>());
- }
-
- public InsertLoadTest__InsertVector128Int161()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int16>, byte>(ref _fld1), ref Unsafe.As<Int16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int16>, byte>(ref _fld2), ref Unsafe.As<Int16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int16>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt16(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt16(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Int16, Int16, Int16>(_data1, _data2, new Int16[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx2.InsertVector128(
- Unsafe.Read<Vector256<Int16>>(_dataTable.inArray1Ptr),
- (Int16*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx2.InsertVector128(
- Avx.LoadVector256((Int16*)(_dataTable.inArray1Ptr)),
- (Int16*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx2.InsertVector128(
- Avx.LoadAlignedVector256((Int16*)(_dataTable.inArray1Ptr)),
- (Int16*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int16>), typeof(Int16*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Int16>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int16>), typeof(Int16*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Int16*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int16>), typeof(Int16*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Int16*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx2.InsertVector128(
- _clsVar1,
- (Int16*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Int16*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Int16>>(_dataTable.inArray1Ptr);
- var right = (Int16*)_dataTable.inArray2Ptr;
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Int16*)(_dataTable.inArray1Ptr));
- var right = (Int16*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Int16*)(_dataTable.inArray1Ptr));
- var right = (Int16*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Int161();
- var result = Avx2.InsertVector128(test._fld1, (Int16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx2.InsertVector128(_fld1, (Int16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Int16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx2.InsertVector128(test._fld1, (Int16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int16> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray1 = new Int16[Op1ElementCount];
- Int16[] inArray2 = new Int16[Op2ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int16, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int16>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int16[] inArray1 = new Int16[Op1ElementCount];
- Int16[] inArray2 = new Int16[Op2ElementCount];
- Int16[] outArray = new Int16[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Int16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int16>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Int16[] left, Int16[] right, Int16[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 7 ? result[i] != right[i - 8] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.InsertVector128)}<Int16>(Vector256<Int16>, Vector128<Int16>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Int321Load()
- {
- var test = new InsertLoadTest__InsertVector128Int321();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Int321
- {
- private struct TestStruct
- {
- public Vector256<Int32> _fld1;
- public Vector128<Int32> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref testStruct._fld1), ref Unsafe.As<Int32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref testStruct._fld2), ref Unsafe.As<Int32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Int321 testClass)
- {
- var result = Avx2.InsertVector128(_fld1, (Int32*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Int32*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int32>>() / sizeof(Int32);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Int32>>() / sizeof(Int32);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Int32>>() / sizeof(Int32);
-
- private static Int32[] _data1 = new Int32[Op1ElementCount];
- private static Int32[] _data2 = new Int32[Op2ElementCount];
-
- private static Vector256<Int32> _clsVar1;
- private static Vector128<Int32> _clsVar2;
-
- private Vector256<Int32> _fld1;
- private Vector128<Int32> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Int32, Int32, Int32> _dataTable;
-
- static InsertLoadTest__InsertVector128Int321()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref _clsVar1), ref Unsafe.As<Int32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _clsVar2), ref Unsafe.As<Int32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>());
- }
-
- public InsertLoadTest__InsertVector128Int321()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int32>, byte>(ref _fld1), ref Unsafe.As<Int32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int32>, byte>(ref _fld2), ref Unsafe.As<Int32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int32>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt32(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt32(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Int32, Int32, Int32>(_data1, _data2, new Int32[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx2.InsertVector128(
- Unsafe.Read<Vector256<Int32>>(_dataTable.inArray1Ptr),
- (Int32*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx2.InsertVector128(
- Avx.LoadVector256((Int32*)(_dataTable.inArray1Ptr)),
- (Int32*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx2.InsertVector128(
- Avx.LoadAlignedVector256((Int32*)(_dataTable.inArray1Ptr)),
- (Int32*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int32>), typeof(Int32*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Int32>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int32>), typeof(Int32*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Int32*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int32>), typeof(Int32*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Int32*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx2.InsertVector128(
- _clsVar1,
- (Int32*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Int32*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Int32>>(_dataTable.inArray1Ptr);
- var right = (Int32*)_dataTable.inArray2Ptr;
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Int32*)(_dataTable.inArray1Ptr));
- var right = (Int32*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Int32*)(_dataTable.inArray1Ptr));
- var right = (Int32*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Int321();
- var result = Avx2.InsertVector128(test._fld1, (Int32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx2.InsertVector128(_fld1, (Int32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Int32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx2.InsertVector128(test._fld1, (Int32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int32> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray1 = new Int32[Op1ElementCount];
- Int32[] inArray2 = new Int32[Op2ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int32, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int32>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int32[] inArray1 = new Int32[Op1ElementCount];
- Int32[] inArray2 = new Int32[Op2ElementCount];
- Int32[] outArray = new Int32[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Int32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int32>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Int32[] left, Int32[] right, Int32[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 3 ? result[i] != right[i - 4] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.InsertVector128)}<Int32>(Vector256<Int32>, Vector128<Int32>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128Int641Load()
- {
- var test = new InsertLoadTest__InsertVector128Int641();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128Int641
- {
- private struct TestStruct
- {
- public Vector256<Int64> _fld1;
- public Vector128<Int64> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref testStruct._fld1), ref Unsafe.As<Int64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int64>, byte>(ref testStruct._fld2), ref Unsafe.As<Int64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128Int641 testClass)
- {
- var result = Avx2.InsertVector128(_fld1, (Int64*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (Int64*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<Int64>>() / sizeof(Int64);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Int64>>() / sizeof(Int64);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<Int64>>() / sizeof(Int64);
-
- private static Int64[] _data1 = new Int64[Op1ElementCount];
- private static Int64[] _data2 = new Int64[Op2ElementCount];
-
- private static Vector256<Int64> _clsVar1;
- private static Vector128<Int64> _clsVar2;
-
- private Vector256<Int64> _fld1;
- private Vector128<Int64> _fld2;
-
- private SimpleBinaryOpTest__DataTable<Int64, Int64, Int64> _dataTable;
-
- static InsertLoadTest__InsertVector128Int641()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref _clsVar1), ref Unsafe.As<Int64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int64>, byte>(ref _clsVar2), ref Unsafe.As<Int64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int64>>());
- }
-
- public InsertLoadTest__InsertVector128Int641()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<Int64>, byte>(ref _fld1), ref Unsafe.As<Int64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Int64>, byte>(ref _fld2), ref Unsafe.As<Int64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Int64>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetInt64(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetInt64(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<Int64, Int64, Int64>(_data1, _data2, new Int64[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx2.InsertVector128(
- Unsafe.Read<Vector256<Int64>>(_dataTable.inArray1Ptr),
- (Int64*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx2.InsertVector128(
- Avx.LoadVector256((Int64*)(_dataTable.inArray1Ptr)),
- (Int64*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx2.InsertVector128(
- Avx.LoadAlignedVector256((Int64*)(_dataTable.inArray1Ptr)),
- (Int64*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int64>), typeof(Int64*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<Int64>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int64>), typeof(Int64*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((Int64*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<Int64>), typeof(Int64*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((Int64*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(Int64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<Int64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx2.InsertVector128(
- _clsVar1,
- (Int64*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (Int64*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<Int64>>(_dataTable.inArray1Ptr);
- var right = (Int64*)_dataTable.inArray2Ptr;
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((Int64*)(_dataTable.inArray1Ptr));
- var right = (Int64*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((Int64*)(_dataTable.inArray1Ptr));
- var right = (Int64*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128Int641();
- var result = Avx2.InsertVector128(test._fld1, (Int64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx2.InsertVector128(_fld1, (Int64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (Int64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx2.InsertVector128(test._fld1, (Int64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (Int64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<Int64> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray1 = new Int64[Op1ElementCount];
- Int64[] inArray2 = new Int64[Op2ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<Int64, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int64>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- Int64[] inArray1 = new Int64[Op1ElementCount];
- Int64[] inArray2 = new Int64[Op2ElementCount];
- Int64[] outArray = new Int64[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<Int64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Int64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Int64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<Int64>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(Int64[] left, Int64[] right, Int64[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 1 ? result[i] != right[i - 2] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.InsertVector128)}<Int64>(Vector256<Int64>, Vector128<Int64>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128SByte1Load()
- {
- var test = new InsertLoadTest__InsertVector128SByte1();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128SByte1
- {
- private struct TestStruct
- {
- public Vector256<SByte> _fld1;
- public Vector128<SByte> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref testStruct._fld1), ref Unsafe.As<SByte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref testStruct._fld2), ref Unsafe.As<SByte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128SByte1 testClass)
- {
- var result = Avx2.InsertVector128(_fld1, (SByte*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (SByte*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<SByte>>() / sizeof(SByte);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<SByte>>() / sizeof(SByte);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<SByte>>() / sizeof(SByte);
-
- private static SByte[] _data1 = new SByte[Op1ElementCount];
- private static SByte[] _data2 = new SByte[Op2ElementCount];
-
- private static Vector256<SByte> _clsVar1;
- private static Vector128<SByte> _clsVar2;
-
- private Vector256<SByte> _fld1;
- private Vector128<SByte> _fld2;
-
- private SimpleBinaryOpTest__DataTable<SByte, SByte, SByte> _dataTable;
-
- static InsertLoadTest__InsertVector128SByte1()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref _clsVar1), ref Unsafe.As<SByte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref _clsVar2), ref Unsafe.As<SByte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>());
- }
-
- public InsertLoadTest__InsertVector128SByte1()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<SByte>, byte>(ref _fld1), ref Unsafe.As<SByte, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<SByte>, byte>(ref _fld2), ref Unsafe.As<SByte, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<SByte>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSByte(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSByte(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<SByte, SByte, SByte>(_data1, _data2, new SByte[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx2.InsertVector128(
- Unsafe.Read<Vector256<SByte>>(_dataTable.inArray1Ptr),
- (SByte*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx2.InsertVector128(
- Avx.LoadVector256((SByte*)(_dataTable.inArray1Ptr)),
- (SByte*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx2.InsertVector128(
- Avx.LoadAlignedVector256((SByte*)(_dataTable.inArray1Ptr)),
- (SByte*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<SByte>), typeof(SByte*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<SByte>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(SByte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<SByte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<SByte>), typeof(SByte*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((SByte*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(SByte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<SByte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<SByte>), typeof(SByte*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((SByte*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(SByte*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<SByte>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx2.InsertVector128(
- _clsVar1,
- (SByte*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (SByte*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<SByte>>(_dataTable.inArray1Ptr);
- var right = (SByte*)_dataTable.inArray2Ptr;
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((SByte*)(_dataTable.inArray1Ptr));
- var right = (SByte*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((SByte*)(_dataTable.inArray1Ptr));
- var right = (SByte*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128SByte1();
- var result = Avx2.InsertVector128(test._fld1, (SByte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (SByte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx2.InsertVector128(_fld1, (SByte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (SByte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx2.InsertVector128(test._fld1, (SByte*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (SByte*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<SByte> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray1 = new SByte[Op1ElementCount];
- SByte[] inArray2 = new SByte[Op2ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<SByte, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<SByte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<SByte>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- SByte[] inArray1 = new SByte[Op1ElementCount];
- SByte[] inArray2 = new SByte[Op2ElementCount];
- SByte[] outArray = new SByte[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<SByte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<SByte>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<SByte, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<SByte>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(SByte[] left, SByte[] right, SByte[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 15 ? result[i] != right[i - 16] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.InsertVector128)}<SByte>(Vector256<SByte>, Vector128<SByte>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128UInt161Load()
- {
- var test = new InsertLoadTest__InsertVector128UInt161();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128UInt161
- {
- private struct TestStruct
- {
- public Vector256<UInt16> _fld1;
- public Vector128<UInt16> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref testStruct._fld1), ref Unsafe.As<UInt16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref testStruct._fld2), ref Unsafe.As<UInt16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128UInt161 testClass)
- {
- var result = Avx2.InsertVector128(_fld1, (UInt16*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (UInt16*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt16>>() / sizeof(UInt16);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<UInt16>>() / sizeof(UInt16);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<UInt16>>() / sizeof(UInt16);
-
- private static UInt16[] _data1 = new UInt16[Op1ElementCount];
- private static UInt16[] _data2 = new UInt16[Op2ElementCount];
-
- private static Vector256<UInt16> _clsVar1;
- private static Vector128<UInt16> _clsVar2;
-
- private Vector256<UInt16> _fld1;
- private Vector128<UInt16> _fld2;
-
- private SimpleBinaryOpTest__DataTable<UInt16, UInt16, UInt16> _dataTable;
-
- static InsertLoadTest__InsertVector128UInt161()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref _clsVar1), ref Unsafe.As<UInt16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _clsVar2), ref Unsafe.As<UInt16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
- }
-
- public InsertLoadTest__InsertVector128UInt161()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt16>, byte>(ref _fld1), ref Unsafe.As<UInt16, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt16>, byte>(ref _fld2), ref Unsafe.As<UInt16, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt16(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt16(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<UInt16, UInt16, UInt16>(_data1, _data2, new UInt16[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx2.InsertVector128(
- Unsafe.Read<Vector256<UInt16>>(_dataTable.inArray1Ptr),
- (UInt16*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx2.InsertVector128(
- Avx.LoadVector256((UInt16*)(_dataTable.inArray1Ptr)),
- (UInt16*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx2.InsertVector128(
- Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArray1Ptr)),
- (UInt16*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt16>), typeof(UInt16*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<UInt16>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt16>), typeof(UInt16*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((UInt16*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt16>), typeof(UInt16*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt16*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt16>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx2.InsertVector128(
- _clsVar1,
- (UInt16*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (UInt16*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<UInt16>>(_dataTable.inArray1Ptr);
- var right = (UInt16*)_dataTable.inArray2Ptr;
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((UInt16*)(_dataTable.inArray1Ptr));
- var right = (UInt16*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((UInt16*)(_dataTable.inArray1Ptr));
- var right = (UInt16*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128UInt161();
- var result = Avx2.InsertVector128(test._fld1, (UInt16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx2.InsertVector128(_fld1, (UInt16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (UInt16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx2.InsertVector128(test._fld1, (UInt16*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt16*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt16> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray1 = new UInt16[Op1ElementCount];
- UInt16[] inArray2 = new UInt16[Op2ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt16[] inArray1 = new UInt16[Op1ElementCount];
- UInt16[] inArray2 = new UInt16[Op2ElementCount];
- UInt16[] outArray = new UInt16[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt16>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt16, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt16>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(UInt16[] left, UInt16[] right, UInt16[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 7 ? result[i] != right[i - 8] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.InsertVector128)}<UInt16>(Vector256<UInt16>, Vector128<UInt16>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128UInt321Load()
- {
- var test = new InsertLoadTest__InsertVector128UInt321();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128UInt321
- {
- private struct TestStruct
- {
- public Vector256<UInt32> _fld1;
- public Vector128<UInt32> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref testStruct._fld1), ref Unsafe.As<UInt32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref testStruct._fld2), ref Unsafe.As<UInt32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128UInt321 testClass)
- {
- var result = Avx2.InsertVector128(_fld1, (UInt32*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (UInt32*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt32>>() / sizeof(UInt32);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<UInt32>>() / sizeof(UInt32);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<UInt32>>() / sizeof(UInt32);
-
- private static UInt32[] _data1 = new UInt32[Op1ElementCount];
- private static UInt32[] _data2 = new UInt32[Op2ElementCount];
-
- private static Vector256<UInt32> _clsVar1;
- private static Vector128<UInt32> _clsVar2;
-
- private Vector256<UInt32> _fld1;
- private Vector128<UInt32> _fld2;
-
- private SimpleBinaryOpTest__DataTable<UInt32, UInt32, UInt32> _dataTable;
-
- static InsertLoadTest__InsertVector128UInt321()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref _clsVar1), ref Unsafe.As<UInt32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref _clsVar2), ref Unsafe.As<UInt32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
- }
-
- public InsertLoadTest__InsertVector128UInt321()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt32>, byte>(ref _fld1), ref Unsafe.As<UInt32, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt32>, byte>(ref _fld2), ref Unsafe.As<UInt32, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt32(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt32(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<UInt32, UInt32, UInt32>(_data1, _data2, new UInt32[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx2.InsertVector128(
- Unsafe.Read<Vector256<UInt32>>(_dataTable.inArray1Ptr),
- (UInt32*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx2.InsertVector128(
- Avx.LoadVector256((UInt32*)(_dataTable.inArray1Ptr)),
- (UInt32*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx2.InsertVector128(
- Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArray1Ptr)),
- (UInt32*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt32>), typeof(UInt32*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<UInt32>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt32>), typeof(UInt32*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((UInt32*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt32>), typeof(UInt32*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt32*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt32>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx2.InsertVector128(
- _clsVar1,
- (UInt32*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (UInt32*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<UInt32>>(_dataTable.inArray1Ptr);
- var right = (UInt32*)_dataTable.inArray2Ptr;
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((UInt32*)(_dataTable.inArray1Ptr));
- var right = (UInt32*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((UInt32*)(_dataTable.inArray1Ptr));
- var right = (UInt32*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128UInt321();
- var result = Avx2.InsertVector128(test._fld1, (UInt32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx2.InsertVector128(_fld1, (UInt32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (UInt32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx2.InsertVector128(test._fld1, (UInt32*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt32*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt32> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray1 = new UInt32[Op1ElementCount];
- UInt32[] inArray2 = new UInt32[Op2ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt32[] inArray1 = new UInt32[Op1ElementCount];
- UInt32[] inArray2 = new UInt32[Op2ElementCount];
- UInt32[] outArray = new UInt32[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt32>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt32, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt32>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(UInt32[] left, UInt32[] right, UInt32[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 3 ? result[i] != right[i - 4] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.InsertVector128)}<UInt32>(Vector256<UInt32>, Vector128<UInt32>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void InsertVector128UInt641Load()
- {
- var test = new InsertLoadTest__InsertVector128UInt641();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if (Avx.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__InsertVector128UInt641
- {
- private struct TestStruct
- {
- public Vector256<UInt64> _fld1;
- public Vector128<UInt64> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref testStruct._fld1), ref Unsafe.As<UInt64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt64>, byte>(ref testStruct._fld2), ref Unsafe.As<UInt64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__InsertVector128UInt641 testClass)
- {
- var result = Avx2.InsertVector128(_fld1, (UInt64*)testClass._dataTable.inArray2Ptr, 1);
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, (UInt64*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = 32;
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector256<UInt64>>() / sizeof(UInt64);
- private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<UInt64>>() / sizeof(UInt64);
- private static readonly int RetElementCount = Unsafe.SizeOf<Vector256<UInt64>>() / sizeof(UInt64);
-
- private static UInt64[] _data1 = new UInt64[Op1ElementCount];
- private static UInt64[] _data2 = new UInt64[Op2ElementCount];
-
- private static Vector256<UInt64> _clsVar1;
- private static Vector128<UInt64> _clsVar2;
-
- private Vector256<UInt64> _fld1;
- private Vector128<UInt64> _fld2;
-
- private SimpleBinaryOpTest__DataTable<UInt64, UInt64, UInt64> _dataTable;
-
- static InsertLoadTest__InsertVector128UInt641()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _clsVar1), ref Unsafe.As<UInt64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt64>, byte>(ref _clsVar2), ref Unsafe.As<UInt64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
- }
-
- public InsertLoadTest__InsertVector128UInt641()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _fld1), ref Unsafe.As<UInt64, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<UInt64>, byte>(ref _fld2), ref Unsafe.As<UInt64, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetUInt64(); }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetUInt64(); }
- _dataTable = new SimpleBinaryOpTest__DataTable<UInt64, UInt64, UInt64>(_data1, _data2, new UInt64[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => Avx2.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = Avx2.InsertVector128(
- Unsafe.Read<Vector256<UInt64>>(_dataTable.inArray1Ptr),
- (UInt64*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = Avx2.InsertVector128(
- Avx.LoadVector256((UInt64*)(_dataTable.inArray1Ptr)),
- (UInt64*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = Avx2.InsertVector128(
- Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArray1Ptr)),
- (UInt64*)(_dataTable.inArray2Ptr),
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt64>), typeof(UInt64*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<Vector256<UInt64>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt64>), typeof(UInt64*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadVector256((UInt64*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof(Avx2).GetMethod(nameof(Avx2.InsertVector128), new Type[] { typeof(Vector256<UInt64>), typeof(UInt64*), typeof(byte) })
- .Invoke(null, new object[] {
- Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof(UInt64*)),
- (byte)1
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = Avx2.InsertVector128(
- _clsVar1,
- (UInt64*)_dataTable.inArray2Ptr,
- 1
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, (UInt64*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<Vector256<UInt64>>(_dataTable.inArray1Ptr);
- var right = (UInt64*)_dataTable.inArray2Ptr;
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = Avx.LoadVector256((UInt64*)(_dataTable.inArray1Ptr));
- var right = (UInt64*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArray1Ptr));
- var right = (UInt64*)(_dataTable.inArray2Ptr);
- var result = Avx2.InsertVector128(left, right, 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__InsertVector128UInt641();
- var result = Avx2.InsertVector128(test._fld1, (UInt64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = Avx2.InsertVector128(_fld1, (UInt64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, (UInt64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = Avx2.InsertVector128(test._fld1, (UInt64*)(_dataTable.inArray2Ptr), 1);
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, (UInt64*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult(Vector256<UInt64> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray1 = new UInt64[Op1ElementCount];
- UInt64[] inArray2 = new UInt64[Op2ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- UInt64[] inArray1 = new UInt64[Op1ElementCount];
- UInt64[] inArray2 = new UInt64[Op2ElementCount];
- UInt64[] outArray = new UInt64[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<UInt64>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<Vector256<UInt64>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(UInt64[] left, UInt64[] right, UInt64[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if (result[0] != left[0])
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ((i > 1 ? result[i] != right[i - 2] : result[i] != left[i]))
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof(Avx2)}.{nameof(Avx2.InsertVector128)}<UInt64>(Vector256<UInt64>, Vector128<UInt64>.1): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
["ExtractVector128.UInt32.1"] = ExtractVector128UInt321,
["ExtractVector128.Int64.1"] = ExtractVector128Int641,
["ExtractVector128.UInt64.1"] = ExtractVector128UInt641,
- ["ExtractVector128.Byte.1.Store"] = ExtractVector128Byte1Store,
- ["ExtractVector128.SByte.1.Store"] = ExtractVector128SByte1Store,
- ["ExtractVector128.Int16.1.Store"] = ExtractVector128Int161Store,
- ["ExtractVector128.UInt16.1.Store"] = ExtractVector128UInt161Store,
- ["ExtractVector128.Int32.1.Store"] = ExtractVector128Int321Store,
- ["ExtractVector128.UInt32.1.Store"] = ExtractVector128UInt321Store,
- ["ExtractVector128.Int64.1.Store"] = ExtractVector128Int641Store,
- ["ExtractVector128.UInt64.1.Store"] = ExtractVector128UInt641Store,
["InsertVector128.Byte.1"] = InsertVector128Byte1,
["InsertVector128.SByte.1"] = InsertVector128SByte1,
["InsertVector128.Int16.1"] = InsertVector128Int161,
["InsertVector128.UInt32.1"] = InsertVector128UInt321,
["InsertVector128.Int64.1"] = InsertVector128Int641,
["InsertVector128.UInt64.1"] = InsertVector128UInt641,
- ["InsertVector128.Byte.1.Load"] = InsertVector128Byte1Load,
- ["InsertVector128.SByte.1.Load"] = InsertVector128SByte1Load,
- ["InsertVector128.Int16.1.Load"] = InsertVector128Int161Load,
- ["InsertVector128.UInt16.1.Load"] = InsertVector128UInt161Load,
- ["InsertVector128.Int32.1.Load"] = InsertVector128Int321Load,
- ["InsertVector128.UInt32.1.Load"] = InsertVector128UInt321Load,
- ["InsertVector128.Int64.1.Load"] = InsertVector128Int641Load,
- ["InsertVector128.UInt64.1.Load"] = InsertVector128UInt641Load,
["MaskLoad.Int32"] = MaskLoadInt32,
["MaskLoad.UInt32"] = MaskLoadUInt32,
["MaskLoad.Int64"] = MaskLoadInt64,
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void {Method}{RetBaseType}{Imm}Store()
- {
- var test = new ExtractStoreTest__{Method}{RetBaseType}{Imm}();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if ({LoadIsa}.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if ({LoadIsa}.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if ({LoadIsa}.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class ExtractStoreTest__{Method}{RetBaseType}{Imm}
- {
- private struct TestStruct
- {
- public {Op1VectorType}<{Op1BaseType}> _fld;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = {NextValueOp1}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref testStruct._fld), ref Unsafe.As<{Op1BaseType}, byte>(ref _data[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(ExtractStoreTest__{Method}{RetBaseType}{Imm} testClass)
- {
- {Isa}.{Method}(({Op1BaseType}*)testClass._dataTable.outArrayPtr, _fld, {Imm});
- testClass.ValidateResult(_fld, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = {LargestVectorSize};
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>() / sizeof({Op1BaseType});
- private static readonly int RetElementCount = Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>() / sizeof({RetBaseType});
-
- private static {Op1BaseType}[] _data = new {Op1BaseType}[Op1ElementCount];
-
- private static {Op1VectorType}<{Op1BaseType}> _clsVar;
-
- private {Op1VectorType}<{Op1BaseType}> _fld;
-
- private SimpleUnaryOpTest__DataTable<{RetBaseType}, {Op1BaseType}> _dataTable;
-
- static ExtractStoreTest__{Method}{RetBaseType}{Imm}()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = {NextValueOp1}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _clsVar), ref Unsafe.As<{Op1BaseType}, byte>(ref _data[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
- }
-
- public ExtractStoreTest__{Method}{RetBaseType}{Imm}()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = {NextValueOp1}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _fld), ref Unsafe.As<{Op1BaseType}, byte>(ref _data[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data[i] = {NextValueOp1}; }
- _dataTable = new SimpleUnaryOpTest__DataTable<{RetBaseType}, {Op1BaseType}>(_data, new {RetBaseType}[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => {Isa}.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- {Isa}.{Method}(
- ({Op1BaseType}*)_dataTable.outArrayPtr,
- Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArrayPtr),
- {Imm}
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- {Isa}.{Method}(
- ({Op1BaseType}*)_dataTable.outArrayPtr,
- {LoadIsa}.Load{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr)),
- {Imm}
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- {Isa}.{Method}(
- ({Op1BaseType}*)_dataTable.outArrayPtr,
- {LoadIsa}.LoadAligned{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr)),
- {Imm}
- );
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1BaseType}*), typeof({Op1VectorType}<{Op1BaseType}>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof({Op1BaseType}*)),
- Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArrayPtr),
- (byte){Imm}
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1BaseType}*), typeof({Op1VectorType}<{Op1BaseType}>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof({Op1BaseType}*)),
- {LoadIsa}.Load{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr)),
- (byte){Imm}
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1BaseType}*), typeof({Op1VectorType}<{Op1BaseType}>), typeof(byte) })
- .Invoke(null, new object[] {
- Pointer.Box(_dataTable.outArrayPtr, typeof({Op1BaseType}*)),
- {LoadIsa}.LoadAligned{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr)),
- (byte){Imm}
- });
-
- ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- {Isa}.{Method}(
- ({Op1BaseType}*)_dataTable.outArrayPtr,
- _clsVar,
- {Imm}
- );
-
- ValidateResult(_clsVar, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var firstOp = Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArrayPtr);
- {Isa}.{Method}(({Op1BaseType}*)_dataTable.outArrayPtr, firstOp, {Imm});
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var firstOp = {LoadIsa}.Load{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr));
- {Isa}.{Method}(({Op1BaseType}*)_dataTable.outArrayPtr, firstOp, {Imm});
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var firstOp = {LoadIsa}.LoadAligned{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArrayPtr));
- {Isa}.{Method}(({Op1BaseType}*)_dataTable.outArrayPtr, firstOp, {Imm});
- ValidateResult(firstOp, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new ExtractStoreTest__{Method}{RetBaseType}{Imm}();
- {Isa}.{Method}(({Op1BaseType}*)_dataTable.outArrayPtr, test._fld, {Imm});
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- {Isa}.{Method}(({Op1BaseType}*)_dataTable.outArrayPtr, _fld, {Imm});
- ValidateResult(_fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- {Isa}.{Method}(({Op1BaseType}*)_dataTable.outArrayPtr, test._fld, {Imm});
- ValidateResult(test._fld, _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult({Op1VectorType}<{Op1BaseType}> firstOp, void* result, [CallerMemberName] string method = "")
- {
- {Op1BaseType}[] inArray = new {Op1BaseType}[Op1ElementCount];
- {RetBaseType}[] outArray = new {RetBaseType}[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray[0]), firstOp);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
- {
- {Op1BaseType}[] inArray = new {Op1BaseType}[Op1ElementCount];
- {RetBaseType}[] outArray = new {RetBaseType}[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
-
- ValidateResult(inArray, outArray, method);
- }
-
- private void ValidateResult({Op1BaseType}[] firstOp, {RetBaseType}[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if ({ValidateFirstResult})
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ({ValidateRemainingResults})
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof({Isa})}.{nameof({Isa}.{Method})}<{RetBaseType}>({Op1VectorType}<{Op1BaseType}><9>): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "result[0] != firstOp[4]", ["ValidateRemainingResults"] = "result[i] != firstOp[i+4]"}),
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "result[0] != firstOp[2]", ["ValidateRemainingResults"] = "result[i] != firstOp[i+2]"}),
("ImmUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "result[0] != firstOp[2]", ["ValidateRemainingResults"] = "result[i] != firstOp[i+2]"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Byte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "result[0] != firstOp[16]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 16])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "SByte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "result[0] != firstOp[16]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 16])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "result[0] != firstOp[8]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 8])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "result[0] != firstOp[8]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 8])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "result[0] != firstOp[4]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 4])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "result[0] != firstOp[4]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 4])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "result[0] != firstOp[2]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 2])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "result[0] != firstOp[2]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 2])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Single", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Single", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(firstOp[4])", ["ValidateRemainingResults"] = "(BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(firstOp[i + 4]))"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Double", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(firstOp[2])", ["ValidateRemainingResults"] = "(BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(firstOp[i + 2]))"}),
("ImmBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "result[i] != (i < 16 ? left[i] : right[i-16])"}),
("ImmBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "SByte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "SByte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "result[i] != (i < 16 ? left[i] : right[i-16])"}),
("ImmBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "result[i] != (i < 8 ? left[i] : right[i-8])"}),
("ImmBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "result[i] != (i < 2 ? left[i] : right[i-2])"}),
("ImmBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Single", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(left[0])", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != (i < 4 ? BitConverter.SingleToInt32Bits(left[i]) : BitConverter.SingleToInt32Bits(right[i-4]))"}),
("ImmBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(left[0])", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[i]) != (i < 2 ? BitConverter.DoubleToInt64Bits(left[i]) : BitConverter.DoubleToInt64Bits(right[i-2]))"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 15 ? result[i] != right[i - 16] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "SByte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "SByte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 15 ? result[i] != right[i - 16] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 7 ? result[i] != right[i - 8] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 7 ? result[i] != right[i - 8] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 3 ? result[i] != right[i - 4] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 3 ? result[i] != right[i - 4] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 1 ? result[i] != right[i - 2] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 1 ? result[i] != right[i - 2] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Single", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Single", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Single", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["NextValueOp2"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(left[0])", ["ValidateRemainingResults"] = "(i > 3 ? BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(right[i - 4]) : BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(left[i]))"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Double", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Double", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["NextValueOp2"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(left[0])", ["ValidateRemainingResults"] = "(i > 1 ? BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(right[i - 2]) : BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(left[i]))"}),
("SimpleUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "Floor", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Double", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Double", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetDouble()", ["ValidateFirstResult"] = "BitConverter.DoubleToInt64Bits(result[0]) != BitConverter.DoubleToInt64Bits(Math.Floor(firstOp[0]))", ["ValidateRemainingResults"] = "BitConverter.DoubleToInt64Bits(result[i]) != BitConverter.DoubleToInt64Bits(Math.Floor(firstOp[i]))"}),
("SimpleUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["LoadIsa"] = "Avx", ["Method"] = "Floor", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Single", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Single", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(result[0]) != BitConverter.SingleToInt32Bits(MathF.Floor(firstOp[0]))", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(result[i]) != BitConverter.SingleToInt32Bits(MathF.Floor(firstOp[i]))"}),
("LoadUnOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx", ["Method"] = "LoadVector256", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Single", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Single", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSingle()", ["ValidateFirstResult"] = "BitConverter.SingleToInt32Bits(firstOp[0]) != BitConverter.SingleToInt32Bits(result[0])", ["ValidateRemainingResults"] = "BitConverter.SingleToInt32Bits(firstOp[i]) != BitConverter.SingleToInt32Bits(result[i])"}),
("ExtractVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "result[0] != firstOp[4]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 4])"}),
("ExtractVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "result[0] != firstOp[2]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 2])"}),
("ExtractVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "result[0] != firstOp[2]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 2])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Byte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "result[0] != firstOp[16]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 16])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "SByte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "result[0] != firstOp[16]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 16])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "result[0] != firstOp[8]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 8])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "result[0] != firstOp[8]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 8])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "result[0] != firstOp[4]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 4])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "result[0] != firstOp[4]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 4])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "result[0] != firstOp[2]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 2])"}),
- ("ExtractStoreTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "ExtractVector128", ["RetVectorType"] = "Vector128", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "result[0] != firstOp[2]", ["ValidateRemainingResults"] = "(result[i] != firstOp[i + 2])"}),
("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 15 ? result[i] != right[i - 16] : result[i] != left[i])"}),
("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "SByte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "SByte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 15 ? result[i] != right[i - 16] : result[i] != left[i])"}),
("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 7 ? result[i] != right[i - 8] : result[i] != left[i])"}),
("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 3 ? result[i] != right[i - 4] : result[i] != left[i])"}),
("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 1 ? result[i] != right[i - 2] : result[i] != left[i])"}),
("InsertVector128Test.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 1 ? result[i] != right[i - 2] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Byte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Byte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Byte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetByte()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 15 ? result[i] != right[i - 16] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "SByte", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "SByte", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "SByte", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetSByte()", ["NextValueOp2"] = "TestLibrary.Generator.GetSByte()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 15 ? result[i] != right[i - 16] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt16()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 7 ? result[i] != right[i - 8] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt16", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt16", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt16", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt16()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt16()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 7 ? result[i] != right[i - 8] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 3 ? result[i] != right[i - 4] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt32", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt32", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 3 ? result[i] != right[i - 4] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "Int64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 1 ? result[i] != right[i - 2] : result[i] != left[i])"}),
- ("InsertLoadTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "InsertVector128", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt64", ["Op2VectorType"] = "Vector128", ["Op2BaseType"] = "UInt64", ["Imm"] = "1", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt64()", ["ValidateFirstResult"] = "result[0] != left[0]", ["ValidateRemainingResults"] = "(i > 1 ? result[i] != right[i - 2] : result[i] != left[i])"}),
("LoadBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "MaskLoad", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int32", ["Op2VectorType"] = "Vector256", ["Op2BaseType"] = "Int32", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt32()", ["ValidateFirstResult"] = "result[0] != ((right[0] < 0) ? left[0] : 0)", ["ValidateRemainingResults"] = "result[i] != ((right[i] < 0) ? left[i] : 0)"}),
("LoadBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "MaskLoad", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "UInt32", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "UInt32", ["Op2VectorType"] = "Vector256", ["Op2BaseType"] = "UInt32", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetUInt32()", ["NextValueOp2"] = "TestLibrary.Generator.GetUInt32()", ["ValidateFirstResult"] = "result[0] != (((right[0] & (1U << 31)) != 0) ? left[0] : 0)", ["ValidateRemainingResults"] = "result[i] != (((right[i] & (1U << 31)) != 0) ? left[i] : 0)"}),
("LoadBinOpTest.template", new Dictionary<string, string> { ["Isa"] = "Avx2", ["LoadIsa"] = "Avx", ["Method"] = "MaskLoad", ["RetVectorType"] = "Vector256", ["RetBaseType"] = "Int64", ["Op1VectorType"] = "Vector256", ["Op1BaseType"] = "Int64", ["Op2VectorType"] = "Vector256", ["Op2BaseType"] = "Int64", ["LargestVectorSize"] = "32", ["NextValueOp1"] = "TestLibrary.Generator.GetInt64()", ["NextValueOp2"] = "TestLibrary.Generator.GetInt64()", ["ValidateFirstResult"] = "result[0] != ((right[0] < 0) ? left[0] : 0)", ["ValidateRemainingResults"] = "result[i] != ((right[i] < 0) ? left[i] : 0)"}),
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/******************************************************************************
- * This file is auto-generated from a template file by the GenerateTests.csx *
- * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
- * changes, please update the corresponding template and run according to the *
- * directions listed in the file. *
- ******************************************************************************/
-
-using System;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Runtime.Intrinsics;
-using System.Runtime.Intrinsics.X86;
-using static System.Runtime.Intrinsics.X86.Sse2;
-
-namespace JIT.HardwareIntrinsics.X86
-{
- public static partial class Program
- {
- private static void {Method}{RetBaseType}{Imm}Load()
- {
- var test = new InsertLoadTest__{Method}{RetBaseType}{Imm}();
-
- if (test.IsSupported)
- {
- // Validates basic functionality works, using Unsafe.Read
- test.RunBasicScenario_UnsafeRead();
-
- if ({LoadIsa}.IsSupported)
- {
- // Validates basic functionality works, using Load
- test.RunBasicScenario_Load();
-
- // Validates basic functionality works, using LoadAligned
- test.RunBasicScenario_LoadAligned();
- }
-
- // Validates calling via reflection works, using Unsafe.Read
- test.RunReflectionScenario_UnsafeRead();
-
- if ({LoadIsa}.IsSupported)
- {
- // Validates calling via reflection works, using Load
- test.RunReflectionScenario_Load();
-
- // Validates calling via reflection works, using LoadAligned
- test.RunReflectionScenario_LoadAligned();
- }
-
- // Validates passing a static member works
- test.RunClsVarScenario();
-
- // Validates passing a local works, using Unsafe.Read
- test.RunLclVarScenario_UnsafeRead();
-
- if ({LoadIsa}.IsSupported)
- {
- // Validates passing a local works, using Load
- test.RunLclVarScenario_Load();
-
- // Validates passing a local works, using LoadAligned
- test.RunLclVarScenario_LoadAligned();
- }
-
- // Validates passing the field of a local class works
- test.RunClassLclFldScenario();
-
- // Validates passing an instance member of a class works
- test.RunClassFldScenario();
-
- // Validates passing the field of a local struct works
- test.RunStructLclFldScenario();
-
- // Validates passing an instance member of a struct works
- test.RunStructFldScenario();
- }
- else
- {
- // Validates we throw on unsupported hardware
- test.RunUnsupportedScenario();
- }
-
- if (!test.Succeeded)
- {
- throw new Exception("One or more scenarios did not complete as expected.");
- }
- }
- }
-
- public sealed unsafe class InsertLoadTest__{Method}{RetBaseType}{Imm}
- {
- private struct TestStruct
- {
- public {Op1VectorType}<{Op1BaseType}> _fld1;
- public {Op2VectorType}<{Op2BaseType}> _fld2;
-
- public static TestStruct Create()
- {
- var testStruct = new TestStruct();
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref testStruct._fld1), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = {NextValueOp2}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2VectorType}<{Op2BaseType}>, byte>(ref testStruct._fld2), ref Unsafe.As<{Op2BaseType}, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>());
-
- return testStruct;
- }
-
- public void RunStructFldScenario(InsertLoadTest__{Method}{RetBaseType}{Imm} testClass)
- {
- var result = {Isa}.{Method}(_fld1, ({Op2BaseType}*)testClass._dataTable.inArray2Ptr, {Imm});
-
- Unsafe.Write(testClass._dataTable.outArrayPtr, result);
- testClass.ValidateResult(_fld1, ({Op2BaseType}*)testClass._dataTable.inArray2Ptr, testClass._dataTable.outArrayPtr);
- }
- }
-
- private static readonly int LargestVectorSize = {LargestVectorSize};
-
- private static readonly int Op1ElementCount = Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>() / sizeof({Op1BaseType});
- private static readonly int Op2ElementCount = Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>() / sizeof({Op2BaseType});
- private static readonly int RetElementCount = Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>() / sizeof({RetBaseType});
-
- private static {Op1BaseType}[] _data1 = new {Op1BaseType}[Op1ElementCount];
- private static {Op2BaseType}[] _data2 = new {Op2BaseType}[Op2ElementCount];
-
- private static {Op1VectorType}<{Op1BaseType}> _clsVar1;
- private static {Op2VectorType}<{Op2BaseType}> _clsVar2;
-
- private {Op1VectorType}<{Op1BaseType}> _fld1;
- private {Op2VectorType}<{Op2BaseType}> _fld2;
-
- private SimpleBinaryOpTest__DataTable<{RetBaseType}, {Op1BaseType}, {Op2BaseType}> _dataTable;
-
- static InsertLoadTest__{Method}{RetBaseType}{Imm}()
- {
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _clsVar1), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = {NextValueOp2}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2VectorType}<{Op2BaseType}>, byte>(ref _clsVar2), ref Unsafe.As<{Op2BaseType}, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>());
- }
-
- public InsertLoadTest__{Method}{RetBaseType}{Imm}()
- {
- Succeeded = true;
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _fld1), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = {NextValueOp2}; }
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2VectorType}<{Op2BaseType}>, byte>(ref _fld2), ref Unsafe.As<{Op2BaseType}, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>());
-
- for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; }
- for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = {NextValueOp2}; }
- _dataTable = new SimpleBinaryOpTest__DataTable<{RetBaseType}, {Op1BaseType}, {Op2BaseType}>(_data1, _data2, new {RetBaseType}[RetElementCount], LargestVectorSize);
- }
-
- public bool IsSupported => {Isa}.IsSupported;
-
- public bool Succeeded { get; set; }
-
- public void RunBasicScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_UnsafeRead));
-
- var result = {Isa}.{Method}(
- Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArray1Ptr),
- ({Op2BaseType}*)_dataTable.inArray2Ptr,
- {Imm}
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_Load));
-
- var result = {Isa}.{Method}(
- {LoadIsa}.Load{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArray1Ptr)),
- ({Op2BaseType}*)(_dataTable.inArray2Ptr),
- {Imm}
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunBasicScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunBasicScenario_LoadAligned));
-
- var result = {Isa}.{Method}(
- {LoadIsa}.LoadAligned{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArray1Ptr)),
- ({Op2BaseType}*)(_dataTable.inArray2Ptr),
- {Imm}
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_UnsafeRead));
-
- var result = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1VectorType}<{Op1BaseType}>), typeof({Op2BaseType}*), typeof(byte) })
- .Invoke(null, new object[] {
- Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArray1Ptr),
- Pointer.Box(_dataTable.inArray2Ptr, typeof({Op2BaseType}*)),
- (byte){Imm}
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_Load));
-
- var result = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1VectorType}<{Op1BaseType}>), typeof({Op2BaseType}*), typeof(byte) })
- .Invoke(null, new object[] {
- {LoadIsa}.Load{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof({Op2BaseType}*)),
- (byte){Imm}
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunReflectionScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunReflectionScenario_LoadAligned));
-
- var result = typeof({Isa}).GetMethod(nameof({Isa}.{Method}), new Type[] { typeof({Op1VectorType}<{Op1BaseType}>), typeof({Op2BaseType}*), typeof(byte) })
- .Invoke(null, new object[] {
- {LoadIsa}.LoadAligned{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArray1Ptr)),
- Pointer.Box(_dataTable.inArray2Ptr, typeof({Op2BaseType}*)),
- (byte){Imm}
- });
-
- Unsafe.Write(_dataTable.outArrayPtr, ({RetVectorType}<{RetBaseType}>)(result));
- ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunClsVarScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClsVarScenario));
-
- var result = {Isa}.{Method}(
- _clsVar1,
- ({Op2BaseType}*)_dataTable.inArray2Ptr,
- {Imm}
- );
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_clsVar1, ({Op2BaseType}*)_dataTable.inArray2Ptr, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_UnsafeRead()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_UnsafeRead));
-
- var left = Unsafe.Read<{Op1VectorType}<{Op1BaseType}>>(_dataTable.inArray1Ptr);
- var right = ({Op2BaseType}*)_dataTable.inArray2Ptr;
- var result = {Isa}.{Method}(left, right, {Imm});
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_Load()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_Load));
-
- var left = {LoadIsa}.Load{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArray1Ptr));
- var right = ({Op2BaseType}*)(_dataTable.inArray2Ptr);
- var result = {Isa}.{Method}(left, right, {Imm});
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunLclVarScenario_LoadAligned()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunLclVarScenario_LoadAligned));
-
- var left = {LoadIsa}.LoadAligned{Op1VectorType}(({Op1BaseType}*)(_dataTable.inArray1Ptr));
- var right = ({Op2BaseType}*)(_dataTable.inArray2Ptr);
- var result = {Isa}.{Method}(left, right, {Imm});
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(left, right, _dataTable.outArrayPtr);
- }
-
- public void RunClassLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassLclFldScenario));
-
- var test = new InsertLoadTest__{Method}{RetBaseType}{Imm}();
- var result = {Isa}.{Method}(test._fld1, ({Op2BaseType}*)(_dataTable.inArray2Ptr), {Imm});
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, ({Op2BaseType}*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunClassFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunClassFldScenario));
-
- var result = {Isa}.{Method}(_fld1, ({Op2BaseType}*)(_dataTable.inArray2Ptr), {Imm});
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(_fld1, ({Op2BaseType}*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructLclFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructLclFldScenario));
-
- var test = TestStruct.Create();
- var result = {Isa}.{Method}(test._fld1, ({Op2BaseType}*)(_dataTable.inArray2Ptr), {Imm});
-
- Unsafe.Write(_dataTable.outArrayPtr, result);
- ValidateResult(test._fld1, ({Op2BaseType}*)(_dataTable.inArray2Ptr), _dataTable.outArrayPtr);
- }
-
- public void RunStructFldScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunStructFldScenario));
-
- var test = TestStruct.Create();
- test.RunStructFldScenario(this);
- }
-
- public void RunUnsupportedScenario()
- {
- TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
-
- bool succeeded = false;
-
- try
- {
- RunBasicScenario_UnsafeRead();
- }
- catch (PlatformNotSupportedException)
- {
- succeeded = true;
- }
-
- if (!succeeded)
- {
- Succeeded = false;
- }
- }
-
- private void ValidateResult({Op1VectorType}<{Op1BaseType}> left, void* right, void* result, [CallerMemberName] string method = "")
- {
- {Op1BaseType}[] inArray1 = new {Op1BaseType}[Op1ElementCount];
- {Op2BaseType}[] inArray2 = new {Op2BaseType}[Op2ElementCount];
- {RetBaseType}[] outArray = new {RetBaseType}[RetElementCount];
-
- Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray1[0]), left);
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2BaseType}, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult(void* left, void* right, void* result, [CallerMemberName] string method = "")
- {
- {Op1BaseType}[] inArray1 = new {Op1BaseType}[Op1ElementCount];
- {Op2BaseType}[] inArray2 = new {Op2BaseType}[Op2ElementCount];
- {RetBaseType}[] outArray = new {RetBaseType}[RetElementCount];
-
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op2BaseType}, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<{Op2VectorType}<{Op2BaseType}>>());
- Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
-
- ValidateResult(inArray1, inArray2, outArray, method);
- }
-
- private void ValidateResult({Op1BaseType}[] left, {Op2BaseType}[] right, {RetBaseType}[] result, [CallerMemberName] string method = "")
- {
- bool succeeded = true;
-
- if ({ValidateFirstResult})
- {
- succeeded = false;
- }
- else
- {
- for (var i = 1; i < RetElementCount; i++)
- {
- if ({ValidateRemainingResults})
- {
- succeeded = false;
- break;
- }
- }
- }
-
- if (!succeeded)
- {
- TestLibrary.TestFramework.LogInformation($"{nameof({Isa})}.{nameof({Isa}.{Method})}<{RetBaseType}>({Op1VectorType}<{Op1BaseType}>, {Op2VectorType}<{Op2BaseType}>.{Imm}): {method} failed:");
- TestLibrary.TestFramework.LogInformation($" left: ({string.Join(", ", left)})");
- TestLibrary.TestFramework.LogInformation($" right: ({string.Join(", ", right)})");
- TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
- TestLibrary.TestFramework.LogInformation(string.Empty);
-
- Succeeded = false;
- }
- }
- }
-}
Vector256<float> m03 = LoadVector128(&vectors[0]).ToVector256(); // load lower halves
Vector256<float> m14 = LoadVector128(&vectors[4]).ToVector256();
Vector256<float> m25 = LoadVector128(&vectors[8]).ToVector256();
- m03 = InsertVector128(m03, &vectors[12], 1); // load higher halves
- m14 = InsertVector128(m14, &vectors[16], 1);
- m25 = InsertVector128(m25, &vectors[20], 1);
+ m03 = InsertVector128(m03, LoadVector128(&vectors[12]), 1); // load higher halves
+ m14 = InsertVector128(m14, LoadVector128(&vectors[16]), 1);
+ m25 = InsertVector128(m25, LoadVector128(&vectors[20]), 1);
var xy = Shuffle(m14, m25, 2 << 6 | 1 << 4 | 3 << 2 | 2);
var yz = Shuffle(m03, m14, 1 << 6 | 0 << 4 | 2 << 2 | 1);