hlcgppc.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {
  2. Copyright (c) 1998-2010 by Florian Klaempfl and Jonas Maebe
  3. Member of the Free Pascal development team
  4. This unit contains routines high-level code generator support shared by
  5. ppc32 and ppc64
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit hlcgppc;
  20. {$mode objfpc}
  21. interface
  22. uses
  23. aasmdata,
  24. symtype,
  25. cgbase,cgutils,hlcgobj,hlcg2ll;
  26. type
  27. thlcgppcgen = class(thlcg2ll)
  28. protected
  29. procedure a_load_subsetref_regs_noindex(list: TAsmList; subsetsize: tdef; loadbitsize: byte; const sref: tsubsetreference; valuereg, extra_value_reg: tregister); override;
  30. end;
  31. implementation
  32. uses
  33. cpubase,globtype,
  34. symdef,defutil;
  35. { thlcgppc }
  36. procedure thlcgppcgen.a_load_subsetref_regs_noindex(list: TAsmList; subsetsize: tdef; loadbitsize: byte; const sref: tsubsetreference; valuereg, extra_value_reg: tregister);
  37. var
  38. fromsreg, tosreg: tsubsetregister;
  39. restbits: byte;
  40. begin
  41. restbits:=(sref.bitlen-(loadbitsize-sref.startbit));
  42. if is_signed(subsetsize) then
  43. begin
  44. { sign extend }
  45. a_op_const_reg(list,OP_SHL,osuinttype,AIntBits-loadbitsize+sref.startbit,valuereg);
  46. a_op_const_reg(list,OP_SAR,osuinttype,AIntBits-sref.bitlen,valuereg);
  47. end
  48. else
  49. begin
  50. a_op_const_reg(list,OP_SHL,osuinttype,restbits,valuereg);
  51. { mask other bits }
  52. if (sref.bitlen<>AIntBits) then
  53. a_op_const_reg(list,OP_AND,osuinttype,(aword(1) shl sref.bitlen)-1,valuereg);
  54. end;
  55. { use subsetreg routine, it may have been overridden with an optimized version }
  56. fromsreg.subsetreg:=extra_value_reg;
  57. fromsreg.subsetregsize:=OS_INT;
  58. { subsetregs always count bits from right to left }
  59. fromsreg.startbit:=loadbitsize-restbits;
  60. fromsreg.bitlen:=restbits;
  61. tosreg.subsetreg:=valuereg;
  62. tosreg.subsetregsize:=OS_INT;
  63. tosreg.startbit:=0;
  64. tosreg.bitlen:=restbits;
  65. a_load_subsetreg_subsetreg(list,subsetsize,subsetsize,fromsreg,tosreg);
  66. end;
  67. end.