InstEmitSimdLogical32.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 Vorr_I(ArmEmitterContext context)
  53. {
  54. if (Optimizations.UseSse2)
  55. {
  56. EmitVectorBinaryOpF32(context, Intrinsic.X86Por, Intrinsic.X86Por);
  57. }
  58. else
  59. {
  60. EmitVectorBinaryOpZx32(context, (op1, op2) => context.BitwiseOr(op1, op2));
  61. }
  62. }
  63. public static void Vorr_II(ArmEmitterContext context)
  64. {
  65. OpCode32SimdImm op = (OpCode32SimdImm)context.CurrOp;
  66. long immediate = op.Immediate;
  67. // Replicate fields to fill the 64-bits, if size is < 64-bits.
  68. switch (op.Size)
  69. {
  70. case 0: immediate *= 0x0101010101010101L; break;
  71. case 1: immediate *= 0x0001000100010001L; break;
  72. case 2: immediate *= 0x0000000100000001L; break;
  73. }
  74. Operand imm = Const(immediate);
  75. Operand res = GetVecA32(op.Qd);
  76. if (op.Q)
  77. {
  78. for (int elem = 0; elem < 2; elem++)
  79. {
  80. Operand de = EmitVectorExtractZx(context, op.Qd, elem, 3);
  81. res = EmitVectorInsert(context, res, context.BitwiseOr(de, imm), elem, 3);
  82. }
  83. }
  84. else
  85. {
  86. Operand de = EmitVectorExtractZx(context, op.Qd, op.Vd & 1, 3);
  87. res = EmitVectorInsert(context, res, context.BitwiseOr(de, imm), op.Vd & 1, 3);
  88. }
  89. context.Copy(GetVecA32(op.Qd), res);
  90. }
  91. private static void EmitBifBit(ArmEmitterContext context, bool notRm)
  92. {
  93. OpCode32SimdReg op = (OpCode32SimdReg)context.CurrOp;
  94. if (Optimizations.UseSse2)
  95. {
  96. EmitVectorTernaryOpSimd32(context, (d, n, m) =>
  97. {
  98. Operand res = context.AddIntrinsic(Intrinsic.X86Pxor, n, d);
  99. res = context.AddIntrinsic((notRm) ? Intrinsic.X86Pandn : Intrinsic.X86Pand, m, res);
  100. return context.AddIntrinsic(Intrinsic.X86Pxor, d, res);
  101. });
  102. }
  103. else
  104. {
  105. EmitVectorTernaryOpZx32(context, (d, n, m) =>
  106. {
  107. if (notRm)
  108. {
  109. m = context.BitwiseNot(m);
  110. }
  111. return context.BitwiseExclusiveOr(
  112. context.BitwiseAnd(m,
  113. context.BitwiseExclusiveOr(d, n)), d);
  114. });
  115. }
  116. }
  117. }
  118. }