narmadd.pas 26 KB

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