nx64add.pas 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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,cga,cgobj;
  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. location_release(exprasmlist,left.location);
  46. {Allocate EAX.}
  47. cg.getexplicitregister(exprasmlist,NR_EAX);
  48. {Load the right value.}
  49. cg.a_load_loc_reg(exprasmlist,OS_INT,right.location,NR_EAX);
  50. location_release(exprasmlist,right.location);
  51. {The mul instruction frees register r.}
  52. cg.ungetregister(exprasmlist,r);
  53. {Also allocate EDX, since it is also modified by a mul (JM).}
  54. cg.getexplicitregister(exprasmlist,NR_EDX);
  55. emit_reg(A_MUL,S_L,r);
  56. if cs_check_overflow in aktlocalswitches then
  57. begin
  58. objectlibrary.getlabel(hl4);
  59. cg.a_jmp_flags(exprasmlist,F_AE,hl4);
  60. cg.a_call_name(exprasmlist,'FPC_OVERFLOW');
  61. cg.a_label(exprasmlist,hl4);
  62. end;
  63. {Free EDX}
  64. cg.ungetregister(exprasmlist,NR_EDX);
  65. {Free EAX}
  66. cg.ungetregister(exprasmlist,NR_EAX);
  67. {Allocate a new register and store the result in EAX in it.}
  68. location.register:=cg.getintregister(exprasmlist,OS_INT);
  69. emit_reg_reg(A_MOV,S_L,NR_EAX,location.register);
  70. location_freetemp(exprasmlist,left.location);
  71. location_freetemp(exprasmlist,right.location);
  72. end;
  73. begin
  74. caddnode:=tx8664addnode;
  75. end.
  76. {
  77. $Log$
  78. Revision 1.1 2004-01-20 12:59:37 florian
  79. * common addnode code for x86-64 and i386
  80. }