navradd.pas 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. var
  109. tmpreg : tregister;
  110. begin
  111. { TODO : implement tavraddnode.second_cmpsmallset }
  112. {
  113. pass_left_right;
  114. location_reset(location,LOC_FLAGS,OS_NO);
  115. force_reg_left_right(false,false);
  116. case nodetype of
  117. equaln:
  118. begin
  119. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
  120. location.resflags:=F_EQ;
  121. end;
  122. unequaln:
  123. begin
  124. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,left.location.register,right.location.register));
  125. location.resflags:=F_NE;
  126. end;
  127. lten,
  128. gten:
  129. begin
  130. if (not(nf_swapped in flags) and
  131. (nodetype = lten)) or
  132. ((nf_swapped in flags) and
  133. (nodetype = gten)) then
  134. swapleftright;
  135. tmpreg:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  136. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_AND,tmpreg,left.location.register,right.location.register));
  137. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CMP,tmpreg,right.location.register));
  138. location.resflags:=F_EQ;
  139. end;
  140. else
  141. internalerror(2004012401);
  142. end;
  143. }
  144. end;
  145. procedure tavraddnode.second_cmp;
  146. var
  147. unsigned : boolean;
  148. tmpreg1,tmpreg2 : tregister;
  149. i : longint;
  150. begin
  151. pass_left_right;
  152. force_reg_left_right(true,false);
  153. unsigned:=not(is_signed(left.resultdef)) or
  154. not(is_signed(right.resultdef));
  155. if getresflags(unsigned)=F_NotPossible then
  156. swapleftright;
  157. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CP,left.location.register,right.location.register));
  158. tmpreg1:=left.location.register;
  159. tmpreg2:=right.location.register;
  160. for i:=2 to tcgsize2size[left.location.size] do
  161. begin
  162. tmpreg1:=GetNextReg(tmpreg1);
  163. tmpreg2:=GetNextReg(tmpreg2);
  164. if i=5 then
  165. begin
  166. tmpreg1:=left.location.registerhi;
  167. tmpreg2:=right.location.registerhi;
  168. end;
  169. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_CPC,tmpreg1,tmpreg2));
  170. end;
  171. location_reset(location,LOC_FLAGS,OS_NO);
  172. location.resflags:=getresflags(unsigned);
  173. end;
  174. procedure tavraddnode.second_cmp64bit;
  175. begin
  176. second_cmp;
  177. end;
  178. function tavraddnode.pass_1 : tnode;
  179. begin
  180. result:=inherited pass_1;
  181. {
  182. if not(assigned(result)) then
  183. begin
  184. unsigned:=not(is_signed(left.resultdef)) or
  185. not(is_signed(right.resultdef));
  186. if is_64bit(left.resultdef) and
  187. ((nodetype in [equaln,unequaln]) or
  188. (unsigned and (nodetype in [ltn,lten,gtn,gten]))
  189. ) then
  190. expectloc:=LOC_FLAGS;
  191. end;
  192. { handling boolean expressions }
  193. if not(assigned(result)) and
  194. (
  195. not(is_boolean(left.resultdef)) or
  196. not(is_boolean(right.resultdef)) or
  197. is_dynamic_array(left.resultdef)
  198. ) then
  199. expectloc:=LOC_FLAGS;
  200. }
  201. end;
  202. procedure tavraddnode.second_cmpordinal;
  203. begin
  204. second_cmp;
  205. end;
  206. begin
  207. caddnode:=tavraddnode;
  208. end.