n68kadd.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl and Jonas Maebe
  3. Code generation for add nodes on the Motorola 680x0 family
  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 n68kadd;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nadd,ncgadd,cpubase,cgbase;
  22. type
  23. t68kaddnode = class(tcgaddnode)
  24. private
  25. function getresflags(unsigned: boolean) : tresflags;
  26. function getfloatresflags: tresflags;
  27. protected
  28. procedure second_addfloat;override;
  29. procedure second_cmpfloat;override;
  30. procedure second_addordinal;override;
  31. procedure second_cmpordinal;override;
  32. procedure second_cmpsmallset;override;
  33. procedure second_cmp64bit;override;
  34. end;
  35. implementation
  36. uses
  37. globtype,systems,
  38. cutils,verbose,globals,
  39. symconst,symdef,paramgr,symtype,
  40. aasmbase,aasmtai,aasmdata,aasmcpu,defutil,htypechk,
  41. cpuinfo,pass_1,pass_2,regvars,
  42. cpupara,cgutils,procinfo,
  43. ncon,nset,
  44. ncgutil,tgobj,rgobj,rgcpu,cgobj,cgcpu,hlcgobj,cg64f32;
  45. {*****************************************************************************
  46. Helpers
  47. *****************************************************************************}
  48. function t68kaddnode.getresflags(unsigned : boolean) : tresflags;
  49. begin
  50. case nodetype of
  51. equaln : getresflags:=F_E;
  52. unequaln : getresflags:=F_NE;
  53. else
  54. if not(unsigned) then
  55. begin
  56. if nf_swapped in flags then
  57. case nodetype of
  58. ltn : getresflags:=F_G;
  59. lten : getresflags:=F_GE;
  60. gtn : getresflags:=F_L;
  61. gten : getresflags:=F_LE;
  62. else
  63. internalerror(2014082030);
  64. end
  65. else
  66. case nodetype of
  67. ltn : getresflags:=F_L;
  68. lten : getresflags:=F_LE;
  69. gtn : getresflags:=F_G;
  70. gten : getresflags:=F_GE;
  71. else
  72. internalerror(2014082031);
  73. end;
  74. end
  75. else
  76. begin
  77. if nf_swapped in flags then
  78. case nodetype of
  79. ltn : getresflags:=F_A;
  80. lten : getresflags:=F_AE;
  81. gtn : getresflags:=F_B;
  82. gten : getresflags:=F_BE;
  83. else
  84. internalerror(2014082032);
  85. end
  86. else
  87. case nodetype of
  88. ltn : getresflags:=F_B;
  89. lten : getresflags:=F_BE;
  90. gtn : getresflags:=F_A;
  91. gten : getresflags:=F_AE;
  92. else
  93. internalerror(2014082033);
  94. end;
  95. end;
  96. end;
  97. end;
  98. function t68kaddnode.getfloatresflags : tresflags;
  99. begin
  100. case nodetype of
  101. equaln : getfloatresflags:=F_FE;
  102. unequaln : getfloatresflags:=F_FNE;
  103. else
  104. if nf_swapped in flags then
  105. case nodetype of
  106. ltn : getfloatresflags:=F_FG;
  107. lten : getfloatresflags:=F_FGE;
  108. gtn : getfloatresflags:=F_FL;
  109. gten : getfloatresflags:=F_FLE;
  110. else
  111. internalerror(201604260);
  112. end
  113. else
  114. case nodetype of
  115. ltn : getfloatresflags:=F_FL;
  116. lten : getfloatresflags:=F_FLE;
  117. gtn : getfloatresflags:=F_FG;
  118. gten : getfloatresflags:=F_FGE;
  119. else
  120. internalerror(201604261);
  121. end;
  122. end;
  123. end;
  124. {*****************************************************************************
  125. AddFloat
  126. *****************************************************************************}
  127. procedure t68kaddnode.second_addfloat;
  128. var
  129. op : TAsmOp;
  130. href : TReference;
  131. begin
  132. pass_left_right;
  133. case nodetype of
  134. addn :
  135. op:=A_FADD;
  136. muln :
  137. op:=A_FMUL;
  138. subn :
  139. op:=A_FSUB;
  140. slashn :
  141. op:=A_FDIV;
  142. else
  143. internalerror(200403182);
  144. end;
  145. // get the operands in the correct order, there are no special cases
  146. // here, everything is register-based
  147. if nf_swapped in flags then
  148. swapleftright;
  149. case current_settings.fputype of
  150. fpu_68881,fpu_coldfire:
  151. begin
  152. { initialize the result }
  153. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  154. { have left in the register, right can be a memory location }
  155. if not (current_settings.fputype = fpu_coldfire) and
  156. (left.nodetype = realconstn) then
  157. begin
  158. location.register := cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  159. current_asmdata.CurrAsmList.concat(taicpu.op_realconst_reg(A_FMOVE,tcgsize2opsize[left.location.size],trealconstnode(left).value_real,location.register))
  160. end
  161. else
  162. begin
  163. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  164. location.register := cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  165. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmlist,OS_NO,OS_NO,left.location.register,location.register);
  166. end;
  167. { emit the actual operation }
  168. case right.location.loc of
  169. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  170. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,fpuregopsize,right.location.register,location.register));
  171. LOC_REFERENCE,LOC_CREFERENCE:
  172. begin
  173. if not (current_settings.fputype = fpu_coldfire) and
  174. (right.nodetype = realconstn) then
  175. current_asmdata.CurrAsmList.concat(taicpu.op_realconst_reg(op,tcgsize2opsize[right.location.size],trealconstnode(right).value_real,location.register))
  176. else
  177. begin
  178. href:=right.location.reference;
  179. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,current_settings.fputype = fpu_coldfire);
  180. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(op,tcgsize2opsize[right.location.size],href,location.register));
  181. end;
  182. end
  183. else
  184. internalerror(2015021501);
  185. end;
  186. end;
  187. else
  188. // softfpu should be handled in pass1, others are not yet supported...
  189. internalerror(2015010201);
  190. end;
  191. end;
  192. procedure t68kaddnode.second_cmpfloat;
  193. var
  194. tmpreg : tregister;
  195. ai: taicpu;
  196. href : TReference;
  197. begin
  198. pass_left_right;
  199. if (nf_swapped in flags) then
  200. swapleftright;
  201. case current_settings.fputype of
  202. fpu_68881,fpu_coldfire:
  203. begin
  204. { force left fpureg as register, right can be reference }
  205. { emit compare }
  206. case right.location.loc of
  207. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  208. begin
  209. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  210. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FCMP,fpuregopsize,right.location.register,left.location.register));
  211. end;
  212. LOC_REFERENCE,LOC_CREFERENCE:
  213. begin
  214. { use FTST, if realconst is 0.0, it would be very had to do this in the
  215. optimized, because we would need to investigate the referenced value... }
  216. if (right.nodetype = realconstn) and
  217. (trealconstnode(right).value_real = 0.0) then
  218. begin
  219. if left.location.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER] then
  220. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_FTST,fpuregopsize,left.location.register))
  221. else
  222. if left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  223. begin
  224. href:=left.location.reference;
  225. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  226. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_FTST,tcgsize2opsize[left.location.size],href))
  227. end
  228. else
  229. internalerror(2016051001);
  230. end
  231. else
  232. begin
  233. hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
  234. if not (current_settings.fputype = fpu_coldfire) and
  235. (right.nodetype = realconstn) then
  236. current_asmdata.CurrAsmList.concat(taicpu.op_realconst_reg(A_FCMP,tcgsize2opsize[right.location.size],trealconstnode(right).value_real,left.location.register))
  237. else
  238. begin
  239. href:=right.location.reference;
  240. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,current_settings.fputype = fpu_coldfire);
  241. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_FCMP,tcgsize2opsize[right.location.size],href,left.location.register));
  242. end;
  243. end;
  244. end
  245. else
  246. internalerror(2015021502);
  247. end;
  248. location_reset(location,LOC_FLAGS,OS_NO);
  249. location.resflags:=getfloatresflags;
  250. end;
  251. else
  252. // softfpu should be handled in pass1, others are not yet supported...
  253. internalerror(2015010201);
  254. end;
  255. end;
  256. {*****************************************************************************
  257. Smallsets
  258. *****************************************************************************}
  259. procedure t68kaddnode.second_cmpsmallset;
  260. var
  261. tmpreg : tregister;
  262. begin
  263. pass_left_right;
  264. location_reset(location,LOC_FLAGS,OS_NO);
  265. if (not(nf_swapped in flags) and
  266. (nodetype = lten)) or
  267. ((nf_swapped in flags) and
  268. (nodetype = gten)) then
  269. swapleftright;
  270. { Try to keep right as a constant }
  271. if right.location.loc<>LOC_CONSTANT then
  272. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  273. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  274. case nodetype of
  275. equaln,
  276. unequaln:
  277. begin
  278. if right.location.loc=LOC_CONSTANT then
  279. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,right.location.value,left.location.register))
  280. else
  281. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,S_L,right.location.register,left.location.register));
  282. if nodetype=equaln then
  283. location.resflags:=F_E
  284. else
  285. location.resflags:=F_NE;
  286. end;
  287. lten,
  288. gten:
  289. begin
  290. tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,left.location.size);
  291. if right.location.loc=LOC_CONSTANT then
  292. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  293. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_AND,OS_32,left.location.register,right.location.register,tmpreg);
  294. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,S_L,tmpreg,right.location.register));
  295. location.resflags:=F_E;
  296. end;
  297. else
  298. internalerror(2013092701);
  299. end;
  300. end;
  301. {*****************************************************************************
  302. Ordinals
  303. *****************************************************************************}
  304. procedure t68kaddnode.second_addordinal;
  305. var
  306. cgop : topcg;
  307. begin
  308. { if we need to handle overflow checking, fall back to the generic cg }
  309. if (nodetype in [addn,subn,muln]) and
  310. (left.resultdef.typ<>pointerdef) and
  311. (right.resultdef.typ<>pointerdef) and
  312. (cs_check_overflow in current_settings.localswitches) then
  313. begin
  314. inherited;
  315. exit;
  316. end;
  317. case nodetype of
  318. addn: cgop:=OP_ADD;
  319. xorn: cgop:=OP_XOR;
  320. orn : cgop:=OP_OR;
  321. andn: cgop:=OP_AND;
  322. subn: cgop:=OP_SUB;
  323. muln:
  324. begin
  325. if not(is_signed(left.resultdef)) or
  326. not(is_signed(right.resultdef)) then
  327. cgop:=OP_MUL
  328. else
  329. cgop:=OP_IMUL;
  330. end;
  331. else
  332. internalerror(2013120104);
  333. end;
  334. pass_left_right;
  335. if (nodetype=subn) and (nf_swapped in flags) then
  336. swapleftright;
  337. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  338. { initialize the result }
  339. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  340. location.register := cg.getintregister(current_asmdata.CurrAsmList,location.size);
  341. cg.a_load_reg_reg(current_asmdata.CurrAsmlist,left.location.size,location.size,left.location.register,location.register);
  342. if (location.size <> right.location.size) or
  343. not (right.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_CONSTANT,LOC_REFERENCE,LOC_CREFERENCE]) or
  344. (not(CPUM68K_HAS_32BITMUL in cpu_capabilities[current_settings.cputype]) and (nodetype = muln)) then
  345. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  346. case right.location.loc of
  347. LOC_REGISTER,
  348. LOC_CREGISTER:
  349. cg.a_op_reg_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.register,location.register);
  350. LOC_CONSTANT:
  351. cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.value,location.register);
  352. LOC_REFERENCE,
  353. LOC_CREFERENCE:
  354. cg.a_op_ref_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.reference,location.register);
  355. else
  356. internalerror(2016052101);
  357. end;
  358. end;
  359. procedure t68kaddnode.second_cmpordinal;
  360. var
  361. unsigned : boolean;
  362. tmpreg : tregister;
  363. opsize : topsize;
  364. cmpsize : tcgsize;
  365. href: treference;
  366. begin
  367. { determine if the comparison will be unsigned }
  368. unsigned:=not(is_signed(left.resultdef)) or
  369. not(is_signed(right.resultdef));
  370. { this puts constant operand (if any) to the right }
  371. pass_left_right;
  372. { tentatively assume left size (correct for possible TST, will fix later) }
  373. cmpsize:=def_cgsize(left.resultdef);
  374. opsize:=tcgsize2opsize[cmpsize];
  375. { set result location }
  376. location_reset(location,LOC_FLAGS,OS_NO);
  377. { see if we can optimize into TST }
  378. if (right.location.loc=LOC_CONSTANT) and (right.location.value=0) then
  379. begin
  380. { Unsigned <0 or >=0 should not reach pass2, most likely }
  381. case left.location.loc of
  382. LOC_REFERENCE,
  383. LOC_CREFERENCE:
  384. begin
  385. href:=left.location.reference;
  386. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  387. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_TST,opsize,href));
  388. location_freetemp(current_asmdata.CurrAsmList,left.location);
  389. end;
  390. else
  391. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  392. if (current_settings.cputype = cpu_mc68000) and isaddressregister(left.location.register) then
  393. begin
  394. tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,cmpsize);
  395. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,cmpsize,left.location.register,tmpreg);
  396. end
  397. else
  398. tmpreg:=left.location.register;
  399. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_TST,opsize,tmpreg));
  400. end;
  401. location.resflags := getresflags(unsigned);
  402. exit;
  403. end;
  404. { Coldfire supports byte/word compares only starting with ISA_B,
  405. !!see remark about Qemu weirdness in tcg68k.a_cmp_const_reg_label }
  406. if (opsize<>S_L) and (current_settings.cputype in cpu_coldfire{-[cpu_isa_b,cpu_isa_c,cfv4e]}) then
  407. begin
  408. { 1) Extension is needed for LOC_REFERENCE, but what about LOC_REGISTER ? Perhaps after fixing cg we can assume
  409. that high bits of registers are correct.
  410. 2) Assuming that extension depends only on source signedness --> destination OS_32 is acceptable. }
  411. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(OS_32),false);
  412. if (right.location.loc<>LOC_CONSTANT) then
  413. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,cgsize_orddef(OS_32),false);
  414. opsize:=S_L;
  415. end
  416. else if not (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  417. begin
  418. if not (right.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  419. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true)
  420. else
  421. begin
  422. location_swap(left.location,right.location);
  423. toggleflag(nf_swapped);
  424. end;
  425. end;
  426. { left is now in register }
  427. case right.location.loc of
  428. LOC_CONSTANT:
  429. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,opsize,
  430. longint(right.location.value),left.location.register));
  431. LOC_REFERENCE,
  432. LOC_CREFERENCE:
  433. begin
  434. href:=right.location.reference;
  435. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  436. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,opsize,href,
  437. left.location.register));
  438. end;
  439. LOC_REGISTER,
  440. LOC_CREGISTER:
  441. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,opsize,
  442. right.location.register,left.location.register));
  443. else
  444. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  445. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,opsize,
  446. right.location.register,left.location.register));
  447. end;
  448. { update location because sides could have been swapped }
  449. location.resflags:=getresflags(unsigned);
  450. end;
  451. {*****************************************************************************
  452. 64-bit
  453. *****************************************************************************}
  454. procedure t68kaddnode.second_cmp64bit;
  455. var
  456. truelabel,
  457. falselabel: tasmlabel;
  458. hlab: tasmlabel;
  459. unsigned : boolean;
  460. href: treference;
  461. procedure firstjmp64bitcmp;
  462. var
  463. oldnodetype : tnodetype;
  464. begin
  465. case nodetype of
  466. ltn,gtn:
  467. begin
  468. if (hlab<>location.truelabel) then
  469. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.truelabel);
  470. { cheat a little bit for the negative test }
  471. toggleflag(nf_swapped);
  472. if (hlab<>location.falselabel) then
  473. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.falselabel);
  474. toggleflag(nf_swapped);
  475. end;
  476. lten,gten:
  477. begin
  478. oldnodetype:=nodetype;
  479. if nodetype=lten then
  480. nodetype:=ltn
  481. else
  482. nodetype:=gtn;
  483. if (hlab<>location.truelabel) then
  484. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.truelabel);
  485. { cheat for the negative test }
  486. if nodetype=ltn then
  487. nodetype:=gtn
  488. else
  489. nodetype:=ltn;
  490. if (hlab<>location.falselabel) then
  491. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.falselabel);
  492. nodetype:=oldnodetype;
  493. end;
  494. equaln:
  495. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.falselabel);
  496. unequaln:
  497. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.truelabel);
  498. end;
  499. end;
  500. procedure secondjmp64bitcmp;
  501. begin
  502. case nodetype of
  503. ltn,gtn,lten,gten:
  504. begin
  505. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(true),location.truelabel);
  506. cg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  507. end;
  508. equaln:
  509. begin
  510. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.falselabel);
  511. cg.a_jmp_always(current_asmdata.CurrAsmList,location.truelabel);
  512. end;
  513. unequaln:
  514. begin
  515. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.truelabel);
  516. cg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  517. end;
  518. end;
  519. end;
  520. begin
  521. truelabel:=nil;
  522. falselabel:=nil;
  523. { This puts constant operand (if any) to the right }
  524. pass_left_right;
  525. unsigned:=not(is_signed(left.resultdef)) or
  526. not(is_signed(right.resultdef));
  527. current_asmdata.getjumplabel(truelabel);
  528. current_asmdata.getjumplabel(falselabel);
  529. location_reset_jump(location,truelabel,falselabel);
  530. { Relational compares against constants having low dword=0 can omit the
  531. second compare based on the fact that any unsigned value is >=0 }
  532. hlab:=nil;
  533. if (right.location.loc=LOC_CONSTANT) and
  534. (lo(right.location.value64)=0) then
  535. begin
  536. case getresflags(true) of
  537. F_AE: hlab:=location.truelabel;
  538. F_B: hlab:=location.falselabel;
  539. end;
  540. end;
  541. if (right.location.loc=LOC_CONSTANT) and (right.location.value64=0) and
  542. (nodetype in [equaln,unequaln]) then
  543. begin
  544. case left.location.loc of
  545. LOC_REFERENCE,
  546. LOC_CREFERENCE:
  547. begin
  548. href:=left.location.reference;
  549. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  550. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_TST,S_L,href));
  551. firstjmp64bitcmp;
  552. inc(href.offset,4);
  553. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_TST,S_L,href));
  554. secondjmp64bitcmp;
  555. location_freetemp(current_asmdata.CurrAsmList,left.location);
  556. end;
  557. else
  558. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  559. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_TST,S_L,left.location.register64.reglo));
  560. firstjmp64bitcmp;
  561. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_TST,S_L,left.location.register64.reghi));
  562. secondjmp64bitcmp;
  563. end;
  564. exit;
  565. end;
  566. { left and right no register? }
  567. { then one must be demanded }
  568. if not (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  569. begin
  570. if not (right.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  571. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true)
  572. else
  573. begin
  574. location_swap(left.location,right.location);
  575. toggleflag(nf_swapped);
  576. end;
  577. end;
  578. { left is now in register }
  579. case right.location.loc of
  580. LOC_REGISTER,LOC_CREGISTER:
  581. begin
  582. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,S_L,right.location.register64.reghi,left.location.register64.reghi));
  583. firstjmp64bitcmp;
  584. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,S_L,right.location.register64.reglo,left.location.register64.reglo));
  585. secondjmp64bitcmp;
  586. end;
  587. LOC_REFERENCE,LOC_CREFERENCE:
  588. begin
  589. href:=right.location.reference;
  590. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  591. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,S_L,href,left.location.register64.reghi));
  592. firstjmp64bitcmp;
  593. inc(href.offset,4);
  594. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,S_L,href,left.location.register64.reglo));
  595. secondjmp64bitcmp;
  596. location_freetemp(current_asmdata.CurrAsmList,right.location);
  597. end;
  598. LOC_CONSTANT:
  599. begin
  600. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,aint(hi(right.location.value64)),left.location.register64.reghi));
  601. firstjmp64bitcmp;
  602. if assigned(hlab) then
  603. cg.a_jmp_always(current_asmdata.CurrAsmList,hlab)
  604. else
  605. begin
  606. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,aint(lo(right.location.value64)),left.location.register64.reglo));
  607. secondjmp64bitcmp;
  608. end;
  609. end;
  610. else
  611. InternalError(2014072501);
  612. end;
  613. end;
  614. begin
  615. caddnode:=t68kaddnode;
  616. end.