nz80add.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. {
  2. Copyright (c) 2008 by Florian Klaempfl
  3. Code generation for add nodes on the AVR
  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 nz80add;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgadd, symtype,cpubase;
  22. type
  23. { TZ80AddNode }
  24. TZ80AddNode = class(tcgaddnode)
  25. private
  26. function NoEqual(anodetype:tnodetype):tnodetype;
  27. function GetResFlags(unsigned:Boolean;anodetype:tnodetype):TResFlags;
  28. protected
  29. function pass_1 : tnode;override;
  30. procedure second_cmpordinal;override;
  31. procedure second_cmpsmallset;override;
  32. procedure second_cmp64bit;override;
  33. procedure second_cmp16_32_64bit;
  34. procedure second_cmp;
  35. end;
  36. implementation
  37. uses
  38. globtype,systems,
  39. cutils,verbose,globals,
  40. symconst,symdef,paramgr,
  41. aasmbase,aasmtai,aasmdata,aasmcpu,defutil,htypechk,
  42. cgbase,cgutils,cgcpu,
  43. cpuinfo,pass_1,pass_2,procinfo,
  44. cpupara,
  45. ncon,nset,nadd,
  46. ncgutil,tgobj,rgobj,rgcpu,cgobj,cg64f32,
  47. hlcgobj;
  48. {*****************************************************************************
  49. TZ80AddNode
  50. *****************************************************************************}
  51. function TZ80AddNode.NoEqual(anodetype: tnodetype): tnodetype;
  52. begin
  53. if anodetype=lten then
  54. result:=ltn
  55. else if anodetype=gten then
  56. result:=gtn
  57. else
  58. result:=anodetype;
  59. end;
  60. function TZ80AddNode.GetResFlags(unsigned: Boolean; anodetype: tnodetype): TResFlags;
  61. begin
  62. case anodetype of
  63. equaln:
  64. GetResFlags:=F_E;
  65. unequaln:
  66. GetResFlags:=F_NE;
  67. else
  68. if not(unsigned) then
  69. begin
  70. { signed }
  71. if nf_swapped in flags then
  72. case anodetype of
  73. ltn:
  74. GetResFlags:=F_NotPossible;
  75. lten:
  76. GetResFlags:=F_P;
  77. gtn:
  78. GetResFlags:=F_M;
  79. gten:
  80. GetResFlags:=F_NotPossible;
  81. else
  82. internalerror(2014082020);
  83. end
  84. else
  85. case anodetype of
  86. ltn:
  87. GetResFlags:=F_M;
  88. lten:
  89. GetResFlags:=F_NotPossible;
  90. gtn:
  91. GetResFlags:=F_NotPossible;
  92. gten:
  93. GetResFlags:=F_P;
  94. else
  95. internalerror(2014082021);
  96. end;
  97. end
  98. else
  99. begin
  100. { unsigned }
  101. if nf_swapped in Flags then
  102. case anodetype of
  103. ltn:
  104. GetResFlags:=F_NotPossible;
  105. lten:
  106. GetResFlags:=F_NC;
  107. gtn:
  108. GetResFlags:=F_C;
  109. gten:
  110. GetResFlags:=F_NotPossible;
  111. else
  112. internalerror(2014082022);
  113. end
  114. else
  115. case anodetype of
  116. ltn:
  117. GetResFlags:=F_C;
  118. lten:
  119. GetResFlags:=F_NotPossible;
  120. gtn:
  121. GetResFlags:=F_NotPossible;
  122. gten:
  123. GetResFlags:=F_NC;
  124. else
  125. internalerror(2014082023);
  126. end;
  127. end;
  128. end;
  129. end;
  130. procedure TZ80AddNode.second_cmpsmallset;
  131. procedure gencmp(tmpreg1,tmpreg2 : tregister);
  132. var
  133. i : byte;
  134. begin
  135. //current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CP,tmpreg1,tmpreg2));
  136. //for i:=2 to tcgsize2size[left.location.size] do
  137. // begin
  138. // tmpreg1:=GetNextReg(tmpreg1);
  139. // tmpreg2:=GetNextReg(tmpreg2);
  140. // current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CPC,tmpreg1,tmpreg2));
  141. // end;
  142. end;
  143. var
  144. tmpreg : tregister;
  145. begin
  146. //pass_left_right;
  147. //location_reset(location,LOC_FLAGS,OS_NO);
  148. //force_reg_left_right(false,false);
  149. //
  150. //case nodetype of
  151. // equaln:
  152. // begin
  153. // gencmp(left.location.register,right.location.register);
  154. // location.resflags:=F_EQ;
  155. // end;
  156. // unequaln:
  157. // begin
  158. // gencmp(left.location.register,right.location.register);
  159. // location.resflags:=F_NE;
  160. // end;
  161. // lten,
  162. // gten:
  163. // begin
  164. // if (not(nf_swapped in flags) and
  165. // (nodetype = lten)) or
  166. // ((nf_swapped in flags) and
  167. // (nodetype = gten)) then
  168. // swapleftright;
  169. // tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  170. // cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_AND,location.size,
  171. // left.location.register,right.location.register,tmpreg);
  172. // gencmp(tmpreg,right.location.register);
  173. // location.resflags:=F_EQ;
  174. // end;
  175. // else
  176. // internalerror(2004012401);
  177. //end;
  178. end;
  179. procedure TZ80AddNode.second_cmp;
  180. var
  181. unsigned : boolean;
  182. tmpreg1,tmpreg2 : tregister;
  183. i : longint;
  184. opdef: tdef;
  185. opsize: TCgSize;
  186. l: TAsmLabel;
  187. begin
  188. unsigned:=not(is_signed(left.resultdef)) or
  189. not(is_signed(right.resultdef));
  190. opdef:=left.resultdef;
  191. opsize:=def_cgsize(opdef);
  192. pass_left_right;
  193. if (opsize=OS_8) or ((opsize=OS_S8) and (NodeType in [equaln,unequaln])) then
  194. begin
  195. if getresflags(unsigned,NodeType)=F_NotPossible then
  196. swapleftright;
  197. if left.location.loc<>LOC_REGISTER then
  198. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  199. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  200. begin
  201. if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  202. begin
  203. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  204. cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  205. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_CP,NR_A,right.location.reference));
  206. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  207. end
  208. else
  209. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  210. end;
  211. case right.location.loc of
  212. LOC_CONSTANT:
  213. begin
  214. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  215. cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  216. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_CP,NR_A,right.location.value));
  217. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  218. end;
  219. LOC_REGISTER,LOC_CREGISTER:
  220. begin
  221. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  222. cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  223. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_CP,NR_A,right.location.register));
  224. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  225. end;
  226. LOC_REFERENCE,LOC_CREFERENCE:
  227. begin
  228. { Already handled before the case statement. Nothing to do here. }
  229. end;
  230. else
  231. internalerror(2020040402);
  232. end;
  233. location_reset(location,LOC_FLAGS,OS_NO);
  234. location.resflags:=getresflags(unsigned,NodeType);
  235. end
  236. else if opsize=OS_S8 then
  237. begin
  238. if getresflags(unsigned,NodeType)=F_NotPossible then
  239. swapleftright;
  240. if left.location.loc<>LOC_REGISTER then
  241. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  242. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  243. begin
  244. if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  245. begin
  246. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  247. cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  248. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_SUB,NR_A,right.location.reference));
  249. end
  250. else
  251. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  252. end;
  253. case right.location.loc of
  254. LOC_CONSTANT:
  255. begin
  256. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  257. cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  258. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_SUB,NR_A,right.location.value));
  259. end;
  260. LOC_REGISTER,LOC_CREGISTER:
  261. begin
  262. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  263. cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  264. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_SUB,NR_A,right.location.register));
  265. end;
  266. LOC_REFERENCE,LOC_CREFERENCE:
  267. begin
  268. { Already handled before the case statement. Nothing to do here. }
  269. end;
  270. else
  271. internalerror(2020040402);
  272. end;
  273. current_asmdata.getjumplabel(l);
  274. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_PO,l);
  275. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_XOR,NR_A,$80));
  276. cg.a_label(current_asmdata.CurrAsmList,l);
  277. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  278. location_reset(location,LOC_FLAGS,OS_NO);
  279. location.resflags:=getresflags(unsigned,NodeType);
  280. end
  281. else
  282. internalerror(2020040401);
  283. end;
  284. procedure TZ80AddNode.second_cmp64bit;
  285. begin
  286. second_cmp16_32_64bit;
  287. end;
  288. procedure TZ80AddNode.second_cmp16_32_64bit;
  289. var
  290. truelabel,
  291. falselabel: tasmlabel;
  292. unsigned : boolean;
  293. i, size: Integer;
  294. tmpref: treference;
  295. op: TAsmOp;
  296. begin
  297. truelabel:=nil;
  298. falselabel:=nil;
  299. pass_left_right;
  300. unsigned:=not(is_signed(left.resultdef)) or
  301. not(is_signed(right.resultdef));
  302. { we have LOC_JUMP as result }
  303. current_asmdata.getjumplabel(truelabel);
  304. current_asmdata.getjumplabel(falselabel);
  305. location_reset_jump(location,truelabel,falselabel);
  306. size:=tcgsize2size[def_cgsize(left.resultdef)];
  307. if NodeType in [equaln,unequaln] then
  308. begin
  309. if left.location.loc<>LOC_REGISTER then
  310. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  311. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  312. begin
  313. if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  314. begin
  315. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  316. tmpref:=right.location.reference;
  317. for i:=0 to size-1 do
  318. begin
  319. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  320. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_CP,NR_A,tmpref));
  321. case NodeType of
  322. equaln:
  323. if i<>(size-1) then
  324. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,falselabel)
  325. else
  326. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,truelabel);
  327. unequaln:
  328. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,truelabel);
  329. else
  330. internalerror(2020042102);
  331. end;
  332. if i<>(size-1) then
  333. tcgz80(cg).adjust_normalized_ref(current_asmdata.CurrAsmList,tmpref,1);
  334. end;
  335. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  336. cg.a_jmp_always(current_asmdata.CurrAsmList,falselabel);
  337. end
  338. else
  339. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  340. end;
  341. case right.location.loc of
  342. LOC_CONSTANT:
  343. begin
  344. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  345. for i:=0 to size-1 do
  346. begin
  347. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  348. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_CP,NR_A,byte(right.location.value shr (i*8))));
  349. case NodeType of
  350. equaln:
  351. if i<>(size-1) then
  352. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,falselabel)
  353. else
  354. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,truelabel);
  355. unequaln:
  356. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,truelabel);
  357. else
  358. internalerror(2020042102);
  359. end;
  360. end;
  361. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  362. cg.a_jmp_always(current_asmdata.CurrAsmList,falselabel);
  363. end;
  364. LOC_REGISTER,LOC_CREGISTER:
  365. begin
  366. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  367. for i:=0 to size-1 do
  368. begin
  369. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  370. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_CP,NR_A,tcgz80(cg).GetOffsetReg64(right.location.register,right.location.registerhi,i)));
  371. case NodeType of
  372. equaln:
  373. if i<>(size-1) then
  374. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,falselabel)
  375. else
  376. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,truelabel);
  377. unequaln:
  378. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,truelabel);
  379. else
  380. internalerror(2020042102);
  381. end;
  382. end;
  383. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  384. cg.a_jmp_always(current_asmdata.CurrAsmList,falselabel);
  385. end;
  386. LOC_REFERENCE,LOC_CREFERENCE:
  387. begin
  388. { Already handled before the case statement. Nothing to do here. }
  389. end;
  390. else
  391. internalerror(2020042103);
  392. end;
  393. end
  394. else
  395. begin
  396. if left.location.loc<>LOC_REGISTER then
  397. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  398. if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  399. begin
  400. if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  401. begin
  402. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  403. tmpref:=right.location.reference;
  404. tcgz80(cg).adjust_normalized_ref(current_asmdata.CurrAsmList,tmpref,size-1);
  405. for i:=size-1 downto 0 do
  406. begin
  407. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  408. if (i=(size-1)) and (not unsigned) then
  409. op:=A_SUB
  410. else
  411. op:=A_CP;
  412. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(op,NR_A,tmpref));
  413. if (i=(size-1)) and (not unsigned) then
  414. case NodeType of
  415. ltn,
  416. lten:
  417. tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  418. gtn,
  419. gten:
  420. tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  421. else
  422. internalerror(2020042202);
  423. end
  424. else if i<>0 then
  425. case NodeType of
  426. ltn,
  427. lten:
  428. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  429. gtn,
  430. gten:
  431. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  432. else
  433. internalerror(2020042202);
  434. end
  435. else
  436. case NodeType of
  437. ltn:
  438. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,falselabel,falselabel);
  439. lten:
  440. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,truelabel,falselabel);
  441. gtn:
  442. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,falselabel,truelabel);
  443. gten:
  444. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,truelabel,truelabel);
  445. else
  446. internalerror(2020042203);
  447. end;
  448. if i<>0 then
  449. tcgz80(cg).adjust_normalized_ref(current_asmdata.CurrAsmList,tmpref,-1);
  450. end;
  451. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  452. end
  453. else
  454. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  455. end;
  456. case right.location.loc of
  457. LOC_CONSTANT:
  458. begin
  459. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  460. for i:=size-1 downto 0 do
  461. begin
  462. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  463. if (i=(size-1)) and (not unsigned) then
  464. op:=A_SUB
  465. else
  466. op:=A_CP;
  467. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(op,NR_A,byte(right.location.value shr (i*8))));
  468. if (i=(size-1)) and (not unsigned) then
  469. case NodeType of
  470. ltn,
  471. lten:
  472. tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  473. gtn,
  474. gten:
  475. tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  476. else
  477. internalerror(2020042202);
  478. end
  479. else if i<>0 then
  480. case NodeType of
  481. ltn,
  482. lten:
  483. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  484. gtn,
  485. gten:
  486. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  487. else
  488. internalerror(2020042202);
  489. end
  490. else
  491. case NodeType of
  492. ltn:
  493. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,falselabel,falselabel);
  494. lten:
  495. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,truelabel,falselabel);
  496. gtn:
  497. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,falselabel,truelabel);
  498. gten:
  499. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,truelabel,truelabel);
  500. else
  501. internalerror(2020042203);
  502. end;
  503. end;
  504. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  505. end;
  506. LOC_REGISTER,LOC_CREGISTER:
  507. begin
  508. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  509. for i:=size-1 downto 0 do
  510. begin
  511. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  512. if (i=(size-1)) and (not unsigned) then
  513. op:=A_SUB
  514. else
  515. op:=A_CP;
  516. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(op,NR_A,tcgz80(cg).GetOffsetReg64(right.location.register,right.location.registerhi,i)));
  517. if (i=(size-1)) and (not unsigned) then
  518. case NodeType of
  519. ltn,
  520. lten:
  521. tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  522. gtn,
  523. gten:
  524. tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  525. else
  526. internalerror(2020042202);
  527. end
  528. else if i<>0 then
  529. case NodeType of
  530. ltn,
  531. lten:
  532. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  533. gtn,
  534. gten:
  535. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  536. else
  537. internalerror(2020042202);
  538. end
  539. else
  540. case NodeType of
  541. ltn:
  542. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,falselabel,falselabel);
  543. lten:
  544. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,truelabel,falselabel);
  545. gtn:
  546. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,falselabel,truelabel);
  547. gten:
  548. tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,truelabel,truelabel);
  549. else
  550. internalerror(2020042203);
  551. end;
  552. end;
  553. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  554. end;
  555. LOC_REFERENCE,LOC_CREFERENCE:
  556. begin
  557. { Already handled before the case statement. Nothing to do here. }
  558. end;
  559. else
  560. internalerror(2020042103);
  561. end;
  562. end;
  563. end;
  564. function TZ80AddNode.pass_1 : tnode;
  565. begin
  566. result:=inherited pass_1;
  567. {$ifdef dummy}
  568. if not(assigned(result)) then
  569. begin
  570. unsigned:=not(is_signed(left.resultdef)) or
  571. not(is_signed(right.resultdef));
  572. if is_64bit(left.resultdef) and
  573. ((nodetype in [equaln,unequaln]) or
  574. (unsigned and (nodetype in [ltn,lten,gtn,gten]))
  575. ) then
  576. expectloc:=LOC_FLAGS;
  577. end;
  578. { handling boolean expressions }
  579. if not(assigned(result)) and
  580. (
  581. not(is_boolean(left.resultdef)) or
  582. not(is_boolean(right.resultdef)) or
  583. is_dynamic_array(left.resultdef)
  584. ) then
  585. expectloc:=LOC_FLAGS;
  586. {$endif dummy}
  587. end;
  588. procedure TZ80AddNode.second_cmpordinal;
  589. begin
  590. if left.resultdef.size>=2 then
  591. second_cmp16_32_64bit
  592. else
  593. second_cmp;
  594. end;
  595. begin
  596. caddnode:=TZ80AddNode;
  597. end.