narmadd.pas 27 KB

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