narmadd.pas 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. Code generation for add nodes on the ARM
  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 narmadd;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncgadd,cpubase,cginfo;
  23. type
  24. tarmaddnode = 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 tarmaddnode.GetResFlags(unsigned:Boolean):TResFlags;
  49. begin
  50. case NodeType of
  51. equaln:
  52. GetResFlags:=F_EQ;
  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_GT;
  62. lten:
  63. GetResFlags:=F_GE;
  64. gtn:
  65. GetResFlags:=F_LT;
  66. gten:
  67. GetResFlags:=F_LE;
  68. end
  69. else
  70. case NodeType of
  71. ltn:
  72. GetResFlags:=F_LT;
  73. lten:
  74. GetResFlags:=F_LE;
  75. gtn:
  76. GetResFlags:=F_GT;
  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_CC;
  87. lten:
  88. GetResFlags:=F_LS;
  89. gtn:
  90. GetResFlags:=F_HI;
  91. gten:
  92. GetResFlags:=F_CS;
  93. end
  94. else
  95. case NodeType of
  96. ltn:
  97. GetResFlags:=F_HI;
  98. lten:
  99. GetResFlags:=F_CS;
  100. gtn:
  101. GetResFlags:=F_CC;
  102. gten:
  103. GetResFlags:=F_LS;
  104. end;
  105. end;
  106. end;
  107. end;
  108. procedure tarmaddnode.second_addfloat;
  109. var
  110. op : TAsmOp;
  111. begin
  112. { we will see what instruction set we'll use on the arm for FP
  113. pass_left_right;
  114. if (nf_swaped in flags) then
  115. swapleftright;
  116. case nodetype of
  117. addn :
  118. op:=A_FADDs;
  119. muln :
  120. op:=A_FMULs;
  121. subn :
  122. op:=A_FSUBs;
  123. slashn :
  124. op:=A_FDIVs;
  125. else
  126. internalerror(200306014);
  127. end;
  128. { force fpureg as location, left right doesn't matter
  129. as both will be in a fpureg }
  130. location_force_fpureg(exprasmlist,left.location,true);
  131. location_force_fpureg(exprasmlist,right.location,(left.location.loc<>LOC_CFPUREGISTER));
  132. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  133. if left.location.loc<>LOC_CFPUREGISTER then
  134. location.register:=left.location.register
  135. else
  136. location.register:=right.location.register;
  137. exprasmlist.concat(taicpu.op_reg_reg_reg(op,
  138. left.location.register,right.location.register,location.register));
  139. release_reg_left_right;
  140. }
  141. end;
  142. procedure tarmaddnode.second_cmpfloat;
  143. begin
  144. { we will see what instruction set we'll use on the arm for FP
  145. pass_left_right;
  146. if (nf_swaped in flags) then
  147. swapleftright;
  148. { force fpureg as location, left right doesn't matter
  149. as both will be in a fpureg }
  150. location_force_fpureg(exprasmlist,left.location,true);
  151. location_force_fpureg(exprasmlist,right.location,true);
  152. location_reset(location,LOC_FLAGS,OS_NO);
  153. location.resflags:=getresflags(true);
  154. exprasmlist.concat(taicpu.op_reg_reg(A_FCMPs,
  155. left.location.register,right.location.register));
  156. { Delay slot (can only contain integer operation) }
  157. exprasmlist.concat(taicpu.op_none(A_NOP));
  158. release_reg_left_right;
  159. }
  160. end;
  161. procedure tarmaddnode.second_cmpboolean;
  162. var
  163. zeroreg : tregister;
  164. begin
  165. {!!!!!!!
  166. pass_left_right;
  167. force_reg_left_right(true,true);
  168. zeroreg.enum:=R_INTREGISTER;
  169. zeroreg.number:=NR_G0;
  170. if right.location.loc = LOC_CONSTANT then
  171. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,zeroreg)
  172. else
  173. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,zeroreg));
  174. location_reset(location,LOC_FLAGS,OS_NO);
  175. location.resflags:=getresflags(true);
  176. release_reg_left_right;
  177. }
  178. end;
  179. procedure tarmaddnode.second_cmpsmallset;
  180. var
  181. zeroreg : tregister;
  182. begin
  183. {!!!!!!!
  184. pass_left_right;
  185. force_reg_left_right(true,true);
  186. zeroreg.enum:=R_INTREGISTER;
  187. zeroreg.number:=NR_G0;
  188. if right.location.loc = LOC_CONSTANT then
  189. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,zeroreg)
  190. else
  191. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,zeroreg));
  192. location_reset(location,LOC_FLAGS,OS_NO);
  193. location.resflags:=getresflags(true);
  194. release_reg_left_right;
  195. }
  196. end;
  197. procedure tarmaddnode.second_cmp64bit;
  198. var
  199. unsigned : boolean;
  200. begin
  201. {!!!!!!!
  202. {$warning TODO 64bit compare}
  203. unsigned:=not(is_signed(left.resulttype.def)) or
  204. not(is_signed(right.resulttype.def));
  205. location_reset(location,LOC_FLAGS,OS_NO);
  206. location.resflags:=getresflags(unsigned);
  207. release_reg_left_right;
  208. }
  209. end;
  210. procedure tarmaddnode.second_cmpordinal;
  211. var
  212. zeroreg : tregister;
  213. unsigned : boolean;
  214. begin
  215. {!!!!!!!
  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. zeroreg.enum:=R_INTREGISTER;
  221. zeroreg.number:=NR_G0;
  222. if right.location.loc = LOC_CONSTANT then
  223. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,zeroreg)
  224. else
  225. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,zeroreg));
  226. location_reset(location,LOC_FLAGS,OS_NO);
  227. location.resflags:=getresflags(unsigned);
  228. release_reg_left_right;
  229. }
  230. end;
  231. begin
  232. caddnode:=tarmaddnode;
  233. end.
  234. {
  235. $Log$
  236. Revision 1.1 2003-08-21 03:14:00 florian
  237. * arm compiler can be compiled; far from being working
  238. }