ncpuinln.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. {
  2. Copyright (c) 1998-2009 by Florian Klaempfl and David Zhang
  3. Generate MIPSEL inline 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 ncpuinln;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node, ninl, ncginl;
  22. type
  23. tMIPSELinlinenode = class(tcgInlineNode)
  24. function first_abs_real: tnode; override;
  25. function first_sqr_real: tnode; override;
  26. function first_sqrt_real: tnode; override;
  27. procedure second_abs_real; override;
  28. procedure second_sqr_real; override;
  29. procedure second_sqrt_real; override;
  30. procedure second_get_frame; override;
  31. private
  32. procedure load_fpu_location;
  33. end;
  34. implementation
  35. uses
  36. systems,
  37. globtype,globals,
  38. cutils, verbose,
  39. symconst, symdef,
  40. aasmtai, aasmcpu, aasmdata,
  41. cgbase, pass_2,
  42. cpubase, paramgr,
  43. nbas, ncon, ncal, ncnv, nld,
  44. hlcgobj, ncgutil, cgobj, cgutils;
  45. {*****************************************************************************
  46. tMIPSELinlinenode
  47. *****************************************************************************}
  48. procedure tMIPSELinlinenode.load_fpu_location;
  49. begin
  50. secondpass(left);
  51. hlcg.location_force_fpureg(current_asmdata.CurrAsmList, left.location, left.resultdef, True);
  52. location_copy(location, left.location);
  53. if left.location.loc = LOC_CFPUREGISTER then
  54. begin
  55. location.Register := cg.getfpuregister(current_asmdata.CurrAsmList, location.size);
  56. location.loc := LOC_FPUREGISTER;
  57. end;
  58. end;
  59. function tMIPSELinlinenode.first_abs_real: tnode;
  60. begin
  61. if not (cs_fp_emulation in current_settings.moduleswitches) then
  62. begin
  63. expectloc := LOC_FPUREGISTER;
  64. first_abs_real := nil;
  65. end
  66. else
  67. result:=inherited;
  68. end;
  69. function tMIPSELinlinenode.first_sqr_real: tnode;
  70. begin
  71. if not (cs_fp_emulation in current_settings.moduleswitches) then
  72. begin
  73. expectloc := LOC_FPUREGISTER;
  74. first_sqr_real := nil;
  75. end
  76. else
  77. result:=inherited;
  78. end;
  79. function tMIPSELinlinenode.first_sqrt_real: tnode;
  80. begin
  81. if not (cs_fp_emulation in current_settings.moduleswitches) then
  82. begin
  83. expectloc := LOC_FPUREGISTER;
  84. first_sqrt_real := nil;
  85. end
  86. else
  87. result:=inherited;
  88. end;
  89. procedure tMIPSELinlinenode.second_abs_real;
  90. begin
  91. load_fpu_location;
  92. case tfloatdef(left.resultdef).floattype of
  93. s32real:
  94. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_ABS_s, location.Register, left.location.Register));
  95. s64real:
  96. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_ABS_d, location.Register, left.location.Register));
  97. else
  98. internalerror(2004100305);
  99. end;
  100. end;
  101. procedure tMIPSELinlinenode.second_sqr_real;
  102. begin
  103. load_fpu_location;
  104. case tfloatdef(left.resultdef).floattype of
  105. s32real:
  106. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_MUL_s, location.Register, left.location.Register, left.location.Register));
  107. s64real:
  108. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_MUL_d, location.Register, left.location.Register, left.location.Register));
  109. else
  110. internalerror(200410032);
  111. end;
  112. end;
  113. procedure tMIPSELinlinenode.second_sqrt_real;
  114. begin
  115. load_fpu_location;
  116. case tfloatdef(left.resultdef).floattype of
  117. s32real:
  118. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SQRT_s, location.Register, left.location.Register));
  119. s64real:
  120. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_SQRT_d, location.Register, left.location.Register));
  121. else
  122. internalerror(200410033);
  123. end;
  124. end;
  125. procedure tMIPSELinlinenode.second_get_frame;
  126. begin
  127. location_reset(location,LOC_CREGISTER,OS_ADDR);
  128. location.register:=NR_FRAME_POINTER_REG;
  129. end;
  130. begin
  131. cInlineNode := tMIPSELinlinenode;
  132. end.