InstEmitAlu32.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. using ARMeilleure.Decoders;
  2. using ARMeilleure.IntermediateRepresentation;
  3. using ARMeilleure.State;
  4. using ARMeilleure.Translation;
  5. using static ARMeilleure.Instructions.InstEmitAluHelper;
  6. using static ARMeilleure.Instructions.InstEmitHelper;
  7. using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
  8. namespace ARMeilleure.Instructions
  9. {
  10. static partial class InstEmit32
  11. {
  12. public static void Add(ArmEmitterContext context)
  13. {
  14. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  15. Operand n = GetAluN(context);
  16. Operand m = GetAluM(context, setCarry: false);
  17. Operand res = context.Add(n, m);
  18. if (op.SetFlags)
  19. {
  20. EmitNZFlagsCheck(context, res);
  21. EmitAddsCCheck(context, n, res);
  22. EmitAddsVCheck(context, n, m, res);
  23. }
  24. EmitAluStore(context, res);
  25. }
  26. public static void Adc(ArmEmitterContext context)
  27. {
  28. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  29. Operand n = GetAluN(context);
  30. Operand m = GetAluM(context, setCarry: false);
  31. Operand res = context.Add(n, m);
  32. Operand carry = GetFlag(PState.CFlag);
  33. res = context.Add(res, carry);
  34. if (op.SetFlags)
  35. {
  36. EmitNZFlagsCheck(context, res);
  37. EmitAdcsCCheck(context, n, res);
  38. EmitAddsVCheck(context, n, m, res);
  39. }
  40. EmitAluStore(context, res);
  41. }
  42. public static void And(ArmEmitterContext context)
  43. {
  44. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  45. Operand n = GetAluN(context);
  46. Operand m = GetAluM(context);
  47. Operand res = context.BitwiseAnd(n, m);
  48. if (op.SetFlags)
  49. {
  50. EmitNZFlagsCheck(context, res);
  51. }
  52. EmitAluStore(context, res);
  53. }
  54. public static void Bfc(ArmEmitterContext context)
  55. {
  56. OpCode32AluBf op = (OpCode32AluBf)context.CurrOp;
  57. Operand d = GetIntA32(context, op.Rd);
  58. Operand res = context.BitwiseAnd(d, Const(~op.DestMask));
  59. SetIntA32(context, op.Rd, res);
  60. }
  61. public static void Bfi(ArmEmitterContext context)
  62. {
  63. OpCode32AluBf op = (OpCode32AluBf)context.CurrOp;
  64. Operand n = GetIntA32(context, op.Rn);
  65. Operand d = GetIntA32(context, op.Rd);
  66. Operand part = context.BitwiseAnd(n, Const(op.SourceMask));
  67. if (op.Lsb != 0)
  68. {
  69. part = context.ShiftLeft(part, Const(op.Lsb));
  70. }
  71. Operand res = context.BitwiseAnd(d, Const(~op.DestMask));
  72. res = context.BitwiseOr(res, context.BitwiseAnd(part, Const(op.DestMask)));
  73. SetIntA32(context, op.Rd, res);
  74. }
  75. public static void Bic(ArmEmitterContext context)
  76. {
  77. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  78. Operand n = GetAluN(context);
  79. Operand m = GetAluM(context);
  80. Operand res = context.BitwiseAnd(n, context.BitwiseNot(m));
  81. if (op.SetFlags)
  82. {
  83. EmitNZFlagsCheck(context, res);
  84. }
  85. EmitAluStore(context, res);
  86. }
  87. public static void Clz(ArmEmitterContext context)
  88. {
  89. Operand m = GetAluM(context, setCarry: false);
  90. Operand res = context.CountLeadingZeros(m);
  91. EmitAluStore(context, res);
  92. }
  93. public static void Cmp(ArmEmitterContext context)
  94. {
  95. Operand n = GetAluN(context);
  96. Operand m = GetAluM(context, setCarry: false);
  97. Operand res = context.Subtract(n, m);
  98. EmitNZFlagsCheck(context, res);
  99. EmitSubsCCheck(context, n, res);
  100. EmitSubsVCheck(context, n, m, res);
  101. }
  102. public static void Cmn(ArmEmitterContext context)
  103. {
  104. Operand n = GetAluN(context);
  105. Operand m = GetAluM(context, setCarry: false);
  106. Operand res = context.Add(n, m);
  107. EmitNZFlagsCheck(context, res);
  108. EmitAddsCCheck(context, n, res);
  109. EmitAddsVCheck(context, n, m, res);
  110. }
  111. public static void Eor(ArmEmitterContext context)
  112. {
  113. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  114. Operand n = GetAluN(context);
  115. Operand m = GetAluM(context);
  116. Operand res = context.BitwiseExclusiveOr(n, m);
  117. if (op.SetFlags)
  118. {
  119. EmitNZFlagsCheck(context, res);
  120. }
  121. EmitAluStore(context, res);
  122. }
  123. public static void Mov(ArmEmitterContext context)
  124. {
  125. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  126. Operand m = GetAluM(context);
  127. if (op.SetFlags)
  128. {
  129. EmitNZFlagsCheck(context, m);
  130. }
  131. EmitAluStore(context, m);
  132. }
  133. public static void Movt(ArmEmitterContext context)
  134. {
  135. OpCode32AluImm16 op = (OpCode32AluImm16)context.CurrOp;
  136. Operand d = GetIntA32(context, op.Rd);
  137. Operand imm = Const(op.Immediate << 16); // Immeditate value as top halfword.
  138. Operand res = context.BitwiseAnd(d, Const(0x0000ffff));
  139. res = context.BitwiseOr(res, imm);
  140. EmitAluStore(context, res);
  141. }
  142. public static void Mul(ArmEmitterContext context)
  143. {
  144. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  145. Operand n = GetAluN(context);
  146. Operand m = GetAluM(context);
  147. Operand res = context.Multiply(n, m);
  148. if (op.SetFlags)
  149. {
  150. EmitNZFlagsCheck(context, res);
  151. }
  152. EmitAluStore(context, res);
  153. }
  154. public static void Mvn(ArmEmitterContext context)
  155. {
  156. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  157. Operand m = GetAluM(context);
  158. Operand res = context.BitwiseNot(m);
  159. if (op.SetFlags)
  160. {
  161. EmitNZFlagsCheck(context, res);
  162. }
  163. EmitAluStore(context, res);
  164. }
  165. public static void Orr(ArmEmitterContext context)
  166. {
  167. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  168. Operand n = GetAluN(context);
  169. Operand m = GetAluM(context);
  170. Operand res = context.BitwiseOr(n, m);
  171. if (op.SetFlags)
  172. {
  173. EmitNZFlagsCheck(context, res);
  174. }
  175. EmitAluStore(context, res);
  176. }
  177. public static void Pkh(ArmEmitterContext context)
  178. {
  179. OpCode32AluRsImm op = (OpCode32AluRsImm)context.CurrOp;
  180. Operand n = GetAluN(context);
  181. Operand m = GetAluM(context);
  182. Operand res;
  183. bool tbform = op.ShiftType == ShiftType.Asr;
  184. if (tbform)
  185. {
  186. res = context.BitwiseOr(context.BitwiseAnd(n, Const(0xFFFF0000)), context.BitwiseAnd(m, Const(0xFFFF)));
  187. }
  188. else
  189. {
  190. res = context.BitwiseOr(context.BitwiseAnd(m, Const(0xFFFF0000)), context.BitwiseAnd(n, Const(0xFFFF)));
  191. }
  192. EmitAluStore(context, res);
  193. }
  194. public static void Rbit(ArmEmitterContext context)
  195. {
  196. Operand m = GetAluM(context);
  197. Operand res = EmitReverseBits32Op(context, m);
  198. EmitAluStore(context, res);
  199. }
  200. public static void Rev(ArmEmitterContext context)
  201. {
  202. Operand m = GetAluM(context);
  203. Operand res = context.ByteSwap(m);
  204. EmitAluStore(context, res);
  205. }
  206. public static void Rev16(ArmEmitterContext context)
  207. {
  208. Operand m = GetAluM(context);
  209. Operand res = EmitReverseBytes16_32Op(context, m);
  210. EmitAluStore(context, res);
  211. }
  212. public static void Revsh(ArmEmitterContext context)
  213. {
  214. Operand m = GetAluM(context);
  215. Operand res = EmitReverseBytes16_32Op(context, m);
  216. EmitAluStore(context, context.SignExtend16(OperandType.I32, res));
  217. }
  218. public static void Rsc(ArmEmitterContext context)
  219. {
  220. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  221. Operand n = GetAluN(context);
  222. Operand m = GetAluM(context, setCarry: false);
  223. Operand res = context.Subtract(m, n);
  224. Operand borrow = context.BitwiseExclusiveOr(GetFlag(PState.CFlag), Const(1));
  225. res = context.Subtract(res, borrow);
  226. if (op.SetFlags)
  227. {
  228. EmitNZFlagsCheck(context, res);
  229. EmitSbcsCCheck(context, m, n);
  230. EmitSubsVCheck(context, m, n, res);
  231. }
  232. EmitAluStore(context, res);
  233. }
  234. public static void Rsb(ArmEmitterContext context)
  235. {
  236. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  237. Operand n = GetAluN(context);
  238. Operand m = GetAluM(context, setCarry: false);
  239. Operand res = context.Subtract(m, n);
  240. if (op.SetFlags)
  241. {
  242. EmitNZFlagsCheck(context, res);
  243. EmitSubsCCheck(context, m, res);
  244. EmitSubsVCheck(context, m, n, res);
  245. }
  246. EmitAluStore(context, res);
  247. }
  248. public static void Sbc(ArmEmitterContext context)
  249. {
  250. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  251. Operand n = GetAluN(context);
  252. Operand m = GetAluM(context, setCarry: false);
  253. Operand res = context.Subtract(n, m);
  254. Operand borrow = context.BitwiseExclusiveOr(GetFlag(PState.CFlag), Const(1));
  255. res = context.Subtract(res, borrow);
  256. if (op.SetFlags)
  257. {
  258. EmitNZFlagsCheck(context, res);
  259. EmitSbcsCCheck(context, n, m);
  260. EmitSubsVCheck(context, n, m, res);
  261. }
  262. EmitAluStore(context, res);
  263. }
  264. public static void Sbfx(ArmEmitterContext context)
  265. {
  266. OpCode32AluBf op = (OpCode32AluBf)context.CurrOp;
  267. var msb = op.Lsb + op.Msb; // For this instruction, the msb is actually a width.
  268. Operand n = GetIntA32(context, op.Rn);
  269. Operand res = context.ShiftRightSI(context.ShiftLeft(n, Const(31 - msb)), Const(31 - op.Msb));
  270. SetIntA32(context, op.Rd, res);
  271. }
  272. public static void Sdiv(ArmEmitterContext context)
  273. {
  274. EmitDiv(context, false);
  275. }
  276. public static void Ssat(ArmEmitterContext context)
  277. {
  278. OpCode32Sat op = (OpCode32Sat)context.CurrOp;
  279. EmitSat(context, -(1 << op.SatImm), (1 << op.SatImm) - 1);
  280. }
  281. public static void Ssat16(ArmEmitterContext context)
  282. {
  283. OpCode32Sat16 op = (OpCode32Sat16)context.CurrOp;
  284. EmitSat16(context, -(1 << op.SatImm), (1 << op.SatImm) - 1);
  285. }
  286. public static void Sub(ArmEmitterContext context)
  287. {
  288. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  289. Operand n = GetAluN(context);
  290. Operand m = GetAluM(context, setCarry: false);
  291. Operand res = context.Subtract(n, m);
  292. if (op.SetFlags)
  293. {
  294. EmitNZFlagsCheck(context, res);
  295. EmitSubsCCheck(context, n, res);
  296. EmitSubsVCheck(context, n, m, res);
  297. }
  298. EmitAluStore(context, res);
  299. }
  300. public static void Sxtb(ArmEmitterContext context)
  301. {
  302. EmitSignExtend(context, true, 8);
  303. }
  304. public static void Sxtb16(ArmEmitterContext context)
  305. {
  306. EmitExtend16(context, true);
  307. }
  308. public static void Sxth(ArmEmitterContext context)
  309. {
  310. EmitSignExtend(context, true, 16);
  311. }
  312. public static void Teq(ArmEmitterContext context)
  313. {
  314. Operand n = GetAluN(context);
  315. Operand m = GetAluM(context);
  316. Operand res = context.BitwiseExclusiveOr(n, m);
  317. EmitNZFlagsCheck(context, res);
  318. }
  319. public static void Tst(ArmEmitterContext context)
  320. {
  321. Operand n = GetAluN(context);
  322. Operand m = GetAluM(context);
  323. Operand res = context.BitwiseAnd(n, m);
  324. EmitNZFlagsCheck(context, res);
  325. }
  326. public static void Ubfx(ArmEmitterContext context)
  327. {
  328. OpCode32AluBf op = (OpCode32AluBf)context.CurrOp;
  329. var msb = op.Lsb + op.Msb; // For this instruction, the msb is actually a width.
  330. Operand n = GetIntA32(context, op.Rn);
  331. Operand res = context.ShiftRightUI(context.ShiftLeft(n, Const(31 - msb)), Const(31 - op.Msb));
  332. SetIntA32(context, op.Rd, res);
  333. }
  334. public static void Udiv(ArmEmitterContext context)
  335. {
  336. EmitDiv(context, true);
  337. }
  338. public static void Uhadd8(ArmEmitterContext context)
  339. {
  340. OpCode32AluReg op = (OpCode32AluReg)context.CurrOp;
  341. Operand m = GetIntA32(context, op.Rm);
  342. Operand n = GetIntA32(context, op.Rn);
  343. Operand xor, res;
  344. res = context.BitwiseAnd(m, n);
  345. xor = context.BitwiseExclusiveOr(m, n);
  346. xor = context.ShiftRightUI(xor, Const(1));
  347. xor = context.BitwiseAnd(xor, Const(0x7F7F7F7Fu));
  348. res = context.Add(res, xor);
  349. SetIntA32(context, op.Rd, res);
  350. }
  351. public static void Usat(ArmEmitterContext context)
  352. {
  353. OpCode32Sat op = (OpCode32Sat)context.CurrOp;
  354. EmitSat(context, 0, op.SatImm == 32 ? (int)(~0) : (1 << op.SatImm) - 1);
  355. }
  356. public static void Usat16(ArmEmitterContext context)
  357. {
  358. OpCode32Sat16 op = (OpCode32Sat16)context.CurrOp;
  359. EmitSat16(context, 0, (1 << op.SatImm) - 1);
  360. }
  361. public static void Uxtb(ArmEmitterContext context)
  362. {
  363. EmitSignExtend(context, false, 8);
  364. }
  365. public static void Uxtb16(ArmEmitterContext context)
  366. {
  367. EmitExtend16(context, false);
  368. }
  369. public static void Uxth(ArmEmitterContext context)
  370. {
  371. EmitSignExtend(context, false, 16);
  372. }
  373. private static void EmitSignExtend(ArmEmitterContext context, bool signed, int bits)
  374. {
  375. IOpCode32AluUx op = (IOpCode32AluUx)context.CurrOp;
  376. Operand m = GetAluM(context);
  377. Operand res;
  378. if (op.RotateBits == 0)
  379. {
  380. res = m;
  381. }
  382. else
  383. {
  384. Operand rotate = Const(op.RotateBits);
  385. res = context.RotateRight(m, rotate);
  386. }
  387. switch (bits)
  388. {
  389. case 8:
  390. res = (signed) ? context.SignExtend8(OperandType.I32, res) : context.ZeroExtend8(OperandType.I32, res);
  391. break;
  392. case 16:
  393. res = (signed) ? context.SignExtend16(OperandType.I32, res) : context.ZeroExtend16(OperandType.I32, res);
  394. break;
  395. }
  396. if (op.Add)
  397. {
  398. res = context.Add(res, GetAluN(context));
  399. }
  400. EmitAluStore(context, res);
  401. }
  402. private static void EmitExtend16(ArmEmitterContext context, bool signed)
  403. {
  404. IOpCode32AluUx op = (IOpCode32AluUx)context.CurrOp;
  405. Operand m = GetAluM(context);
  406. Operand res;
  407. if (op.RotateBits == 0)
  408. {
  409. res = m;
  410. }
  411. else
  412. {
  413. Operand rotate = Const(op.RotateBits);
  414. res = context.RotateRight(m, rotate);
  415. }
  416. Operand low16, high16;
  417. if (signed)
  418. {
  419. low16 = context.SignExtend8(OperandType.I32, res);
  420. high16 = context.SignExtend8(OperandType.I32, context.ShiftRightUI(res, Const(16)));
  421. }
  422. else
  423. {
  424. low16 = context.ZeroExtend8(OperandType.I32, res);
  425. high16 = context.ZeroExtend8(OperandType.I32, context.ShiftRightUI(res, Const(16)));
  426. }
  427. if (op.Add)
  428. {
  429. Operand n = GetAluN(context);
  430. Operand lowAdd, highAdd;
  431. if (signed)
  432. {
  433. lowAdd = context.SignExtend16(OperandType.I32, n);
  434. highAdd = context.SignExtend16(OperandType.I32, context.ShiftRightUI(n, Const(16)));
  435. }
  436. else
  437. {
  438. lowAdd = context.ZeroExtend16(OperandType.I32, n);
  439. highAdd = context.ZeroExtend16(OperandType.I32, context.ShiftRightUI(n, Const(16)));
  440. }
  441. low16 = context.Add(low16, lowAdd);
  442. high16 = context.Add(high16, highAdd);
  443. }
  444. res = context.BitwiseOr(
  445. context.ZeroExtend16(OperandType.I32, low16),
  446. context.ShiftLeft(context.ZeroExtend16(OperandType.I32, high16), Const(16)));
  447. EmitAluStore(context, res);
  448. }
  449. private static void EmitDiv(ArmEmitterContext context, bool unsigned)
  450. {
  451. Operand n = GetAluN(context);
  452. Operand m = GetAluM(context);
  453. Operand zero = Const(m.Type, 0);
  454. Operand divisorIsZero = context.ICompareEqual(m, zero);
  455. Operand lblBadDiv = Label();
  456. Operand lblEnd = Label();
  457. context.BranchIfTrue(lblBadDiv, divisorIsZero);
  458. if (!unsigned)
  459. {
  460. // ARM64 behaviour: If Rn == INT_MIN && Rm == -1, Rd = INT_MIN (overflow).
  461. // TODO: tests to ensure A32 works the same
  462. Operand intMin = Const(int.MinValue);
  463. Operand minus1 = Const(-1);
  464. Operand nIsIntMin = context.ICompareEqual(n, intMin);
  465. Operand mIsMinus1 = context.ICompareEqual(m, minus1);
  466. Operand lblGoodDiv = Label();
  467. context.BranchIfFalse(lblGoodDiv, context.BitwiseAnd(nIsIntMin, mIsMinus1));
  468. EmitAluStore(context, intMin);
  469. context.Branch(lblEnd);
  470. context.MarkLabel(lblGoodDiv);
  471. }
  472. Operand res = unsigned
  473. ? context.DivideUI(n, m)
  474. : context.Divide(n, m);
  475. EmitAluStore(context, res);
  476. context.Branch(lblEnd);
  477. context.MarkLabel(lblBadDiv);
  478. EmitAluStore(context, zero);
  479. context.MarkLabel(lblEnd);
  480. }
  481. private static void EmitSat(ArmEmitterContext context, int intMin, int intMax)
  482. {
  483. OpCode32Sat op = (OpCode32Sat)context.CurrOp;
  484. Operand n = GetIntA32(context, op.Rn);
  485. int shift = DecodeImmShift(op.ShiftType, op.Imm5);
  486. switch (op.ShiftType)
  487. {
  488. case ShiftType.Lsl:
  489. if (shift == 32)
  490. {
  491. n = Const(0);
  492. }
  493. else
  494. {
  495. n = context.ShiftLeft(n, Const(shift));
  496. }
  497. break;
  498. case ShiftType.Asr:
  499. if (shift == 32)
  500. {
  501. n = context.ShiftRightSI(n, Const(31));
  502. }
  503. else
  504. {
  505. n = context.ShiftRightSI(n, Const(shift));
  506. }
  507. break;
  508. }
  509. Operand lblCheckLtIntMin = Label();
  510. Operand lblNoSat = Label();
  511. Operand lblEnd = Label();
  512. context.BranchIfFalse(lblCheckLtIntMin, context.ICompareGreater(n, Const(intMax)));
  513. SetFlag(context, PState.QFlag, Const(1));
  514. SetIntA32(context, op.Rd, Const(intMax));
  515. context.Branch(lblEnd);
  516. context.MarkLabel(lblCheckLtIntMin);
  517. context.BranchIfFalse(lblNoSat, context.ICompareLess(n, Const(intMin)));
  518. SetFlag(context, PState.QFlag, Const(1));
  519. SetIntA32(context, op.Rd, Const(intMin));
  520. context.Branch(lblEnd);
  521. context.MarkLabel(lblNoSat);
  522. SetIntA32(context, op.Rd, n);
  523. context.MarkLabel(lblEnd);
  524. }
  525. private static void EmitSat16(ArmEmitterContext context, int intMin, int intMax)
  526. {
  527. OpCode32Sat16 op = (OpCode32Sat16)context.CurrOp;
  528. void SetD(int part, Operand value)
  529. {
  530. if (part == 0)
  531. {
  532. SetIntA32(context, op.Rd, context.ZeroExtend16(OperandType.I32, value));
  533. }
  534. else
  535. {
  536. SetIntA32(context, op.Rd, context.BitwiseOr(GetIntA32(context, op.Rd), context.ShiftLeft(value, Const(16))));
  537. }
  538. }
  539. Operand n = GetIntA32(context, op.Rn);
  540. Operand nLow = context.SignExtend16(OperandType.I32, n);
  541. Operand nHigh = context.ShiftRightSI(n, Const(16));
  542. for (int part = 0; part < 2; part++)
  543. {
  544. Operand nPart = part == 0 ? nLow : nHigh;
  545. Operand lblCheckLtIntMin = Label();
  546. Operand lblNoSat = Label();
  547. Operand lblEnd = Label();
  548. context.BranchIfFalse(lblCheckLtIntMin, context.ICompareGreater(nPart, Const(intMax)));
  549. SetFlag(context, PState.QFlag, Const(1));
  550. SetD(part, Const(intMax));
  551. context.Branch(lblEnd);
  552. context.MarkLabel(lblCheckLtIntMin);
  553. context.BranchIfFalse(lblNoSat, context.ICompareLess(nPart, Const(intMin)));
  554. SetFlag(context, PState.QFlag, Const(1));
  555. SetD(part, Const(intMin));
  556. context.Branch(lblEnd);
  557. context.MarkLabel(lblNoSat);
  558. SetD(part, nPart);
  559. context.MarkLabel(lblEnd);
  560. }
  561. }
  562. private static void EmitAluStore(ArmEmitterContext context, Operand value)
  563. {
  564. IOpCode32Alu op = (IOpCode32Alu)context.CurrOp;
  565. EmitGenericAluStoreA32(context, op.Rd, op.SetFlags, value);
  566. }
  567. }
  568. }