nx64cal.pas 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Implements the x86-64 specific part of call nodes
  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 nx64cal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symdef,
  22. ncal,ncgcal;
  23. type
  24. tx8664callnode = class(tcgcallnode)
  25. protected
  26. procedure extra_call_code;override;
  27. procedure set_result_location(realresdef: tstoreddef);override;
  28. end;
  29. implementation
  30. uses
  31. globtype,
  32. systems,
  33. cpubase,cgbase,cgutils,cgobj,
  34. aasmtai,aasmdata,aasmcpu;
  35. procedure tx8664callnode.extra_call_code;
  36. var
  37. mmregs : aint;
  38. begin
  39. { x86_64 requires %al to contain the no. SSE regs passed }
  40. if (cnf_uses_varargs in callnodeflags) and (target_info.system<>system_x86_64_win64) then
  41. begin
  42. if assigned(varargsparas) then
  43. mmregs:=varargsparas.mmregsused
  44. else
  45. mmregs:=0;
  46. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_MOV,S_Q,mmregs,NR_RAX))
  47. end;
  48. end;
  49. procedure tx8664callnode.set_result_location(realresdef: tstoreddef);
  50. begin
  51. { avoid useless "movq %xmm0,%rax" and "movq %rax,%xmm0" instructions
  52. (which moreover for some reason are not supported by the Darwin
  53. x86-64 assembler) }
  54. if assigned(retloc.location) and
  55. not assigned(retloc.location^.next) and
  56. (retloc.location^.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  57. begin
  58. location_reset(location,LOC_MMREGISTER,retloc.location^.size);
  59. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,retloc.location^.size);
  60. end
  61. else
  62. inherited
  63. end;
  64. begin
  65. ccallnode:=tx8664callnode;
  66. end.