narmadd.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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;
  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_cmpordinal;override;
  31. procedure second_cmpsmallset;override;
  32. procedure second_cmp64bit;override;
  33. end;
  34. implementation
  35. uses
  36. globtype,systems,
  37. cutils,verbose,globals,
  38. symconst,symdef,paramgr,
  39. aasmbase,aasmtai,aasmcpu,defutil,htypechk,
  40. cgbase,cpuinfo,pass_1,pass_2,regvars,cgcpu,
  41. cpupara,
  42. ncon,nset,nadd,
  43. ncgutil,tgobj,rgobj,rgcpu,cgobj,cg64f32;
  44. {*****************************************************************************
  45. TSparcAddNode
  46. *****************************************************************************}
  47. function tarmaddnode.GetResFlags(unsigned:Boolean):TResFlags;
  48. begin
  49. case NodeType of
  50. equaln:
  51. GetResFlags:=F_EQ;
  52. unequaln:
  53. GetResFlags:=F_NE;
  54. else
  55. if not(unsigned) then
  56. begin
  57. if nf_swaped in flags then
  58. case NodeType of
  59. ltn:
  60. GetResFlags:=F_GT;
  61. lten:
  62. GetResFlags:=F_GE;
  63. gtn:
  64. GetResFlags:=F_LT;
  65. gten:
  66. GetResFlags:=F_LE;
  67. end
  68. else
  69. case NodeType of
  70. ltn:
  71. GetResFlags:=F_LT;
  72. lten:
  73. GetResFlags:=F_LE;
  74. gtn:
  75. GetResFlags:=F_GT;
  76. gten:
  77. GetResFlags:=F_GE;
  78. end;
  79. end
  80. else
  81. begin
  82. if nf_swaped in Flags then
  83. case NodeType of
  84. ltn:
  85. GetResFlags:=F_HI;
  86. lten:
  87. GetResFlags:=F_CS;
  88. gtn:
  89. GetResFlags:=F_CC;
  90. gten:
  91. GetResFlags:=F_LS;
  92. end
  93. else
  94. case NodeType of
  95. ltn:
  96. GetResFlags:=F_CC;
  97. lten:
  98. GetResFlags:=F_LS;
  99. gtn:
  100. GetResFlags:=F_HI;
  101. gten:
  102. GetResFlags:=F_CS;
  103. end;
  104. end;
  105. end;
  106. end;
  107. procedure tarmaddnode.second_addfloat;
  108. var
  109. op : TAsmOp;
  110. begin
  111. case aktfputype of
  112. fpu_fpa,
  113. fpu_fpa10,
  114. fpu_fpa11:
  115. begin
  116. pass_left_right;
  117. if (nf_swaped in flags) then
  118. swapleftright;
  119. case nodetype of
  120. addn :
  121. op:=A_ADF;
  122. muln :
  123. op:=A_MUF;
  124. subn :
  125. op:=A_SUF;
  126. slashn :
  127. op:=A_DVF;
  128. else
  129. internalerror(200308313);
  130. end;
  131. { force fpureg as location, left right doesn't matter
  132. as both will be in a fpureg }
  133. location_force_fpureg(exprasmlist,left.location,true);
  134. location_force_fpureg(exprasmlist,right.location,(left.location.loc<>LOC_CFPUREGISTER));
  135. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  136. if left.location.loc<>LOC_CFPUREGISTER then
  137. location.register:=left.location.register
  138. else
  139. location.register:=right.location.register;
  140. exprasmlist.concat(setoppostfix(taicpu.op_reg_reg_reg(op,
  141. location.register,left.location.register,right.location.register),
  142. cgsize2fpuoppostfix[def_cgsize(resulttype.def)]));
  143. location.loc:=LOC_FPUREGISTER;
  144. end;
  145. fpu_soft:
  146. { this case should be handled already by pass1 }
  147. internalerror(200308252);
  148. else
  149. internalerror(200308251);
  150. end;
  151. end;
  152. procedure tarmaddnode.second_cmpfloat;
  153. begin
  154. pass_left_right;
  155. if (nf_swaped in flags) then
  156. swapleftright;
  157. { force fpureg as location, left right doesn't matter
  158. as both will be in a fpureg }
  159. location_force_fpureg(exprasmlist,left.location,true);
  160. location_force_fpureg(exprasmlist,right.location,true);
  161. location_reset(location,LOC_FLAGS,OS_NO);
  162. location.resflags:=getresflags(true);
  163. if nodetype in [equaln,unequaln] then
  164. exprasmlist.concat(setoppostfix(taicpu.op_reg_reg(A_CMF,
  165. left.location.register,right.location.register),
  166. cgsize2fpuoppostfix[def_cgsize(resulttype.def)]))
  167. else
  168. exprasmlist.concat(setoppostfix(taicpu.op_reg_reg(A_CMFE,
  169. left.location.register,right.location.register),
  170. cgsize2fpuoppostfix[def_cgsize(resulttype.def)]));
  171. location_reset(location,LOC_FLAGS,OS_NO);
  172. location.resflags:=getresflags(false);
  173. end;
  174. procedure tarmaddnode.second_cmpsmallset;
  175. var
  176. tmpreg : tregister;
  177. begin
  178. pass_left_right;
  179. location_reset(location,LOC_FLAGS,OS_NO);
  180. force_reg_left_right(false,false);
  181. case nodetype of
  182. equaln:
  183. begin
  184. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
  185. location.resflags:=F_EQ;
  186. end;
  187. unequaln:
  188. begin
  189. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
  190. location.resflags:=F_NE;
  191. end;
  192. lten,
  193. gten:
  194. begin
  195. if (not(nf_swaped in flags) and
  196. (nodetype = lten)) or
  197. ((nf_swaped in flags) and
  198. (nodetype = gten)) then
  199. swapleftright;
  200. tmpreg:=cg.getintregister(exprasmlist,location.size);
  201. exprasmlist.concat(taicpu.op_reg_reg_reg(A_AND,tmpreg,left.location.register,right.location.register));
  202. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,tmpreg,right.location.register));
  203. location.resflags:=F_EQ;
  204. end;
  205. else
  206. internalerror(2004012401);
  207. end;
  208. end;
  209. procedure tarmaddnode.second_cmp64bit;
  210. var
  211. unsigned : boolean;
  212. tmpreg : tregister;
  213. begin
  214. pass_left_right;
  215. force_reg_left_right(false,false);
  216. unsigned:=not(is_signed(left.resulttype.def)) or
  217. not(is_signed(right.resulttype.def));
  218. location_reset(location,LOC_FLAGS,OS_NO);
  219. location.resflags:=getresflags(unsigned);
  220. { operation requiring proper N, Z and C flags ? }
  221. if unsigned or (nodetype in [equaln,unequaln]) then
  222. begin
  223. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
  224. exprasmlist.concat(setcondition(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo),C_EQ));
  225. end
  226. { operation requiring proper N, V and C flags ? }
  227. else if nodetype in [gten,ltn] then
  228. begin
  229. tmpreg:=cg.getintregister(exprasmlist,location.size);
  230. exprasmlist.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,tmpreg,left.location.register64.reglo,right.location.register64.reglo),PF_S));
  231. exprasmlist.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SBC,tmpreg,left.location.register64.reghi,right.location.register64.reghi),PF_S));
  232. end
  233. else
  234. { operation requiring proper N, Z and V flags ? }
  235. begin
  236. { this isn't possible so swap operands and use the "reverse" operation }
  237. tmpreg:=cg.getintregister(exprasmlist,location.size);
  238. exprasmlist.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SUB,tmpreg,right.location.register64.reglo,left.location.register64.reglo),PF_S));
  239. exprasmlist.concat(setoppostfix(taicpu.op_reg_reg_reg(A_SBC,tmpreg,right.location.register64.reghi,left.location.register64.reghi),PF_S));
  240. if nf_swaped in flags then
  241. begin
  242. if location.resflags=F_LT then
  243. location.resflags:=F_GT
  244. else if location.resflags=F_GE then
  245. location.resflags:=F_LE
  246. else
  247. internalerror(200401221);
  248. end
  249. else
  250. begin
  251. if location.resflags=F_GT then
  252. location.resflags:=F_LT
  253. else if location.resflags=F_LE then
  254. location.resflags:=F_GE
  255. else
  256. internalerror(200401221);
  257. end;
  258. end;
  259. end;
  260. procedure tarmaddnode.second_cmpordinal;
  261. var
  262. unsigned : boolean;
  263. tmpreg : tregister;
  264. b : byte;
  265. begin
  266. pass_left_right;
  267. force_reg_left_right(true,true);
  268. unsigned:=not(is_signed(left.resulttype.def)) or
  269. not(is_signed(right.resulttype.def));
  270. if right.location.loc = LOC_CONSTANT then
  271. begin
  272. if is_shifter_const(dword(right.location.value),b) then
  273. exprasmlist.concat(taicpu.op_reg_const(A_CMP,left.location.register,right.location.value))
  274. else
  275. begin
  276. tmpreg:=cg.getintregister(exprasmlist,location.size);
  277. cg.a_load_const_reg(exprasmlist,OS_INT,
  278. right.location.value,tmpreg);
  279. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register,tmpreg));
  280. end;
  281. end
  282. else
  283. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
  284. location_reset(location,LOC_FLAGS,OS_NO);
  285. location.resflags:=getresflags(unsigned);
  286. end;
  287. begin
  288. caddnode:=tarmaddnode;
  289. end.
  290. {
  291. $Log$
  292. Revision 1.17 2004-10-24 17:32:53 florian
  293. * fixed several arm compiler bugs
  294. Revision 1.16 2004/10/24 07:54:25 florian
  295. * fixed compilation of arm compiler
  296. Revision 1.15 2004/06/20 08:55:31 florian
  297. * logs truncated
  298. Revision 1.14 2004/03/23 21:03:50 florian
  299. * arm assembler instructions can have 4 operands
  300. * qword comparisations fixed
  301. Revision 1.13 2004/03/13 18:45:40 florian
  302. * floating compares fixed
  303. * unary minus for floats fixed
  304. Revision 1.12 2004/03/11 22:41:37 florian
  305. + second_cmpfloat implemented, needs probably to be fixed
  306. Revision 1.11 2004/01/26 19:05:56 florian
  307. * fixed several arm issues
  308. Revision 1.10 2004/01/24 20:19:46 florian
  309. * fixed some spilling stuff
  310. + not(<int64>) implemented
  311. + small set comparisations implemented
  312. }