n68kadd.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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,
  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)) or
  345. ((right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and needs_unaligned(right.location.reference.alignment,def_cgsize(resultdef))) then
  346. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  347. case right.location.loc of
  348. LOC_REGISTER,
  349. LOC_CREGISTER:
  350. cg.a_op_reg_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.register,location.register);
  351. LOC_CONSTANT:
  352. cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.value,location.register);
  353. LOC_REFERENCE,
  354. LOC_CREFERENCE:
  355. cg.a_op_ref_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.reference,location.register);
  356. else
  357. internalerror(2016052101);
  358. end;
  359. end;
  360. procedure t68kaddnode.second_cmpordinal;
  361. var
  362. unsigned : boolean;
  363. tmpreg : tregister;
  364. opsize : topsize;
  365. cmpsize : tcgsize;
  366. href: treference;
  367. begin
  368. { determine if the comparison will be unsigned }
  369. unsigned:=not(is_signed(left.resultdef)) or
  370. not(is_signed(right.resultdef));
  371. { this puts constant operand (if any) to the right }
  372. pass_left_right;
  373. { tentatively assume left size (correct for possible TST, will fix later) }
  374. cmpsize:=def_cgsize(left.resultdef);
  375. opsize:=tcgsize2opsize[cmpsize];
  376. { set result location }
  377. location_reset(location,LOC_FLAGS,OS_NO);
  378. { see if we can optimize into TST }
  379. if (right.location.loc=LOC_CONSTANT) and (right.location.value=0) then
  380. begin
  381. { Unsigned <0 or >=0 should not reach pass2, most likely }
  382. if (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and not needs_unaligned(left.location.reference.alignment,cmpsize) then
  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. begin
  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. if (right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and needs_unaligned(right.location.reference.alignment,cmpsize) then
  427. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  428. { left is now in register }
  429. case right.location.loc of
  430. LOC_CONSTANT:
  431. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,opsize,
  432. longint(right.location.value),left.location.register));
  433. LOC_REFERENCE,
  434. LOC_CREFERENCE:
  435. begin
  436. href:=right.location.reference;
  437. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  438. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,opsize,href,
  439. left.location.register));
  440. end;
  441. LOC_REGISTER,
  442. LOC_CREGISTER:
  443. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,opsize,
  444. right.location.register,left.location.register));
  445. else
  446. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  447. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,opsize,
  448. right.location.register,left.location.register));
  449. end;
  450. { update location because sides could have been swapped }
  451. location.resflags:=getresflags(unsigned);
  452. end;
  453. {*****************************************************************************
  454. 64-bit
  455. *****************************************************************************}
  456. procedure t68kaddnode.second_cmp64bit;
  457. var
  458. truelabel,
  459. falselabel: tasmlabel;
  460. hlab: tasmlabel;
  461. unsigned : boolean;
  462. href: treference;
  463. procedure firstjmp64bitcmp;
  464. var
  465. oldnodetype : tnodetype;
  466. begin
  467. case nodetype of
  468. ltn,gtn:
  469. begin
  470. if (hlab<>location.truelabel) then
  471. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.truelabel);
  472. { cheat a little bit for the negative test }
  473. toggleflag(nf_swapped);
  474. if (hlab<>location.falselabel) then
  475. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.falselabel);
  476. toggleflag(nf_swapped);
  477. end;
  478. lten,gten:
  479. begin
  480. oldnodetype:=nodetype;
  481. if nodetype=lten then
  482. nodetype:=ltn
  483. else
  484. nodetype:=gtn;
  485. if (hlab<>location.truelabel) then
  486. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.truelabel);
  487. { cheat for the negative test }
  488. if nodetype=ltn then
  489. nodetype:=gtn
  490. else
  491. nodetype:=ltn;
  492. if (hlab<>location.falselabel) then
  493. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(unsigned),location.falselabel);
  494. nodetype:=oldnodetype;
  495. end;
  496. equaln:
  497. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.falselabel);
  498. unequaln:
  499. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.truelabel);
  500. end;
  501. end;
  502. procedure secondjmp64bitcmp;
  503. begin
  504. case nodetype of
  505. ltn,gtn,lten,gten:
  506. begin
  507. cg.a_jmp_flags(current_asmdata.CurrAsmList,getresflags(true),location.truelabel);
  508. cg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  509. end;
  510. equaln:
  511. begin
  512. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.falselabel);
  513. cg.a_jmp_always(current_asmdata.CurrAsmList,location.truelabel);
  514. end;
  515. unequaln:
  516. begin
  517. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,location.truelabel);
  518. cg.a_jmp_always(current_asmdata.CurrAsmList,location.falselabel);
  519. end;
  520. end;
  521. end;
  522. begin
  523. truelabel:=nil;
  524. falselabel:=nil;
  525. { This puts constant operand (if any) to the right }
  526. pass_left_right;
  527. unsigned:=not(is_signed(left.resultdef)) or
  528. not(is_signed(right.resultdef));
  529. current_asmdata.getjumplabel(truelabel);
  530. current_asmdata.getjumplabel(falselabel);
  531. location_reset_jump(location,truelabel,falselabel);
  532. { Relational compares against constants having low dword=0 can omit the
  533. second compare based on the fact that any unsigned value is >=0 }
  534. hlab:=nil;
  535. if (right.location.loc=LOC_CONSTANT) and
  536. (lo(right.location.value64)=0) then
  537. begin
  538. case getresflags(true) of
  539. F_AE: hlab:=location.truelabel;
  540. F_B: hlab:=location.falselabel;
  541. end;
  542. end;
  543. if (right.location.loc=LOC_CONSTANT) and (right.location.value64=0) and
  544. (nodetype in [equaln,unequaln]) then
  545. begin
  546. if (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and not needs_unaligned(left.location.reference.alignment,OS_INT) then
  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. begin
  559. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  560. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_TST,S_L,left.location.register64.reglo));
  561. firstjmp64bitcmp;
  562. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_TST,S_L,left.location.register64.reghi));
  563. secondjmp64bitcmp;
  564. end;
  565. exit;
  566. end;
  567. { left and right no register? }
  568. { then one must be demanded }
  569. if not (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  570. begin
  571. if not (right.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  572. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true)
  573. else
  574. begin
  575. location_swap(left.location,right.location);
  576. toggleflag(nf_swapped);
  577. end;
  578. end;
  579. if (right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and needs_unaligned(right.location.reference.alignment,OS_INT) then
  580. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  581. { left is now in register }
  582. case right.location.loc of
  583. LOC_REGISTER,LOC_CREGISTER:
  584. begin
  585. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,S_L,right.location.register64.reghi,left.location.register64.reghi));
  586. firstjmp64bitcmp;
  587. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,S_L,right.location.register64.reglo,left.location.register64.reglo));
  588. secondjmp64bitcmp;
  589. end;
  590. LOC_REFERENCE,LOC_CREFERENCE:
  591. begin
  592. href:=right.location.reference;
  593. tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
  594. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,S_L,href,left.location.register64.reghi));
  595. firstjmp64bitcmp;
  596. inc(href.offset,4);
  597. current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_CMP,S_L,href,left.location.register64.reglo));
  598. secondjmp64bitcmp;
  599. location_freetemp(current_asmdata.CurrAsmList,right.location);
  600. end;
  601. LOC_CONSTANT:
  602. begin
  603. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,aint(hi(right.location.value64)),left.location.register64.reghi));
  604. firstjmp64bitcmp;
  605. if assigned(hlab) then
  606. cg.a_jmp_always(current_asmdata.CurrAsmList,hlab)
  607. else
  608. begin
  609. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_CMP,S_L,aint(lo(right.location.value64)),left.location.register64.reglo));
  610. secondjmp64bitcmp;
  611. end;
  612. end;
  613. else
  614. InternalError(2014072501);
  615. end;
  616. end;
  617. begin
  618. caddnode:=t68kaddnode;
  619. end.