ncpuadd.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. function GetFPUResFlags:TResFlags;
  28. protected
  29. procedure second_addfloat;override;
  30. procedure second_cmpfloat;override;
  31. procedure second_cmpboolean;override;
  32. procedure second_cmpsmallset;override;
  33. procedure second_cmp64bit;override;
  34. procedure second_cmpordinal;override;
  35. end;
  36. implementation
  37. uses
  38. systems,
  39. cutils,verbose,
  40. paramgr,
  41. aasmtai,aasmcpu,defutil,
  42. cgbase,cgcpu,cgutils,
  43. cpupara,
  44. ncon,nset,nadd,
  45. ncgutil,cgobj;
  46. {*****************************************************************************
  47. TSparcAddNode
  48. *****************************************************************************}
  49. function TSparcAddNode.GetResFlags(unsigned:Boolean):TResFlags;
  50. begin
  51. case NodeType of
  52. equaln:
  53. GetResFlags:=F_E;
  54. unequaln:
  55. GetResFlags:=F_NE;
  56. else
  57. if not(unsigned) then
  58. begin
  59. if nf_swaped in flags then
  60. case NodeType of
  61. ltn:
  62. GetResFlags:=F_G;
  63. lten:
  64. GetResFlags:=F_GE;
  65. gtn:
  66. GetResFlags:=F_L;
  67. gten:
  68. GetResFlags:=F_LE;
  69. end
  70. else
  71. case NodeType of
  72. ltn:
  73. GetResFlags:=F_L;
  74. lten:
  75. GetResFlags:=F_LE;
  76. gtn:
  77. GetResFlags:=F_G;
  78. gten:
  79. GetResFlags:=F_GE;
  80. end;
  81. end
  82. else
  83. begin
  84. if nf_swaped in Flags then
  85. case NodeType of
  86. ltn:
  87. GetResFlags:=F_A;
  88. lten:
  89. GetResFlags:=F_AE;
  90. gtn:
  91. GetResFlags:=F_B;
  92. gten:
  93. GetResFlags:=F_BE;
  94. end
  95. else
  96. case NodeType of
  97. ltn:
  98. GetResFlags:=F_B;
  99. lten:
  100. GetResFlags:=F_BE;
  101. gtn:
  102. GetResFlags:=F_A;
  103. gten:
  104. GetResFlags:=F_AE;
  105. end;
  106. end;
  107. end;
  108. end;
  109. function TSparcAddNode.GetFPUResFlags:TResFlags;
  110. begin
  111. case NodeType of
  112. equaln:
  113. result:=F_FE;
  114. unequaln:
  115. result:=F_FNE;
  116. else
  117. begin
  118. if nf_swaped in Flags then
  119. case NodeType of
  120. ltn:
  121. result:=F_FG;
  122. lten:
  123. result:=F_FGE;
  124. gtn:
  125. result:=F_FL;
  126. gten:
  127. result:=F_FLE;
  128. end
  129. else
  130. case NodeType of
  131. ltn:
  132. result:=F_FL;
  133. lten:
  134. result:=F_FLE;
  135. gtn:
  136. result:=F_FG;
  137. gten:
  138. result:=F_FGE;
  139. end;
  140. end;
  141. end;
  142. end;
  143. procedure tsparcaddnode.second_addfloat;
  144. var
  145. op : TAsmOp;
  146. begin
  147. pass_left_right;
  148. if (nf_swaped in flags) then
  149. swapleftright;
  150. { force fpureg as location, left right doesn't matter
  151. as both will be in a fpureg }
  152. location_force_fpureg(exprasmlist,left.location,true);
  153. location_force_fpureg(exprasmlist,right.location,(left.location.loc<>LOC_CFPUREGISTER));
  154. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  155. if left.location.loc<>LOC_CFPUREGISTER then
  156. location.register:=left.location.register
  157. else
  158. location.register:=right.location.register;
  159. case nodetype of
  160. addn :
  161. begin
  162. if location.size=OS_F64 then
  163. op:=A_FADDd
  164. else
  165. op:=A_FADDs;
  166. end;
  167. muln :
  168. begin
  169. if location.size=OS_F64 then
  170. op:=A_FMULd
  171. else
  172. op:=A_FMULs;
  173. end;
  174. subn :
  175. begin
  176. if location.size=OS_F64 then
  177. op:=A_FSUBd
  178. else
  179. op:=A_FSUBs;
  180. end;
  181. slashn :
  182. begin
  183. if location.size=OS_F64 then
  184. op:=A_FDIVd
  185. else
  186. op:=A_FDIVs;
  187. end;
  188. else
  189. internalerror(200306014);
  190. end;
  191. exprasmlist.concat(taicpu.op_reg_reg_reg(op,
  192. left.location.register,right.location.register,location.register));
  193. end;
  194. procedure tsparcaddnode.second_cmpfloat;
  195. var
  196. op : tasmop;
  197. begin
  198. pass_left_right;
  199. if (nf_swaped in flags) then
  200. swapleftright;
  201. { force fpureg as location, left right doesn't matter
  202. as both will be in a fpureg }
  203. location_force_fpureg(exprasmlist,left.location,true);
  204. location_force_fpureg(exprasmlist,right.location,true);
  205. location_reset(location,LOC_FLAGS,OS_NO);
  206. location.resflags:=getfpuresflags;
  207. if left.location.size=OS_F64 then
  208. op:=A_FCMPd
  209. else
  210. op:=A_FCMPs;
  211. exprasmlist.concat(taicpu.op_reg_reg(op,
  212. left.location.register,right.location.register));
  213. { Delay slot (can only contain integer operation) }
  214. exprasmlist.concat(taicpu.op_none(A_NOP));
  215. end;
  216. procedure tsparcaddnode.second_cmpboolean;
  217. begin
  218. pass_left_right;
  219. force_reg_left_right(true,true);
  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(true);
  226. end;
  227. procedure tsparcaddnode.second_cmpsmallset;
  228. begin
  229. pass_left_right;
  230. force_reg_left_right(true,true);
  231. if right.location.loc = LOC_CONSTANT then
  232. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  233. else
  234. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  235. location_reset(location,LOC_FLAGS,OS_NO);
  236. location.resflags:=getresflags(true);
  237. end;
  238. procedure tsparcaddnode.second_cmp64bit;
  239. var
  240. unsigned : boolean;
  241. procedure firstjmp64bitcmp;
  242. var
  243. oldnodetype : tnodetype;
  244. begin
  245. { the jump the sequence is a little bit hairy }
  246. case nodetype of
  247. ltn,gtn:
  248. begin
  249. cg.a_jmp_flags(exprasmlist,getresflags(unsigned),truelabel);
  250. { cheat a little bit for the negative test }
  251. toggleflag(nf_swaped);
  252. cg.a_jmp_flags(exprasmlist,getresflags(unsigned),falselabel);
  253. toggleflag(nf_swaped);
  254. end;
  255. lten,gten:
  256. begin
  257. oldnodetype:=nodetype;
  258. if nodetype=lten then
  259. nodetype:=ltn
  260. else
  261. nodetype:=gtn;
  262. cg.a_jmp_flags(exprasmlist,getresflags(unsigned),truelabel);
  263. { cheat for the negative test }
  264. if nodetype=ltn then
  265. nodetype:=gtn
  266. else
  267. nodetype:=ltn;
  268. cg.a_jmp_flags(exprasmlist,getresflags(unsigned),falselabel);
  269. nodetype:=oldnodetype;
  270. end;
  271. equaln:
  272. cg.a_jmp_flags(exprasmlist,F_NE,falselabel);
  273. unequaln:
  274. cg.a_jmp_flags(exprasmlist,F_NE,truelabel);
  275. end;
  276. end;
  277. procedure secondjmp64bitcmp;
  278. begin
  279. { the jump the sequence is a little bit hairy }
  280. case nodetype of
  281. ltn,gtn,lten,gten:
  282. begin
  283. { the comparisaion of the low dword have to be }
  284. { always unsigned! }
  285. cg.a_jmp_flags(exprasmlist,getresflags(true),truelabel);
  286. cg.a_jmp_always(exprasmlist,falselabel);
  287. end;
  288. equaln:
  289. begin
  290. cg.a_jmp_flags(exprasmlist,F_NE,falselabel);
  291. cg.a_jmp_always(exprasmlist,truelabel);
  292. end;
  293. unequaln:
  294. begin
  295. cg.a_jmp_flags(exprasmlist,F_NE,truelabel);
  296. cg.a_jmp_always(exprasmlist,falselabel);
  297. end;
  298. end;
  299. end;
  300. begin
  301. pass_left_right;
  302. force_reg_left_right(false,false);
  303. unsigned:=not(is_signed(left.resulttype.def)) or
  304. not(is_signed(right.resulttype.def));
  305. location_reset(location,LOC_JUMP,OS_NO);
  306. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reghi,right.location.register64.reghi));
  307. firstjmp64bitcmp;
  308. exprasmlist.concat(taicpu.op_reg_reg(A_CMP,left.location.register64.reglo,right.location.register64.reglo));
  309. secondjmp64bitcmp;
  310. end;
  311. procedure tsparcaddnode.second_cmpordinal;
  312. var
  313. unsigned : boolean;
  314. begin
  315. pass_left_right;
  316. force_reg_left_right(true,true);
  317. unsigned:=not(is_signed(left.resulttype.def)) or
  318. not(is_signed(right.resulttype.def));
  319. if right.location.loc = LOC_CONSTANT then
  320. tcgsparc(cg).handle_reg_const_reg(exprasmlist,A_SUBcc,left.location.register,right.location.value,NR_G0)
  321. else
  322. exprasmlist.concat(taicpu.op_reg_reg_reg(A_SUBcc,left.location.register,right.location.register,NR_G0));
  323. location_reset(location,LOC_FLAGS,OS_NO);
  324. location.resflags:=getresflags(unsigned);
  325. end;
  326. begin
  327. caddnode:=tsparcaddnode;
  328. end.
  329. {
  330. $Log$
  331. Revision 1.28 2004-10-31 21:45:04 peter
  332. * generic tlocation
  333. * move tlocation to cgutils
  334. Revision 1.27 2004/09/25 14:23:55 peter
  335. * ungetregister is now only used for cpuregisters, renamed to
  336. ungetcpuregister
  337. * renamed (get|unget)explicitregister(s) to ..cpuregister
  338. * removed location-release/reference_release
  339. Revision 1.26 2004/09/21 17:25:13 peter
  340. * paraloc branch merged
  341. Revision 1.25.4.1 2004/09/19 18:08:30 peter
  342. * int64 compare fixed
  343. Revision 1.25 2004/06/20 08:55:32 florian
  344. * logs truncated
  345. Revision 1.24 2004/06/16 20:07:10 florian
  346. * dwarf branch merged
  347. Revision 1.23.2.3 2004/06/02 16:07:52 peter
  348. * fixed 64bit compare
  349. Revision 1.23.2.2 2004/05/31 16:39:42 peter
  350. * add ungetiftemp in a few locations
  351. Revision 1.23.2.1 2004/05/30 17:54:14 florian
  352. + implemented cmp64bit
  353. * started to fix spilling
  354. * fixed int64 sub partially
  355. Revision 1.23 2004/01/12 22:11:39 peter
  356. * use localalign info for alignment for locals and temps
  357. * sparc fpu flags branching added
  358. * moved powerpc copy_valye_openarray to generic
  359. }