InstEmitSimdLogical32.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 Vorn_I(ArmEmitterContext context)
  103. {
  104. if (Optimizations.UseSse2)
  105. {
  106. Operand mask = context.VectorOne();
  107. EmitVectorBinaryOpSimd32(context, (n, m) =>
  108. {
  109. m = context.AddIntrinsic(Intrinsic.X86Pandn, m, mask);
  110. return context.AddIntrinsic(Intrinsic.X86Por, n, m);
  111. });
  112. }
  113. else
  114. {
  115. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseOr(op1, context.BitwiseNot(op2)));
  116. }
  117. }
  118. public static void Vorr_I(ArmEmitterContext context)
  119. {
  120. if (Optimizations.UseSse2)
  121. {
  122. EmitVectorBinaryOpSimd32(context, (n, m) => context.AddIntrinsic(Intrinsic.X86Por, n, m));
  123. }
  124. else
  125. {
  126. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseOr(op1, op2));
  127. }
  128. }
  129. public static void Vorr_II(ArmEmitterContext context)
  130. {
  131. OpCode32SimdImm op = (OpCode32SimdImm)context.CurrOp;
  132. long immediate = op.Immediate;
  133. // Replicate fields to fill the 64-bits, if size is < 64-bits.
  134. switch (op.Size)
  135. {
  136. case 0: immediate *= 0x0101010101010101L; break;
  137. case 1: immediate *= 0x0001000100010001L; break;
  138. case 2: immediate *= 0x0000000100000001L; break;
  139. }
  140. Operand imm = Const(immediate);
  141. Operand res = GetVecA32(op.Qd);
  142. if (op.Q)
  143. {
  144. for (int elem = 0; elem < 2; elem++)
  145. {
  146. Operand de = EmitVectorExtractZx(context, op.Qd, elem, 3);
  147. res = EmitVectorInsert(context, res, context.BitwiseOr(de, imm), elem, 3);
  148. }
  149. }
  150. else
  151. {
  152. Operand de = EmitVectorExtractZx(context, op.Qd, op.Vd & 1, 3);
  153. res = EmitVectorInsert(context, res, context.BitwiseOr(de, imm), op.Vd & 1, 3);
  154. }
  155. context.Copy(GetVecA32(op.Qd), res);
  156. }
  157. public static void Vtst(ArmEmitterContext context)
  158. {
  159. EmitVectorBinaryOpZx32(context, (op1, op2) =>
  160. {
  161. Operand isZero = context.ICompareEqual(context.BitwiseAnd(op1, op2), Const(0));
  162. return context.ConditionalSelect(isZero, Const(0), Const(-1));
  163. });
  164. }
  165. private static void EmitBifBit(ArmEmitterContext context, bool notRm)
  166. {
  167. OpCode32SimdReg op = (OpCode32SimdReg)context.CurrOp;
  168. if (Optimizations.UseSse2)
  169. {
  170. EmitVectorTernaryOpSimd32(context, (d, n, m) =>
  171. {
  172. Operand res = context.AddIntrinsic(Intrinsic.X86Pxor, n, d);
  173. res = context.AddIntrinsic((notRm) ? Intrinsic.X86Pandn : Intrinsic.X86Pand, m, res);
  174. return context.AddIntrinsic(Intrinsic.X86Pxor, d, res);
  175. });
  176. }
  177. else
  178. {
  179. EmitVectorTernaryOpZx32(context, (d, n, m) =>
  180. {
  181. if (notRm)
  182. {
  183. m = context.BitwiseNot(m);
  184. }
  185. return context.BitwiseExclusiveOr(
  186. context.BitwiseAnd(m,
  187. context.BitwiseExclusiveOr(d, n)), d);
  188. });
  189. }
  190. }
  191. }
  192. }