ncpuadd.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. Code generation for add nodes on the SPARC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncpuadd;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncgadd,cpubase;
  23. type
  24. tsparcaddnode = class(tcgaddnode)
  25. private
  26. function GetResFlags(unsigned:Boolean):TResFlags;
  27. function GetFPUResFlags:TResFlags;
  28. protected
  29. procedure second_addfloat;override;
  30. procedure second_cmpfloat;override;
  31. procedure second_cmpboolean;override;
  32. procedure second_cmpsmallset;override;
  33. procedure second_cmp64bit;override;
  34. procedure second_cmpordinal;override;
  35. end;
  36. implementation
  37. uses
  38. systems,
  39. cutils,verbose,
  40. paramgr,
  41. aasmtai,aasmcpu,defutil,
  42. cgbase,cgcpu,
  43. cpupara,
  44. ncon,nset,nadd,
  45. ncgutil,cgobj;
  46. {*****************************************************************************
  47. TSparcAddNode
  48. *****************************************************************************}
  49. function TSparcAddNode.GetResFlags(unsigned:Boolean):TResFlags;
  50. begin
  51. case NodeType of
  52. equaln:
  53. GetResFlags:=F_E;
  54. unequaln:
  55. GetResFlags:=F_NE;
  56. else
  57. if not(unsigned) then
  58. begin
  59. if nf_swaped in flags then
  60. case NodeType of
  61. ltn:
  62. GetResFlags:=F_G;
  63. lten:
  64. GetResFlags:=F_GE;
  65. gtn:
  66. GetResFlags:=F_L;
  67. gten:
  68. GetResFlags:=F_LE;
  69. end
  70. else
  71. case NodeType of
  72. ltn:
  73. GetResFlags:=F_L;
  74. lten:
  75. GetResFlags:=F_LE;
  76. gtn:
  77. GetResFlags:=F_G;
  78. gten:
  79. GetResFlags:=F_GE;
  80. end;
  81. end
  82. else
  83. begin
  84. if nf_swaped in Flags then
  85. case NodeType of
  86. ltn:
  87. GetResFlags:=F_A;
  88. lten:
  89. GetResFlags:=F_AE;
  90. gtn:
  91. GetResFlags:=F_B;
  92. gten:
  93. GetResFlags:=F_BE;
  94. end
  95. else
  96. case NodeType of
  97. ltn:
  98. GetResFlags:=F_B;
  99. lten:
  100. GetResFlags:=F_BE;
  101. gtn:
  102. GetResFlags:=F_A;
  103. gten:
  104. GetResFlags:=F_AE;
  105. end;
  106. end;
  107. end;
  108. end;
  109. function TSparcAddNode.GetFPUResFlags:TResFlags;
  110. begin
  111. case NodeType of
  112. equaln:
  113. result:=F_FE;
  114. unequaln:
  115. result:=F_FNE;
  116. else
  117. begin
  118. if nf_swaped in Flags then
  119. case NodeType of
  120. ltn:
  121. result:=F_FG;
  122. lten:
  123. result:=F_FGE;
  124. gtn:
  125. result:=F_FL;
  126. gten:
  127. result:=F_FLE;
  128. end
  129. else
  130. case NodeType of
  131. ltn:
  132. result:=F_FL;
  133. lten:
  134. result:=F_FLE;
  135. gtn:
  136. result:=F_FG;
  137. gten:
  138. result:=F_FGE;
  139. end;
  140. end;
  141. end;
  142. end;
  143. procedure tsparcaddnode.second_addfloat;
  144. var
  145. op : TAsmOp;
  146. begin
  147. pass_left_right;
  148. if (nf_swaped in flags) then
  149. swapleftright;
  150. { force fpureg as location, left right doesn't matter
  151. as both will be in a fpureg }
  152. location_force_fpureg(exprasmlist,left.location,true);
  153. location_force_fpureg(exprasmlist,right.location,(left.location.loc<>LOC_CFPUREGISTER));
  154. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  155. if left.location.loc<>LOC_CFPUREGISTER then
  156. location.register:=left.location.register
  157. else
  158. location.register:=right.location.register;
  159. case nodetype of
  160. addn :
  161. begin
  162. if location.size=OS_F64 then
  163. op:=A_FADDd
  164. else
  165. op:=A_FADDs;
  166. end;
  167. muln :
  168. begin
  169. if location.size=OS_F64 then
  170. op:=A_FMULd
  171. else
  172. op:=A_FMULs;
  173. end;
  174. subn :
  175. begin
  176. if location.size=OS_F64 then
  177. op:=A_FSUBd
  178. else
  179. op:=A_FSUBs;
  180. end;
  181. slashn :
  182. begin
  183. if location.size=OS_F64 then
  184. op:=A_FDIVd
  185. else
  186. op:=A_FDIVs;
  187. end;
  188. else
  189. internalerror(200306014);
  190. end;
  191. exprasmlist.concat(taicpu.op_reg_reg_reg(op,
  192. left.location.register,right.location.register,location.register));
  193. release_reg_left_right;
  194. end;
  195. procedure tsparcaddnode.second_cmpfloat;
  196. var
  197. op : tasmop;
  198. begin
  199. pass_left_right;
  200. if (nf_swaped in flags) then
  201. swapleftright;
  202. { force fpureg as location, left right doesn't matter
  203. as both will be in a fpureg }
  204. location_force_fpureg(exprasmlist,left.location,true);
  205. location_force_fpureg(exprasmlist,right.location,true);
  206. location_reset(location,LOC_FLAGS,OS_NO);
  207. location.resflags:=getfpuresflags;
  208. if left.location.size=OS_F64 then
  209. op:=A_FCMPd
  210. else
  211. op:=A_FCMPs;
  212. exprasmlist.concat(taicpu.op_reg_reg(op,
  213. left.location.register,right.location.register));
  214. { Delay slot (can only contain integer operation) }
  215. exprasmlist.concat(taicpu.op_none(A_NOP));
  216. release_reg_left_right;
  217. end;
  218. procedure tsparcaddnode.second_cmpboolean;
  219. begin
  220. pass_left_right;
  221. force_reg_left_right(true,true);
  222. if right.location.loc = LOC_CONSTANT then
  223. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  224. else
  225. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  226. location_reset(location,LOC_FLAGS,OS_NO);
  227. location.resflags:=getresflags(true);
  228. release_reg_left_right;
  229. end;
  230. procedure tsparcaddnode.second_cmpsmallset;
  231. begin
  232. pass_left_right;
  233. force_reg_left_right(true,true);
  234. if right.location.loc = LOC_CONSTANT then
  235. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  236. else
  237. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  238. location_reset(location,LOC_FLAGS,OS_NO);
  239. location.resflags:=getresflags(true);
  240. release_reg_left_right;
  241. end;
  242. procedure tsparcaddnode.second_cmp64bit;
  243. var
  244. unsigned : boolean;
  245. procedure firstjmp64bitcmp;
  246. var
  247. oldnodetype : tnodetype;
  248. begin
  249. { the jump the sequence is a little bit hairy }
  250. case nodetype of
  251. ltn,gtn:
  252. begin
  253. cg.a_jmp_flags(exprasmlist,getresflags(unsigned),truelabel);
  254. { cheat a little bit for the negative test }
  255. toggleflag(nf_swaped);
  256. cg.a_jmp_flags(exprasmlist,getresflags(unsigned),falselabel);
  257. toggleflag(nf_swaped);
  258. end;
  259. lten,gten:
  260. begin
  261. oldnodetype:=nodetype;
  262. if nodetype=lten then
  263. nodetype:=ltn
  264. else
  265. nodetype:=gtn;
  266. cg.a_jmp_flags(exprasmlist,getresflags(unsigned),truelabel);
  267. { cheat for the negative test }
  268. if nodetype=ltn then
  269. nodetype:=gtn
  270. else
  271. nodetype:=ltn;
  272. cg.a_jmp_flags(exprasmlist,getresflags(unsigned),falselabel);
  273. nodetype:=oldnodetype;
  274. end;
  275. equaln:
  276. cg.a_jmp_flags(exprasmlist,F_NE,falselabel);
  277. unequaln:
  278. cg.a_jmp_flags(exprasmlist,F_NE,truelabel);
  279. end;
  280. end;
  281. procedure secondjmp64bitcmp;
  282. begin
  283. { the jump the sequence is a little bit hairy }
  284. case nodetype of
  285. ltn,gtn,lten,gten:
  286. begin
  287. { the comparisaion of the low dword have to be }
  288. { always unsigned! }
  289. cg.a_jmp_flags(exprasmlist,getresflags(true),truelabel);
  290. cg.a_jmp_always(exprasmlist,falselabel);
  291. end;
  292. equaln:
  293. begin
  294. cg.a_jmp_flags(exprasmlist,F_NE,falselabel);
  295. cg.a_jmp_always(exprasmlist,truelabel);
  296. end;
  297. unequaln:
  298. begin
  299. cg.a_jmp_flags(exprasmlist,F_NE,truelabel);
  300. cg.a_jmp_always(exprasmlist,falselabel);
  301. end;
  302. end;
  303. end;
  304. begin
  305. pass_left_right;
  306. force_reg_left_right(false,false);
  307. unsigned:=not(is_signed(left.resulttype.def)) or
  308. not(is_signed(right.resulttype.def));
  309. location_reset(location,LOC_JUMP,OS_NO);
  310. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
  311. firstjmp64bitcmp;
  312. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo));
  313. secondjmp64bitcmp;
  314. release_reg_left_right;
  315. end;
  316. procedure tsparcaddnode.second_cmpordinal;
  317. var
  318. unsigned : boolean;
  319. begin
  320. pass_left_right;
  321. force_reg_left_right(true,true);
  322. unsigned:=not(is_signed(left.resulttype.def)) or
  323. not(is_signed(right.resulttype.def));
  324. if right.location.loc = LOC_CONSTANT then
  325. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  326. else
  327. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  328. location_reset(location,LOC_FLAGS,OS_NO);
  329. location.resflags:=getresflags(unsigned);
  330. release_reg_left_right;
  331. end;
  332. begin
  333. caddnode:=tsparcaddnode;
  334. end.
  335. {
  336. $Log$
  337. Revision 1.26 2004-09-21 17:25:13 peter
  338. * paraloc branch merged
  339. Revision 1.25.4.1 2004/09/19 18:08:30 peter
  340. * int64 compare fixed
  341. Revision 1.25 2004/06/20 08:55:32 florian
  342. * logs truncated
  343. Revision 1.24 2004/06/16 20:07:10 florian
  344. * dwarf branch merged
  345. Revision 1.23.2.3 2004/06/02 16:07:52 peter
  346. * fixed 64bit compare
  347. Revision 1.23.2.2 2004/05/31 16:39:42 peter
  348. * add ungetiftemp in a few locations
  349. Revision 1.23.2.1 2004/05/30 17:54:14 florian
  350. + implemented cmp64bit
  351. * started to fix spilling
  352. * fixed int64 sub partially
  353. Revision 1.23 2004/01/12 22:11:39 peter
  354. * use localalign info for alignment for locals and temps
  355. * sparc fpu flags branching added
  356. * moved powerpc copy_valye_openarray to generic
  357. }