/ src / ARMeilleure / Instructions / InstEmitSimdHashHelper.cs
InstEmitSimdHashHelper.cs
 1  using ARMeilleure.IntermediateRepresentation;
 2  using ARMeilleure.Translation;
 3  using System;
 4  
 5  using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
 6  
 7  namespace ARMeilleure.Instructions
 8  {
 9      static class InstEmitSimdHashHelper
10      {
11          public static Operand EmitSha256h(ArmEmitterContext context, Operand x, Operand y, Operand w, bool part2)
12          {
13              if (Optimizations.UseSha)
14              {
15                  Operand src1 = context.AddIntrinsic(Intrinsic.X86Shufps, y, x, Const(0xbb));
16                  Operand src2 = context.AddIntrinsic(Intrinsic.X86Shufps, y, x, Const(0x11));
17                  Operand w2 = context.AddIntrinsic(Intrinsic.X86Punpckhqdq, w, w);
18  
19                  Operand round2 = context.AddIntrinsic(Intrinsic.X86Sha256Rnds2, src1, src2, w);
20                  Operand round4 = context.AddIntrinsic(Intrinsic.X86Sha256Rnds2, src2, round2, w2);
21  
22                  Operand res = context.AddIntrinsic(Intrinsic.X86Shufps, round4, round2, Const(part2 ? 0x11 : 0xbb));
23  
24                  return res;
25              }
26  
27              String method = part2 ? nameof(SoftFallback.HashUpper) : nameof(SoftFallback.HashLower);
28              return context.Call(typeof(SoftFallback).GetMethod(method), x, y, w);
29          }
30  
31          public static Operand EmitSha256su0(ArmEmitterContext context, Operand x, Operand y)
32          {
33              if (Optimizations.UseSha)
34              {
35                  return context.AddIntrinsic(Intrinsic.X86Sha256Msg1, x, y);
36              }
37  
38              return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha256SchedulePart1)), x, y);
39          }
40  
41          public static Operand EmitSha256su1(ArmEmitterContext context, Operand x, Operand y, Operand z)
42          {
43              if (Optimizations.UseSha && Optimizations.UseSsse3)
44              {
45                  Operand extr = context.AddIntrinsic(Intrinsic.X86Palignr, z, y, Const(4));
46                  Operand tmp = context.AddIntrinsic(Intrinsic.X86Paddd, extr, x);
47  
48                  Operand res = context.AddIntrinsic(Intrinsic.X86Sha256Msg2, tmp, z);
49  
50                  return res;
51              }
52  
53              return context.Call(typeof(SoftFallback).GetMethod(nameof(SoftFallback.Sha256SchedulePart2)), x, y, z);
54          }
55      }
56  }