InstEmitSimdHashHelper.cs 2.2 KB

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