InstEmitSimdMove32.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. using ARMeilleure.Decoders;
  2. using ARMeilleure.IntermediateRepresentation;
  3. using ARMeilleure.Translation;
  4. using System;
  5. using static ARMeilleure.Instructions.InstEmitHelper;
  6. using static ARMeilleure.Instructions.InstEmitSimdHelper;
  7. using static ARMeilleure.Instructions.InstEmitSimdHelper32;
  8. using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
  9. namespace ARMeilleure.Instructions
  10. {
  11. static partial class InstEmit32
  12. {
  13. #region "Masks"
  14. // Same as InstEmitSimdMove, as the instructions do the same thing.
  15. private static readonly long[] _masksE0_Uzp = new long[]
  16. {
  17. 13L << 56 | 09L << 48 | 05L << 40 | 01L << 32 | 12L << 24 | 08L << 16 | 04L << 8 | 00L << 0,
  18. 11L << 56 | 10L << 48 | 03L << 40 | 02L << 32 | 09L << 24 | 08L << 16 | 01L << 8 | 00L << 0
  19. };
  20. private static readonly long[] _masksE1_Uzp = new long[]
  21. {
  22. 15L << 56 | 11L << 48 | 07L << 40 | 03L << 32 | 14L << 24 | 10L << 16 | 06L << 8 | 02L << 0,
  23. 15L << 56 | 14L << 48 | 07L << 40 | 06L << 32 | 13L << 24 | 12L << 16 | 05L << 8 | 04L << 0
  24. };
  25. #endregion
  26. public static void Vmov_I(ArmEmitterContext context)
  27. {
  28. EmitVectorImmUnaryOp32(context, (op1) => op1);
  29. }
  30. public static void Vmvn_I(ArmEmitterContext context)
  31. {
  32. if (Optimizations.UseAvx512Ortho)
  33. {
  34. EmitVectorUnaryOpSimd32(context, (op1) =>
  35. {
  36. return context.AddIntrinsic(Intrinsic.X86Vpternlogd, op1, op1, Const(0b01010101));
  37. });
  38. }
  39. else if (Optimizations.UseSse2)
  40. {
  41. EmitVectorUnaryOpSimd32(context, (op1) =>
  42. {
  43. Operand mask = X86GetAllElements(context, -1L);
  44. return context.AddIntrinsic(Intrinsic.X86Pandn, op1, mask);
  45. });
  46. }
  47. else
  48. {
  49. EmitVectorUnaryOpZx32(context, (op1) => context.BitwiseNot(op1));
  50. }
  51. }
  52. public static void Vmvn_II(ArmEmitterContext context)
  53. {
  54. EmitVectorImmUnaryOp32(context, (op1) => context.BitwiseNot(op1));
  55. }
  56. public static void Vmov_GS(ArmEmitterContext context)
  57. {
  58. OpCode32SimdMovGp op = (OpCode32SimdMovGp)context.CurrOp;
  59. Operand vec = GetVecA32(op.Vn >> 2);
  60. if (op.Op == 1)
  61. {
  62. // To general purpose.
  63. Operand value = context.VectorExtract(OperandType.I32, vec, op.Vn & 0x3);
  64. SetIntA32(context, op.Rt, value);
  65. }
  66. else
  67. {
  68. // From general purpose.
  69. Operand value = GetIntA32(context, op.Rt);
  70. context.Copy(vec, context.VectorInsert(vec, value, op.Vn & 0x3));
  71. }
  72. }
  73. public static void Vmov_G1(ArmEmitterContext context)
  74. {
  75. OpCode32SimdMovGpElem op = (OpCode32SimdMovGpElem)context.CurrOp;
  76. int index = op.Index + ((op.Vd & 1) << (3 - op.Size));
  77. if (op.Op == 1)
  78. {
  79. // To general purpose.
  80. Operand value = EmitVectorExtract32(context, op.Vd >> 1, index, op.Size, !op.U);
  81. SetIntA32(context, op.Rt, value);
  82. }
  83. else
  84. {
  85. // From general purpose.
  86. Operand vec = GetVecA32(op.Vd >> 1);
  87. Operand value = GetIntA32(context, op.Rt);
  88. context.Copy(vec, EmitVectorInsert(context, vec, value, index, op.Size));
  89. }
  90. }
  91. public static void Vmov_G2(ArmEmitterContext context)
  92. {
  93. OpCode32SimdMovGpDouble op = (OpCode32SimdMovGpDouble)context.CurrOp;
  94. Operand vec = GetVecA32(op.Vm >> 2);
  95. int vm1 = op.Vm + 1;
  96. bool sameOwnerVec = (op.Vm >> 2) == (vm1 >> 2);
  97. Operand vec2 = sameOwnerVec ? vec : GetVecA32(vm1 >> 2);
  98. if (op.Op == 1)
  99. {
  100. // To general purpose.
  101. Operand lowValue = context.VectorExtract(OperandType.I32, vec, op.Vm & 3);
  102. SetIntA32(context, op.Rt, lowValue);
  103. Operand highValue = context.VectorExtract(OperandType.I32, vec2, vm1 & 3);
  104. SetIntA32(context, op.Rt2, highValue);
  105. }
  106. else
  107. {
  108. // From general purpose.
  109. Operand lowValue = GetIntA32(context, op.Rt);
  110. Operand resultVec = context.VectorInsert(vec, lowValue, op.Vm & 3);
  111. Operand highValue = GetIntA32(context, op.Rt2);
  112. if (sameOwnerVec)
  113. {
  114. context.Copy(vec, context.VectorInsert(resultVec, highValue, vm1 & 3));
  115. }
  116. else
  117. {
  118. context.Copy(vec, resultVec);
  119. context.Copy(vec2, context.VectorInsert(vec2, highValue, vm1 & 3));
  120. }
  121. }
  122. }
  123. public static void Vmov_GD(ArmEmitterContext context)
  124. {
  125. OpCode32SimdMovGpDouble op = (OpCode32SimdMovGpDouble)context.CurrOp;
  126. Operand vec = GetVecA32(op.Vm >> 1);
  127. if (op.Op == 1)
  128. {
  129. // To general purpose.
  130. Operand value = context.VectorExtract(OperandType.I64, vec, op.Vm & 1);
  131. SetIntA32(context, op.Rt, context.ConvertI64ToI32(value));
  132. SetIntA32(context, op.Rt2, context.ConvertI64ToI32(context.ShiftRightUI(value, Const(32))));
  133. }
  134. else
  135. {
  136. // From general purpose.
  137. Operand lowValue = GetIntA32(context, op.Rt);
  138. Operand highValue = GetIntA32(context, op.Rt2);
  139. Operand value = context.BitwiseOr(
  140. context.ZeroExtend32(OperandType.I64, lowValue),
  141. context.ShiftLeft(context.ZeroExtend32(OperandType.I64, highValue), Const(32)));
  142. context.Copy(vec, context.VectorInsert(vec, value, op.Vm & 1));
  143. }
  144. }
  145. public static void Vmovl(ArmEmitterContext context)
  146. {
  147. OpCode32SimdLong op = (OpCode32SimdLong)context.CurrOp;
  148. Operand res = context.VectorZero();
  149. int elems = op.GetBytesCount() >> op.Size;
  150. for (int index = 0; index < elems; index++)
  151. {
  152. Operand me = EmitVectorExtract32(context, op.Qm, op.Im + index, op.Size, !op.U);
  153. if (op.Size == 2)
  154. {
  155. if (op.U)
  156. {
  157. me = context.ZeroExtend32(OperandType.I64, me);
  158. }
  159. else
  160. {
  161. me = context.SignExtend32(OperandType.I64, me);
  162. }
  163. }
  164. res = EmitVectorInsert(context, res, me, index, op.Size + 1);
  165. }
  166. context.Copy(GetVecA32(op.Qd), res);
  167. }
  168. public static void Vtbl(ArmEmitterContext context)
  169. {
  170. OpCode32SimdTbl op = (OpCode32SimdTbl)context.CurrOp;
  171. bool extension = op.Opc == 1;
  172. int length = op.Length + 1;
  173. if (Optimizations.UseSsse3)
  174. {
  175. Operand d = GetVecA32(op.Qd);
  176. Operand m = EmitMoveDoubleWordToSide(context, GetVecA32(op.Qm), op.Vm, 0);
  177. Operand res;
  178. Operand mask = X86GetAllElements(context, 0x0707070707070707L);
  179. // Fast path for single register table.
  180. {
  181. Operand n = EmitMoveDoubleWordToSide(context, GetVecA32(op.Qn), op.Vn, 0);
  182. Operand mMask = context.AddIntrinsic(Intrinsic.X86Pcmpgtb, m, mask);
  183. mMask = context.AddIntrinsic(Intrinsic.X86Por, mMask, m);
  184. res = context.AddIntrinsic(Intrinsic.X86Pshufb, n, mMask);
  185. }
  186. for (int index = 1; index < length; index++)
  187. {
  188. int newVn = (op.Vn + index) & 0x1F;
  189. (int qn, int ind) = GetQuadwordAndSubindex(newVn, op.RegisterSize);
  190. Operand ni = EmitMoveDoubleWordToSide(context, GetVecA32(qn), newVn, 0);
  191. Operand idxMask = X86GetAllElements(context, 0x0808080808080808L * index);
  192. Operand mSubMask = context.AddIntrinsic(Intrinsic.X86Psubb, m, idxMask);
  193. Operand mMask = context.AddIntrinsic(Intrinsic.X86Pcmpgtb, mSubMask, mask);
  194. mMask = context.AddIntrinsic(Intrinsic.X86Por, mMask, mSubMask);
  195. Operand res2 = context.AddIntrinsic(Intrinsic.X86Pshufb, ni, mMask);
  196. res = context.AddIntrinsic(Intrinsic.X86Por, res, res2);
  197. }
  198. if (extension)
  199. {
  200. Operand idxMask = X86GetAllElements(context, (0x0808080808080808L * length) - 0x0101010101010101L);
  201. Operand zeroMask = context.VectorZero();
  202. Operand mPosMask = context.AddIntrinsic(Intrinsic.X86Pcmpgtb, m, idxMask);
  203. Operand mNegMask = context.AddIntrinsic(Intrinsic.X86Pcmpgtb, zeroMask, m);
  204. Operand mMask = context.AddIntrinsic(Intrinsic.X86Por, mPosMask, mNegMask);
  205. Operand dMask = context.AddIntrinsic(Intrinsic.X86Pand, EmitMoveDoubleWordToSide(context, d, op.Vd, 0), mMask);
  206. res = context.AddIntrinsic(Intrinsic.X86Por, res, dMask);
  207. }
  208. res = EmitMoveDoubleWordToSide(context, res, 0, op.Vd);
  209. context.Copy(d, EmitDoubleWordInsert(context, d, res, op.Vd));
  210. }
  211. else
  212. {
  213. int elems = op.GetBytesCount() >> op.Size;
  214. (int Qx, int Ix)[] tableTuples = new (int, int)[length];
  215. for (int i = 0; i < length; i++)
  216. {
  217. tableTuples[i] = GetQuadwordAndSubindex(op.Vn + i, op.RegisterSize);
  218. }
  219. int byteLength = length * 8;
  220. Operand res = GetVecA32(op.Qd);
  221. Operand m = GetVecA32(op.Qm);
  222. for (int index = 0; index < elems; index++)
  223. {
  224. Operand selectedIndex = context.ZeroExtend8(OperandType.I32, context.VectorExtract8(m, index + op.Im));
  225. Operand inRange = context.ICompareLess(selectedIndex, Const(byteLength));
  226. Operand elemRes = default; // Note: This is I64 for ease of calculation.
  227. // TODO: Branching rather than conditional select.
  228. // Get indexed byte.
  229. // To simplify (ha) the il, we get bytes from every vector and use a nested conditional select to choose the right result.
  230. // This does have to extract `length` times for every element but certainly not as bad as it could be.
  231. // Which vector number is the index on.
  232. Operand vecIndex = context.ShiftRightUI(selectedIndex, Const(3));
  233. // What should we shift by to extract it.
  234. Operand subVecIndexShift = context.ShiftLeft(context.BitwiseAnd(selectedIndex, Const(7)), Const(3));
  235. for (int i = 0; i < length; i++)
  236. {
  237. (int qx, int ix) = tableTuples[i];
  238. // Get the whole vector, we'll get a byte out of it.
  239. Operand lookupResult;
  240. if (qx == op.Qd)
  241. {
  242. // Result contains the current state of the vector.
  243. lookupResult = context.VectorExtract(OperandType.I64, res, ix);
  244. }
  245. else
  246. {
  247. lookupResult = EmitVectorExtract32(context, qx, ix, 3, false); // I64
  248. }
  249. lookupResult = context.ShiftRightUI(lookupResult, subVecIndexShift); // Get the relevant byte from this vector.
  250. if (i == 0)
  251. {
  252. elemRes = lookupResult; // First result is always default.
  253. }
  254. else
  255. {
  256. Operand isThisElem = context.ICompareEqual(vecIndex, Const(i));
  257. elemRes = context.ConditionalSelect(isThisElem, lookupResult, elemRes);
  258. }
  259. }
  260. Operand fallback = (extension) ? context.ZeroExtend32(OperandType.I64, EmitVectorExtract32(context, op.Qd, index + op.Id, 0, false)) : Const(0L);
  261. res = EmitVectorInsert(context, res, context.ConditionalSelect(inRange, elemRes, fallback), index + op.Id, 0);
  262. }
  263. context.Copy(GetVecA32(op.Qd), res);
  264. }
  265. }
  266. public static void Vtrn(ArmEmitterContext context)
  267. {
  268. OpCode32SimdCmpZ op = (OpCode32SimdCmpZ)context.CurrOp;
  269. if (Optimizations.UseSsse3)
  270. {
  271. EmitVectorShuffleOpSimd32(context, (m, d) =>
  272. {
  273. Operand mask = default;
  274. if (op.Size < 3)
  275. {
  276. long maskE0 = EvenMasks[op.Size];
  277. long maskE1 = OddMasks[op.Size];
  278. mask = X86GetScalar(context, maskE0);
  279. mask = EmitVectorInsert(context, mask, Const(maskE1), 1, 3);
  280. }
  281. if (op.Size < 3)
  282. {
  283. d = context.AddIntrinsic(Intrinsic.X86Pshufb, d, mask);
  284. m = context.AddIntrinsic(Intrinsic.X86Pshufb, m, mask);
  285. }
  286. Operand resD = context.AddIntrinsic(X86PunpcklInstruction[op.Size], d, m);
  287. Operand resM = context.AddIntrinsic(X86PunpckhInstruction[op.Size], d, m);
  288. return (resM, resD);
  289. });
  290. }
  291. else
  292. {
  293. int elems = op.GetBytesCount() >> op.Size;
  294. int pairs = elems >> 1;
  295. bool overlap = op.Qm == op.Qd;
  296. Operand resD = GetVecA32(op.Qd);
  297. Operand resM = GetVecA32(op.Qm);
  298. for (int index = 0; index < pairs; index++)
  299. {
  300. int pairIndex = index << 1;
  301. Operand d2 = EmitVectorExtract32(context, op.Qd, pairIndex + 1 + op.Id, op.Size, false);
  302. Operand m1 = EmitVectorExtract32(context, op.Qm, pairIndex + op.Im, op.Size, false);
  303. resD = EmitVectorInsert(context, resD, m1, pairIndex + 1 + op.Id, op.Size);
  304. if (overlap)
  305. {
  306. resM = resD;
  307. }
  308. resM = EmitVectorInsert(context, resM, d2, pairIndex + op.Im, op.Size);
  309. if (overlap)
  310. {
  311. resD = resM;
  312. }
  313. }
  314. context.Copy(GetVecA32(op.Qd), resD);
  315. if (!overlap)
  316. {
  317. context.Copy(GetVecA32(op.Qm), resM);
  318. }
  319. }
  320. }
  321. public static void Vzip(ArmEmitterContext context)
  322. {
  323. OpCode32SimdCmpZ op = (OpCode32SimdCmpZ)context.CurrOp;
  324. if (Optimizations.UseAdvSimd)
  325. {
  326. EmitVectorZipUzpOpSimd32(context, Intrinsic.Arm64Zip1V, Intrinsic.Arm64Zip2V);
  327. }
  328. else if (Optimizations.UseSse2)
  329. {
  330. EmitVectorShuffleOpSimd32(context, (m, d) =>
  331. {
  332. if (op.RegisterSize == RegisterSize.Simd128)
  333. {
  334. Operand resD = context.AddIntrinsic(X86PunpcklInstruction[op.Size], d, m);
  335. Operand resM = context.AddIntrinsic(X86PunpckhInstruction[op.Size], d, m);
  336. return (resM, resD);
  337. }
  338. else
  339. {
  340. Operand res = context.AddIntrinsic(X86PunpcklInstruction[op.Size], d, m);
  341. Operand resD = context.AddIntrinsic(Intrinsic.X86Punpcklqdq, res, context.VectorZero());
  342. Operand resM = context.AddIntrinsic(Intrinsic.X86Punpckhqdq, res, context.VectorZero());
  343. return (resM, resD);
  344. }
  345. });
  346. }
  347. else
  348. {
  349. int elems = op.GetBytesCount() >> op.Size;
  350. int pairs = elems >> 1;
  351. bool overlap = op.Qm == op.Qd;
  352. Operand resD = GetVecA32(op.Qd);
  353. Operand resM = GetVecA32(op.Qm);
  354. for (int index = 0; index < pairs; index++)
  355. {
  356. int pairIndex = index << 1;
  357. Operand dRowD = EmitVectorExtract32(context, op.Qd, index + op.Id, op.Size, false);
  358. Operand mRowD = EmitVectorExtract32(context, op.Qm, index + op.Im, op.Size, false);
  359. Operand dRowM = EmitVectorExtract32(context, op.Qd, index + op.Id + pairs, op.Size, false);
  360. Operand mRowM = EmitVectorExtract32(context, op.Qm, index + op.Im + pairs, op.Size, false);
  361. resD = EmitVectorInsert(context, resD, dRowD, pairIndex + op.Id, op.Size);
  362. resD = EmitVectorInsert(context, resD, mRowD, pairIndex + 1 + op.Id, op.Size);
  363. if (overlap)
  364. {
  365. resM = resD;
  366. }
  367. resM = EmitVectorInsert(context, resM, dRowM, pairIndex + op.Im, op.Size);
  368. resM = EmitVectorInsert(context, resM, mRowM, pairIndex + 1 + op.Im, op.Size);
  369. if (overlap)
  370. {
  371. resD = resM;
  372. }
  373. }
  374. context.Copy(GetVecA32(op.Qd), resD);
  375. if (!overlap)
  376. {
  377. context.Copy(GetVecA32(op.Qm), resM);
  378. }
  379. }
  380. }
  381. public static void Vuzp(ArmEmitterContext context)
  382. {
  383. OpCode32SimdCmpZ op = (OpCode32SimdCmpZ)context.CurrOp;
  384. if (Optimizations.UseAdvSimd)
  385. {
  386. EmitVectorZipUzpOpSimd32(context, Intrinsic.Arm64Uzp1V, Intrinsic.Arm64Uzp2V);
  387. }
  388. else if (Optimizations.UseSsse3)
  389. {
  390. EmitVectorShuffleOpSimd32(context, (m, d) =>
  391. {
  392. if (op.RegisterSize == RegisterSize.Simd128)
  393. {
  394. Operand mask = default;
  395. if (op.Size < 3)
  396. {
  397. long maskE0 = EvenMasks[op.Size];
  398. long maskE1 = OddMasks[op.Size];
  399. mask = X86GetScalar(context, maskE0);
  400. mask = EmitVectorInsert(context, mask, Const(maskE1), 1, 3);
  401. d = context.AddIntrinsic(Intrinsic.X86Pshufb, d, mask);
  402. m = context.AddIntrinsic(Intrinsic.X86Pshufb, m, mask);
  403. }
  404. Operand resD = context.AddIntrinsic(Intrinsic.X86Punpcklqdq, d, m);
  405. Operand resM = context.AddIntrinsic(Intrinsic.X86Punpckhqdq, d, m);
  406. return (resM, resD);
  407. }
  408. else
  409. {
  410. Intrinsic punpcklInst = X86PunpcklInstruction[op.Size];
  411. Operand res = context.AddIntrinsic(punpcklInst, d, m);
  412. if (op.Size < 2)
  413. {
  414. long maskE0 = _masksE0_Uzp[op.Size];
  415. long maskE1 = _masksE1_Uzp[op.Size];
  416. Operand mask = X86GetScalar(context, maskE0);
  417. mask = EmitVectorInsert(context, mask, Const(maskE1), 1, 3);
  418. res = context.AddIntrinsic(Intrinsic.X86Pshufb, res, mask);
  419. }
  420. Operand resD = context.AddIntrinsic(Intrinsic.X86Punpcklqdq, res, context.VectorZero());
  421. Operand resM = context.AddIntrinsic(Intrinsic.X86Punpckhqdq, res, context.VectorZero());
  422. return (resM, resD);
  423. }
  424. });
  425. }
  426. else
  427. {
  428. int elems = op.GetBytesCount() >> op.Size;
  429. int pairs = elems >> 1;
  430. bool overlap = op.Qm == op.Qd;
  431. Operand resD = GetVecA32(op.Qd);
  432. Operand resM = GetVecA32(op.Qm);
  433. for (int index = 0; index < elems; index++)
  434. {
  435. Operand dIns, mIns;
  436. if (index >= pairs)
  437. {
  438. int pairIndex = index - pairs;
  439. dIns = EmitVectorExtract32(context, op.Qm, (pairIndex << 1) + op.Im, op.Size, false);
  440. mIns = EmitVectorExtract32(context, op.Qm, ((pairIndex << 1) | 1) + op.Im, op.Size, false);
  441. }
  442. else
  443. {
  444. dIns = EmitVectorExtract32(context, op.Qd, (index << 1) + op.Id, op.Size, false);
  445. mIns = EmitVectorExtract32(context, op.Qd, ((index << 1) | 1) + op.Id, op.Size, false);
  446. }
  447. resD = EmitVectorInsert(context, resD, dIns, index + op.Id, op.Size);
  448. if (overlap)
  449. {
  450. resM = resD;
  451. }
  452. resM = EmitVectorInsert(context, resM, mIns, index + op.Im, op.Size);
  453. if (overlap)
  454. {
  455. resD = resM;
  456. }
  457. }
  458. context.Copy(GetVecA32(op.Qd), resD);
  459. if (!overlap)
  460. {
  461. context.Copy(GetVecA32(op.Qm), resM);
  462. }
  463. }
  464. }
  465. private static void EmitVectorZipUzpOpSimd32(ArmEmitterContext context, Intrinsic inst1, Intrinsic inst2)
  466. {
  467. OpCode32SimdCmpZ op = (OpCode32SimdCmpZ)context.CurrOp;
  468. bool overlap = op.Qm == op.Qd;
  469. Operand d = GetVecA32(op.Qd);
  470. Operand m = GetVecA32(op.Qm);
  471. Operand dPart = d;
  472. Operand mPart = m;
  473. if (!op.Q) // Register swap: move relevant doubleword to destination side.
  474. {
  475. dPart = InstEmitSimdHelper32Arm64.EmitMoveDoubleWordToSide(context, d, op.Vd, 0);
  476. mPart = InstEmitSimdHelper32Arm64.EmitMoveDoubleWordToSide(context, m, op.Vm, 0);
  477. }
  478. Intrinsic vSize = op.Q ? Intrinsic.Arm64V128 : Intrinsic.Arm64V64;
  479. vSize |= (Intrinsic)(op.Size << (int)Intrinsic.Arm64VSizeShift);
  480. Operand resD = context.AddIntrinsic(inst1 | vSize, dPart, mPart);
  481. Operand resM = context.AddIntrinsic(inst2 | vSize, dPart, mPart);
  482. if (!op.Q) // Register insert.
  483. {
  484. resD = context.AddIntrinsic(Intrinsic.Arm64InsVe | Intrinsic.Arm64VDWord, d, Const(op.Vd & 1), resD, Const(0));
  485. if (overlap)
  486. {
  487. resD = context.AddIntrinsic(Intrinsic.Arm64InsVe | Intrinsic.Arm64VDWord, resD, Const(op.Vm & 1), resM, Const(0));
  488. }
  489. else
  490. {
  491. resM = context.AddIntrinsic(Intrinsic.Arm64InsVe | Intrinsic.Arm64VDWord, m, Const(op.Vm & 1), resM, Const(0));
  492. }
  493. }
  494. context.Copy(d, resD);
  495. if (!overlap)
  496. {
  497. context.Copy(m, resM);
  498. }
  499. }
  500. private static void EmitVectorShuffleOpSimd32(ArmEmitterContext context, Func<Operand, Operand, (Operand, Operand)> shuffleFunc)
  501. {
  502. OpCode32Simd op = (OpCode32Simd)context.CurrOp;
  503. Operand m = GetVecA32(op.Qm);
  504. Operand d = GetVecA32(op.Qd);
  505. Operand initialM = m;
  506. Operand initialD = d;
  507. if (!op.Q) // Register swap: move relevant doubleword to side 0, for consistency.
  508. {
  509. m = EmitMoveDoubleWordToSide(context, m, op.Vm, 0);
  510. d = EmitMoveDoubleWordToSide(context, d, op.Vd, 0);
  511. }
  512. (Operand resM, Operand resD) = shuffleFunc(m, d);
  513. bool overlap = op.Qm == op.Qd;
  514. if (!op.Q) // Register insert.
  515. {
  516. resM = EmitDoubleWordInsert(context, initialM, EmitMoveDoubleWordToSide(context, resM, 0, op.Vm), op.Vm);
  517. resD = EmitDoubleWordInsert(context, overlap ? resM : initialD, EmitMoveDoubleWordToSide(context, resD, 0, op.Vd), op.Vd);
  518. }
  519. if (!overlap)
  520. {
  521. context.Copy(initialM, resM);
  522. }
  523. context.Copy(initialD, resD);
  524. }
  525. }
  526. }