ncpuadd.pas 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. protected
  28. procedure second_addfloat;override;
  29. procedure second_cmpfloat;override;
  30. procedure second_cmpboolean;override;
  31. procedure second_cmpsmallset;override;
  32. procedure second_cmp64bit;override;
  33. procedure second_cmpordinal;override;
  34. end;
  35. implementation
  36. uses
  37. systems,
  38. cutils,verbose,
  39. paramgr,
  40. aasmtai,aasmcpu,defutil,
  41. cgbase,cgcpu,
  42. cpupara,
  43. ncon,nset,nadd,
  44. ncgutil,cgobj;
  45. {*****************************************************************************
  46. TSparcAddNode
  47. *****************************************************************************}
  48. function TSparcAddNode.GetResFlags(unsigned:Boolean):TResFlags;
  49. begin
  50. case NodeType of
  51. equaln:
  52. GetResFlags:=F_E;
  53. unequaln:
  54. GetResFlags:=F_NE;
  55. else
  56. if not(unsigned) then
  57. begin
  58. if nf_swaped in flags then
  59. case NodeType of
  60. ltn:
  61. GetResFlags:=F_G;
  62. lten:
  63. GetResFlags:=F_GE;
  64. gtn:
  65. GetResFlags:=F_L;
  66. gten:
  67. GetResFlags:=F_LE;
  68. end
  69. else
  70. case NodeType of
  71. ltn:
  72. GetResFlags:=F_L;
  73. lten:
  74. GetResFlags:=F_LE;
  75. gtn:
  76. GetResFlags:=F_G;
  77. gten:
  78. GetResFlags:=F_GE;
  79. end;
  80. end
  81. else
  82. begin
  83. if nf_swaped in Flags then
  84. case NodeType of
  85. ltn:
  86. GetResFlags:=F_A;
  87. lten:
  88. GetResFlags:=F_AE;
  89. gtn:
  90. GetResFlags:=F_B;
  91. gten:
  92. GetResFlags:=F_BE;
  93. end
  94. else
  95. case NodeType of
  96. ltn:
  97. GetResFlags:=F_B;
  98. lten:
  99. GetResFlags:=F_BE;
  100. gtn:
  101. GetResFlags:=F_A;
  102. gten:
  103. GetResFlags:=F_AE;
  104. end;
  105. end;
  106. end;
  107. end;
  108. procedure tsparcaddnode.second_addfloat;
  109. var
  110. op : TAsmOp;
  111. begin
  112. pass_left_right;
  113. if (nf_swaped in flags) then
  114. swapleftright;
  115. { force fpureg as location, left right doesn't matter
  116. as both will be in a fpureg }
  117. location_force_fpureg(exprasmlist,left.location,true);
  118. location_force_fpureg(exprasmlist,right.location,(left.location.loc<>LOC_CFPUREGISTER));
  119. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  120. if left.location.loc<>LOC_CFPUREGISTER then
  121. location.register:=left.location.register
  122. else
  123. location.register:=right.location.register;
  124. case nodetype of
  125. addn :
  126. begin
  127. if location.size=OS_F64 then
  128. op:=A_FADDd
  129. else
  130. op:=A_FADDs;
  131. end;
  132. muln :
  133. begin
  134. if location.size=OS_F64 then
  135. op:=A_FMULd
  136. else
  137. op:=A_FMULs;
  138. end;
  139. subn :
  140. begin
  141. if location.size=OS_F64 then
  142. op:=A_FSUBd
  143. else
  144. op:=A_FSUBs;
  145. end;
  146. slashn :
  147. begin
  148. if location.size=OS_F64 then
  149. op:=A_FDIVd
  150. else
  151. op:=A_FDIVs;
  152. end;
  153. else
  154. internalerror(200306014);
  155. end;
  156. exprasmlist.concat(taicpu.op_reg_reg_reg(op,
  157. left.location.register,right.location.register,location.register));
  158. release_reg_left_right;
  159. end;
  160. procedure tsparcaddnode.second_cmpfloat;
  161. begin
  162. pass_left_right;
  163. if (nf_swaped in flags) then
  164. swapleftright;
  165. { force fpureg as location, left right doesn't matter
  166. as both will be in a fpureg }
  167. location_force_fpureg(exprasmlist,left.location,true);
  168. location_force_fpureg(exprasmlist,right.location,true);
  169. location_reset(location,LOC_FLAGS,OS_NO);
  170. location.resflags:=getresflags(true);
  171. exprasmlist.concat(taicpu.op_reg_reg(A_FCMPs,
  172. left.location.register,right.location.register));
  173. { Delay slot (can only contain integer operation) }
  174. exprasmlist.concat(taicpu.op_none(A_NOP));
  175. release_reg_left_right;
  176. end;
  177. procedure tsparcaddnode.second_cmpboolean;
  178. begin
  179. pass_left_right;
  180. force_reg_left_right(true,true);
  181. if right.location.loc = LOC_CONSTANT then
  182. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  183. else
  184. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  185. location_reset(location,LOC_FLAGS,OS_NO);
  186. location.resflags:=getresflags(true);
  187. release_reg_left_right;
  188. end;
  189. procedure tsparcaddnode.second_cmpsmallset;
  190. begin
  191. pass_left_right;
  192. force_reg_left_right(true,true);
  193. if right.location.loc = LOC_CONSTANT then
  194. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  195. else
  196. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  197. location_reset(location,LOC_FLAGS,OS_NO);
  198. location.resflags:=getresflags(true);
  199. release_reg_left_right;
  200. end;
  201. procedure tsparcaddnode.second_cmp64bit;
  202. var
  203. unsigned : boolean;
  204. begin
  205. {$warning TODO 64bit compare}
  206. unsigned:=not(is_signed(left.resulttype.def)) or
  207. not(is_signed(right.resulttype.def));
  208. location_reset(location,LOC_FLAGS,OS_NO);
  209. location.resflags:=getresflags(unsigned);
  210. release_reg_left_right;
  211. end;
  212. procedure tsparcaddnode.second_cmpordinal;
  213. var
  214. unsigned : boolean;
  215. begin
  216. pass_left_right;
  217. force_reg_left_right(true,true);
  218. unsigned:=not(is_signed(left.resulttype.def)) or
  219. not(is_signed(right.resulttype.def));
  220. if right.location.loc = LOC_CONSTANT then
  221. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  222. else
  223. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  224. location_reset(location,LOC_FLAGS,OS_NO);
  225. location.resflags:=getresflags(unsigned);
  226. release_reg_left_right;
  227. end;
  228. begin
  229. caddnode:=tsparcaddnode;
  230. end.
  231. {
  232. $Log$
  233. Revision 1.22 2004-01-12 16:39:41 peter
  234. * sparc updates, mostly float related
  235. Revision 1.21 2003/10/24 11:28:35 mazen
  236. -unused units removed from uses clause
  237. Revision 1.20 2003/10/01 20:34:50 peter
  238. * procinfo unit contains tprocinfo
  239. * cginfo renamed to cgbase
  240. * moved cgmessage to verbose
  241. * fixed ppc and sparc compiles
  242. Revision 1.19 2003/09/03 15:55:01 peter
  243. * NEWRA branch merged
  244. Revision 1.18.2.1 2003/09/01 21:02:55 peter
  245. * sparc updates for new tregister
  246. Revision 1.18 2003/07/08 21:25:00 peter
  247. * sparc fixes
  248. Revision 1.17 2003/07/06 22:09:50 peter
  249. * signed compare fixed
  250. Revision 1.16 2003/07/06 17:44:12 peter
  251. * cleanup and first sparc implementation
  252. Revision 1.15 2003/06/01 21:38:06 peter
  253. * getregisterfpu size parameter added
  254. * op_const_reg size parameter added
  255. * sparc updates
  256. }