narmadd.pas 28 KB

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