nx64add.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. Code generation for add nodes on the x86-64
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit nx64add;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,nadd,cpubase,nx86add;
  23. type
  24. tx8664addnode = class(tx86addnode)
  25. procedure second_mul;override;
  26. end;
  27. implementation
  28. uses
  29. globtype,globals,
  30. aasmbase,aasmtai,
  31. cgbase,cgutils,cga,cgobj,
  32. tgobj;
  33. {*****************************************************************************
  34. MUL
  35. *****************************************************************************}
  36. procedure tx8664addnode.second_mul;
  37. var r:Tregister;
  38. hl4 : tasmlabel;
  39. begin
  40. { The location.register will be filled in later (JM) }
  41. location_reset(location,LOC_REGISTER,OS_INT);
  42. { Get a temp register and load the left value into it
  43. and free the location. }
  44. r:=cg.getintregister(exprasmlist,OS_INT);
  45. cg.a_load_loc_reg(exprasmlist,OS_INT,left.location,r);
  46. { Allocate RAX. }
  47. cg.getcpuregister(exprasmlist,NR_RAX);
  48. { Load the right value. }
  49. cg.a_load_loc_reg(exprasmlist,OS_INT,right.location,NR_RAX);
  50. { Also allocate RDX, since it is also modified by a mul (JM). }
  51. cg.getcpuregister(exprasmlist,NR_RDX);
  52. emit_reg(A_MUL,S_Q,r);
  53. if cs_check_overflow in aktlocalswitches then
  54. begin
  55. objectlibrary.getlabel(hl4);
  56. cg.a_jmp_flags(exprasmlist,F_AE,hl4);
  57. cg.a_call_name(exprasmlist,'FPC_OVERFLOW');
  58. cg.a_label(exprasmlist,hl4);
  59. end;
  60. { Free RDX,RAX }
  61. cg.ungetcpuregister(exprasmlist,NR_RDX);
  62. cg.ungetcpuregister(exprasmlist,NR_RAX);
  63. { Allocate a new register and store the result in RAX in it. }
  64. location.register:=cg.getintregister(exprasmlist,OS_INT);
  65. emit_reg_reg(A_MOV,S_Q,NR_RAX,location.register);
  66. location_freetemp(exprasmlist,left.location);
  67. location_freetemp(exprasmlist,right.location);
  68. end;
  69. begin
  70. caddnode:=tx8664addnode;
  71. end.
  72. {
  73. $Log$
  74. Revision 1.5 2004-11-01 17:40:29 florian
  75. + added cgutils uses clause
  76. Revision 1.4 2004/09/25 14:23:55 peter
  77. * ungetregister is now only used for cpuregisters, renamed to
  78. ungetcpuregister
  79. * renamed (get|unget)explicitregister(s) to ..cpuregister
  80. * removed location-release/reference_release
  81. Revision 1.3 2004/06/16 20:07:11 florian
  82. * dwarf branch merged
  83. Revision 1.2.2.1 2004/04/26 15:54:33 peter
  84. * small x86-64 fixes
  85. Revision 1.2 2004/02/05 01:24:08 florian
  86. * several fixes to compile x86-64 system
  87. Revision 1.1 2004/01/20 12:59:37 florian
  88. * common addnode code for x86-64 and i386
  89. }