navradd.pas 6.7 KB

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