narmmat.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate ARM assembler for math nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit narmmat;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nmat,ncgmat;
  22. type
  23. tarmmoddivnode = class(tmoddivnode)
  24. function first_moddivint: tnode;override;
  25. procedure pass_generate_code;override;
  26. end;
  27. tarmnotnode = class(tcgnotnode)
  28. procedure second_boolean;override;
  29. end;
  30. tarmunaryminusnode = class(tcgunaryminusnode)
  31. function pass_1: tnode; override;
  32. procedure second_float;override;
  33. end;
  34. tarmshlshrnode = class(tcgshlshrnode)
  35. procedure second_64bit;override;
  36. function first_shlshr64bitint: tnode; override;
  37. end;
  38. implementation
  39. uses
  40. globtype,
  41. cutils,verbose,globals,constexp,
  42. aasmbase,aasmcpu,aasmtai,aasmdata,
  43. defutil,
  44. symtype,symconst,symtable,
  45. cgbase,cgobj,hlcgobj,cgutils,
  46. pass_2,procinfo,
  47. ncon,ncnv,ncal,ninl,
  48. cpubase,cpuinfo,
  49. ncgutil,
  50. nadd,pass_1,symdef;
  51. {*****************************************************************************
  52. TARMMODDIVNODE
  53. *****************************************************************************}
  54. function tarmmoddivnode.first_moddivint: tnode;
  55. var
  56. power : longint;
  57. begin
  58. if (right.nodetype=ordconstn) and
  59. (nodetype=divn) and
  60. (ispowerof2(tordconstnode(right).value,power) or
  61. (tordconstnode(right).value=1) or
  62. (tordconstnode(right).value=int64(-1))
  63. ) and
  64. not(is_64bitint(resultdef)) then
  65. result:=nil
  66. else if ((GenerateThumbCode) and (CPUARM_HAS_THUMB_IDIV in cpu_capabilities[current_settings.cputype])) and
  67. (nodetype=divn) and
  68. not(is_64bitint(resultdef)) then
  69. result:=nil
  70. else if ((GenerateThumbCode) and (CPUARM_HAS_THUMB_IDIV in cpu_capabilities[current_settings.cputype])) and
  71. (nodetype=modn) and
  72. not(is_64bitint(resultdef)) then
  73. begin
  74. if (right.nodetype=ordconstn) and
  75. ispowerof2(tordconstnode(right).value,power) and
  76. (tordconstnode(right).value<=256) and
  77. (tordconstnode(right).value>0) then
  78. result:=caddnode.create_internal(andn,left,cordconstnode.create(tordconstnode(right).value-1,sinttype,false))
  79. else
  80. begin
  81. result:=caddnode.create_internal(subn,left,caddnode.create_internal(muln,right,cmoddivnode.Create(divn,left.getcopy,right.getcopy)));
  82. right:=nil;
  83. end;
  84. left:=nil;
  85. firstpass(result);
  86. end
  87. else if (nodetype=modn) and
  88. (is_signed(left.resultdef)) and
  89. (right.nodetype=ordconstn) and
  90. (tordconstnode(right).value=2) then
  91. begin
  92. // result:=(0-(left and 1)) and (1+(sarlongint(left,31) shl 1))
  93. result:=caddnode.create_internal(andn,caddnode.create_internal(subn,cordconstnode.create(0,sinttype,false),caddnode.create_internal(andn,left,cordconstnode.create(1,sinttype,false))),
  94. caddnode.create_internal(addn,cordconstnode.create(1,sinttype,false),
  95. cshlshrnode.create(shln,cinlinenode.create(in_sar_x_y,false,ccallparanode.create(cordconstnode.create(31,sinttype,false),ccallparanode.Create(left.getcopy,nil))),cordconstnode.create(1,sinttype,false))));
  96. left:=nil;
  97. firstpass(result);
  98. end
  99. else
  100. result:=inherited first_moddivint;
  101. { we may not change the result type here }
  102. if assigned(result) and (torddef(result.resultdef).ordtype<>torddef(resultdef).ordtype) then
  103. inserttypeconv(result,resultdef);
  104. end;
  105. procedure tarmmoddivnode.pass_generate_code;
  106. var
  107. power : longint;
  108. numerator,
  109. helper1,
  110. helper2,
  111. resultreg : tregister;
  112. size : Tcgsize;
  113. so : tshifterop;
  114. procedure genOrdConstNodeDiv;
  115. begin
  116. if tordconstnode(right).value=0 then
  117. internalerror(2005061701)
  118. else if tordconstnode(right).value=1 then
  119. cg.a_load_reg_reg(current_asmdata.CurrAsmList, OS_INT, OS_INT, numerator, resultreg)
  120. else if (tordconstnode(right).value = int64(-1)) then
  121. begin
  122. // note: only in the signed case possible..., may overflow
  123. if cs_check_overflow in current_settings.localswitches then
  124. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  125. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_MVN,
  126. resultreg,numerator),toppostfix(ord(cs_check_overflow in current_settings.localswitches)*ord(PF_S))));
  127. end
  128. else if ispowerof2(tordconstnode(right).value,power) then
  129. begin
  130. if (is_signed(right.resultdef)) then
  131. begin
  132. helper1:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  133. helper2:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  134. if power = 1 then
  135. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,numerator,helper1)
  136. else
  137. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,31,numerator,helper1);
  138. if GenerateThumbCode then
  139. begin
  140. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,32-power,helper1);
  141. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_ADD,helper2,numerator,helper1));
  142. end
  143. else
  144. begin
  145. shifterop_reset(so);
  146. so.shiftmode:=SM_LSR;
  147. so.shiftimm:=32-power;
  148. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg_shifterop(A_ADD,helper2,numerator,helper1,so));
  149. end;
  150. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,power,helper2,resultreg);
  151. end
  152. else
  153. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_INT,power,numerator,resultreg)
  154. end;
  155. end;
  156. {
  157. procedure genOrdConstNodeMod;
  158. var
  159. modreg, maskreg, tempreg : tregister;
  160. begin
  161. if (tordconstnode(right).value = 0) then begin
  162. internalerror(2005061702);
  163. end
  164. else if (abs(tordconstnode(right).value.svalue) = 1) then
  165. begin
  166. // x mod +/-1 is always zero
  167. cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, 0, resultreg);
  168. end
  169. else if (ispowerof2(tordconstnode(right).value, power)) then
  170. begin
  171. if (is_signed(right.resultdef)) then begin
  172. tempreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
  173. maskreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
  174. modreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
  175. cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, abs(tordconstnode(right).value.svalue)-1, modreg);
  176. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SAR, OS_INT, 31, numerator, maskreg);
  177. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, numerator, modreg, tempreg);
  178. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_ANDC, maskreg, maskreg, modreg));
  179. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_const(A_SUBFIC, modreg, tempreg, 0));
  180. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_SUBFE, modreg, modreg, modreg));
  181. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, modreg, maskreg, maskreg);
  182. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_OR, OS_INT, maskreg, tempreg, resultreg);
  183. end else begin
  184. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, tordconstnode(right).value.svalue-1, numerator, resultreg);
  185. end;
  186. end else begin
  187. genOrdConstNodeDiv();
  188. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_MUL, OS_INT, tordconstnode(right).value.svalue, resultreg, resultreg);
  189. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_SUB, OS_INT, resultreg, numerator, resultreg);
  190. end;
  191. end;
  192. }
  193. begin
  194. secondpass(left);
  195. secondpass(right);
  196. if ((GenerateThumbCode) and (CPUARM_HAS_THUMB_IDIV in cpu_capabilities[current_settings.cputype])) and
  197. (nodetype=divn) and
  198. not(is_64bitint(resultdef)) then
  199. begin
  200. size:=def_cgsize(left.resultdef);
  201. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  202. location_copy(location,left.location);
  203. location.loc := LOC_REGISTER;
  204. location.register := cg.getintregister(current_asmdata.CurrAsmList,size);
  205. resultreg:=location.register;
  206. if (right.nodetype=ordconstn) and
  207. ((tordconstnode(right).value=1) or
  208. (tordconstnode(right).value=int64(-1)) or
  209. (tordconstnode(right).value=0) or
  210. ispowerof2(tordconstnode(right).value,power)) then
  211. begin
  212. numerator:=left.location.register;
  213. genOrdConstNodeDiv;
  214. end
  215. else
  216. begin
  217. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,left.resultdef,true);
  218. if is_signed(left.resultdef) or
  219. is_signed(right.resultdef) then
  220. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_IDIV,OS_INT,right.location.register,left.location.register,location.register)
  221. else
  222. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_DIV,OS_INT,right.location.register,left.location.register,location.register);
  223. end;
  224. end
  225. else
  226. begin
  227. location_copy(location,left.location);
  228. { put numerator in register }
  229. size:=def_cgsize(left.resultdef);
  230. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,
  231. left.resultdef,left.resultdef,true);
  232. location_copy(location,left.location);
  233. numerator:=location.register;
  234. resultreg:=location.register;
  235. if location.loc=LOC_CREGISTER then
  236. begin
  237. location.loc := LOC_REGISTER;
  238. location.register := cg.getintregister(current_asmdata.CurrAsmList,size);
  239. resultreg:=location.register;
  240. end
  241. else if (nodetype=modn) or (right.nodetype=ordconstn) then
  242. begin
  243. // for a modulus op, and for const nodes we need the result register
  244. // to be an extra register
  245. resultreg:=cg.getintregister(current_asmdata.CurrAsmList,size);
  246. end;
  247. if right.nodetype=ordconstn then
  248. begin
  249. if nodetype=divn then
  250. genOrdConstNodeDiv
  251. else
  252. // genOrdConstNodeMod;
  253. end;
  254. location.register:=resultreg;
  255. end;
  256. { unsigned division/module can only overflow in case of division by zero }
  257. { (but checking this overflow flag is more convoluted than performing a }
  258. { simple comparison with 0) }
  259. if is_signed(right.resultdef) then
  260. cg.g_overflowcheck(current_asmdata.CurrAsmList,location,resultdef);
  261. end;
  262. {*****************************************************************************
  263. TARMNOTNODE
  264. *****************************************************************************}
  265. procedure tarmnotnode.second_boolean;
  266. var
  267. hl : tasmlabel;
  268. begin
  269. { if the location is LOC_JUMP, we do the secondpass after the
  270. labels are allocated
  271. }
  272. if left.expectloc=LOC_JUMP then
  273. begin
  274. hl:=current_procinfo.CurrTrueLabel;
  275. current_procinfo.CurrTrueLabel:=current_procinfo.CurrFalseLabel;
  276. current_procinfo.CurrFalseLabel:=hl;
  277. secondpass(left);
  278. if left.location.loc<>LOC_JUMP then
  279. internalerror(2012081305);
  280. maketojumpbool(current_asmdata.CurrAsmList,left,lr_load_regvars);
  281. hl:=current_procinfo.CurrTrueLabel;
  282. current_procinfo.CurrTrueLabel:=current_procinfo.CurrFalseLabel;
  283. current_procinfo.CurrFalseLabel:=hl;
  284. location.loc:=LOC_JUMP;
  285. end
  286. else
  287. begin
  288. secondpass(left);
  289. case left.location.loc of
  290. LOC_FLAGS :
  291. begin
  292. location_copy(location,left.location);
  293. inverse_flags(location.resflags);
  294. end;
  295. LOC_REGISTER,LOC_CREGISTER,LOC_REFERENCE,LOC_CREFERENCE,
  296. LOC_SUBSETREG,LOC_CSUBSETREG,LOC_SUBSETREF,LOC_CSUBSETREF :
  297. begin
  298. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  299. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  300. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,left.location.register,0));
  301. location_reset(location,LOC_FLAGS,OS_NO);
  302. location.resflags:=F_EQ;
  303. end;
  304. else
  305. internalerror(2003042401);
  306. end;
  307. end;
  308. end;
  309. {*****************************************************************************
  310. TARMUNARYMINUSNODE
  311. *****************************************************************************}
  312. function tarmunaryminusnode.pass_1: tnode;
  313. var
  314. procname: string[31];
  315. fdef : tdef;
  316. begin
  317. if (current_settings.fputype<>fpu_fpv4_s16) or
  318. (tfloatdef(resultdef).floattype=s32real) then
  319. exit(inherited pass_1);
  320. result:=nil;
  321. firstpass(left);
  322. if codegenerror then
  323. exit;
  324. if (left.resultdef.typ=floatdef) then
  325. begin
  326. case tfloatdef(resultdef).floattype of
  327. s64real:
  328. begin
  329. procname:='float64_sub';
  330. fdef:=search_system_type('FLOAT64').typedef;
  331. end;
  332. else
  333. internalerror(2005082801);
  334. end;
  335. result:=ctypeconvnode.create_internal(ccallnode.createintern(procname,ccallparanode.create(
  336. ctypeconvnode.create_internal(left,fDef),
  337. ccallparanode.create(ctypeconvnode.create_internal(crealconstnode.create(0,resultdef),fdef),nil))),resultdef);
  338. left:=nil;
  339. end
  340. else
  341. begin
  342. if (left.resultdef.typ=floatdef) then
  343. expectloc:=LOC_FPUREGISTER
  344. else if (left.resultdef.typ=orddef) then
  345. expectloc:=LOC_REGISTER;
  346. end;
  347. end;
  348. procedure tarmunaryminusnode.second_float;
  349. var
  350. op: tasmop;
  351. begin
  352. secondpass(left);
  353. case current_settings.fputype of
  354. fpu_fpa,
  355. fpu_fpa10,
  356. fpu_fpa11:
  357. begin
  358. location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
  359. location:=left.location;
  360. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_const(A_RSF,
  361. location.register,left.location.register,0),
  362. cgsize2fpuoppostfix[def_cgsize(resultdef)]));
  363. end;
  364. fpu_vfpv2,
  365. fpu_vfpv3,
  366. fpu_vfpv3_d16:
  367. begin
  368. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  369. location:=left.location;
  370. if (left.location.loc=LOC_CMMREGISTER) then
  371. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  372. if (location.size=OS_F32) then
  373. op:=A_FNEGS
  374. else
  375. op:=A_FNEGD;
  376. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,
  377. location.register,left.location.register));
  378. end;
  379. fpu_fpv4_s16:
  380. begin
  381. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  382. location:=left.location;
  383. if (left.location.loc=LOC_CMMREGISTER) then
  384. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  385. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_VNEG,
  386. location.register,left.location.register), PF_F32));
  387. end
  388. else
  389. internalerror(2009112602);
  390. end;
  391. end;
  392. function tarmshlshrnode.first_shlshr64bitint: tnode;
  393. begin
  394. if GenerateThumbCode or GenerateThumb2Code then
  395. result:=inherited
  396. else
  397. result := nil;
  398. end;
  399. procedure tarmshlshrnode.second_64bit;
  400. var
  401. hreg64hi,hreg64lo,shiftreg:Tregister;
  402. v : TConstExprInt;
  403. l1,l2,l3:Tasmlabel;
  404. so: tshifterop;
  405. procedure emit_instr(p: tai);
  406. begin
  407. current_asmdata.CurrAsmList.concat(p);
  408. end;
  409. {Reg1 gets shifted and moved into reg2, and is set to zero afterwards}
  410. procedure shift_more_than_32(reg1, reg2: TRegister; shiftval: Byte ; sm: TShiftMode);
  411. begin
  412. shifterop_reset(so); so.shiftimm:=shiftval - 32; so.shiftmode:=sm;
  413. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, reg2, reg1, so));
  414. emit_instr(taicpu.op_reg_const(A_MOV, reg1, 0));
  415. end;
  416. procedure shift_less_than_32(reg1, reg2: TRegister; shiftval: Byte; shiftright: boolean);
  417. begin
  418. shifterop_reset(so); so.shiftimm:=shiftval;
  419. if shiftright then so.shiftmode:=SM_LSR else so.shiftmode:=SM_LSL;
  420. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, reg1, reg1, so));
  421. if shiftright then so.shiftmode:=SM_LSL else so.shiftmode:=SM_LSR;
  422. so.shiftimm:=32-shiftval;
  423. emit_instr(taicpu.op_reg_reg_reg_shifterop(A_ORR, reg1, reg1, reg2, so));
  424. if shiftright then so.shiftmode:=SM_LSR else so.shiftmode:=SM_LSL;
  425. so.shiftimm:=shiftval;
  426. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, reg2, reg2, so));
  427. end;
  428. procedure shift_by_variable(reg1, reg2, shiftval: TRegister; shiftright: boolean);
  429. var
  430. shiftval2:TRegister;
  431. begin
  432. shifterop_reset(so);
  433. shiftval2:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  434. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  435. {Do we shift more than 32 bits?}
  436. emit_instr(setoppostfix(taicpu.op_reg_reg_const(A_RSB, shiftval2, shiftval, 32), PF_S));
  437. {This part cares for 32 bits and more}
  438. emit_instr(setcondition(taicpu.op_reg_reg_const(A_SUB, shiftval2, shiftval, 32), C_MI));
  439. if shiftright then so.shiftmode:=SM_LSR else so.shiftmode:=SM_LSL;
  440. so.rs:=shiftval2;
  441. emit_instr(setcondition(taicpu.op_reg_reg_shifterop(A_MOV, reg2, reg1, so), C_MI));
  442. {Less than 32 bits}
  443. so.rs:=shiftval;
  444. emit_instr(setcondition(taicpu.op_reg_reg_shifterop(A_MOV, reg2, reg2, so), C_PL));
  445. if shiftright then so.shiftmode:=SM_LSL else so.shiftmode:=SM_LSR;
  446. so.rs:=shiftval2;
  447. emit_instr(setcondition(taicpu.op_reg_reg_reg_shifterop(A_ORR, reg2, reg2, reg1, so), C_PL));
  448. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  449. {Final adjustments}
  450. if shiftright then so.shiftmode:=SM_LSR else so.shiftmode:=SM_LSL;
  451. so.rs:=shiftval;
  452. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, reg1, reg1, so));
  453. end;
  454. begin
  455. if GenerateThumbCode or GenerateThumb2Code then
  456. begin
  457. inherited;
  458. exit;
  459. end;
  460. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  461. { load left operator in a register }
  462. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef,false);
  463. hreg64hi:=left.location.register64.reghi;
  464. hreg64lo:=left.location.register64.reglo;
  465. location.register64.reghi:=hreg64hi;
  466. location.register64.reglo:=hreg64lo;
  467. { shifting by a constant directly coded: }
  468. if (right.nodetype=ordconstn) then
  469. begin
  470. v:=Tordconstnode(right).value and 63;
  471. {Single bit shift}
  472. if v = 1 then
  473. if nodetype=shln then
  474. begin
  475. {Shift left by one by 2 simple 32bit additions}
  476. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  477. emit_instr(setoppostfix(taicpu.op_reg_reg_reg(A_ADD, hreg64lo, hreg64lo, hreg64lo), PF_S));
  478. emit_instr(taicpu.op_reg_reg_reg(A_ADC, hreg64hi, hreg64hi, hreg64hi));
  479. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  480. end
  481. else
  482. begin
  483. {Shift right by first shifting hi by one and then using RRX (rotate right extended), which rotates through the carry}
  484. shifterop_reset(so); so.shiftmode:=SM_LSR; so.shiftimm:=1;
  485. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  486. emit_instr(setoppostfix(taicpu.op_reg_reg_shifterop(A_MOV, hreg64hi, hreg64hi, so), PF_S));
  487. so.shiftmode:=SM_RRX; so.shiftimm:=0; {RRX does NOT have a shift amount}
  488. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, hreg64lo, hreg64lo, so));
  489. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  490. end
  491. {A 32bit shift just replaces a register and clears the other}
  492. else if v = 32 then
  493. begin
  494. if nodetype=shln then
  495. emit_instr(taicpu.op_reg_const(A_MOV, hreg64hi, 0))
  496. else
  497. emit_instr(taicpu.op_reg_const(A_MOV, hreg64lo, 0));
  498. location.register64.reghi:=hreg64lo;
  499. location.register64.reglo:=hreg64hi;
  500. end
  501. {Shift LESS than 32}
  502. else if (v < 32) and (v > 1) then
  503. if nodetype=shln then
  504. shift_less_than_32(hreg64hi, hreg64lo, v.uvalue, false)
  505. else
  506. shift_less_than_32(hreg64lo, hreg64hi, v.uvalue, true)
  507. {More than 32}
  508. else if v > 32 then
  509. if nodetype=shln then
  510. shift_more_than_32(hreg64lo, hreg64hi, v.uvalue, SM_LSL)
  511. else
  512. shift_more_than_32(hreg64hi, hreg64lo, v.uvalue, SM_LSR);
  513. end
  514. else
  515. begin
  516. { force right operators in a register }
  517. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,resultdef,false);
  518. if nodetype = shln then
  519. shift_by_variable(hreg64lo,hreg64hi,right.location.register, false)
  520. else
  521. shift_by_variable(hreg64hi,hreg64lo,right.location.register, true);
  522. end;
  523. end;
  524. begin
  525. cmoddivnode:=tarmmoddivnode;
  526. cnotnode:=tarmnotnode;
  527. cunaryminusnode:=tarmunaryminusnode;
  528. cshlshrnode:=tarmshlshrnode;
  529. end.