navradd.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. {
  2. Copyright (c) 2008 by Florian Klaempfl
  3. Code generation for add nodes on the AVR
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit navradd;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgadd,cpubase;
  22. type
  23. tavraddnode = class(tcgaddnode)
  24. private
  25. function GetResFlags(unsigned:Boolean):TResFlags;
  26. protected
  27. function pass_1 : tnode;override;
  28. procedure second_cmpordinal;override;
  29. procedure second_cmpsmallset;override;
  30. procedure second_cmp64bit;override;
  31. procedure second_cmp;
  32. end;
  33. implementation
  34. uses
  35. globtype,systems,
  36. cutils,verbose,globals,
  37. symconst,symdef,paramgr,
  38. aasmbase,aasmtai,aasmdata,aasmcpu,defutil,htypechk,
  39. cgbase,cgutils,cgcpu,
  40. cpuinfo,pass_1,pass_2,regvars,procinfo,
  41. cpupara,
  42. ncon,nset,nadd,
  43. ncgutil,tgobj,rgobj,rgcpu,cgobj,cg64f32;
  44. {*****************************************************************************
  45. TSparcAddNode
  46. *****************************************************************************}
  47. function tavraddnode.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_swapped in flags then
  58. case NodeType of
  59. ltn:
  60. GetResFlags:=F_NotPossible;
  61. lten:
  62. GetResFlags:=F_GE;
  63. gtn:
  64. GetResFlags:=F_LT;
  65. gten:
  66. GetResFlags:=F_NotPossible;
  67. end
  68. else
  69. case NodeType of
  70. ltn:
  71. GetResFlags:=F_LT;
  72. lten:
  73. GetResFlags:=F_NotPossible;
  74. gtn:
  75. GetResFlags:=F_NotPossible;
  76. gten:
  77. GetResFlags:=F_GE;
  78. end;
  79. end
  80. else
  81. begin
  82. if nf_swapped in Flags then
  83. case NodeType of
  84. ltn:
  85. GetResFlags:=F_NotPossible;
  86. lten:
  87. GetResFlags:=F_CS;
  88. gtn:
  89. GetResFlags:=F_CC;
  90. gten:
  91. GetResFlags:=F_NotPossible;
  92. end
  93. else
  94. case NodeType of
  95. ltn:
  96. GetResFlags:=F_CC;
  97. lten:
  98. GetResFlags:=F_NotPossible;
  99. gtn:
  100. GetResFlags:=F_NotPossible;
  101. gten:
  102. GetResFlags:=F_CS;
  103. end;
  104. end;
  105. end;
  106. end;
  107. procedure tavraddnode.second_cmpsmallset;
  108. procedure gencmp(tmpreg1,tmpreg2 : tregister);
  109. var
  110. i : byte;
  111. begin
  112. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CP,tmpreg1,tmpreg2));
  113. for i:=2 to tcgsize2size[left.location.size] do
  114. begin
  115. tmpreg1:=GetNextReg(tmpreg1);
  116. tmpreg2:=GetNextReg(tmpreg2);
  117. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CPC,tmpreg1,tmpreg2));
  118. end;
  119. end;
  120. var
  121. tmpreg : tregister;
  122. begin
  123. pass_left_right;
  124. location_reset(location,LOC_FLAGS,OS_NO);
  125. force_reg_left_right(false,false);
  126. case nodetype of
  127. equaln:
  128. begin
  129. gencmp(left.location.register,right.location.register);
  130. location.resflags:=F_EQ;
  131. end;
  132. unequaln:
  133. begin
  134. gencmp(left.location.register,right.location.register);
  135. location.resflags:=F_NE;
  136. end;
  137. lten,
  138. gten:
  139. begin
  140. if (not(nf_swapped in flags) and
  141. (nodetype = lten)) or
  142. ((nf_swapped in flags) and
  143. (nodetype = gten)) then
  144. swapleftright;
  145. tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  146. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_AND,location.size,
  147. left.location.register,right.location.register,tmpreg);
  148. gencmp(tmpreg,right.location.register);
  149. location.resflags:=F_EQ;
  150. end;
  151. else
  152. internalerror(2004012401);
  153. end;
  154. end;
  155. procedure tavraddnode.second_cmp;
  156. var
  157. unsigned : boolean;
  158. tmpreg1,tmpreg2 : tregister;
  159. i : longint;
  160. begin
  161. pass_left_right;
  162. force_reg_left_right(true,false);
  163. unsigned:=not(is_signed(left.resultdef)) or
  164. not(is_signed(right.resultdef));
  165. if getresflags(unsigned)=F_NotPossible then
  166. swapleftright;
  167. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CP,left.location.register,right.location.register));
  168. tmpreg1:=left.location.register;
  169. tmpreg2:=right.location.register;
  170. for i:=2 to tcgsize2size[left.location.size] do
  171. begin
  172. tmpreg1:=GetNextReg(tmpreg1);
  173. tmpreg2:=GetNextReg(tmpreg2);
  174. if i=5 then
  175. begin
  176. tmpreg1:=left.location.registerhi;
  177. tmpreg2:=right.location.registerhi;
  178. end;
  179. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CPC,tmpreg1,tmpreg2));
  180. end;
  181. location_reset(location,LOC_FLAGS,OS_NO);
  182. location.resflags:=getresflags(unsigned);
  183. end;
  184. procedure tavraddnode.second_cmp64bit;
  185. begin
  186. second_cmp;
  187. end;
  188. function tavraddnode.pass_1 : tnode;
  189. begin
  190. result:=inherited pass_1;
  191. {
  192. if not(assigned(result)) then
  193. begin
  194. unsigned:=not(is_signed(left.resultdef)) or
  195. not(is_signed(right.resultdef));
  196. if is_64bit(left.resultdef) and
  197. ((nodetype in [equaln,unequaln]) or
  198. (unsigned and (nodetype in [ltn,lten,gtn,gten]))
  199. ) then
  200. expectloc:=LOC_FLAGS;
  201. end;
  202. { handling boolean expressions }
  203. if not(assigned(result)) and
  204. (
  205. not(is_boolean(left.resultdef)) or
  206. not(is_boolean(right.resultdef)) or
  207. is_dynamic_array(left.resultdef)
  208. ) then
  209. expectloc:=LOC_FLAGS;
  210. }
  211. end;
  212. procedure tavraddnode.second_cmpordinal;
  213. begin
  214. second_cmp;
  215. end;
  216. begin
  217. caddnode:=tavraddnode;
  218. end.