n386inl.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate i386 inline nodes
  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 n386inl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nx86inl;
  22. type
  23. ti386inlinenode = class(tx86inlinenode)
  24. public
  25. function first_sar: tnode; override;
  26. procedure second_rox_sar; override;
  27. procedure second_abs_long; override;
  28. end;
  29. implementation
  30. uses
  31. globtype,globals,compinnr,
  32. defutil,
  33. aasmbase,aasmdata,
  34. cgbase,pass_2,
  35. cpuinfo,cpubase,
  36. cga,cgutils,cgx86,cgobj,hlcgobj,
  37. ninl,ncon,ncal;
  38. function ti386inlinenode.first_sar: tnode;
  39. begin
  40. if is_64bitint(resultdef) and (
  41. (inlinenumber=in_sar_x) or (
  42. (inlinenumber=in_sar_x_y) and
  43. (tcallparanode(left).left.nodetype=ordconstn)
  44. )) then
  45. begin
  46. result:=nil;
  47. expectloc:=LOC_REGISTER;
  48. end
  49. else
  50. result:=inherited first_sar;
  51. end;
  52. procedure ti386inlinenode.second_rox_sar;
  53. var
  54. op1: tnode;
  55. hreg64hi,hreg64lo: tregister;
  56. v: aint;
  57. begin
  58. if is_64bitint(resultdef) and (
  59. (inlinenumber=in_sar_x) or (
  60. (inlinenumber=in_sar_x_y) and
  61. (tcallparanode(left).left.nodetype=ordconstn)
  62. )) then
  63. begin
  64. { x sar constant }
  65. if (left.nodetype=callparan) and
  66. assigned(tcallparanode(left).right) then
  67. begin
  68. op1:=tcallparanode(tcallparanode(left).right).left;
  69. secondpass(tcallparanode(left).left);
  70. v:=Tordconstnode(tcallparanode(left).left).value.svalue and 63;
  71. end
  72. else
  73. begin
  74. op1:=left;
  75. v:=1;
  76. end;
  77. secondpass(op1);
  78. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  79. { load left operator in a register }
  80. hlcg.location_force_reg(current_asmdata.CurrAsmList,op1.location,op1.resultdef,resultdef,false);
  81. hreg64hi:=op1.location.register64.reghi;
  82. hreg64lo:=op1.location.register64.reglo;
  83. if (v=63) then
  84. begin
  85. emit_const_reg(A_SAR,S_L,31,hreg64hi);
  86. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,hreg64hi,hreg64lo);
  87. end
  88. else if (v>31) then
  89. begin
  90. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,hreg64hi,hreg64lo);
  91. emit_const_reg(A_SAR,S_L,31,hreg64hi);
  92. emit_const_reg(A_SAR,S_L,v and 31,hreg64lo);
  93. end
  94. else
  95. begin
  96. emit_const_reg_reg(A_SHRD,S_L,v and 31,hreg64hi,hreg64lo);
  97. emit_const_reg(A_SAR,S_L,v and 31,hreg64hi);
  98. end;
  99. location.register64.reghi:=hreg64hi;
  100. location.register64.reglo:=hreg64lo;
  101. end
  102. else
  103. inherited second_rox_sar;
  104. end;
  105. procedure ti386inlinenode.second_abs_long;
  106. begin
  107. if is_64bitint(left.resultdef) then
  108. begin
  109. secondpass(left);
  110. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  111. location:=left.location;
  112. location.register64.reglo:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  113. location.register64.reghi:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  114. cg64.a_load64_reg_reg(current_asmdata.CurrAsmList,left.location.register64,location.register64);
  115. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,OS_32,31,left.location.register64.reghi);
  116. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_XOR,OS_32,left.location.register64.reghi,location.register64.reglo);
  117. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_XOR,OS_32,left.location.register64.reghi,location.register64.reghi);
  118. emit_reg_reg(A_SUB,S_L,left.location.register64.reghi,location.register64.reglo);
  119. emit_reg_reg(A_SBB,S_L,left.location.register64.reghi,location.register64.reghi);
  120. end
  121. else
  122. inherited second_abs_long;
  123. end;
  124. begin
  125. cinlinenode:=ti386inlinenode;
  126. end.