narmmat.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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 (current_settings.cputype in [cpu_armv7m,cpu_armv7em]) and
  67. (nodetype=divn) and
  68. not(is_64bitint(resultdef)) then
  69. result:=nil
  70. else if (current_settings.cputype in [cpu_armv7m,cpu_armv7em]) 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(andn,left,cordconstnode.create(tordconstnode(right).value-1,sinttype,false))
  79. else
  80. begin
  81. result:=caddnode.create(subn,left,caddnode.create(muln,right.getcopy, cmoddivnode.Create(divn,left.getcopy,right.getcopy)));
  82. right:=nil;
  83. end;
  84. left:=nil;
  85. end
  86. else if (nodetype=modn) and
  87. (is_signed(left.resultdef)) and
  88. (right.nodetype=ordconstn) and
  89. (tordconstnode(right).value=2) then
  90. begin
  91. // result:=(0-(left and 1)) and (1+(sarlongint(left,31) shl 1))
  92. result:=caddnode.create(andn,caddnode.create(subn,cordconstnode.create(0,sinttype,false),caddnode.create(andn,left,cordconstnode.create(1,sinttype,false))),
  93. caddnode.create(addn,cordconstnode.create(1,sinttype,false),
  94. 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))));
  95. left:=nil;
  96. end
  97. else
  98. result:=inherited first_moddivint;
  99. end;
  100. procedure tarmmoddivnode.pass_generate_code;
  101. var
  102. power : longint;
  103. numerator,
  104. helper1,
  105. helper2,
  106. resultreg : tregister;
  107. size : Tcgsize;
  108. so : tshifterop;
  109. procedure genOrdConstNodeDiv;
  110. begin
  111. if tordconstnode(right).value=0 then
  112. internalerror(2005061701)
  113. else if tordconstnode(right).value=1 then
  114. cg.a_load_reg_reg(current_asmdata.CurrAsmList, OS_INT, OS_INT, numerator, resultreg)
  115. else if (tordconstnode(right).value = int64(-1)) then
  116. begin
  117. // note: only in the signed case possible..., may overflow
  118. if cs_check_overflow in current_settings.localswitches then
  119. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  120. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_MVN,
  121. resultreg,numerator),toppostfix(ord(cs_check_overflow in current_settings.localswitches)*ord(PF_S))));
  122. end
  123. else if ispowerof2(tordconstnode(right).value,power) then
  124. begin
  125. if (is_signed(right.resultdef)) then
  126. begin
  127. helper1:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  128. helper2:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  129. if power = 1 then
  130. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,numerator,helper1)
  131. else
  132. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,31,numerator,helper1);
  133. if current_settings.cputype in cpu_thumb then
  134. begin
  135. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,32-power,helper1);
  136. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_ADD,helper2,numerator,helper1));
  137. end
  138. else
  139. begin
  140. shifterop_reset(so);
  141. so.shiftmode:=SM_LSR;
  142. so.shiftimm:=32-power;
  143. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg_shifterop(A_ADD,helper2,numerator,helper1,so));
  144. end;
  145. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,OS_INT,power,helper2,resultreg);
  146. end
  147. else
  148. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SHR,OS_INT,power,numerator,resultreg)
  149. end;
  150. end;
  151. {
  152. procedure genOrdConstNodeMod;
  153. var
  154. modreg, maskreg, tempreg : tregister;
  155. begin
  156. if (tordconstnode(right).value = 0) then begin
  157. internalerror(2005061702);
  158. end
  159. else if (abs(tordconstnode(right).value.svalue) = 1) then
  160. begin
  161. // x mod +/-1 is always zero
  162. cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, 0, resultreg);
  163. end
  164. else if (ispowerof2(tordconstnode(right).value, power)) then
  165. begin
  166. if (is_signed(right.resultdef)) then begin
  167. tempreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
  168. maskreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
  169. modreg := cg.getintregister(current_asmdata.CurrAsmList, OS_INT);
  170. cg.a_load_const_reg(current_asmdata.CurrAsmList, OS_INT, abs(tordconstnode(right).value.svalue)-1, modreg);
  171. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SAR, OS_INT, 31, numerator, maskreg);
  172. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, numerator, modreg, tempreg);
  173. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_ANDC, maskreg, maskreg, modreg));
  174. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_const(A_SUBFIC, modreg, tempreg, 0));
  175. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_SUBFE, modreg, modreg, modreg));
  176. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, modreg, maskreg, maskreg);
  177. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_OR, OS_INT, maskreg, tempreg, resultreg);
  178. end else begin
  179. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_AND, OS_INT, tordconstnode(right).value.svalue-1, numerator, resultreg);
  180. end;
  181. end else begin
  182. genOrdConstNodeDiv();
  183. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_MUL, OS_INT, tordconstnode(right).value.svalue, resultreg, resultreg);
  184. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_SUB, OS_INT, resultreg, numerator, resultreg);
  185. end;
  186. end;
  187. }
  188. begin
  189. secondpass(left);
  190. secondpass(right);
  191. if (current_settings.cputype in [cpu_armv7m,cpu_armv7em]) and
  192. (nodetype=divn) and
  193. not(is_64bitint(resultdef)) then
  194. begin
  195. size:=def_cgsize(left.resultdef);
  196. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  197. location_copy(location,left.location);
  198. location.loc := LOC_REGISTER;
  199. location.register := cg.getintregister(current_asmdata.CurrAsmList,size);
  200. resultreg:=location.register;
  201. if (right.nodetype=ordconstn) and
  202. ((tordconstnode(right).value=1) or
  203. (tordconstnode(right).value=int64(-1)) or
  204. (tordconstnode(right).value=0) or
  205. ispowerof2(tordconstnode(right).value,power)) then
  206. begin
  207. numerator:=left.location.register;
  208. genOrdConstNodeDiv;
  209. end
  210. else
  211. begin
  212. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,left.resultdef,true);
  213. if is_signed(left.resultdef) or
  214. is_signed(right.resultdef) then
  215. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_IDIV,OS_INT,right.location.register,left.location.register,location.register)
  216. else
  217. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_DIV,OS_INT,right.location.register,left.location.register,location.register);
  218. end;
  219. end
  220. else
  221. begin
  222. location_copy(location,left.location);
  223. { put numerator in register }
  224. size:=def_cgsize(left.resultdef);
  225. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,
  226. left.resultdef,left.resultdef,true);
  227. location_copy(location,left.location);
  228. numerator:=location.register;
  229. resultreg:=location.register;
  230. if location.loc=LOC_CREGISTER then
  231. begin
  232. location.loc := LOC_REGISTER;
  233. location.register := cg.getintregister(current_asmdata.CurrAsmList,size);
  234. resultreg:=location.register;
  235. end
  236. else if (nodetype=modn) or (right.nodetype=ordconstn) then
  237. begin
  238. // for a modulus op, and for const nodes we need the result register
  239. // to be an extra register
  240. resultreg:=cg.getintregister(current_asmdata.CurrAsmList,size);
  241. end;
  242. if right.nodetype=ordconstn then
  243. begin
  244. if nodetype=divn then
  245. genOrdConstNodeDiv
  246. else
  247. // genOrdConstNodeMod;
  248. end;
  249. location.register:=resultreg;
  250. end;
  251. { unsigned division/module can only overflow in case of division by zero }
  252. { (but checking this overflow flag is more convoluted than performing a }
  253. { simple comparison with 0) }
  254. if is_signed(right.resultdef) then
  255. cg.g_overflowcheck(current_asmdata.CurrAsmList,location,resultdef);
  256. end;
  257. {*****************************************************************************
  258. TARMNOTNODE
  259. *****************************************************************************}
  260. procedure tarmnotnode.second_boolean;
  261. var
  262. hl : tasmlabel;
  263. begin
  264. { if the location is LOC_JUMP, we do the secondpass after the
  265. labels are allocated
  266. }
  267. if left.expectloc=LOC_JUMP then
  268. begin
  269. hl:=current_procinfo.CurrTrueLabel;
  270. current_procinfo.CurrTrueLabel:=current_procinfo.CurrFalseLabel;
  271. current_procinfo.CurrFalseLabel:=hl;
  272. secondpass(left);
  273. if left.location.loc<>LOC_JUMP then
  274. internalerror(2012081305);
  275. maketojumpbool(current_asmdata.CurrAsmList,left,lr_load_regvars);
  276. hl:=current_procinfo.CurrTrueLabel;
  277. current_procinfo.CurrTrueLabel:=current_procinfo.CurrFalseLabel;
  278. current_procinfo.CurrFalseLabel:=hl;
  279. location.loc:=LOC_JUMP;
  280. end
  281. else
  282. begin
  283. secondpass(left);
  284. case left.location.loc of
  285. LOC_FLAGS :
  286. begin
  287. location_copy(location,left.location);
  288. inverse_flags(location.resflags);
  289. end;
  290. LOC_REGISTER,LOC_CREGISTER,LOC_REFERENCE,LOC_CREFERENCE,
  291. LOC_SUBSETREG,LOC_CSUBSETREG,LOC_SUBSETREF,LOC_CSUBSETREF :
  292. begin
  293. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  294. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  295. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,left.location.register,0));
  296. location_reset(location,LOC_FLAGS,OS_NO);
  297. location.resflags:=F_EQ;
  298. end;
  299. else
  300. internalerror(2003042401);
  301. end;
  302. end;
  303. end;
  304. {*****************************************************************************
  305. TARMUNARYMINUSNODE
  306. *****************************************************************************}
  307. function tarmunaryminusnode.pass_1: tnode;
  308. var
  309. procname: string[31];
  310. fdef : tdef;
  311. begin
  312. if (current_settings.fputype<>fpu_fpv4_s16) or
  313. (tfloatdef(resultdef).floattype=s32real) then
  314. exit(inherited pass_1);
  315. result:=nil;
  316. firstpass(left);
  317. if codegenerror then
  318. exit;
  319. if (left.resultdef.typ=floatdef) then
  320. begin
  321. case tfloatdef(resultdef).floattype of
  322. s64real:
  323. begin
  324. procname:='float64_sub';
  325. fdef:=search_system_type('FLOAT64').typedef;
  326. end;
  327. else
  328. internalerror(2005082801);
  329. end;
  330. result:=ctypeconvnode.create_internal(ccallnode.createintern(procname,ccallparanode.create(
  331. ctypeconvnode.create_internal(left,fDef),
  332. ccallparanode.create(ctypeconvnode.create_internal(crealconstnode.create(0,resultdef),fdef),nil))),resultdef);
  333. left:=nil;
  334. end
  335. else
  336. begin
  337. if (left.resultdef.typ=floatdef) then
  338. expectloc:=LOC_FPUREGISTER
  339. else if (left.resultdef.typ=orddef) then
  340. expectloc:=LOC_REGISTER;
  341. end;
  342. end;
  343. procedure tarmunaryminusnode.second_float;
  344. var
  345. op: tasmop;
  346. begin
  347. secondpass(left);
  348. case current_settings.fputype of
  349. fpu_fpa,
  350. fpu_fpa10,
  351. fpu_fpa11:
  352. begin
  353. location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
  354. location:=left.location;
  355. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_const(A_RSF,
  356. location.register,left.location.register,0),
  357. cgsize2fpuoppostfix[def_cgsize(resultdef)]));
  358. end;
  359. fpu_vfpv2,
  360. fpu_vfpv3,
  361. fpu_vfpv3_d16:
  362. begin
  363. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  364. location:=left.location;
  365. if (left.location.loc=LOC_CMMREGISTER) then
  366. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  367. if (location.size=OS_F32) then
  368. op:=A_FNEGS
  369. else
  370. op:=A_FNEGD;
  371. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,
  372. location.register,left.location.register));
  373. end;
  374. fpu_fpv4_s16:
  375. begin
  376. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  377. location:=left.location;
  378. if (left.location.loc=LOC_CMMREGISTER) then
  379. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  380. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_VNEG,
  381. location.register,left.location.register), PF_F32));
  382. end
  383. else
  384. internalerror(2009112602);
  385. end;
  386. end;
  387. function tarmshlshrnode.first_shlshr64bitint: tnode;
  388. begin
  389. if (current_settings.cputype in cpu_thumb+cpu_thumb2) then
  390. result:=inherited
  391. else
  392. result := nil;
  393. end;
  394. procedure tarmshlshrnode.second_64bit;
  395. var
  396. hreg64hi,hreg64lo,shiftreg:Tregister;
  397. v : TConstExprInt;
  398. l1,l2,l3:Tasmlabel;
  399. so: tshifterop;
  400. procedure emit_instr(p: tai);
  401. begin
  402. current_asmdata.CurrAsmList.concat(p);
  403. end;
  404. {Reg1 gets shifted and moved into reg2, and is set to zero afterwards}
  405. procedure shift_more_than_32(reg1, reg2: TRegister; shiftval: Byte ; sm: TShiftMode);
  406. begin
  407. shifterop_reset(so); so.shiftimm:=shiftval - 32; so.shiftmode:=sm;
  408. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, reg2, reg1, so));
  409. emit_instr(taicpu.op_reg_const(A_MOV, reg1, 0));
  410. end;
  411. procedure shift_less_than_32(reg1, reg2: TRegister; shiftval: Byte; shiftright: boolean);
  412. begin
  413. shifterop_reset(so); so.shiftimm:=shiftval;
  414. if shiftright then so.shiftmode:=SM_LSR else so.shiftmode:=SM_LSL;
  415. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, reg1, reg1, so));
  416. if shiftright then so.shiftmode:=SM_LSL else so.shiftmode:=SM_LSR;
  417. so.shiftimm:=32-shiftval;
  418. emit_instr(taicpu.op_reg_reg_reg_shifterop(A_ORR, reg1, reg1, reg2, so));
  419. if shiftright then so.shiftmode:=SM_LSR else so.shiftmode:=SM_LSL;
  420. so.shiftimm:=shiftval;
  421. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, reg2, reg2, so));
  422. end;
  423. procedure shift_by_variable(reg1, reg2, shiftval: TRegister; shiftright: boolean);
  424. var
  425. shiftval2:TRegister;
  426. begin
  427. shifterop_reset(so);
  428. shiftval2:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  429. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  430. {Do we shift more than 32 bits?}
  431. emit_instr(setoppostfix(taicpu.op_reg_reg_const(A_RSB, shiftval2, shiftval, 32), PF_S));
  432. {This part cares for 32 bits and more}
  433. emit_instr(setcondition(taicpu.op_reg_reg_const(A_SUB, shiftval2, shiftval, 32), C_MI));
  434. if shiftright then so.shiftmode:=SM_LSR else so.shiftmode:=SM_LSL;
  435. so.rs:=shiftval2;
  436. emit_instr(setcondition(taicpu.op_reg_reg_shifterop(A_MOV, reg2, reg1, so), C_MI));
  437. {Less than 32 bits}
  438. so.rs:=shiftval;
  439. emit_instr(setcondition(taicpu.op_reg_reg_shifterop(A_MOV, reg2, reg2, so), C_PL));
  440. if shiftright then so.shiftmode:=SM_LSL else so.shiftmode:=SM_LSR;
  441. so.rs:=shiftval2;
  442. emit_instr(setcondition(taicpu.op_reg_reg_reg_shifterop(A_ORR, reg2, reg2, reg1, so), C_PL));
  443. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  444. {Final adjustments}
  445. if shiftright then so.shiftmode:=SM_LSR else so.shiftmode:=SM_LSL;
  446. so.rs:=shiftval;
  447. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, reg1, reg1, so));
  448. end;
  449. begin
  450. if (current_settings.cputype in cpu_thumb+cpu_thumb2) then
  451. begin
  452. inherited;
  453. exit;
  454. end;
  455. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  456. { load left operator in a register }
  457. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef,false);
  458. hreg64hi:=left.location.register64.reghi;
  459. hreg64lo:=left.location.register64.reglo;
  460. location.register64.reghi:=hreg64hi;
  461. location.register64.reglo:=hreg64lo;
  462. { shifting by a constant directly coded: }
  463. if (right.nodetype=ordconstn) then
  464. begin
  465. v:=Tordconstnode(right).value and 63;
  466. {Single bit shift}
  467. if v = 1 then
  468. if nodetype=shln then
  469. begin
  470. {Shift left by one by 2 simple 32bit additions}
  471. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  472. emit_instr(setoppostfix(taicpu.op_reg_reg_reg(A_ADD, hreg64lo, hreg64lo, hreg64lo), PF_S));
  473. emit_instr(taicpu.op_reg_reg_reg(A_ADC, hreg64hi, hreg64hi, hreg64hi));
  474. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  475. end
  476. else
  477. begin
  478. {Shift right by first shifting hi by one and then using RRX (rotate right extended), which rotates through the carry}
  479. shifterop_reset(so); so.shiftmode:=SM_LSR; so.shiftimm:=1;
  480. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  481. emit_instr(setoppostfix(taicpu.op_reg_reg_shifterop(A_MOV, hreg64hi, hreg64hi, so), PF_S));
  482. so.shiftmode:=SM_RRX; so.shiftimm:=0; {RRX does NOT have a shift amount}
  483. emit_instr(taicpu.op_reg_reg_shifterop(A_MOV, hreg64lo, hreg64lo, so));
  484. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  485. end
  486. {A 32bit shift just replaces a register and clears the other}
  487. else if v = 32 then
  488. begin
  489. if nodetype=shln then
  490. emit_instr(taicpu.op_reg_const(A_MOV, hreg64hi, 0))
  491. else
  492. emit_instr(taicpu.op_reg_const(A_MOV, hreg64lo, 0));
  493. location.register64.reghi:=hreg64lo;
  494. location.register64.reglo:=hreg64hi;
  495. end
  496. {Shift LESS than 32}
  497. else if (v < 32) and (v > 1) then
  498. if nodetype=shln then
  499. shift_less_than_32(hreg64hi, hreg64lo, v.uvalue, false)
  500. else
  501. shift_less_than_32(hreg64lo, hreg64hi, v.uvalue, true)
  502. {More than 32}
  503. else if v > 32 then
  504. if nodetype=shln then
  505. shift_more_than_32(hreg64lo, hreg64hi, v.uvalue, SM_LSL)
  506. else
  507. shift_more_than_32(hreg64hi, hreg64lo, v.uvalue, SM_LSR);
  508. end
  509. else
  510. begin
  511. { force right operators in a register }
  512. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,resultdef,false);
  513. if nodetype = shln then
  514. shift_by_variable(hreg64lo,hreg64hi,right.location.register, false)
  515. else
  516. shift_by_variable(hreg64hi,hreg64lo,right.location.register, true);
  517. end;
  518. end;
  519. begin
  520. cmoddivnode:=tarmmoddivnode;
  521. cnotnode:=tarmnotnode;
  522. cunaryminusnode:=tarmunaryminusnode;
  523. cshlshrnode:=tarmshlshrnode;
  524. end.