ncpuadd.pas 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. case nodetype of
  116. addn :
  117. op:=A_FADDs;
  118. muln :
  119. op:=A_FMULs;
  120. subn :
  121. op:=A_FSUBs;
  122. slashn :
  123. op:=A_FDIVs;
  124. else
  125. internalerror(200306014);
  126. end;
  127. { force fpureg as location, left right doesn't matter
  128. as both will be in a fpureg }
  129. location_force_fpureg(exprasmlist,left.location,true);
  130. location_force_fpureg(exprasmlist,right.location,(left.location.loc<>LOC_CFPUREGISTER));
  131. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  132. if left.location.loc<>LOC_CFPUREGISTER then
  133. location.register:=left.location.register
  134. else
  135. location.register:=right.location.register;
  136. exprasmlist.concat(taicpu.op_reg_reg_reg(op,
  137. left.location.register,right.location.register,location.register));
  138. release_reg_left_right;
  139. end;
  140. procedure tsparcaddnode.second_cmpfloat;
  141. begin
  142. pass_left_right;
  143. if (nf_swaped in flags) then
  144. swapleftright;
  145. { force fpureg as location, left right doesn't matter
  146. as both will be in a fpureg }
  147. location_force_fpureg(exprasmlist,left.location,true);
  148. location_force_fpureg(exprasmlist,right.location,true);
  149. location_reset(location,LOC_FLAGS,OS_NO);
  150. location.resflags:=getresflags(true);
  151. exprasmlist.concat(taicpu.op_reg_reg(A_FCMPs,
  152. left.location.register,right.location.register));
  153. { Delay slot (can only contain integer operation) }
  154. exprasmlist.concat(taicpu.op_none(A_NOP));
  155. release_reg_left_right;
  156. end;
  157. procedure tsparcaddnode.second_cmpboolean;
  158. begin
  159. pass_left_right;
  160. force_reg_left_right(true,true);
  161. if right.location.loc = LOC_CONSTANT then
  162. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  163. else
  164. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  165. location_reset(location,LOC_FLAGS,OS_NO);
  166. location.resflags:=getresflags(true);
  167. release_reg_left_right;
  168. end;
  169. procedure tsparcaddnode.second_cmpsmallset;
  170. begin
  171. pass_left_right;
  172. force_reg_left_right(true,true);
  173. if right.location.loc = LOC_CONSTANT then
  174. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  175. else
  176. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  177. location_reset(location,LOC_FLAGS,OS_NO);
  178. location.resflags:=getresflags(true);
  179. release_reg_left_right;
  180. end;
  181. procedure tsparcaddnode.second_cmp64bit;
  182. var
  183. unsigned : boolean;
  184. begin
  185. {$warning TODO 64bit compare}
  186. unsigned:=not(is_signed(left.resulttype.def)) or
  187. not(is_signed(right.resulttype.def));
  188. location_reset(location,LOC_FLAGS,OS_NO);
  189. location.resflags:=getresflags(unsigned);
  190. release_reg_left_right;
  191. end;
  192. procedure tsparcaddnode.second_cmpordinal;
  193. var
  194. unsigned : boolean;
  195. begin
  196. pass_left_right;
  197. force_reg_left_right(true,true);
  198. unsigned:=not(is_signed(left.resulttype.def)) or
  199. not(is_signed(right.resulttype.def));
  200. if right.location.loc = LOC_CONSTANT then
  201. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  202. else
  203. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  204. location_reset(location,LOC_FLAGS,OS_NO);
  205. location.resflags:=getresflags(unsigned);
  206. release_reg_left_right;
  207. end;
  208. begin
  209. caddnode:=tsparcaddnode;
  210. end.
  211. {
  212. $Log$
  213. Revision 1.21 2003-10-24 11:28:35 mazen
  214. -unused units removed from uses clause
  215. Revision 1.20 2003/10/01 20:34:50 peter
  216. * procinfo unit contains tprocinfo
  217. * cginfo renamed to cgbase
  218. * moved cgmessage to verbose
  219. * fixed ppc and sparc compiles
  220. Revision 1.19 2003/09/03 15:55:01 peter
  221. * NEWRA branch merged
  222. Revision 1.18.2.1 2003/09/01 21:02:55 peter
  223. * sparc updates for new tregister
  224. Revision 1.18 2003/07/08 21:25:00 peter
  225. * sparc fixes
  226. Revision 1.17 2003/07/06 22:09:50 peter
  227. * signed compare fixed
  228. Revision 1.16 2003/07/06 17:44:12 peter
  229. * cleanup and first sparc implementation
  230. Revision 1.15 2003/06/01 21:38:06 peter
  231. * getregisterfpu size parameter added
  232. * op_const_reg size parameter added
  233. * sparc updates
  234. }