nx64add.pas 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 r:Tregister;
  37. hl4 : tasmlabel;
  38. begin
  39. pass_left_right;
  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(current_asmdata.CurrAsmList,OS_INT);
  45. cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,left.location,r);
  46. { Allocate RAX. }
  47. cg.getcpuregister(current_asmdata.CurrAsmList,NR_RAX);
  48. { Load the right value. }
  49. cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,right.location,NR_RAX);
  50. { Also allocate RDX, since it is also modified by a mul (JM). }
  51. cg.getcpuregister(current_asmdata.CurrAsmList,NR_RDX);
  52. emit_reg(A_MUL,S_Q,r);
  53. if cs_check_overflow in current_settings.localswitches then
  54. begin
  55. current_asmdata.getjumplabel(hl4);
  56. cg.a_jmp_flags(current_asmdata.CurrAsmList,F_AE,hl4);
  57. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_OVERFLOW');
  58. cg.a_label(current_asmdata.CurrAsmList,hl4);
  59. end;
  60. { Free RDX,RAX }
  61. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_RDX);
  62. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_RAX);
  63. { Allocate a new register and store the result in RAX in it. }
  64. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  65. emit_reg_reg(A_MOV,S_Q,NR_RAX,location.register);
  66. location_freetemp(current_asmdata.CurrAsmList,left.location);
  67. location_freetemp(current_asmdata.CurrAsmList,right.location);
  68. end;
  69. begin
  70. caddnode:=tx8664addnode;
  71. end.