hlcgcpu.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {
  2. Copyright (c) 1998-2010 by Florian Klaempfl and Jonas Maebe
  3. Member of the Free Pascal development team
  4. This unit contains high-level code generator support for ppc64
  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 hlcgcpu;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype,
  23. aasmdata,
  24. symtype,
  25. cgbase,cgutils,hlcgobj,hlcgppc;
  26. type
  27. thlcgcpu = class(thlcgppcgen)
  28. procedure a_load_subsetreg_reg(list : TAsmList; subsetsize, tosize: tdef; const sreg: tsubsetregister; destreg: tregister); override;
  29. procedure a_load_const_subsetreg(list: TAsmlist; tosubsetsize: tdef; a: tcgint; const sreg: tsubsetregister); override;
  30. protected
  31. procedure a_load_regconst_subsetreg_intern(list : TAsmList; fromsize, subsetsize: tdef; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt); override;
  32. end;
  33. implementation
  34. uses
  35. cpubase,aasmcpu,
  36. defutil,
  37. {$ifdef extdebug}
  38. aasmtai,cutils,cgppc,
  39. {$endif}
  40. cgobj,cgcpu;
  41. { thlcgcpu }
  42. procedure thlcgcpu.a_load_subsetreg_reg(list: TAsmList; subsetsize, tosize: tdef; const sreg: tsubsetregister; destreg: tregister);
  43. var
  44. subsetcgsize: tcgsize;
  45. begin
  46. subsetcgsize:=def_cgsize(subsetsize);
  47. {$ifdef extdebug}
  48. list.concat(tai_comment.create(strpnew('a_load_subsetreg_reg subsetregsize = ' + cgsize2string(sreg.subsetregsize) + ' subsetsize = ' + cgsize2string(subsetcgsize) + ' startbit = ' + ToStr(sreg.startbit) + ' tosize = ' + cgsize2string(def_cgsize(tosize)))));
  49. {$endif}
  50. { do the extraction if required and then extend the sign correctly. (The latter is actually required only for signed subsets
  51. and if that subset is not >= the tosize). }
  52. if (sreg.startbit<>0) or
  53. (sreg.bitlen<>tcgsize2size[subsetcgsize]*8) then
  54. begin
  55. list.concat(taicpu.op_reg_reg_const_const(A_RLDICL,destreg,sreg.subsetreg,(64-sreg.startbit) and 63,64-sreg.bitlen));
  56. if subsetcgsize in [OS_S8..OS_S128] then
  57. if (sreg.bitlen mod 8)=0 then
  58. begin
  59. cg.a_load_reg_reg(list, tcgsize2unsigned[subsetcgsize],subsetcgsize,destreg,destreg);
  60. cg.a_load_reg_reg(list,subsetcgsize,def_cgsize(tosize),destreg,destreg);
  61. end
  62. else
  63. begin
  64. cg.a_op_const_reg(list,OP_SHL,OS_INT,64-sreg.bitlen,destreg);
  65. cg.a_op_const_reg(list,OP_SAR,OS_INT,64-sreg.bitlen,destreg);
  66. end;
  67. end
  68. else
  69. begin
  70. cg.a_load_reg_reg(list,tcgsize2unsigned[sreg.subsetregsize],subsetcgsize,sreg.subsetreg,destreg);
  71. cg.a_load_reg_reg(list,subsetcgsize,def_cgsize(tosize),destreg,destreg);
  72. end;
  73. end;
  74. procedure thlcgcpu.a_load_const_subsetreg(list: TAsmlist; tosubsetsize: tdef; a: tcgint; const sreg: tsubsetregister);
  75. var
  76. tmpreg : TRegister;
  77. begin
  78. {$ifdef extdebug}
  79. list.concat(tai_comment.create(strpnew('a_load_const_subsetreg subsetregsize = ' + cgsize2string(sreg.subsetregsize) + ' subsetsize = ' + cgsize2string(def_cgsize(tosubsetsize)) + ' startbit = ' + ToStr(sreg.startbit) + ' a = ' + ToStr(a))));
  80. {$endif}
  81. { loading the constant into the lowest bits of a temp register and then inserting is
  82. better than loading some usually large constants and do some masking and shifting on ppc64 }
  83. tmpreg:=getintregister(list,tosubsetsize);
  84. a_load_const_reg(list,tosubsetsize,a,tmpreg);
  85. a_load_reg_subsetreg(list,tosubsetsize,tosubsetsize,tmpreg,sreg);
  86. end;
  87. procedure thlcgcpu.a_load_regconst_subsetreg_intern(list: TAsmList; fromsize, subsetsize: tdef; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt);
  88. begin
  89. {$ifdef extdebug}
  90. list.concat(tai_comment.create(strpnew('a_load_reg_subsetreg fromsize = ' + cgsize2string(def_cgsize(fromsize)) + ' subsetregsize = ' + cgsize2string(sreg.subsetregsize) + ' subsetsize = ' + cgsize2string(def_cgsize(subsetsize)) + ' startbit = ' + ToStr(sreg.startbit))));
  91. {$endif}
  92. if slopt in [SL_SETZERO,SL_SETMAX] then
  93. inherited a_load_regconst_subsetreg_intern(list,fromsize,subsetsize,fromreg,sreg,slopt)
  94. else if sreg.bitlen<>sizeof(aint)*8 then
  95. { simply use the INSRDI instruction }
  96. list.concat(taicpu.op_reg_reg_const_const(A_INSRDI,sreg.subsetreg,fromreg,sreg.bitlen,(64-(sreg.startbit+sreg.bitlen)) and 63))
  97. else
  98. a_load_reg_reg(list,fromsize,subsetsize,fromreg,sreg.subsetreg);
  99. end;
  100. procedure create_hlcodegen_cpu;
  101. begin
  102. hlcg:=thlcgcpu.create;
  103. create_codegen;
  104. end;
  105. begin
  106. chlcgobj:=thlcgcpu;
  107. create_hlcodegen:=@create_hlcodegen_cpu;
  108. end.