narmadd.pas 27 KB

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