InstEmitHash.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using ChocolArm64.Decoders;
  2. using ChocolArm64.State;
  3. using ChocolArm64.Translation;
  4. using System;
  5. using System.Reflection.Emit;
  6. using System.Runtime.Intrinsics.X86;
  7. namespace ChocolArm64.Instructions
  8. {
  9. static partial class InstEmit
  10. {
  11. public static void Crc32b(ILEmitterCtx context)
  12. {
  13. EmitCrc32(context, nameof(SoftFallback.Crc32B));
  14. }
  15. public static void Crc32h(ILEmitterCtx context)
  16. {
  17. EmitCrc32(context, nameof(SoftFallback.Crc32H));
  18. }
  19. public static void Crc32w(ILEmitterCtx context)
  20. {
  21. EmitCrc32(context, nameof(SoftFallback.Crc32W));
  22. }
  23. public static void Crc32x(ILEmitterCtx context)
  24. {
  25. EmitCrc32(context, nameof(SoftFallback.Crc32X));
  26. }
  27. public static void Crc32cb(ILEmitterCtx context)
  28. {
  29. if (Optimizations.UseSse42)
  30. {
  31. EmitSse42Crc32(context, typeof(uint), typeof(byte));
  32. }
  33. else
  34. {
  35. EmitCrc32(context, nameof(SoftFallback.Crc32Cb));
  36. }
  37. }
  38. public static void Crc32ch(ILEmitterCtx context)
  39. {
  40. if (Optimizations.UseSse42)
  41. {
  42. EmitSse42Crc32(context, typeof(uint), typeof(ushort));
  43. }
  44. else
  45. {
  46. EmitCrc32(context, nameof(SoftFallback.Crc32Ch));
  47. }
  48. }
  49. public static void Crc32cw(ILEmitterCtx context)
  50. {
  51. if (Optimizations.UseSse42)
  52. {
  53. EmitSse42Crc32(context, typeof(uint), typeof(uint));
  54. }
  55. else
  56. {
  57. EmitCrc32(context, nameof(SoftFallback.Crc32Cw));
  58. }
  59. }
  60. public static void Crc32cx(ILEmitterCtx context)
  61. {
  62. if (Optimizations.UseSse42)
  63. {
  64. EmitSse42Crc32(context, typeof(ulong), typeof(ulong));
  65. }
  66. else
  67. {
  68. EmitCrc32(context, nameof(SoftFallback.Crc32Cx));
  69. }
  70. }
  71. private static void EmitSse42Crc32(ILEmitterCtx context, Type tCrc, Type tData)
  72. {
  73. OpCodeAluRs64 op = (OpCodeAluRs64)context.CurrOp;
  74. context.EmitLdintzr(op.Rn);
  75. context.EmitLdintzr(op.Rm);
  76. context.EmitCall(typeof(Sse42).GetMethod(nameof(Sse42.Crc32), new Type[] { tCrc, tData }));
  77. context.EmitStintzr(op.Rd);
  78. }
  79. private static void EmitCrc32(ILEmitterCtx context, string name)
  80. {
  81. OpCodeAluRs64 op = (OpCodeAluRs64)context.CurrOp;
  82. context.EmitLdintzr(op.Rn);
  83. if (op.RegisterSize != RegisterSize.Int32)
  84. {
  85. context.Emit(OpCodes.Conv_U4);
  86. }
  87. context.EmitLdintzr(op.Rm);
  88. SoftFallback.EmitCall(context, name);
  89. if (op.RegisterSize != RegisterSize.Int32)
  90. {
  91. context.Emit(OpCodes.Conv_U8);
  92. }
  93. context.EmitStintzr(op.Rd);
  94. }
  95. }
  96. }