InstEmitSimdLogical32.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using ARMeilleure.Decoders;
  2. using ARMeilleure.IntermediateRepresentation;
  3. using ARMeilleure.Translation;
  4. using static ARMeilleure.Instructions.InstEmitHelper;
  5. using static ARMeilleure.Instructions.InstEmitSimdHelper;
  6. using static ARMeilleure.Instructions.InstEmitSimdHelper32;
  7. using static ARMeilleure.IntermediateRepresentation.OperandHelper;
  8. namespace ARMeilleure.Instructions
  9. {
  10. static partial class InstEmit32
  11. {
  12. public static void Vand_I(ArmEmitterContext context)
  13. {
  14. if (Optimizations.UseSse2)
  15. {
  16. EmitVectorBinaryOpSimd32(context, (n, m) => context.AddIntrinsic(Intrinsic.X86Pand, n, m));
  17. }
  18. else
  19. {
  20. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseAnd(op1, op2));
  21. }
  22. }
  23. public static void Vbic_I(ArmEmitterContext context)
  24. {
  25. if (Optimizations.UseSse2)
  26. {
  27. EmitVectorBinaryOpSimd32(context, (n, m) => context.AddIntrinsic(Intrinsic.X86Pandn, m, n));
  28. }
  29. else
  30. {
  31. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseAnd(op1, context.BitwiseNot(op2)));
  32. }
  33. }
  34. public static void Vbic_II(ArmEmitterContext context)
  35. {
  36. OpCode32SimdImm op = (OpCode32SimdImm)context.CurrOp;
  37. long immediate = op.Immediate;
  38. // Replicate fields to fill the 64-bits, if size is < 64-bits.
  39. switch (op.Size)
  40. {
  41. case 0: immediate *= 0x0101010101010101L; break;
  42. case 1: immediate *= 0x0001000100010001L; break;
  43. case 2: immediate *= 0x0000000100000001L; break;
  44. }
  45. Operand imm = Const(immediate);
  46. Operand res = GetVecA32(op.Qd);
  47. if (op.Q)
  48. {
  49. for (int elem = 0; elem < 2; elem++)
  50. {
  51. Operand de = EmitVectorExtractZx(context, op.Qd, elem, 3);
  52. res = EmitVectorInsert(context, res, context.BitwiseAnd(de, context.BitwiseNot(imm)), elem, 3);
  53. }
  54. }
  55. else
  56. {
  57. Operand de = EmitVectorExtractZx(context, op.Qd, op.Vd & 1, 3);
  58. res = EmitVectorInsert(context, res, context.BitwiseAnd(de, context.BitwiseNot(imm)), op.Vd & 1, 3);
  59. }
  60. context.Copy(GetVecA32(op.Qd), res);
  61. }
  62. public static void Vbif(ArmEmitterContext context)
  63. {
  64. EmitBifBit(context, true);
  65. }
  66. public static void Vbit(ArmEmitterContext context)
  67. {
  68. EmitBifBit(context, false);
  69. }
  70. public static void Vbsl(ArmEmitterContext context)
  71. {
  72. if (Optimizations.UseSse2)
  73. {
  74. EmitVectorTernaryOpSimd32(context, (d, n, m) =>
  75. {
  76. Operand res = context.AddIntrinsic(Intrinsic.X86Pxor, n, m);
  77. res = context.AddIntrinsic(Intrinsic.X86Pand, res, d);
  78. return context.AddIntrinsic(Intrinsic.X86Pxor, res, m);
  79. });
  80. }
  81. else
  82. {
  83. EmitVectorTernaryOpZx32(context, (op1, op2, op3) =>
  84. {
  85. return context.BitwiseExclusiveOr(
  86. context.BitwiseAnd(op1,
  87. context.BitwiseExclusiveOr(op2, op3)), op3);
  88. });
  89. }
  90. }
  91. public static void Veor_I(ArmEmitterContext context)
  92. {
  93. if (Optimizations.UseSse2)
  94. {
  95. EmitVectorBinaryOpSimd32(context, (n, m) => context.AddIntrinsic(Intrinsic.X86Pxor, n, m));
  96. }
  97. else
  98. {
  99. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseExclusiveOr(op1, op2));
  100. }
  101. }
  102. public static void Vorr_I(ArmEmitterContext context)
  103. {
  104. if (Optimizations.UseSse2)
  105. {
  106. EmitVectorBinaryOpSimd32(context, (n, m) => context.AddIntrinsic(Intrinsic.X86Por, n, m));
  107. }
  108. else
  109. {
  110. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseOr(op1, op2));
  111. }
  112. }
  113. public static void Vorr_II(ArmEmitterContext context)
  114. {
  115. OpCode32SimdImm op = (OpCode32SimdImm)context.CurrOp;
  116. long immediate = op.Immediate;
  117. // Replicate fields to fill the 64-bits, if size is < 64-bits.
  118. switch (op.Size)
  119. {
  120. case 0: immediate *= 0x0101010101010101L; break;
  121. case 1: immediate *= 0x0001000100010001L; break;
  122. case 2: immediate *= 0x0000000100000001L; break;
  123. }
  124. Operand imm = Const(immediate);
  125. Operand res = GetVecA32(op.Qd);
  126. if (op.Q)
  127. {
  128. for (int elem = 0; elem < 2; elem++)
  129. {
  130. Operand de = EmitVectorExtractZx(context, op.Qd, elem, 3);
  131. res = EmitVectorInsert(context, res, context.BitwiseOr(de, imm), elem, 3);
  132. }
  133. }
  134. else
  135. {
  136. Operand de = EmitVectorExtractZx(context, op.Qd, op.Vd & 1, 3);
  137. res = EmitVectorInsert(context, res, context.BitwiseOr(de, imm), op.Vd & 1, 3);
  138. }
  139. context.Copy(GetVecA32(op.Qd), res);
  140. }
  141. public static void Vtst(ArmEmitterContext context)
  142. {
  143. EmitVectorBinaryOpZx32(context, (op1, op2) =>
  144. {
  145. Operand isZero = context.ICompareEqual(context.BitwiseAnd(op1, op2), Const(0));
  146. return context.ConditionalSelect(isZero, Const(0), Const(-1));
  147. });
  148. }
  149. private static void EmitBifBit(ArmEmitterContext context, bool notRm)
  150. {
  151. OpCode32SimdReg op = (OpCode32SimdReg)context.CurrOp;
  152. if (Optimizations.UseSse2)
  153. {
  154. EmitVectorTernaryOpSimd32(context, (d, n, m) =>
  155. {
  156. Operand res = context.AddIntrinsic(Intrinsic.X86Pxor, n, d);
  157. res = context.AddIntrinsic((notRm) ? Intrinsic.X86Pandn : Intrinsic.X86Pand, m, res);
  158. return context.AddIntrinsic(Intrinsic.X86Pxor, d, res);
  159. });
  160. }
  161. else
  162. {
  163. EmitVectorTernaryOpZx32(context, (d, n, m) =>
  164. {
  165. if (notRm)
  166. {
  167. m = context.BitwiseNot(m);
  168. }
  169. return context.BitwiseExclusiveOr(
  170. context.BitwiseAnd(m,
  171. context.BitwiseExclusiveOr(d, n)), d);
  172. });
  173. }
  174. }
  175. }
  176. }