narmadd.pas 27 KB

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