ncpuadd.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. aasmbase,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. l : tasmlabel;
  246. begin
  247. pass_left_right;
  248. force_reg_left_right(false,false);
  249. unsigned:=not(is_signed(left.resulttype.def)) or
  250. not(is_signed(right.resulttype.def));
  251. location_reset(location,LOC_FLAGS,OS_NO);
  252. location.resflags:=getresflags(unsigned);
  253. { operation requiring proper N, Z and C flags ? }
  254. if unsigned or (nodetype in [equaln,unequaln]) then
  255. begin
  256. objectlibrary.getlabel(l);
  257. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
  258. tcgsparc(cg).a_jmp_cond(exprasmlist,OC_NE,l);
  259. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo));
  260. cg.a_label(exprasmlist,l);
  261. end
  262. { operation requiring proper N, V and C flags ? }
  263. else if nodetype in [gten,ltn] then
  264. begin
  265. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBCC,left.location.register64.reglo,right.location.register64.reglo,NR_G0));
  266. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBXCC,left.location.register64.reghi,right.location.register64.reghi,NR_G0));
  267. end
  268. else
  269. { operation requiring proper N, Z and V flags ? }
  270. begin
  271. { this isn't possible so swap operands and use the "reverse" operation }
  272. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBCC,right.location.register64.reglo,left.location.register64.reglo,NR_G0));
  273. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBXCC,right.location.register64.reghi,left.location.register64.reghi,NR_G0));
  274. if nf_swaped in flags then
  275. begin
  276. if location.resflags=F_L then
  277. location.resflags:=F_G
  278. else if location.resflags=F_GE then
  279. location.resflags:=F_LE
  280. else
  281. internalerror(200401221);
  282. end
  283. else
  284. begin
  285. if location.resflags=F_G then
  286. location.resflags:=F_L
  287. else if location.resflags=F_LE then
  288. location.resflags:=F_GE
  289. else
  290. internalerror(200401221);
  291. end;
  292. end;
  293. release_reg_left_right;
  294. end;
  295. procedure tsparcaddnode.second_cmpordinal;
  296. var
  297. unsigned : boolean;
  298. begin
  299. pass_left_right;
  300. force_reg_left_right(true,true);
  301. unsigned:=not(is_signed(left.resulttype.def)) or
  302. not(is_signed(right.resulttype.def));
  303. if right.location.loc = LOC_CONSTANT then
  304. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  305. else
  306. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  307. location_reset(location,LOC_FLAGS,OS_NO);
  308. location.resflags:=getresflags(unsigned);
  309. release_reg_left_right;
  310. end;
  311. begin
  312. caddnode:=tsparcaddnode;
  313. end.
  314. {
  315. $Log$
  316. Revision 1.25 2004-06-20 08:55:32 florian
  317. * logs truncated
  318. Revision 1.24 2004/06/16 20:07:10 florian
  319. * dwarf branch merged
  320. Revision 1.23.2.3 2004/06/02 16:07:52 peter
  321. * fixed 64bit compare
  322. Revision 1.23.2.2 2004/05/31 16:39:42 peter
  323. * add ungetiftemp in a few locations
  324. Revision 1.23.2.1 2004/05/30 17:54:14 florian
  325. + implemented cmp64bit
  326. * started to fix spilling
  327. * fixed int64 sub partially
  328. Revision 1.23 2004/01/12 22:11:39 peter
  329. * use localalign info for alignment for locals and temps
  330. * sparc fpu flags branching added
  331. * moved powerpc copy_valye_openarray to generic
  332. }