InstEmitSimdShift.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. // https://github.com/intel/ARM_NEON_2_x86_SSE/blob/master/NEON_2_SSE.h
  2. using ARMeilleure.Decoders;
  3. using ARMeilleure.IntermediateRepresentation;
  4. using ARMeilleure.Translation;
  5. using System;
  6. using System.Diagnostics;
  7. using System.Reflection;
  8. using static ARMeilleure.Instructions.InstEmitHelper;
  9. using static ARMeilleure.Instructions.InstEmitSimdHelper;
  10. using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
  11. namespace ARMeilleure.Instructions
  12. {
  13. using Func2I = Func<Operand, Operand, Operand>;
  14. static partial class InstEmit
  15. {
  16. #region "Masks"
  17. private static readonly long[] _masks_SliSri = new long[] // Replication masks.
  18. {
  19. 0x0101010101010101L, 0x0001000100010001L, 0x0000000100000001L, 0x0000000000000001L
  20. };
  21. #endregion
  22. public static void Rshrn_V(ArmEmitterContext context)
  23. {
  24. if (Optimizations.UseSsse3)
  25. {
  26. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  27. int shift = GetImmShr(op);
  28. long roundConst = 1L << (shift - 1);
  29. Operand d = GetVec(op.Rd);
  30. Operand n = GetVec(op.Rn);
  31. Operand dLow = context.VectorZeroUpper64(d);
  32. Operand mask = default;
  33. switch (op.Size + 1)
  34. {
  35. case 1: mask = X86GetAllElements(context, (int)roundConst * 0x00010001); break;
  36. case 2: mask = X86GetAllElements(context, (int)roundConst); break;
  37. case 3: mask = X86GetAllElements(context, roundConst); break;
  38. }
  39. Intrinsic addInst = X86PaddInstruction[op.Size + 1];
  40. Operand res = context.AddIntrinsic(addInst, n, mask);
  41. Intrinsic srlInst = X86PsrlInstruction[op.Size + 1];
  42. res = context.AddIntrinsic(srlInst, res, Const(shift));
  43. Operand mask2 = X86GetAllElements(context, EvenMasks[op.Size]);
  44. res = context.AddIntrinsic(Intrinsic.X86Pshufb, res, mask2);
  45. Intrinsic movInst = op.RegisterSize == RegisterSize.Simd128
  46. ? Intrinsic.X86Movlhps
  47. : Intrinsic.X86Movhlps;
  48. res = context.AddIntrinsic(movInst, dLow, res);
  49. context.Copy(d, res);
  50. }
  51. else
  52. {
  53. EmitVectorShrImmNarrowOpZx(context, round: true);
  54. }
  55. }
  56. public static void Shl_S(ArmEmitterContext context)
  57. {
  58. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  59. int shift = GetImmShl(op);
  60. EmitScalarUnaryOpZx(context, (op1) => context.ShiftLeft(op1, Const(shift)));
  61. }
  62. public static void Shl_V(ArmEmitterContext context)
  63. {
  64. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  65. int shift = GetImmShl(op);
  66. if (Optimizations.UseSse2 && op.Size > 0)
  67. {
  68. Operand n = GetVec(op.Rn);
  69. Intrinsic sllInst = X86PsllInstruction[op.Size];
  70. Operand res = context.AddIntrinsic(sllInst, n, Const(shift));
  71. if (op.RegisterSize == RegisterSize.Simd64)
  72. {
  73. res = context.VectorZeroUpper64(res);
  74. }
  75. context.Copy(GetVec(op.Rd), res);
  76. }
  77. else
  78. {
  79. EmitVectorUnaryOpZx(context, (op1) => context.ShiftLeft(op1, Const(shift)));
  80. }
  81. }
  82. public static void Shll_V(ArmEmitterContext context)
  83. {
  84. OpCodeSimd op = (OpCodeSimd)context.CurrOp;
  85. int shift = 8 << op.Size;
  86. if (Optimizations.UseSse41)
  87. {
  88. Operand n = GetVec(op.Rn);
  89. if (op.RegisterSize == RegisterSize.Simd128)
  90. {
  91. n = context.AddIntrinsic(Intrinsic.X86Psrldq, n, Const(8));
  92. }
  93. Intrinsic movsxInst = X86PmovsxInstruction[op.Size];
  94. Operand res = context.AddIntrinsic(movsxInst, n);
  95. Intrinsic sllInst = X86PsllInstruction[op.Size + 1];
  96. res = context.AddIntrinsic(sllInst, res, Const(shift));
  97. context.Copy(GetVec(op.Rd), res);
  98. }
  99. else
  100. {
  101. EmitVectorShImmWidenBinaryZx(context, (op1, op2) => context.ShiftLeft(op1, op2), shift);
  102. }
  103. }
  104. public static void Shrn_V(ArmEmitterContext context)
  105. {
  106. if (Optimizations.UseSsse3)
  107. {
  108. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  109. int shift = GetImmShr(op);
  110. Operand d = GetVec(op.Rd);
  111. Operand n = GetVec(op.Rn);
  112. Operand dLow = context.VectorZeroUpper64(d);
  113. Intrinsic srlInst = X86PsrlInstruction[op.Size + 1];
  114. Operand nShifted = context.AddIntrinsic(srlInst, n, Const(shift));
  115. Operand mask = X86GetAllElements(context, EvenMasks[op.Size]);
  116. Operand res = context.AddIntrinsic(Intrinsic.X86Pshufb, nShifted, mask);
  117. Intrinsic movInst = op.RegisterSize == RegisterSize.Simd128
  118. ? Intrinsic.X86Movlhps
  119. : Intrinsic.X86Movhlps;
  120. res = context.AddIntrinsic(movInst, dLow, res);
  121. context.Copy(d, res);
  122. }
  123. else
  124. {
  125. EmitVectorShrImmNarrowOpZx(context, round: false);
  126. }
  127. }
  128. public static void Sli_S(ArmEmitterContext context)
  129. {
  130. EmitSli(context, scalar: true);
  131. }
  132. public static void Sli_V(ArmEmitterContext context)
  133. {
  134. EmitSli(context, scalar: false);
  135. }
  136. public static void Sqrshl_V(ArmEmitterContext context)
  137. {
  138. EmitShlRegOp(context, ShlRegFlags.Signed | ShlRegFlags.Round | ShlRegFlags.Saturating);
  139. }
  140. public static void Sqrshrn_S(ArmEmitterContext context)
  141. {
  142. EmitRoundShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.ScalarSxSx);
  143. }
  144. public static void Sqrshrn_V(ArmEmitterContext context)
  145. {
  146. EmitRoundShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.VectorSxSx);
  147. }
  148. public static void Sqrshrun_S(ArmEmitterContext context)
  149. {
  150. EmitRoundShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.ScalarSxZx);
  151. }
  152. public static void Sqrshrun_V(ArmEmitterContext context)
  153. {
  154. EmitRoundShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.VectorSxZx);
  155. }
  156. public static void Sqshl_V(ArmEmitterContext context)
  157. {
  158. EmitShlRegOp(context, ShlRegFlags.Signed | ShlRegFlags.Saturating);
  159. }
  160. public static void Sqshrn_S(ArmEmitterContext context)
  161. {
  162. EmitShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.ScalarSxSx);
  163. }
  164. public static void Sqshrn_V(ArmEmitterContext context)
  165. {
  166. EmitShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.VectorSxSx);
  167. }
  168. public static void Sqshrun_S(ArmEmitterContext context)
  169. {
  170. EmitShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.ScalarSxZx);
  171. }
  172. public static void Sqshrun_V(ArmEmitterContext context)
  173. {
  174. EmitShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.VectorSxZx);
  175. }
  176. public static void Sri_S(ArmEmitterContext context)
  177. {
  178. EmitSri(context, scalar: true);
  179. }
  180. public static void Sri_V(ArmEmitterContext context)
  181. {
  182. EmitSri(context, scalar: false);
  183. }
  184. public static void Srshl_V(ArmEmitterContext context)
  185. {
  186. EmitShlRegOp(context, ShlRegFlags.Signed | ShlRegFlags.Round);
  187. }
  188. public static void Srshr_S(ArmEmitterContext context)
  189. {
  190. EmitScalarShrImmOpSx(context, ShrImmFlags.Round);
  191. }
  192. public static void Srshr_V(ArmEmitterContext context)
  193. {
  194. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  195. if (Optimizations.UseSse2 && op.Size > 0 && op.Size < 3)
  196. {
  197. int shift = GetImmShr(op);
  198. int eSize = 8 << op.Size;
  199. Operand n = GetVec(op.Rn);
  200. Intrinsic sllInst = X86PsllInstruction[op.Size];
  201. Operand res = context.AddIntrinsic(sllInst, n, Const(eSize - shift));
  202. Intrinsic srlInst = X86PsrlInstruction[op.Size];
  203. res = context.AddIntrinsic(srlInst, res, Const(eSize - 1));
  204. Intrinsic sraInst = X86PsraInstruction[op.Size];
  205. Operand nSra = context.AddIntrinsic(sraInst, n, Const(shift));
  206. Intrinsic addInst = X86PaddInstruction[op.Size];
  207. res = context.AddIntrinsic(addInst, res, nSra);
  208. if (op.RegisterSize == RegisterSize.Simd64)
  209. {
  210. res = context.VectorZeroUpper64(res);
  211. }
  212. context.Copy(GetVec(op.Rd), res);
  213. }
  214. else
  215. {
  216. EmitVectorShrImmOpSx(context, ShrImmFlags.Round);
  217. }
  218. }
  219. public static void Srsra_S(ArmEmitterContext context)
  220. {
  221. EmitScalarShrImmOpSx(context, ShrImmFlags.Round | ShrImmFlags.Accumulate);
  222. }
  223. public static void Srsra_V(ArmEmitterContext context)
  224. {
  225. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  226. if (Optimizations.UseSse2 && op.Size > 0 && op.Size < 3)
  227. {
  228. int shift = GetImmShr(op);
  229. int eSize = 8 << op.Size;
  230. Operand d = GetVec(op.Rd);
  231. Operand n = GetVec(op.Rn);
  232. Intrinsic sllInst = X86PsllInstruction[op.Size];
  233. Operand res = context.AddIntrinsic(sllInst, n, Const(eSize - shift));
  234. Intrinsic srlInst = X86PsrlInstruction[op.Size];
  235. res = context.AddIntrinsic(srlInst, res, Const(eSize - 1));
  236. Intrinsic sraInst = X86PsraInstruction[op.Size];
  237. Operand nSra = context.AddIntrinsic(sraInst, n, Const(shift));
  238. Intrinsic addInst = X86PaddInstruction[op.Size];
  239. res = context.AddIntrinsic(addInst, res, nSra);
  240. res = context.AddIntrinsic(addInst, res, d);
  241. if (op.RegisterSize == RegisterSize.Simd64)
  242. {
  243. res = context.VectorZeroUpper64(res);
  244. }
  245. context.Copy(d, res);
  246. }
  247. else
  248. {
  249. EmitVectorShrImmOpSx(context, ShrImmFlags.Round | ShrImmFlags.Accumulate);
  250. }
  251. }
  252. public static void Sshl_S(ArmEmitterContext context)
  253. {
  254. EmitShlRegOp(context, ShlRegFlags.Scalar | ShlRegFlags.Signed);
  255. }
  256. public static void Sshl_V(ArmEmitterContext context)
  257. {
  258. EmitShlRegOp(context, ShlRegFlags.Signed);
  259. }
  260. public static void Sshll_V(ArmEmitterContext context)
  261. {
  262. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  263. int shift = GetImmShl(op);
  264. if (Optimizations.UseSse41)
  265. {
  266. Operand n = GetVec(op.Rn);
  267. if (op.RegisterSize == RegisterSize.Simd128)
  268. {
  269. n = context.AddIntrinsic(Intrinsic.X86Psrldq, n, Const(8));
  270. }
  271. Intrinsic movsxInst = X86PmovsxInstruction[op.Size];
  272. Operand res = context.AddIntrinsic(movsxInst, n);
  273. if (shift != 0)
  274. {
  275. Intrinsic sllInst = X86PsllInstruction[op.Size + 1];
  276. res = context.AddIntrinsic(sllInst, res, Const(shift));
  277. }
  278. context.Copy(GetVec(op.Rd), res);
  279. }
  280. else
  281. {
  282. EmitVectorShImmWidenBinarySx(context, (op1, op2) => context.ShiftLeft(op1, op2), shift);
  283. }
  284. }
  285. public static void Sshr_S(ArmEmitterContext context)
  286. {
  287. EmitShrImmOp(context, ShrImmFlags.ScalarSx);
  288. }
  289. public static void Sshr_V(ArmEmitterContext context)
  290. {
  291. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  292. if (Optimizations.UseSse2 && op.Size > 0 && op.Size < 3)
  293. {
  294. int shift = GetImmShr(op);
  295. Operand n = GetVec(op.Rn);
  296. Intrinsic sraInst = X86PsraInstruction[op.Size];
  297. Operand res = context.AddIntrinsic(sraInst, n, Const(shift));
  298. if (op.RegisterSize == RegisterSize.Simd64)
  299. {
  300. res = context.VectorZeroUpper64(res);
  301. }
  302. context.Copy(GetVec(op.Rd), res);
  303. }
  304. else
  305. {
  306. EmitShrImmOp(context, ShrImmFlags.VectorSx);
  307. }
  308. }
  309. public static void Ssra_S(ArmEmitterContext context)
  310. {
  311. EmitScalarShrImmOpSx(context, ShrImmFlags.Accumulate);
  312. }
  313. public static void Ssra_V(ArmEmitterContext context)
  314. {
  315. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  316. if (Optimizations.UseSse2 && op.Size > 0 && op.Size < 3)
  317. {
  318. int shift = GetImmShr(op);
  319. Operand d = GetVec(op.Rd);
  320. Operand n = GetVec(op.Rn);
  321. Intrinsic sraInst = X86PsraInstruction[op.Size];
  322. Operand res = context.AddIntrinsic(sraInst, n, Const(shift));
  323. Intrinsic addInst = X86PaddInstruction[op.Size];
  324. res = context.AddIntrinsic(addInst, res, d);
  325. if (op.RegisterSize == RegisterSize.Simd64)
  326. {
  327. res = context.VectorZeroUpper64(res);
  328. }
  329. context.Copy(d, res);
  330. }
  331. else
  332. {
  333. EmitVectorShrImmOpSx(context, ShrImmFlags.Accumulate);
  334. }
  335. }
  336. public static void Uqrshl_V(ArmEmitterContext context)
  337. {
  338. EmitShlRegOp(context, ShlRegFlags.Round | ShlRegFlags.Saturating);
  339. }
  340. public static void Uqrshrn_S(ArmEmitterContext context)
  341. {
  342. EmitRoundShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.ScalarZxZx);
  343. }
  344. public static void Uqrshrn_V(ArmEmitterContext context)
  345. {
  346. EmitRoundShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.VectorZxZx);
  347. }
  348. public static void Uqshl_V(ArmEmitterContext context)
  349. {
  350. EmitShlRegOp(context, ShlRegFlags.Saturating);
  351. }
  352. public static void Uqshrn_S(ArmEmitterContext context)
  353. {
  354. EmitShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.ScalarZxZx);
  355. }
  356. public static void Uqshrn_V(ArmEmitterContext context)
  357. {
  358. EmitShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.VectorZxZx);
  359. }
  360. public static void Urshl_V(ArmEmitterContext context)
  361. {
  362. EmitShlRegOp(context, ShlRegFlags.Round);
  363. }
  364. public static void Urshr_S(ArmEmitterContext context)
  365. {
  366. EmitScalarShrImmOpZx(context, ShrImmFlags.Round);
  367. }
  368. public static void Urshr_V(ArmEmitterContext context)
  369. {
  370. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  371. if (Optimizations.UseSse2 && op.Size > 0)
  372. {
  373. int shift = GetImmShr(op);
  374. int eSize = 8 << op.Size;
  375. Operand n = GetVec(op.Rn);
  376. Intrinsic sllInst = X86PsllInstruction[op.Size];
  377. Operand res = context.AddIntrinsic(sllInst, n, Const(eSize - shift));
  378. Intrinsic srlInst = X86PsrlInstruction[op.Size];
  379. res = context.AddIntrinsic(srlInst, res, Const(eSize - 1));
  380. Operand nSrl = context.AddIntrinsic(srlInst, n, Const(shift));
  381. Intrinsic addInst = X86PaddInstruction[op.Size];
  382. res = context.AddIntrinsic(addInst, res, nSrl);
  383. if (op.RegisterSize == RegisterSize.Simd64)
  384. {
  385. res = context.VectorZeroUpper64(res);
  386. }
  387. context.Copy(GetVec(op.Rd), res);
  388. }
  389. else
  390. {
  391. EmitVectorShrImmOpZx(context, ShrImmFlags.Round);
  392. }
  393. }
  394. public static void Ursra_S(ArmEmitterContext context)
  395. {
  396. EmitScalarShrImmOpZx(context, ShrImmFlags.Round | ShrImmFlags.Accumulate);
  397. }
  398. public static void Ursra_V(ArmEmitterContext context)
  399. {
  400. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  401. if (Optimizations.UseSse2 && op.Size > 0)
  402. {
  403. int shift = GetImmShr(op);
  404. int eSize = 8 << op.Size;
  405. Operand d = GetVec(op.Rd);
  406. Operand n = GetVec(op.Rn);
  407. Intrinsic sllInst = X86PsllInstruction[op.Size];
  408. Operand res = context.AddIntrinsic(sllInst, n, Const(eSize - shift));
  409. Intrinsic srlInst = X86PsrlInstruction[op.Size];
  410. res = context.AddIntrinsic(srlInst, res, Const(eSize - 1));
  411. Operand nSrl = context.AddIntrinsic(srlInst, n, Const(shift));
  412. Intrinsic addInst = X86PaddInstruction[op.Size];
  413. res = context.AddIntrinsic(addInst, res, nSrl);
  414. res = context.AddIntrinsic(addInst, res, d);
  415. if (op.RegisterSize == RegisterSize.Simd64)
  416. {
  417. res = context.VectorZeroUpper64(res);
  418. }
  419. context.Copy(d, res);
  420. }
  421. else
  422. {
  423. EmitVectorShrImmOpZx(context, ShrImmFlags.Round | ShrImmFlags.Accumulate);
  424. }
  425. }
  426. public static void Ushl_S(ArmEmitterContext context)
  427. {
  428. EmitShlRegOp(context, ShlRegFlags.Scalar);
  429. }
  430. public static void Ushl_V(ArmEmitterContext context)
  431. {
  432. EmitShlRegOp(context, ShlRegFlags.None);
  433. }
  434. public static void Ushll_V(ArmEmitterContext context)
  435. {
  436. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  437. int shift = GetImmShl(op);
  438. if (Optimizations.UseSse41)
  439. {
  440. Operand n = GetVec(op.Rn);
  441. if (op.RegisterSize == RegisterSize.Simd128)
  442. {
  443. n = context.AddIntrinsic(Intrinsic.X86Psrldq, n, Const(8));
  444. }
  445. Intrinsic movzxInst = X86PmovzxInstruction[op.Size];
  446. Operand res = context.AddIntrinsic(movzxInst, n);
  447. if (shift != 0)
  448. {
  449. Intrinsic sllInst = X86PsllInstruction[op.Size + 1];
  450. res = context.AddIntrinsic(sllInst, res, Const(shift));
  451. }
  452. context.Copy(GetVec(op.Rd), res);
  453. }
  454. else
  455. {
  456. EmitVectorShImmWidenBinaryZx(context, (op1, op2) => context.ShiftLeft(op1, op2), shift);
  457. }
  458. }
  459. public static void Ushr_S(ArmEmitterContext context)
  460. {
  461. EmitShrImmOp(context, ShrImmFlags.ScalarZx);
  462. }
  463. public static void Ushr_V(ArmEmitterContext context)
  464. {
  465. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  466. if (Optimizations.UseSse2 && op.Size > 0)
  467. {
  468. int shift = GetImmShr(op);
  469. Operand n = GetVec(op.Rn);
  470. Intrinsic srlInst = X86PsrlInstruction[op.Size];
  471. Operand res = context.AddIntrinsic(srlInst, n, Const(shift));
  472. if (op.RegisterSize == RegisterSize.Simd64)
  473. {
  474. res = context.VectorZeroUpper64(res);
  475. }
  476. context.Copy(GetVec(op.Rd), res);
  477. }
  478. else
  479. {
  480. EmitShrImmOp(context, ShrImmFlags.VectorZx);
  481. }
  482. }
  483. public static void Usra_S(ArmEmitterContext context)
  484. {
  485. EmitScalarShrImmOpZx(context, ShrImmFlags.Accumulate);
  486. }
  487. public static void Usra_V(ArmEmitterContext context)
  488. {
  489. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  490. if (Optimizations.UseSse2 && op.Size > 0)
  491. {
  492. int shift = GetImmShr(op);
  493. Operand d = GetVec(op.Rd);
  494. Operand n = GetVec(op.Rn);
  495. Intrinsic srlInst = X86PsrlInstruction[op.Size];
  496. Operand res = context.AddIntrinsic(srlInst, n, Const(shift));
  497. Intrinsic addInst = X86PaddInstruction[op.Size];
  498. res = context.AddIntrinsic(addInst, res, d);
  499. if (op.RegisterSize == RegisterSize.Simd64)
  500. {
  501. res = context.VectorZeroUpper64(res);
  502. }
  503. context.Copy(d, res);
  504. }
  505. else
  506. {
  507. EmitVectorShrImmOpZx(context, ShrImmFlags.Accumulate);
  508. }
  509. }
  510. [Flags]
  511. private enum ShrImmFlags
  512. {
  513. Scalar = 1 << 0,
  514. Signed = 1 << 1,
  515. Round = 1 << 2,
  516. Accumulate = 1 << 3,
  517. ScalarSx = Scalar | Signed,
  518. ScalarZx = Scalar,
  519. VectorSx = Signed,
  520. VectorZx = 0
  521. }
  522. private static void EmitScalarShrImmOpSx(ArmEmitterContext context, ShrImmFlags flags)
  523. {
  524. EmitShrImmOp(context, ShrImmFlags.ScalarSx | flags);
  525. }
  526. private static void EmitScalarShrImmOpZx(ArmEmitterContext context, ShrImmFlags flags)
  527. {
  528. EmitShrImmOp(context, ShrImmFlags.ScalarZx | flags);
  529. }
  530. private static void EmitVectorShrImmOpSx(ArmEmitterContext context, ShrImmFlags flags)
  531. {
  532. EmitShrImmOp(context, ShrImmFlags.VectorSx | flags);
  533. }
  534. private static void EmitVectorShrImmOpZx(ArmEmitterContext context, ShrImmFlags flags)
  535. {
  536. EmitShrImmOp(context, ShrImmFlags.VectorZx | flags);
  537. }
  538. private static void EmitShrImmOp(ArmEmitterContext context, ShrImmFlags flags)
  539. {
  540. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  541. Operand res = context.VectorZero();
  542. bool scalar = (flags & ShrImmFlags.Scalar) != 0;
  543. bool signed = (flags & ShrImmFlags.Signed) != 0;
  544. bool round = (flags & ShrImmFlags.Round) != 0;
  545. bool accumulate = (flags & ShrImmFlags.Accumulate) != 0;
  546. int shift = GetImmShr(op);
  547. long roundConst = 1L << (shift - 1);
  548. int elems = !scalar ? op.GetBytesCount() >> op.Size : 1;
  549. for (int index = 0; index < elems; index++)
  550. {
  551. Operand e = EmitVectorExtract(context, op.Rn, index, op.Size, signed);
  552. if (op.Size <= 2)
  553. {
  554. if (round)
  555. {
  556. e = context.Add(e, Const(roundConst));
  557. }
  558. e = signed ? context.ShiftRightSI(e, Const(shift)) : context.ShiftRightUI(e, Const(shift));
  559. }
  560. else /* if (op.Size == 3) */
  561. {
  562. e = EmitShrImm64(context, e, signed, round ? roundConst : 0L, shift);
  563. }
  564. if (accumulate)
  565. {
  566. Operand de = EmitVectorExtract(context, op.Rd, index, op.Size, signed);
  567. e = context.Add(e, de);
  568. }
  569. res = EmitVectorInsert(context, res, e, index, op.Size);
  570. }
  571. context.Copy(GetVec(op.Rd), res);
  572. }
  573. private static void EmitVectorShrImmNarrowOpZx(ArmEmitterContext context, bool round)
  574. {
  575. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  576. int shift = GetImmShr(op);
  577. long roundConst = 1L << (shift - 1);
  578. int elems = 8 >> op.Size;
  579. int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0;
  580. Operand d = GetVec(op.Rd);
  581. Operand res = part == 0 ? context.VectorZero() : context.Copy(d);
  582. for (int index = 0; index < elems; index++)
  583. {
  584. Operand e = EmitVectorExtractZx(context, op.Rn, index, op.Size + 1);
  585. if (round)
  586. {
  587. e = context.Add(e, Const(roundConst));
  588. }
  589. e = context.ShiftRightUI(e, Const(shift));
  590. res = EmitVectorInsert(context, res, e, part + index, op.Size);
  591. }
  592. context.Copy(d, res);
  593. }
  594. [Flags]
  595. private enum ShrImmSaturatingNarrowFlags
  596. {
  597. Scalar = 1 << 0,
  598. SignedSrc = 1 << 1,
  599. SignedDst = 1 << 2,
  600. Round = 1 << 3,
  601. ScalarSxSx = Scalar | SignedSrc | SignedDst,
  602. ScalarSxZx = Scalar | SignedSrc,
  603. ScalarZxZx = Scalar,
  604. VectorSxSx = SignedSrc | SignedDst,
  605. VectorSxZx = SignedSrc,
  606. VectorZxZx = 0
  607. }
  608. private static void EmitRoundShrImmSaturatingNarrowOp(ArmEmitterContext context, ShrImmSaturatingNarrowFlags flags)
  609. {
  610. EmitShrImmSaturatingNarrowOp(context, ShrImmSaturatingNarrowFlags.Round | flags);
  611. }
  612. private static void EmitShrImmSaturatingNarrowOp(ArmEmitterContext context, ShrImmSaturatingNarrowFlags flags)
  613. {
  614. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  615. bool scalar = (flags & ShrImmSaturatingNarrowFlags.Scalar) != 0;
  616. bool signedSrc = (flags & ShrImmSaturatingNarrowFlags.SignedSrc) != 0;
  617. bool signedDst = (flags & ShrImmSaturatingNarrowFlags.SignedDst) != 0;
  618. bool round = (flags & ShrImmSaturatingNarrowFlags.Round) != 0;
  619. int shift = GetImmShr(op);
  620. long roundConst = 1L << (shift - 1);
  621. int elems = !scalar ? 8 >> op.Size : 1;
  622. int part = !scalar && (op.RegisterSize == RegisterSize.Simd128) ? elems : 0;
  623. Operand d = GetVec(op.Rd);
  624. Operand res = part == 0 ? context.VectorZero() : context.Copy(d);
  625. for (int index = 0; index < elems; index++)
  626. {
  627. Operand e = EmitVectorExtract(context, op.Rn, index, op.Size + 1, signedSrc);
  628. if (op.Size <= 1 || !round)
  629. {
  630. if (round)
  631. {
  632. e = context.Add(e, Const(roundConst));
  633. }
  634. e = signedSrc ? context.ShiftRightSI(e, Const(shift)) : context.ShiftRightUI(e, Const(shift));
  635. }
  636. else /* if (op.Size == 2 && round) */
  637. {
  638. e = EmitShrImm64(context, e, signedSrc, roundConst, shift); // shift <= 32
  639. }
  640. e = signedSrc ? EmitSignedSrcSatQ(context, e, op.Size, signedDst) : EmitUnsignedSrcSatQ(context, e, op.Size, signedDst);
  641. res = EmitVectorInsert(context, res, e, part + index, op.Size);
  642. }
  643. context.Copy(d, res);
  644. }
  645. // dst64 = (Int(src64, signed) + roundConst) >> shift;
  646. private static Operand EmitShrImm64(
  647. ArmEmitterContext context,
  648. Operand value,
  649. bool signed,
  650. long roundConst,
  651. int shift)
  652. {
  653. MethodInfo info = signed
  654. ? typeof(SoftFallback).GetMethod(nameof(SoftFallback.SignedShrImm64))
  655. : typeof(SoftFallback).GetMethod(nameof(SoftFallback.UnsignedShrImm64));
  656. return context.Call(info, value, Const(roundConst), Const(shift));
  657. }
  658. private static void EmitVectorShImmWidenBinarySx(ArmEmitterContext context, Func2I emit, int imm)
  659. {
  660. EmitVectorShImmWidenBinaryOp(context, emit, imm, signed: true);
  661. }
  662. private static void EmitVectorShImmWidenBinaryZx(ArmEmitterContext context, Func2I emit, int imm)
  663. {
  664. EmitVectorShImmWidenBinaryOp(context, emit, imm, signed: false);
  665. }
  666. private static void EmitVectorShImmWidenBinaryOp(ArmEmitterContext context, Func2I emit, int imm, bool signed)
  667. {
  668. OpCodeSimd op = (OpCodeSimd)context.CurrOp;
  669. Operand res = context.VectorZero();
  670. int elems = 8 >> op.Size;
  671. int part = op.RegisterSize == RegisterSize.Simd128 ? elems : 0;
  672. for (int index = 0; index < elems; index++)
  673. {
  674. Operand ne = EmitVectorExtract(context, op.Rn, part + index, op.Size, signed);
  675. res = EmitVectorInsert(context, res, emit(ne, Const(imm)), index, op.Size + 1);
  676. }
  677. context.Copy(GetVec(op.Rd), res);
  678. }
  679. private static void EmitSli(ArmEmitterContext context, bool scalar)
  680. {
  681. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  682. int shift = GetImmShl(op);
  683. ulong mask = shift != 0 ? ulong.MaxValue >> (64 - shift) : 0UL;
  684. if (Optimizations.UseSse2 && op.Size > 0)
  685. {
  686. Operand d = GetVec(op.Rd);
  687. Operand n = GetVec(op.Rn);
  688. Intrinsic sllInst = X86PsllInstruction[op.Size];
  689. Operand nShifted = context.AddIntrinsic(sllInst, n, Const(shift));
  690. Operand dMask = X86GetAllElements(context, (long)mask * _masks_SliSri[op.Size]);
  691. Operand dMasked = context.AddIntrinsic(Intrinsic.X86Pand, d, dMask);
  692. Operand res = context.AddIntrinsic(Intrinsic.X86Por, nShifted, dMasked);
  693. if ((op.RegisterSize == RegisterSize.Simd64) || scalar)
  694. {
  695. res = context.VectorZeroUpper64(res);
  696. }
  697. context.Copy(d, res);
  698. }
  699. else
  700. {
  701. Operand res = context.VectorZero();
  702. int elems = !scalar ? op.GetBytesCount() >> op.Size : 1;
  703. for (int index = 0; index < elems; index++)
  704. {
  705. Operand ne = EmitVectorExtractZx(context, op.Rn, index, op.Size);
  706. Operand neShifted = context.ShiftLeft(ne, Const(shift));
  707. Operand de = EmitVectorExtractZx(context, op.Rd, index, op.Size);
  708. Operand deMasked = context.BitwiseAnd(de, Const(mask));
  709. Operand e = context.BitwiseOr(neShifted, deMasked);
  710. res = EmitVectorInsert(context, res, e, index, op.Size);
  711. }
  712. context.Copy(GetVec(op.Rd), res);
  713. }
  714. }
  715. private static void EmitSri(ArmEmitterContext context, bool scalar)
  716. {
  717. OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
  718. int shift = GetImmShr(op);
  719. int eSize = 8 << op.Size;
  720. ulong mask = (ulong.MaxValue << (eSize - shift)) & (ulong.MaxValue >> (64 - eSize));
  721. if (Optimizations.UseSse2 && op.Size > 0)
  722. {
  723. Operand d = GetVec(op.Rd);
  724. Operand n = GetVec(op.Rn);
  725. Intrinsic srlInst = X86PsrlInstruction[op.Size];
  726. Operand nShifted = context.AddIntrinsic(srlInst, n, Const(shift));
  727. Operand dMask = X86GetAllElements(context, (long)mask * _masks_SliSri[op.Size]);
  728. Operand dMasked = context.AddIntrinsic(Intrinsic.X86Pand, d, dMask);
  729. Operand res = context.AddIntrinsic(Intrinsic.X86Por, nShifted, dMasked);
  730. if ((op.RegisterSize == RegisterSize.Simd64) || scalar)
  731. {
  732. res = context.VectorZeroUpper64(res);
  733. }
  734. context.Copy(d, res);
  735. }
  736. else
  737. {
  738. Operand res = context.VectorZero();
  739. int elems = !scalar ? op.GetBytesCount() >> op.Size : 1;
  740. for (int index = 0; index < elems; index++)
  741. {
  742. Operand ne = EmitVectorExtractZx(context, op.Rn, index, op.Size);
  743. Operand neShifted = shift != 64 ? context.ShiftRightUI(ne, Const(shift)) : Const(0UL);
  744. Operand de = EmitVectorExtractZx(context, op.Rd, index, op.Size);
  745. Operand deMasked = context.BitwiseAnd(de, Const(mask));
  746. Operand e = context.BitwiseOr(neShifted, deMasked);
  747. res = EmitVectorInsert(context, res, e, index, op.Size);
  748. }
  749. context.Copy(GetVec(op.Rd), res);
  750. }
  751. }
  752. [Flags]
  753. private enum ShlRegFlags
  754. {
  755. None = 0,
  756. Scalar = 1 << 0,
  757. Signed = 1 << 1,
  758. Round = 1 << 2,
  759. Saturating = 1 << 3
  760. }
  761. private static void EmitShlRegOp(ArmEmitterContext context, ShlRegFlags flags = ShlRegFlags.None)
  762. {
  763. bool scalar = flags.HasFlag(ShlRegFlags.Scalar);
  764. bool signed = flags.HasFlag(ShlRegFlags.Signed);
  765. bool round = flags.HasFlag(ShlRegFlags.Round);
  766. bool saturating = flags.HasFlag(ShlRegFlags.Saturating);
  767. OpCodeSimdReg op = (OpCodeSimdReg)context.CurrOp;
  768. Operand res = context.VectorZero();
  769. int elems = !scalar ? op.GetBytesCount() >> op.Size : 1;
  770. for (int index = 0; index < elems; index++)
  771. {
  772. Operand ne = EmitVectorExtract(context, op.Rn, index, op.Size, signed);
  773. Operand me = EmitVectorExtractSx(context, op.Rm, index << op.Size, size: 0);
  774. Operand e = !saturating
  775. ? EmitShlReg(context, ne, context.ConvertI64ToI32(me), round, op.Size, signed)
  776. : EmitShlRegSatQ(context, ne, context.ConvertI64ToI32(me), round, op.Size, signed);
  777. res = EmitVectorInsert(context, res, e, index, op.Size);
  778. }
  779. context.Copy(GetVec(op.Rd), res);
  780. }
  781. // long SignedShlReg(long op, int shiftLsB, bool round, int size);
  782. // ulong UnsignedShlReg(ulong op, int shiftLsB, bool round, int size);
  783. private static Operand EmitShlReg(ArmEmitterContext context, Operand op, Operand shiftLsB, bool round, int size, bool signed)
  784. {
  785. int eSize = 8 << size;
  786. Debug.Assert(op.Type == OperandType.I64);
  787. Debug.Assert(shiftLsB.Type == OperandType.I32);
  788. Debug.Assert(eSize == 8 || eSize == 16 || eSize == 32 || eSize == 64);
  789. Operand lbl1 = Label();
  790. Operand lblEnd = Label();
  791. Operand eSizeOp = Const(eSize);
  792. Operand zero = Const(0);
  793. Operand zeroL = Const(0L);
  794. Operand res = context.Copy(context.AllocateLocal(OperandType.I64), op);
  795. context.BranchIf(lbl1, shiftLsB, zero, Comparison.GreaterOrEqual);
  796. context.Copy(res, signed
  797. ? EmitSignedShrReg(context, op, context.Negate(shiftLsB), round, eSize)
  798. : EmitUnsignedShrReg(context, op, context.Negate(shiftLsB), round, eSize));
  799. context.Branch(lblEnd);
  800. context.MarkLabel(lbl1);
  801. context.BranchIf(lblEnd, shiftLsB, zero, Comparison.LessOrEqual);
  802. Operand shl = context.ShiftLeft(op, shiftLsB);
  803. Operand isGreaterOrEqual = context.ICompareGreaterOrEqual(shiftLsB, eSizeOp);
  804. context.Copy(res, context.ConditionalSelect(isGreaterOrEqual, zeroL, shl));
  805. context.Branch(lblEnd);
  806. context.MarkLabel(lblEnd);
  807. return res;
  808. }
  809. // long SignedShlRegSatQ(long op, int shiftLsB, bool round, int size);
  810. // ulong UnsignedShlRegSatQ(ulong op, int shiftLsB, bool round, int size);
  811. private static Operand EmitShlRegSatQ(ArmEmitterContext context, Operand op, Operand shiftLsB, bool round, int size, bool signed)
  812. {
  813. int eSize = 8 << size;
  814. Debug.Assert(op.Type == OperandType.I64);
  815. Debug.Assert(shiftLsB.Type == OperandType.I32);
  816. Debug.Assert(eSize == 8 || eSize == 16 || eSize == 32 || eSize == 64);
  817. Operand lbl1 = Label();
  818. Operand lbl2 = Label();
  819. Operand lblEnd = Label();
  820. Operand eSizeOp = Const(eSize);
  821. Operand zero = Const(0);
  822. Operand res = context.Copy(context.AllocateLocal(OperandType.I64), op);
  823. context.BranchIf(lbl1, shiftLsB, zero, Comparison.GreaterOrEqual);
  824. context.Copy(res, signed
  825. ? EmitSignedShrReg(context, op, context.Negate(shiftLsB), round, eSize)
  826. : EmitUnsignedShrReg(context, op, context.Negate(shiftLsB), round, eSize));
  827. context.Branch(lblEnd);
  828. context.MarkLabel(lbl1);
  829. context.BranchIf(lblEnd, shiftLsB, zero, Comparison.LessOrEqual);
  830. context.BranchIf(lbl2, shiftLsB, eSizeOp, Comparison.Less);
  831. context.Copy(res, signed
  832. ? EmitSignedSignSatQ(context, op, size)
  833. : EmitUnsignedSignSatQ(context, op, size));
  834. context.Branch(lblEnd);
  835. context.MarkLabel(lbl2);
  836. Operand shl = context.ShiftLeft(op, shiftLsB);
  837. if (eSize == 64)
  838. {
  839. Operand sarOrShr = signed
  840. ? context.ShiftRightSI(shl, shiftLsB)
  841. : context.ShiftRightUI(shl, shiftLsB);
  842. context.Copy(res, shl);
  843. context.BranchIf(lblEnd, sarOrShr, op, Comparison.Equal);
  844. context.Copy(res, signed
  845. ? EmitSignedSignSatQ(context, op, size)
  846. : EmitUnsignedSignSatQ(context, op, size));
  847. }
  848. else
  849. {
  850. context.Copy(res, signed
  851. ? EmitSignedSrcSatQ(context, shl, size, signedDst: true)
  852. : EmitUnsignedSrcSatQ(context, shl, size, signedDst: false));
  853. }
  854. context.Branch(lblEnd);
  855. context.MarkLabel(lblEnd);
  856. return res;
  857. }
  858. // shift := [1, 128]; eSize := {8, 16, 32, 64}.
  859. // long SignedShrReg(long op, int shift, bool round, int eSize);
  860. private static Operand EmitSignedShrReg(ArmEmitterContext context, Operand op, Operand shift, bool round, int eSize)
  861. {
  862. if (round)
  863. {
  864. Operand lblEnd = Label();
  865. Operand eSizeOp = Const(eSize);
  866. Operand zeroL = Const(0L);
  867. Operand one = Const(1);
  868. Operand oneL = Const(1L);
  869. Operand res = context.Copy(context.AllocateLocal(OperandType.I64), zeroL);
  870. context.BranchIf(lblEnd, shift, eSizeOp, Comparison.GreaterOrEqual);
  871. Operand roundConst = context.ShiftLeft(oneL, context.Subtract(shift, one));
  872. Operand add = context.Add(op, roundConst);
  873. Operand sar = context.ShiftRightSI(add, shift);
  874. if (eSize == 64)
  875. {
  876. Operand shr = context.ShiftRightUI(add, shift);
  877. Operand left = context.BitwiseAnd(context.Negate(op), context.BitwiseExclusiveOr(op, add));
  878. Operand isLess = context.ICompareLess(left, zeroL);
  879. context.Copy(res, context.ConditionalSelect(isLess, shr, sar));
  880. }
  881. else
  882. {
  883. context.Copy(res, sar);
  884. }
  885. context.Branch(lblEnd);
  886. context.MarkLabel(lblEnd);
  887. return res;
  888. }
  889. else
  890. {
  891. Operand lblEnd = Label();
  892. Operand eSizeOp = Const(eSize);
  893. Operand zeroL = Const(0L);
  894. Operand negOneL = Const(-1L);
  895. Operand sar = context.ShiftRightSI(op, shift);
  896. Operand res = context.Copy(context.AllocateLocal(OperandType.I64), sar);
  897. context.BranchIf(lblEnd, shift, eSizeOp, Comparison.Less);
  898. Operand isLess = context.ICompareLess(op, zeroL);
  899. context.Copy(res, context.ConditionalSelect(isLess, negOneL, zeroL));
  900. context.Branch(lblEnd);
  901. context.MarkLabel(lblEnd);
  902. return res;
  903. }
  904. }
  905. // shift := [1, 128]; eSize := {8, 16, 32, 64}.
  906. // ulong UnsignedShrReg(ulong op, int shift, bool round, int eSize);
  907. private static Operand EmitUnsignedShrReg(ArmEmitterContext context, Operand op, Operand shift, bool round, int eSize)
  908. {
  909. if (round)
  910. {
  911. Operand lblEnd = Label();
  912. Operand zeroUL = Const(0UL);
  913. Operand one = Const(1);
  914. Operand oneUL = Const(1UL);
  915. Operand eSizeMaxOp = Const(64);
  916. Operand oneShl63UL = Const(1UL << 63);
  917. Operand res = context.Copy(context.AllocateLocal(OperandType.I64), zeroUL);
  918. context.BranchIf(lblEnd, shift, eSizeMaxOp, Comparison.Greater);
  919. Operand roundConst = context.ShiftLeft(oneUL, context.Subtract(shift, one));
  920. Operand add = context.Add(op, roundConst);
  921. Operand shr = context.ShiftRightUI(add, shift);
  922. Operand isEqual = context.ICompareEqual(shift, eSizeMaxOp);
  923. context.Copy(res, context.ConditionalSelect(isEqual, zeroUL, shr));
  924. if (eSize == 64)
  925. {
  926. context.BranchIf(lblEnd, add, op, Comparison.GreaterOrEqualUI);
  927. Operand right = context.BitwiseOr(shr, context.ShiftRightUI(oneShl63UL, context.Subtract(shift, one)));
  928. context.Copy(res, context.ConditionalSelect(isEqual, oneUL, right));
  929. }
  930. context.Branch(lblEnd);
  931. context.MarkLabel(lblEnd);
  932. return res;
  933. }
  934. else
  935. {
  936. Operand lblEnd = Label();
  937. Operand eSizeOp = Const(eSize);
  938. Operand zeroUL = Const(0UL);
  939. Operand shr = context.ShiftRightUI(op, shift);
  940. Operand res = context.Copy(context.AllocateLocal(OperandType.I64), shr);
  941. context.BranchIf(lblEnd, shift, eSizeOp, Comparison.Less);
  942. context.Copy(res, zeroUL);
  943. context.Branch(lblEnd);
  944. context.MarkLabel(lblEnd);
  945. return res;
  946. }
  947. }
  948. }
  949. }