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