nx64add.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Code generation for add nodes on the x86-64
  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 nx64add;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nadd,cpubase,nx86add;
  22. type
  23. tx8664addnode = class(tx86addnode)
  24. procedure second_mul;override;
  25. end;
  26. implementation
  27. uses
  28. globtype,globals,
  29. aasmbase,aasmtai,aasmdata,
  30. cgbase,cgutils,cga,cgobj,
  31. tgobj;
  32. {*****************************************************************************
  33. MUL
  34. *****************************************************************************}
  35. procedure tx8664addnode.second_mul;
  36. var reg:Tregister;
  37. ref:Treference;
  38. use_ref:boolean;
  39. hl4 : tasmlabel;
  40. begin
  41. pass_left_right;
  42. { The location.register will be filled in later (JM) }
  43. location_reset(location,LOC_REGISTER,OS_INT);
  44. { Mul supports registers and references, so if not register/reference,
  45. load the location into a register}
  46. use_ref:=false;
  47. if left.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
  48. reg:=left.location.register
  49. else if left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  50. begin
  51. ref:=left.location.reference;
  52. use_ref:=true;
  53. end
  54. else
  55. begin
  56. {LOC_CONSTANT for example.}
  57. reg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  58. cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,left.location,reg);
  59. end;
  60. { Allocate RAX. }
  61. cg.getcpuregister(current_asmdata.CurrAsmList,NR_RAX);
  62. { Load the right value. }
  63. cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,right.location,NR_RAX);
  64. { Also allocate RDX, since it is also modified by a mul (JM). }
  65. cg.getcpuregister(current_asmdata.CurrAsmList,NR_RDX);
  66. if use_ref then
  67. emit_ref(A_MUL,S_Q,ref)
  68. else
  69. emit_reg(A_MUL,S_Q,reg);
  70. if cs_check_overflow in current_settings.localswitches then
  71. begin
  72. current_asmdata.getjumplabel(hl4);
  73. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_AE,hl4);
  74. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_OVERFLOW');
  75. cg.a_label(current_asmdata.CurrAsmList,hl4);
  76. end;
  77. { Free RDX,RAX }
  78. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_RDX);
  79. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_RAX);
  80. { Allocate a new register and store the result in RAX in it. }
  81. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  82. emit_reg_reg(A_MOV,S_Q,NR_RAX,location.register);
  83. location_freetemp(current_asmdata.CurrAsmList,left.location);
  84. location_freetemp(current_asmdata.CurrAsmList,right.location);
  85. end;
  86. begin
  87. caddnode:=tx8664addnode;
  88. end.