narmmem.pas 4.4 KB

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