n386mem.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate i386 assembler for in memory related nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit n386mem;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,
  23. cgbase,cpuinfo,cpubase,
  24. node,nmem,ncgmem;
  25. type
  26. ti386addrnode = class(tcgaddrnode)
  27. procedure pass_2;override;
  28. end;
  29. ti386derefnode = class(tcgderefnode)
  30. procedure pass_2;override;
  31. end;
  32. ti386vecnode = class(tcgvecnode)
  33. procedure update_reference_reg_mul(reg:tregister;l:aint);override;
  34. procedure pass_2;override;
  35. end;
  36. implementation
  37. uses
  38. systems,
  39. cutils,verbose,
  40. symdef,paramgr,
  41. aasmtai,
  42. nld,ncon,nadd,
  43. cgutils,cgobj;
  44. {*****************************************************************************
  45. TI386ADDRNODE
  46. *****************************************************************************}
  47. procedure ti386addrnode.pass_2;
  48. begin
  49. inherited pass_2;
  50. { for use of other segments, not used }
  51. {if left.location.reference.segment<>NR_NO then
  52. location.segment:=left.location.reference.segment;}
  53. end;
  54. {*****************************************************************************
  55. TI386DEREFNODE
  56. *****************************************************************************}
  57. procedure ti386derefnode.pass_2;
  58. begin
  59. inherited pass_2;
  60. if tpointerdef(left.resulttype.def).is_far then
  61. location.reference.segment:=NR_FS;
  62. end;
  63. {*****************************************************************************
  64. TI386VECNODE
  65. *****************************************************************************}
  66. procedure ti386vecnode.update_reference_reg_mul(reg:tregister;l:aint);
  67. var
  68. l2 : integer;
  69. hreg : tregister;
  70. begin
  71. { Optimized for x86 to use the index register and scalefactor }
  72. if location.reference.index=NR_NO then
  73. begin
  74. { no preparations needed }
  75. end
  76. else if location.reference.base=NR_NO then
  77. begin
  78. case location.reference.scalefactor of
  79. 2 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,1,location.reference.index);
  80. 4 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,2,location.reference.index);
  81. 8 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,3,location.reference.index);
  82. end;
  83. location.reference.base:=location.reference.index;
  84. end
  85. else
  86. begin
  87. hreg := cg.getaddressregister(exprasmlist);
  88. cg.a_loadaddr_ref_reg(exprasmlist,location.reference,hreg);
  89. reference_reset_base(location.reference,hreg,0);
  90. end;
  91. { insert the new index register and scalefactor or
  92. do the multiplication manual }
  93. case l of
  94. 1,2,4,8 : location.reference.scalefactor:=l;
  95. else
  96. begin
  97. if ispowerof2(l,l2) then
  98. cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,l2,reg)
  99. else
  100. cg.a_op_const_reg(exprasmlist,OP_IMUL,OS_ADDR,l,reg);
  101. end;
  102. end;
  103. location.reference.index:=reg;
  104. end;
  105. procedure ti386vecnode.pass_2;
  106. begin
  107. inherited pass_2;
  108. if nf_memseg in flags then
  109. location.reference.segment:=NR_FS;
  110. end;
  111. begin
  112. caddrnode:=ti386addrnode;
  113. cderefnode:=ti386derefnode;
  114. cvecnode:=ti386vecnode;
  115. end.
  116. {
  117. $Log$
  118. Revision 1.65 2004-10-31 21:45:03 peter
  119. * generic tlocation
  120. * move tlocation to cgutils
  121. Revision 1.64 2004/10/15 09:16:22 mazen
  122. - remove $IFDEF DELPHI and related code
  123. - remove $IFDEF FPCPROCVAR and related code
  124. Revision 1.63 2004/09/25 14:23:54 peter
  125. * ungetregister is now only used for cpuregisters, renamed to
  126. ungetcpuregister
  127. * renamed (get|unget)explicitregister(s) to ..cpuregister
  128. * removed location-release/reference_release
  129. Revision 1.62 2004/06/20 08:55:31 florian
  130. * logs truncated
  131. Revision 1.61 2004/06/16 20:07:10 florian
  132. * dwarf branch merged
  133. Revision 1.60.2.2 2004/05/01 16:02:10 peter
  134. * POINTER_SIZE replaced with sizeof(aint)
  135. * aint,aword,tconst*int moved to globtype
  136. Revision 1.60.2.1 2004/04/29 19:07:22 peter
  137. * compile fixes
  138. Revision 1.60 2004/02/27 10:21:05 florian
  139. * top_symbol killed
  140. + refaddr to treference added
  141. + refsymbol to treference added
  142. * top_local stuff moved to an extra record to save memory
  143. + aint introduced
  144. * tppufile.get/putint64/aint implemented
  145. }