narmadd.pas 28 KB

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