n386mem.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. cg.ungetreference(exprasmlist,location.reference);
  91. hreg := cg.getaddressregister(exprasmlist);
  92. cg.a_loadaddr_ref_reg(exprasmlist,location.reference,hreg);
  93. reference_reset_base(location.reference,hreg,0);
  94. end;
  95. { insert the new index register and scalefactor or
  96. do the multiplication manual }
  97. case l of
  98. 1,2,4,8 : location.reference.scalefactor:=l;
  99. else
  100. begin
  101. if ispowerof2(l,l2) then
  102. cg.a_op_const_reg(exprasmlist,OP_SHL,OS_ADDR,l2,reg)
  103. else
  104. cg.a_op_const_reg(exprasmlist,OP_IMUL,OS_ADDR,l,reg);
  105. end;
  106. end;
  107. location.reference.index:=reg;
  108. end;
  109. procedure ti386vecnode.pass_2;
  110. begin
  111. inherited pass_2;
  112. if nf_memseg in flags then
  113. location.reference.segment:=NR_FS;
  114. end;
  115. begin
  116. caddrnode:=ti386addrnode;
  117. cderefnode:=ti386derefnode;
  118. cvecnode:=ti386vecnode;
  119. end.
  120. {
  121. $Log$
  122. Revision 1.62 2004-06-20 08:55:31 florian
  123. * logs truncated
  124. Revision 1.61 2004/06/16 20:07:10 florian
  125. * dwarf branch merged
  126. Revision 1.60.2.2 2004/05/01 16:02:10 peter
  127. * POINTER_SIZE replaced with sizeof(aint)
  128. * aint,aword,tconst*int moved to globtype
  129. Revision 1.60.2.1 2004/04/29 19:07:22 peter
  130. * compile fixes
  131. Revision 1.60 2004/02/27 10:21:05 florian
  132. * top_symbol killed
  133. + refaddr to treference added
  134. + refsymbol to treference added
  135. * top_local stuff moved to an extra record to save memory
  136. + aint introduced
  137. * tppufile.get/putint64/aint implemented
  138. }