n68kmem.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. {
  2. Copyright (c) 2014 by the Free Pascal development team
  3. Generate m68k assembler for in memory related 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 n68kmem;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. symtype,
  23. cgbase,cpuinfo,cpubase,
  24. node,nmem,ncgmem;
  25. type
  26. t68kvecnode = class(tcgvecnode)
  27. procedure update_reference_reg_mul(maybe_const_reg: tregister; regsize: tdef; l: aint); override;
  28. //procedure pass_generate_code;override;
  29. end;
  30. implementation
  31. uses
  32. systems,globals,
  33. cutils,verbose,
  34. symdef,paramgr,
  35. aasmtai,aasmdata,
  36. nld,ncon,nadd,
  37. cgutils,cgobj;
  38. {*****************************************************************************
  39. T68KVECNODE
  40. *****************************************************************************}
  41. { this routine must, like any other routine, not change the contents }
  42. { of base/index registers of references, as these may be regvars. }
  43. { The register allocator can coalesce one LOC_REGISTER being moved }
  44. { into another (as their live ranges won't overlap), but not a }
  45. { LOC_CREGISTER moved into a LOC_(C)REGISTER most of the time (as }
  46. { the live range of the LOC_CREGISTER will most likely overlap the }
  47. { the live range of the target LOC_(C)REGISTER) }
  48. { The passed register may be a LOC_CREGISTER as well. }
  49. procedure t68kvecnode.update_reference_reg_mul(maybe_const_reg: tregister; regsize: tdef; l: aint);
  50. var
  51. hreg: tregister;
  52. scaled: boolean;
  53. begin
  54. scaled:=false;
  55. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('updref: called')));
  56. if l<>1 then
  57. begin
  58. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('updref: l <> 1')));
  59. hreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  60. { if we have a possibility, setup a scalefactor instead of the MUL }
  61. if (location.reference.index<>NR_NO) or
  62. (current_settings.cputype in [cpu_mc68000]) or
  63. ((current_settings.cputype in cpu_coldfire) and not (l in [2,4])) or
  64. not (l in [2,4,8]) then
  65. begin
  66. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('updref: mul')));
  67. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_IMUL,OS_ADDR,l,maybe_const_reg,hreg);
  68. end
  69. else
  70. begin
  71. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('updref: scale')));
  72. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,maybe_const_reg,hreg);
  73. scaled:=true;
  74. end;
  75. maybe_const_reg:=hreg;
  76. end;
  77. if (location.reference.base=NR_NO) and not (scaled) then
  78. begin
  79. { prefer an address reg, if we will be a base, for indexes any register works }
  80. if isintregister(maybe_const_reg) then
  81. begin
  82. //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('updref: copytoa')));
  83. hreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  84. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,maybe_const_reg,hreg);
  85. maybe_const_reg:=hreg;
  86. end;
  87. location.reference.base:=maybe_const_reg;
  88. end
  89. else if location.reference.index=NR_NO then
  90. begin
  91. location.reference.index:=maybe_const_reg;
  92. if (scaled) then
  93. location.reference.scalefactor:=l;
  94. end
  95. else
  96. begin
  97. hreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  98. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,location.reference,hreg);
  99. reference_reset_base(location.reference,hreg,0,location.reference.alignment);
  100. { insert new index register }
  101. location.reference.index:=maybe_const_reg;
  102. if (scaled) then
  103. location.reference.scalefactor:=l;
  104. end;
  105. { update alignment }
  106. if (location.reference.alignment=0) then
  107. internalerror(2009020704);
  108. location.reference.alignment:=newalignment(location.reference.alignment,l);
  109. end;
  110. {procedure t68kvecnode.pass_generate_code;
  111. begin
  112. inherited pass_generate_code;
  113. end;}
  114. begin
  115. cvecnode:=t68kvecnode;
  116. end.