narmadd.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Code generation for add nodes on the ARM
  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 narmadd;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgadd,cpubase;
  22. type
  23. tarmaddnode = class(tcgaddnode)
  24. private
  25. function GetResFlags(unsigned:Boolean):TResFlags;
  26. function GetFpuResFlags:TResFlags;
  27. public
  28. function pass_1 : tnode;override;
  29. function use_generic_mul32to64: boolean; override;
  30. function use_generic_mul64bit: boolean; override;
  31. protected
  32. function first_addfloat: tnode; override;
  33. procedure second_addordinal;override;
  34. procedure second_addfloat;override;
  35. procedure second_cmpfloat;override;
  36. procedure second_cmpordinal;override;
  37. procedure second_cmpsmallset;override;
  38. procedure second_cmp64bit;override;
  39. procedure second_add64bit;override;
  40. end;
  41. implementation
  42. uses
  43. globtype,verbose,globals,systems,
  44. constexp,symdef,symtable,symtype,symconst,
  45. aasmbase,aasmdata,aasmcpu,
  46. defutil,htypechk,cgbase,cgutils,
  47. cpuinfo,pass_1,pass_2,procinfo,
  48. ncon,nadd,ncnv,ncal,nmat,
  49. ncgutil,cgobj,cgcpu,
  50. hlcgobj
  51. ;
  52. {*****************************************************************************
  53. TSparcAddNode
  54. *****************************************************************************}
  55. function tarmaddnode.GetResFlags(unsigned:Boolean):TResFlags;
  56. begin
  57. case NodeType of
  58. equaln:
  59. GetResFlags:=F_EQ;
  60. unequaln:
  61. GetResFlags:=F_NE;
  62. else
  63. if not(unsigned) then
  64. begin
  65. if nf_swapped in flags then
  66. case NodeType of
  67. ltn:
  68. GetResFlags:=F_GT;
  69. lten:
  70. GetResFlags:=F_GE;
  71. gtn:
  72. GetResFlags:=F_LT;
  73. gten:
  74. GetResFlags:=F_LE;
  75. end
  76. else
  77. case NodeType of
  78. ltn:
  79. GetResFlags:=F_LT;
  80. lten:
  81. GetResFlags:=F_LE;
  82. gtn:
  83. GetResFlags:=F_GT;
  84. gten:
  85. GetResFlags:=F_GE;
  86. end;
  87. end
  88. else
  89. begin
  90. if nf_swapped in Flags then
  91. case NodeType of
  92. ltn:
  93. GetResFlags:=F_HI;
  94. lten:
  95. GetResFlags:=F_CS;
  96. gtn:
  97. GetResFlags:=F_CC;
  98. gten:
  99. GetResFlags:=F_LS;
  100. end
  101. else
  102. case NodeType of
  103. ltn:
  104. GetResFlags:=F_CC;
  105. lten:
  106. GetResFlags:=F_LS;
  107. gtn:
  108. GetResFlags:=F_HI;
  109. gten:
  110. GetResFlags:=F_CS;
  111. end;
  112. end;
  113. end;
  114. end;
  115. function tarmaddnode.GetFpuResFlags:TResFlags;
  116. begin
  117. if nf_swapped in Flags then
  118. internalerror(2014042001);
  119. case NodeType of
  120. equaln:
  121. result:=F_EQ;
  122. unequaln:
  123. result:=F_NE;
  124. ltn:
  125. result:=F_MI;
  126. lten:
  127. result:=F_LS;
  128. gtn:
  129. result:=F_GT;
  130. gten:
  131. result:=F_GE;
  132. end;
  133. end;
  134. procedure tarmaddnode.second_addfloat;
  135. var
  136. op : TAsmOp;
  137. singleprec: boolean;
  138. begin
  139. pass_left_right;
  140. if (nf_swapped in flags) then
  141. swapleftright;
  142. case current_settings.fputype of
  143. fpu_fpa,
  144. fpu_fpa10,
  145. fpu_fpa11:
  146. begin
  147. { force fpureg as location, left right doesn't matter
  148. as both will be in a fpureg }
  149. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  150. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,right.location,right.resultdef,true);
  151. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  152. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  153. case nodetype of
  154. addn :
  155. op:=A_ADF;
  156. muln :
  157. op:=A_MUF;
  158. subn :
  159. op:=A_SUF;
  160. slashn :
  161. op:=A_DVF;
  162. else
  163. internalerror(200308313);
  164. end;
  165. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_reg(op,
  166. location.register,left.location.register,right.location.register),
  167. cgsize2fpuoppostfix[def_cgsize(resultdef)]));
  168. end;
  169. fpu_vfpv2,
  170. fpu_vfpv3,
  171. fpu_vfpv3_d16:
  172. begin
  173. { force mmreg as location, left right doesn't matter
  174. as both will be in a fpureg }
  175. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  176. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,right.location,right.resultdef,true);
  177. location_reset(location,LOC_MMREGISTER,def_cgsize(resultdef));
  178. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  179. singleprec:=tfloatdef(left.resultdef).floattype=s32real;
  180. case nodetype of
  181. addn :
  182. if singleprec then
  183. op:=A_FADDS
  184. else
  185. op:=A_FADDD;
  186. muln :
  187. if singleprec then
  188. op:=A_FMULS
  189. else
  190. op:=A_FMULD;
  191. subn :
  192. if singleprec then
  193. op:=A_FSUBS
  194. else
  195. op:=A_FSUBD;
  196. slashn :
  197. if singleprec then
  198. op:=A_FDIVS
  199. else
  200. op:=A_FDIVD;
  201. else
  202. internalerror(2009111401);
  203. end;
  204. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(op,
  205. location.register,left.location.register,right.location.register));
  206. end;
  207. fpu_fpv4_s16:
  208. begin
  209. { force mmreg as location, left right doesn't matter
  210. as both will be in a fpureg }
  211. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  212. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,right.location,right.resultdef,true);
  213. location_reset(location,LOC_MMREGISTER,def_cgsize(resultdef));
  214. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  215. case nodetype of
  216. addn :
  217. op:=A_VADD;
  218. muln :
  219. op:=A_VMUL;
  220. subn :
  221. op:=A_VSUB;
  222. slashn :
  223. op:=A_VDIV;
  224. else
  225. internalerror(2009111401);
  226. end;
  227. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_reg(op, location.register,left.location.register,right.location.register), PF_F32));
  228. end;
  229. fpu_soft:
  230. { this case should be handled already by pass1 }
  231. internalerror(200308252);
  232. else
  233. internalerror(200308251);
  234. end;
  235. end;
  236. procedure tarmaddnode.second_cmpfloat;
  237. var
  238. op: TAsmOp;
  239. begin
  240. pass_left_right;
  241. if (nf_swapped in flags) then
  242. swapleftright;
  243. location_reset(location,LOC_FLAGS,OS_NO);
  244. location.resflags:=getresflags(false);
  245. case current_settings.fputype of
  246. fpu_fpa,
  247. fpu_fpa10,
  248. fpu_fpa11:
  249. begin
  250. { force fpureg as location, left right doesn't matter
  251. as both will be in a fpureg }
  252. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  253. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,right.location,right.resultdef,true);
  254. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  255. if nodetype in [equaln,unequaln] then
  256. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_CMF,
  257. left.location.register,right.location.register),
  258. cgsize2fpuoppostfix[def_cgsize(resultdef)]))
  259. else
  260. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg(A_CMFE,
  261. left.location.register,right.location.register),
  262. cgsize2fpuoppostfix[def_cgsize(resultdef)]));
  263. end;
  264. fpu_vfpv2,
  265. fpu_vfpv3,
  266. fpu_vfpv3_d16:
  267. begin
  268. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  269. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,right.location,right.resultdef,true);
  270. if (tfloatdef(left.resultdef).floattype=s32real) then
  271. if nodetype in [equaln,unequaln] then
  272. op:=A_FCMPS
  273. else
  274. op:=A_FCMPES
  275. else if nodetype in [equaln,unequaln] then
  276. op:=A_FCMPD
  277. else
  278. op:=A_FCMPED;
  279. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,
  280. left.location.register,right.location.register));
  281. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  282. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_FMSTAT));
  283. location.resflags:=GetFpuResFlags;
  284. end;
  285. fpu_fpv4_s16:
  286. begin
  287. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  288. hlcg.location_force_mmregscalar(current_asmdata.CurrAsmList,right.location,right.resultdef,true);
  289. if nodetype in [equaln,unequaln] then
  290. op:=A_VCMP
  291. else
  292. op:=A_VCMPE;
  293. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,
  294. left.location.register,right.location.register));
  295. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  296. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_VMRS, NR_APSR_nzcv, NR_FPSCR));
  297. end;
  298. fpu_soft:
  299. { this case should be handled already by pass1 }
  300. internalerror(2009112404);
  301. end;
  302. end;
  303. procedure tarmaddnode.second_cmpsmallset;
  304. var
  305. tmpreg : tregister;
  306. b: byte;
  307. begin
  308. pass_left_right;
  309. location_reset(location,LOC_FLAGS,OS_NO);
  310. if (not(nf_swapped in flags) and
  311. (nodetype = lten)) or
  312. ((nf_swapped in flags) and
  313. (nodetype = gten)) then
  314. swapleftright;
  315. (* Try to keep right as a constant *)
  316. if (right.location.loc <> LOC_CONSTANT) or
  317. not(is_shifter_const(right.location.value, b)) or
  318. ((GenerateThumbCode) and not(is_thumb_imm(right.location.value))) then
  319. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  320. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  321. case nodetype of
  322. equaln,
  323. unequaln:
  324. begin
  325. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  326. if right.location.loc = LOC_CONSTANT then
  327. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,left.location.register,right.location.value))
  328. else
  329. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
  330. if nodetype = equaln then
  331. location.resflags:=F_EQ
  332. else
  333. location.resflags:=F_NE;
  334. end;
  335. lten,
  336. gten:
  337. begin
  338. tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  339. if right.location.loc = LOC_CONSTANT then
  340. begin
  341. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_const(A_AND,tmpreg,left.location.register,right.location.value));
  342. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  343. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,tmpreg,right.location.value));
  344. end
  345. else
  346. begin
  347. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_AND,tmpreg,left.location.register,right.location.register));
  348. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  349. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,tmpreg,right.location.register));
  350. end;
  351. location.resflags:=F_EQ;
  352. end;
  353. else
  354. internalerror(2004012401);
  355. end;
  356. end;
  357. procedure tarmaddnode.second_cmp64bit;
  358. var
  359. unsigned : boolean;
  360. oldnodetype : tnodetype;
  361. dummyreg : tregister;
  362. l: tasmlabel;
  363. begin
  364. unsigned:=not(is_signed(left.resultdef)) or
  365. not(is_signed(right.resultdef));
  366. pass_left_right;
  367. { pass_left_right moves possible consts to the right, the only
  368. remaining case with left consts (currency) can take this path too (KB) }
  369. if (nodetype in [equaln,unequaln]) and
  370. (right.nodetype=ordconstn) and (tordconstnode(right).value=0) then
  371. begin
  372. location_reset(location,LOC_FLAGS,OS_NO);
  373. location.resflags:=getresflags(unsigned);
  374. if not(left.location.loc in [LOC_CREGISTER,LOC_REGISTER]) then
  375. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  376. dummyreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  377. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  378. if GenerateThumbCode then
  379. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,left.location.register64.reglo,left.location.register64.reghi,dummyreg)
  380. else
  381. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ORR,dummyreg,left.location.register64.reglo,left.location.register64.reghi),PF_S));
  382. end
  383. else
  384. begin
  385. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  386. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  387. { operation requiring proper N, Z and C flags ? }
  388. if unsigned or (nodetype in [equaln,unequaln]) then
  389. begin
  390. location_reset(location,LOC_FLAGS,OS_NO);
  391. location.resflags:=getresflags(unsigned);
  392. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  393. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
  394. if GenerateThumbCode or GenerateThumb2Code then
  395. begin
  396. current_asmdata.getjumplabel(l);
  397. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,l);
  398. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo));
  399. cg.a_label(current_asmdata.CurrAsmList,l);
  400. end
  401. else
  402. current_asmdata.CurrAsmList.concat(setcondition(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo),C_EQ));
  403. end
  404. else
  405. { operation requiring proper N, Z and V flags ? }
  406. begin
  407. location_reset(location,LOC_JUMP,OS_NO);
  408. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  409. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
  410. { the jump the sequence is a little bit hairy }
  411. case nodetype of
  412. ltn,gtn:
  413. begin
  414. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(false),current_procinfo.CurrTrueLabel);
  415. { cheat a little bit for the negative test }
  416. toggleflag(nf_swapped);
  417. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(false),current_procinfo.CurrFalseLabel);
  418. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  419. toggleflag(nf_swapped);
  420. end;
  421. lten,gten:
  422. begin
  423. oldnodetype:=nodetype;
  424. if nodetype=lten then
  425. nodetype:=ltn
  426. else
  427. nodetype:=gtn;
  428. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),current_procinfo.CurrTrueLabel);
  429. { cheat for the negative test }
  430. if nodetype=ltn then
  431. nodetype:=gtn
  432. else
  433. nodetype:=ltn;
  434. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),current_procinfo.CurrFalseLabel);
  435. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  436. nodetype:=oldnodetype;
  437. end;
  438. end;
  439. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  440. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo));
  441. { the comparisaion of the low dword have to be
  442. always unsigned! }
  443. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(true),current_procinfo.CurrTrueLabel);
  444. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  445. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  446. end;
  447. end;
  448. end;
  449. procedure tarmaddnode.second_add64bit;
  450. var
  451. asmList : TAsmList;
  452. ll,rl,res : TRegister64;
  453. tmpreg: TRegister;
  454. begin
  455. if (nodetype in [muln]) then
  456. begin
  457. asmList := current_asmdata.CurrAsmList;
  458. pass_left_right;
  459. force_reg_left_right(true, (left.location.loc<>LOC_CONSTANT) and (right.location.loc<>LOC_CONSTANT));
  460. set_result_location_reg;
  461. { shortcuts to register64s }
  462. ll:=left.location.register64;
  463. rl:=right.location.register64;
  464. res:=location.register64;
  465. tmpreg := cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  466. asmList.concat(taicpu.op_reg_reg_reg(A_MUL,tmpreg,ll.reglo,rl.reghi));
  467. asmList.concat(taicpu.op_reg_reg_reg_reg(A_UMULL,res.reglo,res.reghi,rl.reglo,ll.reglo));
  468. tbasecgarm(cg).safe_mla(asmList,tmpreg,rl.reglo,ll.reghi,tmpreg);
  469. asmList.concat(taicpu.op_reg_reg_reg(A_ADD,res.reghi,tmpreg,res.reghi));
  470. end
  471. else
  472. inherited second_add64bit;
  473. end;
  474. function tarmaddnode.pass_1 : tnode;
  475. var
  476. unsigned : boolean;
  477. begin
  478. result:=inherited pass_1;
  479. if not(assigned(result)) then
  480. begin
  481. unsigned:=not(is_signed(left.resultdef)) or
  482. not(is_signed(right.resultdef));
  483. if is_64bit(left.resultdef) and
  484. ((nodetype in [equaln,unequaln]) or
  485. (unsigned and (nodetype in [ltn,lten,gtn,gten]))
  486. ) then
  487. expectloc:=LOC_FLAGS;
  488. end;
  489. end;
  490. function tarmaddnode.first_addfloat: tnode;
  491. var
  492. procname: string[31];
  493. { do we need to reverse the result ? }
  494. notnode : boolean;
  495. fdef : tdef;
  496. begin
  497. result := nil;
  498. notnode := false;
  499. if current_settings.fputype = fpu_fpv4_s16 then
  500. begin
  501. case tfloatdef(left.resultdef).floattype of
  502. s32real:
  503. begin
  504. result:=nil;
  505. notnode:=false;
  506. end;
  507. s64real:
  508. begin
  509. fdef:=search_system_type('FLOAT64').typedef;
  510. procname:='float64';
  511. case nodetype of
  512. addn:
  513. procname:=procname+'_add';
  514. muln:
  515. procname:=procname+'_mul';
  516. subn:
  517. procname:=procname+'_sub';
  518. slashn:
  519. procname:=procname+'_div';
  520. ltn:
  521. procname:=procname+'_lt';
  522. lten:
  523. procname:=procname+'_le';
  524. gtn:
  525. begin
  526. procname:=procname+'_lt';
  527. swapleftright;
  528. end;
  529. gten:
  530. begin
  531. procname:=procname+'_le';
  532. swapleftright;
  533. end;
  534. equaln:
  535. procname:=procname+'_eq';
  536. unequaln:
  537. begin
  538. procname:=procname+'_eq';
  539. notnode:=true;
  540. end;
  541. else
  542. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),left.resultdef.typename,right.resultdef.typename);
  543. end;
  544. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  545. resultdef:=pasbool8type;
  546. result:=ctypeconvnode.create_internal(ccallnode.createintern(procname,ccallparanode.create(
  547. ctypeconvnode.create_internal(right,fdef),
  548. ccallparanode.create(
  549. ctypeconvnode.create_internal(left,fdef),nil))),resultdef);
  550. left:=nil;
  551. right:=nil;
  552. { do we need to reverse the result }
  553. if notnode then
  554. result:=cnotnode.create(result);
  555. end;
  556. end;
  557. end
  558. else
  559. result:=inherited first_addfloat;
  560. end;
  561. procedure tarmaddnode.second_cmpordinal;
  562. var
  563. unsigned : boolean;
  564. tmpreg : tregister;
  565. b : byte;
  566. begin
  567. pass_left_right;
  568. force_reg_left_right(true,true);
  569. unsigned:=not(is_signed(left.resultdef)) or
  570. not(is_signed(right.resultdef));
  571. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  572. if right.location.loc = LOC_CONSTANT then
  573. begin
  574. if (not(GenerateThumbCode) and is_shifter_const(right.location.value,b)) or
  575. ((GenerateThumbCode) and is_thumb_imm(right.location.value)) then
  576. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,left.location.register,right.location.value))
  577. else
  578. begin
  579. tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  580. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_INT,
  581. right.location.value,tmpreg);
  582. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,tmpreg));
  583. end;
  584. end
  585. else
  586. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
  587. location_reset(location,LOC_FLAGS,OS_NO);
  588. location.resflags:=getresflags(unsigned);
  589. end;
  590. const
  591. multops: array[boolean] of TAsmOp = (A_SMULL, A_UMULL);
  592. procedure tarmaddnode.second_addordinal;
  593. var
  594. unsigned: boolean;
  595. begin
  596. if (nodetype=muln) and
  597. is_64bit(resultdef) and
  598. not(GenerateThumbCode) and
  599. (CPUARM_HAS_UMULL in cpu_capabilities[current_settings.cputype]) then
  600. begin
  601. pass_left_right;
  602. force_reg_left_right(true, false);
  603. set_result_location_reg;
  604. unsigned:=not(is_signed(left.resultdef)) or
  605. not(is_signed(right.resultdef));
  606. current_asmdata.CurrAsmList.Concat(
  607. taicpu.op_reg_reg_reg_reg(multops[unsigned], location.register64.reglo, location.register64.reghi,
  608. left.location.register,right.location.register));
  609. end
  610. else
  611. inherited second_addordinal;
  612. end;
  613. function tarmaddnode.use_generic_mul32to64: boolean;
  614. begin
  615. result:=GenerateThumbCode or not(CPUARM_HAS_UMULL in cpu_capabilities[current_settings.cputype]);
  616. end;
  617. function tarmaddnode.use_generic_mul64bit: boolean;
  618. begin
  619. result:=GenerateThumbCode or
  620. not(CPUARM_HAS_UMULL in cpu_capabilities[current_settings.cputype]) or
  621. (cs_check_overflow in current_settings.localswitches);
  622. end;
  623. begin
  624. caddnode:=tarmaddnode;
  625. end.