InstEmitSimdLogical32.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. EmitVectorBinaryOpF32(context, Intrinsic.X86Pand, Intrinsic.X86Pand);
  17. }
  18. else
  19. {
  20. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseAnd(op1, op2));
  21. }
  22. }
  23. public static void Vbif(ArmEmitterContext context)
  24. {
  25. EmitBifBit(context, true);
  26. }
  27. public static void Vbit(ArmEmitterContext context)
  28. {
  29. EmitBifBit(context, false);
  30. }
  31. public static void Vbsl(ArmEmitterContext context)
  32. {
  33. if (Optimizations.UseSse2)
  34. {
  35. EmitVectorTernaryOpSimd32(context, (d, n, m) =>
  36. {
  37. Operand res = context.AddIntrinsic(Intrinsic.X86Pxor, n, m);
  38. res = context.AddIntrinsic(Intrinsic.X86Pand, res, d);
  39. return context.AddIntrinsic(Intrinsic.X86Pxor, res, m);
  40. });
  41. }
  42. else
  43. {
  44. EmitVectorTernaryOpZx32(context, (op1, op2, op3) =>
  45. {
  46. return context.BitwiseExclusiveOr(
  47. context.BitwiseAnd(op1,
  48. context.BitwiseExclusiveOr(op2, op3)), op3);
  49. });
  50. }
  51. }
  52. public static void Veor_I(ArmEmitterContext context)
  53. {
  54. if (Optimizations.UseSse2)
  55. {
  56. EmitVectorBinaryOpF32(context, Intrinsic.X86Pxor, Intrinsic.X86Pxor);
  57. }
  58. else
  59. {
  60. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseExclusiveOr(op1, op2));
  61. }
  62. }
  63. public static void Vorr_I(ArmEmitterContext context)
  64. {
  65. if (Optimizations.UseSse2)
  66. {
  67. EmitVectorBinaryOpF32(context, Intrinsic.X86Por, Intrinsic.X86Por);
  68. }
  69. else
  70. {
  71. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseOr(op1, op2));
  72. }
  73. }
  74. public static void Vorr_II(ArmEmitterContext context)
  75. {
  76. OpCode32SimdImm op = (OpCode32SimdImm)context.CurrOp;
  77. long immediate = op.Immediate;
  78. // Replicate fields to fill the 64-bits, if size is < 64-bits.
  79. switch (op.Size)
  80. {
  81. case 0: immediate *= 0x0101010101010101L; break;
  82. case 1: immediate *= 0x0001000100010001L; break;
  83. case 2: immediate *= 0x0000000100000001L; break;
  84. }
  85. Operand imm = Const(immediate);
  86. Operand res = GetVecA32(op.Qd);
  87. if (op.Q)
  88. {
  89. for (int elem = 0; elem < 2; elem++)
  90. {
  91. Operand de = EmitVectorExtractZx(context, op.Qd, elem, 3);
  92. res = EmitVectorInsert(context, res, context.BitwiseOr(de, imm), elem, 3);
  93. }
  94. }
  95. else
  96. {
  97. Operand de = EmitVectorExtractZx(context, op.Qd, op.Vd & 1, 3);
  98. res = EmitVectorInsert(context, res, context.BitwiseOr(de, imm), op.Vd & 1, 3);
  99. }
  100. context.Copy(GetVecA32(op.Qd), res);
  101. }
  102. private static void EmitBifBit(ArmEmitterContext context, bool notRm)
  103. {
  104. OpCode32SimdReg op = (OpCode32SimdReg)context.CurrOp;
  105. if (Optimizations.UseSse2)
  106. {
  107. EmitVectorTernaryOpSimd32(context, (d, n, m) =>
  108. {
  109. Operand res = context.AddIntrinsic(Intrinsic.X86Pxor, n, d);
  110. res = context.AddIntrinsic((notRm) ? Intrinsic.X86Pandn : Intrinsic.X86Pand, m, res);
  111. return context.AddIntrinsic(Intrinsic.X86Pxor, d, res);
  112. });
  113. }
  114. else
  115. {
  116. EmitVectorTernaryOpZx32(context, (d, n, m) =>
  117. {
  118. if (notRm)
  119. {
  120. m = context.BitwiseNot(m);
  121. }
  122. return context.BitwiseExclusiveOr(
  123. context.BitwiseAnd(m,
  124. context.BitwiseExclusiveOr(d, n)), d);
  125. });
  126. }
  127. }
  128. }
  129. }