ncpuadd.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. begin
  246. {$warning TODO 64bit compare}
  247. unsigned:=not(is_signed(left.resulttype.def)) or
  248. not(is_signed(right.resulttype.def));
  249. location_reset(location,LOC_FLAGS,OS_NO);
  250. location.resflags:=getresflags(unsigned);
  251. release_reg_left_right;
  252. end;
  253. procedure tsparcaddnode.second_cmpordinal;
  254. var
  255. unsigned : boolean;
  256. begin
  257. pass_left_right;
  258. force_reg_left_right(true,true);
  259. unsigned:=not(is_signed(left.resulttype.def)) or
  260. not(is_signed(right.resulttype.def));
  261. if right.location.loc = LOC_CONSTANT then
  262. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  263. else
  264. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  265. location_reset(location,LOC_FLAGS,OS_NO);
  266. location.resflags:=getresflags(unsigned);
  267. release_reg_left_right;
  268. end;
  269. begin
  270. caddnode:=tsparcaddnode;
  271. end.
  272. {
  273. $Log$
  274. Revision 1.23 2004-01-12 22:11:39 peter
  275. * use localalign info for alignment for locals and temps
  276. * sparc fpu flags branching added
  277. * moved powerpc copy_valye_openarray to generic
  278. Revision 1.22 2004/01/12 16:39:41 peter
  279. * sparc updates, mostly float related
  280. Revision 1.21 2003/10/24 11:28:35 mazen
  281. -unused units removed from uses clause
  282. Revision 1.20 2003/10/01 20:34:50 peter
  283. * procinfo unit contains tprocinfo
  284. * cginfo renamed to cgbase
  285. * moved cgmessage to verbose
  286. * fixed ppc and sparc compiles
  287. Revision 1.19 2003/09/03 15:55:01 peter
  288. * NEWRA branch merged
  289. Revision 1.18.2.1 2003/09/01 21:02:55 peter
  290. * sparc updates for new tregister
  291. Revision 1.18 2003/07/08 21:25:00 peter
  292. * sparc fixes
  293. Revision 1.17 2003/07/06 22:09:50 peter
  294. * signed compare fixed
  295. Revision 1.16 2003/07/06 17:44:12 peter
  296. * cleanup and first sparc implementation
  297. Revision 1.15 2003/06/01 21:38:06 peter
  298. * getregisterfpu size parameter added
  299. * op_const_reg size parameter added
  300. * sparc updates
  301. }