nx64add.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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,
  30. cgbase,cgutils,cga,cgobj,
  31. tgobj;
  32. {*****************************************************************************
  33. MUL
  34. *****************************************************************************}
  35. procedure tx8664addnode.second_mul;
  36. var r:Tregister;
  37. hl4 : tasmlabel;
  38. begin
  39. { The location.register will be filled in later (JM) }
  40. location_reset(location,LOC_REGISTER,OS_INT);
  41. { Get a temp register and load the left value into it
  42. and free the location. }
  43. r:=cg.getintregister(exprasmlist,OS_INT);
  44. cg.a_load_loc_reg(exprasmlist,OS_INT,left.location,r);
  45. { Allocate RAX. }
  46. cg.getcpuregister(exprasmlist,NR_RAX);
  47. { Load the right value. }
  48. cg.a_load_loc_reg(exprasmlist,OS_INT,right.location,NR_RAX);
  49. { Also allocate RDX, since it is also modified by a mul (JM). }
  50. cg.getcpuregister(exprasmlist,NR_RDX);
  51. emit_reg(A_MUL,S_Q,r);
  52. if cs_check_overflow in aktlocalswitches then
  53. begin
  54. objectlibrary.getjumplabel(hl4);
  55. cg.a_jmp_flags(exprasmlist,F_AE,hl4);
  56. cg.a_call_name(exprasmlist,'FPC_OVERFLOW');
  57. cg.a_label(exprasmlist,hl4);
  58. end;
  59. { Free RDX,RAX }
  60. cg.ungetcpuregister(exprasmlist,NR_RDX);
  61. cg.ungetcpuregister(exprasmlist,NR_RAX);
  62. { Allocate a new register and store the result in RAX in it. }
  63. location.register:=cg.getintregister(exprasmlist,OS_INT);
  64. emit_reg_reg(A_MOV,S_Q,NR_RAX,location.register);
  65. location_freetemp(exprasmlist,left.location);
  66. location_freetemp(exprasmlist,right.location);
  67. end;
  68. begin
  69. caddnode:=tx8664addnode;
  70. end.