Skip to content

Commit

Permalink
Workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar committed Jul 9, 2023
1 parent b4c17c0 commit 67862f0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/External/RawIntrinsics/AVX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,22 @@ public static unsafe partial class AVX
/// <returns><c>__m256 dst {FP32}</c></returns>
public static __m256 _mm256_broadcast_ss(float* mem_addr) => System.Runtime.Intrinsics.X86.Avx.BroadcastScalarToVector256(mem_addr);

/// <summary>
/// Round the packed double-precision (64-bit) floating-point elements in "a" up to an integer value, and store the results as packed double-precision floating-point elements in "dst".
/// </summary>
/// <remarks><c>VROUNDPD ymm, ymm, imm8</c></remarks>
/// <param name="a"><c>__m256d {FP64}</c></param>
/// <returns><c>__m256d dst {FP64}</c></returns>
public static __m256d _mm256_ceil_pd(__m256d a) => System.Runtime.Intrinsics.X86.Avx.Ceiling(a.FP64);

/// <summary>
/// Round the packed single-precision (32-bit) floating-point elements in "a" up to an integer value, and store the results as packed single-precision floating-point elements in "dst".
/// </summary>
/// <remarks><c>VROUNDPS ymm, ymm, imm8</c></remarks>
/// <param name="a"><c>__m256 {FP32}</c></param>
/// <returns><c>__m256 dst {FP32}</c></returns>
public static __m256 _mm256_ceil_ps(__m256 a) => System.Runtime.Intrinsics.X86.Avx.Ceiling(a.FP32);

/// <summary>
/// Compare packed double-precision (64-bit) floating-point elements in "a" and "b" based on the comparison operand specified by "imm8", and store the results in "dst".
/// </summary>
Expand Down Expand Up @@ -986,6 +1002,15 @@ public static unsafe partial class AVX
/// <returns><c>__m256d dst {FP64}</c></returns>
public static __m256d _mm256_setr_m128d(__m128d lo, __m128d hi) => System.Runtime.Intrinsics.Vector256.Create(lo.FP64, hi.FP64);

/// <summary>
/// Set packed __m256i vector "dst" with the supplied values.
/// </summary>
/// <remarks><c>VINSERTF128 ymm, ymm, xmm, imm8</c></remarks>
/// <param name="lo"><c>__m128i {M128}</c></param>
/// <param name="hi"><c>__m128i {M128}</c></param>
/// <returns><c>__m256i dst {M128}</c></returns>
public static __m256i _mm256_setr_m128i(__m128i lo, __m128i hi) => System.Runtime.Intrinsics.Vector256.Create(lo.SI32, hi.SI32);

/// <summary>
/// Set packed double-precision (64-bit) floating-point elements in "dst" with the supplied values in reverse order.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/External/RawIntrinsics/Other.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public static unsafe partial class Other
/// <returns><c>__m128i dst {M128}</c></returns>
public static __m128i _mm_aeskeygenassist_si128(__m128i a, [System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute] int imm8) => System.Runtime.Intrinsics.X86.Aes.KeygenAssist(a.UI8, (byte)imm8);

/// <summary>
/// Perform a carry-less multiplication of two 64-bit integers, selected from "a" and "b" according to "imm8", and store the results in "dst".
/// </summary>
/// <remarks><c>PCLMULQDQ xmm, xmm, imm8</c></remarks>
/// <param name="a"><c>__m128i {M128}</c></param>
/// <param name="b"><c>__m128i {M128}</c></param>
/// <param name="imm8"><c>int {IMM}</c></param>
/// <returns><c>__m128i dst {M128}</c></returns>
public static __m128i _mm_clmulepi64_si128(__m128i a, __m128i b, [System.Diagnostics.CodeAnalysis.ConstantExpectedAttribute] int imm8) => System.Runtime.Intrinsics.X86.Pclmulqdq.CarrylessMultiply(a.SI64, b.SI64, (byte)imm8);

/// <summary>
/// Count the number of bits set to 1 in unsigned 32-bit integer "a", and return that count in "dst".
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions src/External/RawIntrinsics/SSE2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,14 @@ public static unsafe partial class SSE2
/// <returns><c>__m128d dst {FP64}</c></returns>
public static __m128d _mm_loadh_pd(__m128d a, double* mem_addr) => System.Runtime.Intrinsics.X86.Sse2.LoadHigh(a.FP64, mem_addr);

/// <summary>
/// Load 64-bit integer from memory into the first element of "dst".
/// </summary>
/// <remarks><c>MOVQ xmm, m64</c></remarks>
/// <param name="mem_addr"><c>__m128i {UI64}</c></param>
/// <returns><c>__m128i dst {UI64}</c></returns>
public static __m128i _mm_loadl_epi64(__m128i* mem_addr) => System.Runtime.Intrinsics.X86.Sse2.LoadScalarVector128((long*)mem_addr);

/// <summary>
/// Load a double-precision (64-bit) floating-point element from memory into the lower element of "dst", and copy the upper element from "a" to "dst". "mem_addr" does not need to be aligned on any particular boundary.
/// </summary>
Expand All @@ -781,6 +789,14 @@ public static unsafe partial class SSE2
/// <returns><c>__m128i dst {M128}</c></returns>
public static __m128i _mm_loadu_si128(__m128i* mem_addr) => System.Runtime.Intrinsics.X86.Sse2.LoadVector128((sbyte*)mem_addr);

/// <summary>
/// Load unaligned 32-bit integer from memory into the first element of "dst".
/// </summary>
/// <remarks><c>MOVD xmm, m32</c></remarks>
/// <param name="mem_addr"><c>void {UI32}</c></param>
/// <returns><c>__m128i dst {UI32}</c></returns>
public static __m128i _mm_loadu_si32(void* mem_addr) => System.Runtime.Intrinsics.X86.Sse2.LoadScalarVector128((int*)mem_addr);

/// <summary>
/// Multiply packed signed 16-bit integers in "a" and "b", producing intermediate signed 32-bit integers. Horizontally add adjacent pairs of intermediate 32-bit integers, and pack the results in "dst".
/// </summary>
Expand Down Expand Up @@ -1086,6 +1102,15 @@ public static unsafe partial class SSE2
/// <returns><c>__m128i dst {UI32}</c></returns>
public static __m128i _mm_setr_epi32(int e3, int e2, int e1, int e0) => System.Runtime.Intrinsics.Vector128.Create((uint)e3, (uint)e2, (uint)e1, (uint)e0);

/// <summary>
/// Set packed 64-bit integers in "dst" with the supplied values in reverse order.
/// </summary>
/// <remarks><c></c></remarks>
/// <param name="e1"><c>__m64 {UI64}</c></param>
/// <param name="e0"><c>__m64 {UI64}</c></param>
/// <returns><c>__m128i dst {UI64}</c></returns>
public static __m128i _mm_setr_epi64(__m64 e1, __m64 e0) => System.Runtime.Intrinsics.Vector128.Create(e1.SI32, e0.SI32);

/// <summary>
/// Set packed 8-bit integers in "dst" with the supplied values in reverse order.
/// </summary>
Expand Down
15 changes: 13 additions & 2 deletions src/External/RawIntrinsicsGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ private static async Task Generate(string sriUrl, Regex cppIntrinsicNameMatcher,
throw new Exception("Unexpected error - couldnt find end of c method intrinsic");
var cMethod = xmlDoc[cMethodIndex..cMethodEndIndex];

// Remove when merged: https://github.com/dotnet/runtime/pull/88552
if (cMethod == "_mm256_ceil_ps" && methodSymbol.Name == "Floor")
cMethod = "_mm256_floor_ps";
if (cMethod == "_mm256_ceil_pd" && methodSymbol.Name == "Floor")
cMethod = "_mm256_floor_pd";

var csMethod = new CsMethod
{
Name = methodDeclaration.Identifier.ToString(),
Expand Down Expand Up @@ -547,7 +553,11 @@ static string IntelTypeNameToSystemTypeName(string itn)
.Count(
cpt => !intelMethod.Parameters
.Select((ip, j) => (ip, j))
.Any(ipt => cpt.i == ipt.j && ipt.ip.Type.CsType.Name == cpt.cp.Type.Name && ipt.ip.Type.CsType.TypeParameter == cpt.cp.Type.TypeParameter)
.Any(ipt =>
cpt.i == ipt.j &&
ipt.ip.Type.CsType.Name == cpt.cp.Type.Name &&
ipt.ip.Type.CsType.TypeParameter == cpt.cp.Type.TypeParameter
)
)
))
.OrderBy(m => m.s)
Expand All @@ -559,7 +569,8 @@ static string IntelTypeNameToSystemTypeName(string itn)
return null;
}

if ((csMethodCand.Length == 8 || csMethodCand.Length == 4) && csMethodCand.Select(m => m.s).Distinct().Count() == 1)
var oneDistinctScore = csMethodCand.Select(m => m.s).Distinct().Count() == 1;
if ((csMethodCand.Length == 8 || csMethodCand.Length == 4 || csMethodCand.Length == 2) && oneDistinctScore)
return csMethodCand[0].m;

if (csMethodCand.Length > 1)
Expand Down

0 comments on commit 67862f0

Please sign in to comment.