ncpuadd.pas 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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,cginfo;
  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. globtype,systems,
  38. cutils,verbose,globals,
  39. symconst,symdef,paramgr,
  40. aasmbase,aasmtai,aasmcpu,defutil,htypechk,
  41. cgbase,cpuinfo,pass_1,pass_2,regvars,cgcpu,
  42. cpupara,
  43. ncon,nset,nadd,
  44. ncgutil,tgobj,rgobj,rgcpu,cgobj,cg64f32;
  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. end;
  139. procedure tsparcaddnode.second_cmpfloat;
  140. begin
  141. pass_left_right;
  142. if (nf_swaped in flags) then
  143. swapleftright;
  144. { force fpureg as location, left right doesn't matter
  145. as both will be in a fpureg }
  146. location_force_fpureg(exprasmlist,left.location,true);
  147. location_force_fpureg(exprasmlist,right.location,true);
  148. location_reset(location,LOC_FLAGS,OS_NO);
  149. location.resflags:=getresflags(true);
  150. exprasmlist.concat(taicpu.op_reg_reg(A_FCMPs,
  151. left.location.register,right.location.register));
  152. { Delay slot (can only contain integer operation) }
  153. exprasmlist.concat(taicpu.op_none(A_NOP));
  154. end;
  155. procedure tsparcaddnode.second_cmpboolean;
  156. var
  157. zeroreg : tregister;
  158. begin
  159. pass_left_right;
  160. force_reg_left_right(true,true);
  161. zeroreg.enum:=R_INTREGISTER;
  162. zeroreg.number:=NR_G0;
  163. if right.location.loc = LOC_CONSTANT then
  164. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,zeroreg)
  165. else
  166. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,zeroreg));
  167. location_reset(location,LOC_FLAGS,OS_NO);
  168. location.resflags:=getresflags(true);
  169. end;
  170. procedure tsparcaddnode.second_cmpsmallset;
  171. var
  172. zeroreg : tregister;
  173. begin
  174. pass_left_right;
  175. force_reg_left_right(true,true);
  176. zeroreg.enum:=R_INTREGISTER;
  177. zeroreg.number:=NR_G0;
  178. if right.location.loc = LOC_CONSTANT then
  179. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,zeroreg)
  180. else
  181. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,zeroreg));
  182. location_reset(location,LOC_FLAGS,OS_NO);
  183. location.resflags:=getresflags(true);
  184. end;
  185. procedure tsparcaddnode.second_cmp64bit;
  186. var
  187. unsigned : boolean;
  188. begin
  189. {$warning TODO 64bit compare}
  190. unsigned:=not(is_signed(left.resulttype.def)) or
  191. not(is_signed(right.resulttype.def));
  192. location_reset(location,LOC_FLAGS,OS_NO);
  193. location.resflags:=getresflags(unsigned);
  194. end;
  195. procedure tsparcaddnode.second_cmpordinal;
  196. var
  197. zeroreg : tregister;
  198. unsigned : boolean;
  199. begin
  200. pass_left_right;
  201. force_reg_left_right(true,true);
  202. unsigned:=not(is_signed(left.resulttype.def)) or
  203. not(is_signed(right.resulttype.def));
  204. zeroreg.enum:=R_INTREGISTER;
  205. zeroreg.number:=NR_G0;
  206. if right.location.loc = LOC_CONSTANT then
  207. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,zeroreg)
  208. else
  209. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,zeroreg));
  210. location_reset(location,LOC_FLAGS,OS_NO);
  211. location.resflags:=getresflags(unsigned);
  212. end;
  213. begin
  214. caddnode:=tsparcaddnode;
  215. end.
  216. {
  217. $Log$
  218. Revision 1.17 2003-07-06 22:09:50 peter
  219. * signed compare fixed
  220. Revision 1.16 2003/07/06 17:44:12 peter
  221. * cleanup and first sparc implementation
  222. Revision 1.15 2003/06/01 21:38:06 peter
  223. * getregisterfpu size parameter added
  224. * op_const_reg size parameter added
  225. * sparc updates
  226. }