InstEmitSimdMemory.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using ARMeilleure.Decoders;
  2. using ARMeilleure.IntermediateRepresentation;
  3. using ARMeilleure.State;
  4. using ARMeilleure.Translation;
  5. using System.Diagnostics;
  6. using static ARMeilleure.Instructions.InstEmitHelper;
  7. using static ARMeilleure.Instructions.InstEmitMemoryHelper;
  8. using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
  9. namespace ARMeilleure.Instructions
  10. {
  11. static partial class InstEmit
  12. {
  13. public static void Ld__Vms(ArmEmitterContext context)
  14. {
  15. EmitSimdMemMs(context, isLoad: true);
  16. }
  17. public static void Ld__Vss(ArmEmitterContext context)
  18. {
  19. EmitSimdMemSs(context, isLoad: true);
  20. }
  21. public static void St__Vms(ArmEmitterContext context)
  22. {
  23. EmitSimdMemMs(context, isLoad: false);
  24. }
  25. public static void St__Vss(ArmEmitterContext context)
  26. {
  27. EmitSimdMemSs(context, isLoad: false);
  28. }
  29. private static void EmitSimdMemMs(ArmEmitterContext context, bool isLoad)
  30. {
  31. OpCodeSimdMemMs op = (OpCodeSimdMemMs)context.CurrOp;
  32. Operand n = GetIntOrSP(context, op.Rn);
  33. long offset = 0;
  34. for (int rep = 0; rep < op.Reps; rep++)
  35. for (int elem = 0; elem < op.Elems; elem++)
  36. for (int sElem = 0; sElem < op.SElems; sElem++)
  37. {
  38. int rtt = (op.Rt + rep + sElem) & 0x1f;
  39. Operand tt = GetVec(rtt);
  40. Operand address = context.Add(n, Const(offset));
  41. if (isLoad)
  42. {
  43. EmitLoadSimd(context, address, tt, rtt, elem, op.Size);
  44. if (op.RegisterSize == RegisterSize.Simd64 && elem == op.Elems - 1)
  45. {
  46. context.Copy(tt, context.VectorZeroUpper64(tt));
  47. }
  48. }
  49. else
  50. {
  51. EmitStoreSimd(context, address, rtt, elem, op.Size);
  52. }
  53. offset += 1 << op.Size;
  54. }
  55. if (op.WBack)
  56. {
  57. EmitSimdMemWBack(context, offset);
  58. }
  59. }
  60. private static void EmitSimdMemSs(ArmEmitterContext context, bool isLoad)
  61. {
  62. OpCodeSimdMemSs op = (OpCodeSimdMemSs)context.CurrOp;
  63. Operand n = GetIntOrSP(context, op.Rn);
  64. long offset = 0;
  65. if (op.Replicate)
  66. {
  67. // Only loads uses the replicate mode.
  68. Debug.Assert(isLoad, "Replicate mode is not valid for stores.");
  69. int elems = op.GetBytesCount() >> op.Size;
  70. for (int sElem = 0; sElem < op.SElems; sElem++)
  71. {
  72. int rt = (op.Rt + sElem) & 0x1f;
  73. Operand t = GetVec(rt);
  74. Operand address = context.Add(n, Const(offset));
  75. for (int index = 0; index < elems; index++)
  76. {
  77. EmitLoadSimd(context, address, t, rt, index, op.Size);
  78. }
  79. if (op.RegisterSize == RegisterSize.Simd64)
  80. {
  81. context.Copy(t, context.VectorZeroUpper64(t));
  82. }
  83. offset += 1 << op.Size;
  84. }
  85. }
  86. else
  87. {
  88. for (int sElem = 0; sElem < op.SElems; sElem++)
  89. {
  90. int rt = (op.Rt + sElem) & 0x1f;
  91. Operand t = GetVec(rt);
  92. Operand address = context.Add(n, Const(offset));
  93. if (isLoad)
  94. {
  95. EmitLoadSimd(context, address, t, rt, op.Index, op.Size);
  96. }
  97. else
  98. {
  99. EmitStoreSimd(context, address, rt, op.Index, op.Size);
  100. }
  101. offset += 1 << op.Size;
  102. }
  103. }
  104. if (op.WBack)
  105. {
  106. EmitSimdMemWBack(context, offset);
  107. }
  108. }
  109. private static void EmitSimdMemWBack(ArmEmitterContext context, long offset)
  110. {
  111. OpCodeMemReg op = (OpCodeMemReg)context.CurrOp;
  112. Operand n = GetIntOrSP(context, op.Rn);
  113. Operand m;
  114. if (op.Rm != RegisterAlias.Zr)
  115. {
  116. m = GetIntOrZR(context, op.Rm);
  117. }
  118. else
  119. {
  120. m = Const(offset);
  121. }
  122. context.Copy(n, context.Add(n, m));
  123. }
  124. }
  125. }