narmmem.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. {
  2. Copyright (c) 2012 by Florian Klaempfl
  3. Generate arm 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 narmmem;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cgbase,cpubase,nmem,ncgmem;
  23. type
  24. tarmloadparentfpnode = class(tcgloadparentfpnode)
  25. procedure pass_generate_code; override;
  26. end;
  27. tarmvecnode = class(tcgvecnode)
  28. procedure update_reference_reg_mul(maybe_const_reg: tregister; l: aint);override;
  29. end;
  30. implementation
  31. uses
  32. cutils,verbose,globals,aasmdata,aasmcpu,cgobj,cgcpu,
  33. cpuinfo,
  34. cgutils,
  35. procinfo;
  36. {*****************************************************************************
  37. TARMLOADPARENTFPNODE
  38. *****************************************************************************}
  39. procedure tarmloadparentfpnode.pass_generate_code;
  40. begin
  41. { normally, we cannot use the stack pointer as normal register on arm thumb }
  42. if (GenerateThumbCode) and
  43. (getsupreg(current_procinfo.framepointer) in [RS_R8..RS_R15]) and
  44. (current_procinfo.procdef.parast.symtablelevel=parentpd.parast.symtablelevel) then
  45. begin
  46. location_reset(location,LOC_REGISTER,OS_ADDR);
  47. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  48. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,current_procinfo.framepointer,location.register);
  49. end
  50. else
  51. inherited pass_generate_code;
  52. end;
  53. {*****************************************************************************
  54. TARMVECNODE
  55. *****************************************************************************}
  56. procedure tarmvecnode.update_reference_reg_mul(maybe_const_reg:tregister;l:aint);
  57. var
  58. hreg: tregister;
  59. hl : longint;
  60. begin
  61. if ((location.reference.base=NR_NO) and (location.reference.index=NR_NO)) or
  62. (GenerateThumbCode) or
  63. { simple constant? }
  64. (l=1) or ispowerof2(l,hl) or ispowerof2(l+1,hl) or ispowerof2(l-1,hl) then
  65. inherited update_reference_reg_mul(maybe_const_reg,l)
  66. else if (location.reference.base<>NR_NO) then
  67. begin
  68. hreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  69. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_ADDR,l,hreg);
  70. tbasecgarm(cg).safe_mla(current_asmdata.CurrAsmList,hreg,maybe_const_reg,hreg,location.reference.base);
  71. location.reference.base:=hreg;
  72. { update alignment }
  73. if (location.reference.alignment=0) then
  74. internalerror(2012052202);
  75. location.reference.alignment:=newalignment(location.reference.alignment,l);
  76. end
  77. else if (location.reference.index<>NR_NO) then
  78. begin
  79. hreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  80. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_ADDR,l,hreg);
  81. tbasecgarm(cg).safe_mla(current_asmdata.CurrAsmList,hreg,maybe_const_reg,hreg,location.reference.index);
  82. location.reference.base:=hreg;
  83. location.reference.index:=NR_NO;
  84. { update alignment }
  85. if (location.reference.alignment=0) then
  86. internalerror(2012052203);
  87. location.reference.alignment:=newalignment(location.reference.alignment,l);
  88. end
  89. else
  90. internalerror(2012052201);
  91. end;
  92. begin
  93. cvecnode:=tarmvecnode;
  94. cloadparentfpnode:=tarmloadparentfpnode;
  95. end.