hlcgcpu.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. procedure create_hlcodegen;
  34. implementation
  35. uses
  36. cpubase,aasmcpu,
  37. defutil,
  38. {$ifdef extdebug}
  39. aasmtai,cutils,cgppc,
  40. {$endif}
  41. cgobj,cgcpu;
  42. { thlcgcpu }
  43. procedure thlcgcpu.a_load_subsetreg_reg(list: TAsmList; subsetsize, tosize: tdef; const sreg: tsubsetregister; destreg: tregister);
  44. var
  45. subsetcgsize: tcgsize;
  46. begin
  47. subsetcgsize:=def_cgsize(subsetsize);
  48. {$ifdef extdebug}
  49. 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)))));
  50. {$endif}
  51. { do the extraction if required and then extend the sign correctly. (The latter is actually required only for signed subsets
  52. and if that subset is not >= the tosize). }
  53. if (sreg.startbit<>0) or
  54. (sreg.bitlen<>tcgsize2size[subsetcgsize]*8) then
  55. begin
  56. list.concat(taicpu.op_reg_reg_const_const(A_RLDICL,destreg,sreg.subsetreg,(64-sreg.startbit) and 63,64-sreg.bitlen));
  57. if subsetcgsize in [OS_S8..OS_S128] then
  58. if (sreg.bitlen mod 8)=0 then
  59. begin
  60. cg.a_load_reg_reg(list, tcgsize2unsigned[subsetcgsize],subsetcgsize,destreg,destreg);
  61. cg.a_load_reg_reg(list,subsetcgsize,def_cgsize(tosize),destreg,destreg);
  62. end
  63. else
  64. begin
  65. cg.a_op_const_reg(list,OP_SHL,OS_INT,64-sreg.bitlen,destreg);
  66. cg.a_op_const_reg(list,OP_SAR,OS_INT,64-sreg.bitlen,destreg);
  67. end;
  68. end
  69. else
  70. begin
  71. cg.a_load_reg_reg(list,tcgsize2unsigned[sreg.subsetregsize],subsetcgsize,sreg.subsetreg,destreg);
  72. cg.a_load_reg_reg(list,subsetcgsize,def_cgsize(tosize),destreg,destreg);
  73. end;
  74. end;
  75. procedure thlcgcpu.a_load_const_subsetreg(list: TAsmlist; tosubsetsize: tdef; a: tcgint; const sreg: tsubsetregister);
  76. var
  77. tmpreg : TRegister;
  78. begin
  79. {$ifdef extdebug}
  80. 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))));
  81. {$endif}
  82. { loading the constant into the lowest bits of a temp register and then inserting is
  83. better than loading some usually large constants and do some masking and shifting on ppc64 }
  84. tmpreg:=getintregister(list,tosubsetsize);
  85. a_load_const_reg(list,tosubsetsize,a,tmpreg);
  86. a_load_reg_subsetreg(list,tosubsetsize,tosubsetsize,tmpreg,sreg);
  87. end;
  88. procedure thlcgcpu.a_load_regconst_subsetreg_intern(list: TAsmList; fromsize, subsetsize: tdef; fromreg: tregister; const sreg: tsubsetregister; slopt: tsubsetloadopt);
  89. begin
  90. {$ifdef extdebug}
  91. 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))));
  92. {$endif}
  93. if slopt in [SL_SETZERO,SL_SETMAX] then
  94. inherited a_load_regconst_subsetreg_intern(list,fromsize,subsetsize,fromreg,sreg,slopt)
  95. else if sreg.bitlen<>sizeof(aint)*8 then
  96. { simply use the INSRDI instruction }
  97. list.concat(taicpu.op_reg_reg_const_const(A_INSRDI,sreg.subsetreg,fromreg,sreg.bitlen,(64-(sreg.startbit+sreg.bitlen)) and 63))
  98. else
  99. a_load_reg_reg(list,fromsize,subsetsize,fromreg,sreg.subsetreg);
  100. end;
  101. procedure create_hlcodegen;
  102. begin
  103. hlcg:=thlcgcpu.create;
  104. create_codegen;
  105. end;
  106. begin
  107. chlcgobj:=thlcgcpu;
  108. end.