nx64mat.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate x86-64 assembler for math 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 nx64mat;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nmat,nx86mat;
  22. type
  23. tx8664shlshrnode = class(tx86shlshrnode)
  24. procedure pass_generate_code;override;
  25. end;
  26. tx8664unaryminusnode = class(tx86unaryminusnode)
  27. end;
  28. tx8664notnode = class(tx86notnode)
  29. end;
  30. implementation
  31. uses
  32. globtype,constexp,
  33. cutils,
  34. aasmdata,defutil,
  35. pass_2,
  36. ncon,
  37. cgbase,cgutils,cgobj,hlcgobj;
  38. {*****************************************************************************
  39. TX8664SHLRSHRNODE
  40. *****************************************************************************}
  41. procedure tx8664shlshrnode.pass_generate_code;
  42. var
  43. op : topcg;
  44. opsize : tcgsize;
  45. mask : aint;
  46. begin
  47. secondpass(left);
  48. secondpass(right);
  49. { determine operator }
  50. if nodetype=shln then
  51. op:=OP_SHL
  52. else
  53. op:=OP_SHR;
  54. opsize:=def_cgsize(resultdef);
  55. mask:=max(resultdef.size,4)*8-1;
  56. { load left operators in a register }
  57. if not(left.location.loc in [LOC_CREGISTER,LOC_REGISTER]) or
  58. { location_force_reg can be also used to change the size of a register }
  59. (left.location.size<>opsize) then
  60. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(opsize),true);
  61. location_reset(location,LOC_REGISTER,opsize);
  62. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  63. { shifting by a constant directly coded: }
  64. if (right.nodetype=ordconstn) then
  65. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,location.size,
  66. tordconstnode(right).value.uvalue and mask,left.location.register,location.register)
  67. else
  68. begin
  69. { load right operators in a register - this
  70. is done since most target cpu which will use this
  71. node do not support a shift count in a mem. location (cec)
  72. }
  73. if not(right.location.loc in [LOC_CREGISTER,LOC_REGISTER]) or
  74. { location_force_reg can be also used to change the size of a register }
  75. (right.location.size<>opsize) then
  76. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,cgsize_orddef(opsize),true);
  77. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,op,opsize,right.location.register,left.location.register,location.register);
  78. end;
  79. end;
  80. begin
  81. cunaryminusnode:=tx8664unaryminusnode;
  82. cmoddivnode:=tx86moddivnode;
  83. cshlshrnode:=tx8664shlshrnode;
  84. cnotnode:=tx8664notnode;
  85. end.