n386mem.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. {$ifdef delphi}
  39. sysutils,
  40. {$endif}
  41. systems,
  42. cutils,verbose,
  43. symdef,paramgr,
  44. aasmtai,
  45. nld,ncon,nadd,
  46. cgutils,cgobj;
  47. {*****************************************************************************
  48. TI386ADDRNODE
  49. *****************************************************************************}
  50. procedure ti386addrnode.pass_2;
  51. begin
  52. inherited pass_2;
  53. { for use of other segments }
  54. if left.location.reference.segment<>NR_NO then
  55. location.segment:=left.location.reference.segment;
  56. end;
  57. {*****************************************************************************
  58. TI386DEREFNODE
  59. *****************************************************************************}
  60. procedure ti386derefnode.pass_2;
  61. begin
  62. inherited pass_2;
  63. if tpointerdef(left.resulttype.def).is_far then
  64. location.reference.segment:=NR_FS;
  65. end;
  66. {*****************************************************************************
  67. TI386VECNODE
  68. *****************************************************************************}
  69. procedure ti386vecnode.update_reference_reg_mul(reg:tregister;l:aint);
  70. var
  71. l2 : integer;
  72. hreg : tregister;
  73. begin
  74. { Optimized for x86 to use the index register and scalefactor }
  75. if location.reference.index=NR_NO then
  76. begin
  77. { no preparations needed }
  78. end
  79. else if location.reference.base=NR_NO then
  80. begin
  81. case location.reference.scalefactor of
  82. 2 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,1,location.reference.index);
  83. 4 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,2,location.reference.index);
  84. 8 : cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,3,location.reference.index);
  85. end;
  86. location.reference.base:=location.reference.index;
  87. end
  88. else
  89. begin
  90. hreg := cg.getaddressregister(exprasmlist);
  91. cg.a_loadaddr_ref_reg(exprasmlist,location.reference,hreg);
  92. reference_reset_base(location.reference,hreg,0);
  93. end;
  94. { insert the new index register and scalefactor or
  95. do the multiplication manual }
  96. case l of
  97. 1,2,4,8 : location.reference.scalefactor:=l;
  98. else
  99. begin
  100. if ispowerof2(l,l2) then
  101. cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,l2,reg)
  102. else
  103. cg.a_op_const_reg(exprasmlist,OP_IMUL,OS_ADDR,l,reg);
  104. end;
  105. end;
  106. location.reference.index:=reg;
  107. end;
  108. procedure ti386vecnode.pass_2;
  109. begin
  110. inherited pass_2;
  111. if nf_memseg in flags then
  112. location.reference.segment:=NR_FS;
  113. end;
  114. begin
  115. caddrnode:=ti386addrnode;
  116. cderefnode:=ti386derefnode;
  117. cvecnode:=ti386vecnode;
  118. end.
  119. {
  120. $Log$
  121. Revision 1.63 2004-09-25 14:23:54 peter
  122. * ungetregister is now only used for cpuregisters, renamed to
  123. ungetcpuregister
  124. * renamed (get|unget)explicitregister(s) to ..cpuregister
  125. * removed location-release/reference_release
  126. Revision 1.62 2004/06/20 08:55:31 florian
  127. * logs truncated
  128. Revision 1.61 2004/06/16 20:07:10 florian
  129. * dwarf branch merged
  130. Revision 1.60.2.2 2004/05/01 16:02:10 peter
  131. * POINTER_SIZE replaced with sizeof(aint)
  132. * aint,aword,tconst*int moved to globtype
  133. Revision 1.60.2.1 2004/04/29 19:07:22 peter
  134. * compile fixes
  135. Revision 1.60 2004/02/27 10:21:05 florian
  136. * top_symbol killed
  137. + refaddr to treference added
  138. + refsymbol to treference added
  139. * top_local stuff moved to an extra record to save memory
  140. + aint introduced
  141. * tppufile.get/putint64/aint implemented
  142. }