nx64mat.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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,ncgmat,nx86mat;
  22. type
  23. tx8664shlshrnode = class(tshlshrnode)
  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,systems,constexp,
  33. cutils,verbose,globals,
  34. symconst,symdef,aasmbase,aasmtai,aasmdata,defutil,
  35. pass_1,pass_2,
  36. ncon,
  37. cpubase,cpuinfo,
  38. cgbase,cgutils,cga,cgobj,hlcgobj,cgx86,
  39. ncgutil;
  40. {*****************************************************************************
  41. TX8664SHLRSHRNODE
  42. *****************************************************************************}
  43. procedure tx8664shlshrnode.pass_generate_code;
  44. var
  45. op : topcg;
  46. opsize : tcgsize;
  47. mask : aint;
  48. begin
  49. secondpass(left);
  50. secondpass(right);
  51. { determine operator }
  52. if nodetype=shln then
  53. op:=OP_SHL
  54. else
  55. op:=OP_SHR;
  56. { special treatment of 32bit values for backwards compatibility }
  57. { mul optimizations require to keep the sign (FK) }
  58. if left.resultdef.size<=4 then
  59. begin
  60. if is_signed(left.resultdef) then
  61. opsize:=OS_S32
  62. else
  63. opsize:=OS_32;
  64. mask:=31;
  65. end
  66. else
  67. begin
  68. if is_signed(left.resultdef) then
  69. opsize:=OS_S64
  70. else
  71. opsize:=OS_64;
  72. mask:=63;
  73. end;
  74. { load left operators in a register }
  75. if not(left.location.loc in [LOC_CREGISTER,LOC_REGISTER]) or
  76. { location_force_reg can be also used to change the size of a register }
  77. (left.location.size<>opsize) then
  78. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(opsize),true);
  79. location_reset(location,LOC_REGISTER,opsize);
  80. location.register:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  81. { shifting by a constant directly coded: }
  82. if (right.nodetype=ordconstn) then
  83. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,location.size,
  84. tordconstnode(right).value.uvalue and mask,left.location.register,location.register)
  85. else
  86. begin
  87. { load right operators in a register - this
  88. is done since most target cpu which will use this
  89. node do not support a shift count in a mem. location (cec)
  90. }
  91. if not(right.location.loc in [LOC_CREGISTER,LOC_REGISTER]) or
  92. { location_force_reg can be also used to change the size of a register }
  93. (right.location.size<>opsize) then
  94. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,cgsize_orddef(opsize),true);
  95. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,op,opsize,right.location.register,left.location.register,location.register);
  96. end;
  97. end;
  98. begin
  99. cunaryminusnode:=tx8664unaryminusnode;
  100. cmoddivnode:=tx86moddivnode;
  101. cshlshrnode:=tx8664shlshrnode;
  102. cnotnode:=tx8664notnode;
  103. end.