narmadd.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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. const
  364. lt_zero_swapped: array[boolean] of tnodetype = (ltn, gtn);
  365. begin
  366. unsigned:=not(is_signed(left.resultdef)) or
  367. not(is_signed(right.resultdef));
  368. pass_left_right;
  369. { pass_left_right moves possible consts to the right, the only
  370. remaining case with left consts (currency) can take this path too (KB) }
  371. if (nodetype in [equaln,unequaln,lt_zero_swapped[nf_swapped in Flags]]) and
  372. { In theory the upper layers should not emit a compare in that case at all }
  373. ((nodetype in [ltn, gtn]) and not unsigned) and
  374. (right.nodetype=ordconstn) and (tordconstnode(right).value=0) then
  375. begin
  376. location_reset(location,LOC_FLAGS,OS_NO);
  377. if not(left.location.loc in [LOC_CREGISTER,LOC_REGISTER]) then
  378. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  379. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  380. { Optimize for the common case of int64 < 0 }
  381. if nodetype in [ltn, gtn] then
  382. begin
  383. {Just check for the MSB in reghi to be set or not, this is independed from nf_swapped}
  384. location.resflags:=F_NE;
  385. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_TST,left.location.register64.reghi, $80000000));
  386. end
  387. else
  388. begin
  389. location.resflags:=getresflags(unsigned);
  390. dummyreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  391. if GenerateThumbCode then
  392. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,left.location.register64.reglo,left.location.register64.reghi,dummyreg)
  393. else
  394. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_reg_reg(A_ORR,dummyreg,left.location.register64.reglo,left.location.register64.reghi),PF_S));
  395. end;
  396. end
  397. else
  398. begin
  399. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  400. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  401. { operation requiring proper N, Z and C flags ? }
  402. if unsigned or (nodetype in [equaln,unequaln]) then
  403. begin
  404. location_reset(location,LOC_FLAGS,OS_NO);
  405. location.resflags:=getresflags(unsigned);
  406. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  407. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
  408. if GenerateThumbCode or GenerateThumb2Code then
  409. begin
  410. current_asmdata.getjumplabel(l);
  411. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,l);
  412. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo));
  413. cg.a_label(current_asmdata.CurrAsmList,l);
  414. end
  415. else
  416. current_asmdata.CurrAsmList.concat(setcondition(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo),C_EQ));
  417. end
  418. else
  419. { operation requiring proper N, Z and V flags ? }
  420. begin
  421. location_reset(location,LOC_JUMP,OS_NO);
  422. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  423. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
  424. { the jump the sequence is a little bit hairy }
  425. case nodetype of
  426. ltn,gtn:
  427. begin
  428. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(false),current_procinfo.CurrTrueLabel);
  429. { cheat a little bit for the negative test }
  430. toggleflag(nf_swapped);
  431. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(false),current_procinfo.CurrFalseLabel);
  432. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  433. toggleflag(nf_swapped);
  434. end;
  435. lten,gten:
  436. begin
  437. oldnodetype:=nodetype;
  438. if nodetype=lten then
  439. nodetype:=ltn
  440. else
  441. nodetype:=gtn;
  442. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),current_procinfo.CurrTrueLabel);
  443. { cheat for the negative test }
  444. if nodetype=ltn then
  445. nodetype:=gtn
  446. else
  447. nodetype:=ltn;
  448. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),current_procinfo.CurrFalseLabel);
  449. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  450. nodetype:=oldnodetype;
  451. end;
  452. end;
  453. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  454. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo));
  455. { the comparisaion of the low dword have to be
  456. always unsigned! }
  457. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(true),current_procinfo.CurrTrueLabel);
  458. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  459. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  460. end;
  461. end;
  462. end;
  463. procedure tarmaddnode.second_add64bit;
  464. var
  465. asmList : TAsmList;
  466. ll,rl,res : TRegister64;
  467. tmpreg: TRegister;
  468. begin
  469. if (nodetype in [muln]) then
  470. begin
  471. asmList := current_asmdata.CurrAsmList;
  472. pass_left_right;
  473. force_reg_left_right(true, (left.location.loc<>LOC_CONSTANT) and (right.location.loc<>LOC_CONSTANT));
  474. set_result_location_reg;
  475. { shortcuts to register64s }
  476. ll:=left.location.register64;
  477. rl:=right.location.register64;
  478. res:=location.register64;
  479. tmpreg := cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  480. asmList.concat(taicpu.op_reg_reg_reg(A_MUL,tmpreg,ll.reglo,rl.reghi));
  481. asmList.concat(taicpu.op_reg_reg_reg_reg(A_UMULL,res.reglo,res.reghi,rl.reglo,ll.reglo));
  482. tbasecgarm(cg).safe_mla(asmList,tmpreg,rl.reglo,ll.reghi,tmpreg);
  483. asmList.concat(taicpu.op_reg_reg_reg(A_ADD,res.reghi,tmpreg,res.reghi));
  484. end
  485. else
  486. inherited second_add64bit;
  487. end;
  488. function tarmaddnode.pass_1 : tnode;
  489. var
  490. unsigned : boolean;
  491. begin
  492. result:=inherited pass_1;
  493. if not(assigned(result)) then
  494. begin
  495. unsigned:=not(is_signed(left.resultdef)) or
  496. not(is_signed(right.resultdef));
  497. if is_64bit(left.resultdef) and
  498. ((nodetype in [equaln,unequaln]) or
  499. (unsigned and (nodetype in [ltn,lten,gtn,gten]))
  500. ) then
  501. expectloc:=LOC_FLAGS;
  502. end;
  503. end;
  504. function tarmaddnode.first_addfloat: tnode;
  505. var
  506. procname: string[31];
  507. { do we need to reverse the result ? }
  508. notnode : boolean;
  509. fdef : tdef;
  510. begin
  511. result := nil;
  512. notnode := false;
  513. if current_settings.fputype = fpu_fpv4_s16 then
  514. begin
  515. case tfloatdef(left.resultdef).floattype of
  516. s32real:
  517. begin
  518. result:=nil;
  519. notnode:=false;
  520. end;
  521. s64real:
  522. begin
  523. fdef:=search_system_type('FLOAT64').typedef;
  524. procname:='float64';
  525. case nodetype of
  526. addn:
  527. procname:=procname+'_add';
  528. muln:
  529. procname:=procname+'_mul';
  530. subn:
  531. procname:=procname+'_sub';
  532. slashn:
  533. procname:=procname+'_div';
  534. ltn:
  535. procname:=procname+'_lt';
  536. lten:
  537. procname:=procname+'_le';
  538. gtn:
  539. begin
  540. procname:=procname+'_lt';
  541. swapleftright;
  542. end;
  543. gten:
  544. begin
  545. procname:=procname+'_le';
  546. swapleftright;
  547. end;
  548. equaln:
  549. procname:=procname+'_eq';
  550. unequaln:
  551. begin
  552. procname:=procname+'_eq';
  553. notnode:=true;
  554. end;
  555. else
  556. CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),left.resultdef.typename,right.resultdef.typename);
  557. end;
  558. if nodetype in [ltn,lten,gtn,gten,equaln,unequaln] then
  559. resultdef:=pasbool8type;
  560. result:=ctypeconvnode.create_internal(ccallnode.createintern(procname,ccallparanode.create(
  561. ctypeconvnode.create_internal(right,fdef),
  562. ccallparanode.create(
  563. ctypeconvnode.create_internal(left,fdef),nil))),resultdef);
  564. left:=nil;
  565. right:=nil;
  566. { do we need to reverse the result }
  567. if notnode then
  568. result:=cnotnode.create(result);
  569. end;
  570. end;
  571. end
  572. else
  573. result:=inherited first_addfloat;
  574. end;
  575. procedure tarmaddnode.second_cmpordinal;
  576. var
  577. unsigned : boolean;
  578. tmpreg : tregister;
  579. b : byte;
  580. begin
  581. pass_left_right;
  582. force_reg_left_right(true,true);
  583. unsigned:=not(is_signed(left.resultdef)) or
  584. not(is_signed(right.resultdef));
  585. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_DEFAULTFLAGS);
  586. if right.location.loc = LOC_CONSTANT then
  587. begin
  588. if (not(GenerateThumbCode) and is_shifter_const(right.location.value,b)) or
  589. ((GenerateThumbCode) and is_thumb_imm(right.location.value)) then
  590. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_CMP,left.location.register,right.location.value))
  591. else
  592. begin
  593. tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  594. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_INT,
  595. right.location.value,tmpreg);
  596. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,tmpreg));
  597. end;
  598. end
  599. else
  600. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
  601. location_reset(location,LOC_FLAGS,OS_NO);
  602. location.resflags:=getresflags(unsigned);
  603. end;
  604. const
  605. multops: array[boolean] of TAsmOp = (A_SMULL, A_UMULL);
  606. procedure tarmaddnode.second_addordinal;
  607. var
  608. unsigned: boolean;
  609. begin
  610. if (nodetype=muln) and
  611. is_64bit(resultdef) and
  612. not(GenerateThumbCode) and
  613. (CPUARM_HAS_UMULL in cpu_capabilities[current_settings.cputype]) then
  614. begin
  615. pass_left_right;
  616. force_reg_left_right(true, false);
  617. set_result_location_reg;
  618. unsigned:=not(is_signed(left.resultdef)) or
  619. not(is_signed(right.resultdef));
  620. current_asmdata.CurrAsmList.Concat(
  621. taicpu.op_reg_reg_reg_reg(multops[unsigned], location.register64.reglo, location.register64.reghi,
  622. left.location.register,right.location.register));
  623. end
  624. else
  625. inherited second_addordinal;
  626. end;
  627. function tarmaddnode.use_generic_mul32to64: boolean;
  628. begin
  629. result:=GenerateThumbCode or not(CPUARM_HAS_UMULL in cpu_capabilities[current_settings.cputype]);
  630. end;
  631. function tarmaddnode.use_generic_mul64bit: boolean;
  632. begin
  633. result:=GenerateThumbCode or
  634. not(CPUARM_HAS_UMULL in cpu_capabilities[current_settings.cputype]) or
  635. (cs_check_overflow in current_settings.localswitches);
  636. end;
  637. begin
  638. caddnode:=tarmaddnode;
  639. end.