ncpuadd.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. {
  2. Copyright (c) 2008 by Florian Klaempfl
  3. Code generation for add nodes on the Xtensa
  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 ncpuadd;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgadd,cpubase;
  22. type
  23. TCPUAddNode = class(tcgaddnode)
  24. protected
  25. function pass_1 : tnode;override;
  26. procedure second_cmpordinal;override;
  27. procedure second_cmpsmallset;override;
  28. procedure second_cmp64bit;override;
  29. procedure second_cmp;
  30. end;
  31. implementation
  32. uses
  33. globtype,systems,
  34. cutils,verbose,globals,
  35. symconst,symdef,paramgr,
  36. aasmbase,aasmtai,aasmdata,aasmcpu,defutil,htypechk,
  37. cgbase,cgutils,cgcpu,
  38. cpuinfo,pass_1,pass_2,procinfo,
  39. cpupara,
  40. ncon,nset,nadd,
  41. ncgutil,tgobj,rgobj,rgcpu,cgobj,cg64f32,
  42. hlcgobj;
  43. {*****************************************************************************
  44. TCPUAddNode
  45. *****************************************************************************}
  46. procedure TCPUAddNode.second_cmpsmallset;
  47. var
  48. tmpreg : tregister;
  49. cond: TOpCmp;
  50. instr: taicpu;
  51. truelab, falselab: TAsmLabel;
  52. begin
  53. pass_left_right;
  54. current_asmdata.getjumplabel(truelab);
  55. current_asmdata.getjumplabel(falselab);
  56. location_reset_jump(location,truelab,falselab);
  57. force_reg_left_right(false,false);
  58. case nodetype of
  59. equaln: cond:=OC_EQ;
  60. unequaln: cond:=OC_NE;
  61. ltn: cond:=OC_LT;
  62. lten: cond:=OC_LT;
  63. gtn: cond:=OC_GT;
  64. gten: cond:=OC_GTE;
  65. else
  66. internalerror(2020030801);
  67. end;
  68. cg.a_cmp_reg_reg_label(current_asmdata.CurrAsmList,OS_INT,cond,left.location.register,right.location.register,location.truelabel);
  69. current_asmdata.CurrAsmList.concat(taicpu.op_sym(A_J,location.falselabel));
  70. end;
  71. procedure TCPUAddNode.second_cmp;
  72. var
  73. cond: TOpCmp;
  74. instr: taicpu;
  75. truelab, falselab: TAsmLabel;
  76. begin
  77. pass_left_right;
  78. current_asmdata.getjumplabel(truelab);
  79. current_asmdata.getjumplabel(falselab);
  80. location_reset_jump(location,truelab,falselab);
  81. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  82. if is_signed(left.resultdef) then
  83. case nodetype of
  84. equaln: cond:=OC_EQ;
  85. unequaln: cond:=OC_NE;
  86. ltn: cond:=OC_LT;
  87. lten: cond:=OC_LTE;
  88. gtn: cond:=OC_GT;
  89. gten: cond:=OC_GTE;
  90. else
  91. internalerror(2020030801);
  92. end
  93. else
  94. case nodetype of
  95. equaln: cond:=OC_EQ;
  96. unequaln: cond:=OC_NE;
  97. ltn: cond:=OC_B;
  98. lten: cond:=OC_BE;
  99. gtn: cond:=OC_A;
  100. gten: cond:=OC_AE;
  101. else
  102. internalerror(2020030801);
  103. end;
  104. if (right.nodetype=ordconstn) and not(nf_swapped in flags) then
  105. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,cond,right.location.value,left.location.register,location.truelabel)
  106. else
  107. begin
  108. force_reg_left_right(false,false);
  109. if nf_swapped in flags then
  110. cg.a_cmp_reg_reg_label(current_asmdata.CurrAsmList,OS_INT,cond,left.location.register,right.location.register,location.truelabel)
  111. else
  112. cg.a_cmp_reg_reg_label(current_asmdata.CurrAsmList,OS_INT,cond,right.location.register,left.location.register,location.truelabel);
  113. end;
  114. current_asmdata.CurrAsmList.concat(taicpu.op_sym(A_J,location.falselabel));
  115. end;
  116. procedure TCPUAddNode.second_cmp64bit;
  117. begin
  118. second_cmp;
  119. end;
  120. function TCPUAddNode.pass_1 : tnode;
  121. begin
  122. result:=inherited pass_1;
  123. {$ifdef dummy}
  124. if not(assigned(result)) then
  125. begin
  126. unsigned:=not(is_signed(left.resultdef)) or
  127. not(is_signed(right.resultdef));
  128. if is_64bit(left.resultdef) and
  129. ((nodetype in [equaln,unequaln]) or
  130. (unsigned and (nodetype in [ltn,lten,gtn,gten]))
  131. ) then
  132. expectloc:=LOC_FLAGS;
  133. end;
  134. { handling boolean expressions }
  135. if not(assigned(result)) and
  136. (
  137. not(is_boolean(left.resultdef)) or
  138. not(is_boolean(right.resultdef)) or
  139. is_dynamic_array(left.resultdef)
  140. ) then
  141. expectloc:=LOC_FLAGS;
  142. {$endif dummy}
  143. end;
  144. procedure TCPUAddNode.second_cmpordinal;
  145. begin
  146. second_cmp;
  147. end;
  148. begin
  149. caddnode:=tcpuaddnode;
  150. end.