n68kadd.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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]) then
  344. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  345. case right.location.loc of
  346. LOC_REGISTER,
  347. LOC_CREGISTER:
  348. cg.a_op_reg_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.register,location.register);
  349. LOC_CONSTANT:
  350. cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.value,location.register);
  351. LOC_REFERENCE,
  352. LOC_CREFERENCE:
  353. cg.a_op_ref_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.reference,location.register);
  354. else
  355. internalerror(2016052101);
  356. end;
  357. end;
  358. procedure t68kaddnode.second_cmpordinal;
  359. var
  360. unsigned : boolean;
  361. tmpreg : tregister;
  362. opsize : topsize;
  363. cmpsize : tcgsize;
  364. href: treference;
  365. begin
  366. { determine if the comparison will be unsigned }
  367. unsigned:=not(is_signed(left.resultdef)) or
  368. not(is_signed(right.resultdef));
  369. { this puts constant operand (if any) to the right }
  370. pass_left_right;
  371. { tentatively assume left size (correct for possible TST, will fix later) }
  372. cmpsize:=def_cgsize(left.resultdef);
  373. opsize:=tcgsize2opsize[cmpsize];
  374. { set result location }
  375. location_reset(location,LOC_FLAGS,OS_NO);
  376. { see if we can optimize into TST }
  377. if (right.location.loc=LOC_CONSTANT) and (right.location.value=0) then
  378. begin
  379. { Unsigned <0 or >=0 should not reach pass2, most likely }
  380. case left.location.loc of
  381. LOC_REFERENCE,
  382. LOC_CREFERENCE:
  383. begin
  384. href:=left.location.reference;
  385. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  386. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_TST,opsize,href));
  387. location_freetemp(current_asmdata.CurrAsmList,left.location);
  388. end;
  389. else
  390. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  391. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_TST,opsize,left.location.register));
  392. end;
  393. location.resflags := getresflags(unsigned);
  394. exit;
  395. end;
  396. { Coldfire supports byte/word compares only starting with ISA_B,
  397. !!see remark about Qemu weirdness in tcg68k.a_cmp_const_reg_label }
  398. if (opsize<>S_L) and (current_settings.cputype in cpu_coldfire{-[cpu_isa_b,cpu_isa_c,cfv4e]}) then
  399. begin
  400. { 1) Extension is needed for LOC_REFERENCE, but what about LOC_REGISTER ? Perhaps after fixing cg we can assume
  401. that high bits of registers are correct.
  402. 2) Assuming that extension depends only on source signedness --> destination OS_32 is acceptable. }
  403. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(OS_32),false);
  404. if (right.location.loc<>LOC_CONSTANT) then
  405. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,cgsize_orddef(OS_32),false);
  406. opsize:=S_L;
  407. end
  408. else if not (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  409. begin
  410. if not (right.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  411. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true)
  412. else
  413. begin
  414. location_swap(left.location,right.location);
  415. toggleflag(nf_swapped);
  416. end;
  417. end;
  418. { left is now in register }
  419. case right.location.loc of
  420. LOC_CONSTANT:
  421. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,opsize,
  422. longint(right.location.value),left.location.register));
  423. LOC_REFERENCE,
  424. LOC_CREFERENCE:
  425. begin
  426. href:=right.location.reference;
  427. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  428. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,opsize,href,
  429. left.location.register));
  430. end;
  431. LOC_REGISTER,
  432. LOC_CREGISTER:
  433. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,opsize,
  434. right.location.register,left.location.register));
  435. else
  436. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  437. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,opsize,
  438. right.location.register,left.location.register));
  439. end;
  440. { update location because sides could have been swapped }
  441. location.resflags:=getresflags(unsigned);
  442. end;
  443. {*****************************************************************************
  444. 64-bit
  445. *****************************************************************************}
  446. procedure t68kaddnode.second_cmp64bit;
  447. var
  448. truelabel,
  449. falselabel: tasmlabel;
  450. hlab: tasmlabel;
  451. unsigned : boolean;
  452. href: treference;
  453. procedure firstjmp64bitcmp;
  454. var
  455. oldnodetype : tnodetype;
  456. begin
  457. case nodetype of
  458. ltn,gtn:
  459. begin
  460. if (hlab<>location.truelabel) then
  461. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.truelabel);
  462. { cheat a little bit for the negative test }
  463. toggleflag(nf_swapped);
  464. if (hlab<>location.falselabel) then
  465. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.falselabel);
  466. toggleflag(nf_swapped);
  467. end;
  468. lten,gten:
  469. begin
  470. oldnodetype:=nodetype;
  471. if nodetype=lten then
  472. nodetype:=ltn
  473. else
  474. nodetype:=gtn;
  475. if (hlab<>location.truelabel) then
  476. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.truelabel);
  477. { cheat for the negative test }
  478. if nodetype=ltn then
  479. nodetype:=gtn
  480. else
  481. nodetype:=ltn;
  482. if (hlab<>location.falselabel) then
  483. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.falselabel);
  484. nodetype:=oldnodetype;
  485. end;
  486. equaln:
  487. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.falselabel);
  488. unequaln:
  489. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.truelabel);
  490. end;
  491. end;
  492. procedure secondjmp64bitcmp;
  493. begin
  494. case nodetype of
  495. ltn,gtn,lten,gten:
  496. begin
  497. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(true),location.truelabel);
  498. cg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  499. end;
  500. equaln:
  501. begin
  502. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.falselabel);
  503. cg.a_jmp_always(current_asmdata.CurrAsmList,location.truelabel);
  504. end;
  505. unequaln:
  506. begin
  507. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.truelabel);
  508. cg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  509. end;
  510. end;
  511. end;
  512. begin
  513. truelabel:=nil;
  514. falselabel:=nil;
  515. { This puts constant operand (if any) to the right }
  516. pass_left_right;
  517. unsigned:=not(is_signed(left.resultdef)) or
  518. not(is_signed(right.resultdef));
  519. current_asmdata.getjumplabel(truelabel);
  520. current_asmdata.getjumplabel(falselabel);
  521. location_reset_jump(location,truelabel,falselabel);
  522. { Relational compares against constants having low dword=0 can omit the
  523. second compare based on the fact that any unsigned value is >=0 }
  524. hlab:=nil;
  525. if (right.location.loc=LOC_CONSTANT) and
  526. (lo(right.location.value64)=0) then
  527. begin
  528. case getresflags(true) of
  529. F_AE: hlab:=location.truelabel;
  530. F_B: hlab:=location.falselabel;
  531. end;
  532. end;
  533. if (right.location.loc=LOC_CONSTANT) and (right.location.value64=0) and
  534. (nodetype in [equaln,unequaln]) then
  535. begin
  536. case left.location.loc of
  537. LOC_REFERENCE,
  538. LOC_CREFERENCE:
  539. begin
  540. href:=left.location.reference;
  541. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  542. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_TST,S_L,href));
  543. firstjmp64bitcmp;
  544. inc(href.offset,4);
  545. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_TST,S_L,href));
  546. secondjmp64bitcmp;
  547. location_freetemp(current_asmdata.CurrAsmList,left.location);
  548. end;
  549. else
  550. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  551. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_TST,S_L,left.location.register64.reglo));
  552. firstjmp64bitcmp;
  553. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_TST,S_L,left.location.register64.reghi));
  554. secondjmp64bitcmp;
  555. end;
  556. exit;
  557. end;
  558. { left and right no register? }
  559. { then one must be demanded }
  560. if not (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  561. begin
  562. if not (right.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  563. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true)
  564. else
  565. begin
  566. location_swap(left.location,right.location);
  567. toggleflag(nf_swapped);
  568. end;
  569. end;
  570. { left is now in register }
  571. case right.location.loc of
  572. LOC_REGISTER,LOC_CREGISTER:
  573. begin
  574. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,S_L,right.location.register64.reghi,left.location.register64.reghi));
  575. firstjmp64bitcmp;
  576. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,S_L,right.location.register64.reglo,left.location.register64.reglo));
  577. secondjmp64bitcmp;
  578. end;
  579. LOC_REFERENCE,LOC_CREFERENCE:
  580. begin
  581. href:=right.location.reference;
  582. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  583. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,S_L,href,left.location.register64.reghi));
  584. firstjmp64bitcmp;
  585. inc(href.offset,4);
  586. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,S_L,href,left.location.register64.reglo));
  587. secondjmp64bitcmp;
  588. location_freetemp(current_asmdata.CurrAsmList,right.location);
  589. end;
  590. LOC_CONSTANT:
  591. begin
  592. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,aint(hi(right.location.value64)),left.location.register64.reghi));
  593. firstjmp64bitcmp;
  594. if assigned(hlab) then
  595. cg.a_jmp_always(current_asmdata.CurrAsmList,hlab)
  596. else
  597. begin
  598. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,aint(lo(right.location.value64)),left.location.register64.reglo));
  599. secondjmp64bitcmp;
  600. end;
  601. end;
  602. else
  603. InternalError(2014072501);
  604. end;
  605. end;
  606. begin
  607. caddnode:=t68kaddnode;
  608. end.