narmcon.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. {
  2. Copyright (c) 2005 by Florian Klaempfl
  3. Code generation for const nodes on the ARM
  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 narmcon;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgcon,cpubase;
  22. type
  23. tarmrealconstnode = class(tcgrealconstnode)
  24. function pass_1 : tnode;override;
  25. procedure pass_generate_code;override;
  26. end;
  27. implementation
  28. uses
  29. verbose,
  30. globtype,globals,
  31. cpuinfo,
  32. aasmbase,aasmtai,aasmdata,aasmcpu,
  33. symdef,
  34. defutil,
  35. cgbase,cgutils,cgobj,
  36. procinfo,
  37. ncon;
  38. {*****************************************************************************
  39. TARMREALCONSTNODE
  40. *****************************************************************************}
  41. function tarmrealconstnode.pass_1 : tnode;
  42. begin
  43. result:=nil;
  44. if (current_settings.fputype in [fpu_vfpv3,fpu_vfpv4,fpu_vfpv3_d16,fpu_fpv4_s16]) and
  45. IsVFPFloatImmediate(tfloatdef(resultdef).floattype,value_real) then
  46. expectloc:=LOC_MMREGISTER
  47. else
  48. expectloc:=LOC_CREFERENCE;
  49. end;
  50. procedure tarmrealconstnode.pass_generate_code;
  51. { I suppose the parser/pass_1 must make sure the generated real }
  52. { constants are actually supported by the target processor? (JM) }
  53. const
  54. floattype2ait:array[tfloattype] of tairealconsttype=
  55. (aitrealconst_s32bit,aitrealconst_s64bit,aitrealconst_s80bit,aitrealconst_s80bit,aitrealconst_s64comp,aitrealconst_s64comp,aitrealconst_s128bit);
  56. var
  57. lastlabel : tasmlabel;
  58. realait : tairealconsttype;
  59. hiloswapped : boolean;
  60. pf : TOpPostfix;
  61. begin
  62. if (current_settings.fputype in [fpu_vfpv3,fpu_vfpv4,fpu_vfpv3_d16,fpu_fpv4_s16]) and
  63. IsVFPFloatImmediate(tfloatdef(resultdef).floattype,value_real) then
  64. begin
  65. location_reset(location,LOC_MMREGISTER,def_cgsize(resultdef));
  66. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  67. if tfloatdef(resultdef).floattype=s32real then
  68. pf:=PF_F32
  69. else
  70. pf:=PF_F64;
  71. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_realconst(A_VMOV,
  72. location.register,value_real),pf));
  73. end
  74. else
  75. begin
  76. location_reset_ref(location,LOC_CREFERENCE,def_cgsize(resultdef),4,[]);
  77. lastlabel:=nil;
  78. realait:=floattype2ait[tfloatdef(resultdef).floattype];
  79. hiloswapped:=is_double_hilo_swapped;
  80. { const already used ? }
  81. if not assigned(lab_real) then
  82. begin
  83. current_asmdata.getjumplabel(lastlabel);
  84. lab_real:=lastlabel;
  85. current_procinfo.aktlocaldata.concat(Tai_label.Create(lastlabel));
  86. location.reference.symboldata:=current_procinfo.aktlocaldata.last;
  87. case realait of
  88. aitrealconst_s32bit :
  89. begin
  90. current_procinfo.aktlocaldata.concat(tai_realconst.create_s32real(ts32real(value_real)));
  91. { range checking? }
  92. if floating_point_range_check_error and
  93. (tai_realconst(current_procinfo.aktlocaldata.last).value.s32val=MathInf.Value) then
  94. Message(parser_e_range_check_error);
  95. end;
  96. aitrealconst_s64bit :
  97. begin
  98. if hiloswapped then
  99. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64real_hiloswapped(ts64real(value_real)))
  100. else
  101. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64real(ts64real(value_real)));
  102. { range checking? }
  103. if floating_point_range_check_error and
  104. (tai_realconst(current_procinfo.aktlocaldata.last).value.s64val=MathInf.Value) then
  105. Message(parser_e_range_check_error);
  106. end;
  107. aitrealconst_s80bit :
  108. begin
  109. current_procinfo.aktlocaldata.concat(tai_realconst.create_s80real(value_real,tfloatdef(resultdef).size));
  110. { range checking? }
  111. if floating_point_range_check_error and
  112. (tai_realconst(current_procinfo.aktlocaldata.last).value.s80val=MathInf.Value) then
  113. Message(parser_e_range_check_error);
  114. end;
  115. {$ifdef cpufloat128}
  116. aitrealconst_s128bit :
  117. begin
  118. current_procinfo.aktlocaldata.concat(tai_realconst.create_s128real(value_real));
  119. { range checking? }
  120. if floating_point_range_check_error and
  121. (tai_realconst(current_procinfo.aktlocaldata.last).value.s128val=MathInf.Value) then
  122. Message(parser_e_range_check_error);
  123. end;
  124. {$endif cpufloat128}
  125. { the round is necessary for native compilers where comp isn't a float }
  126. aitrealconst_s64comp :
  127. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  128. message(parser_e_range_check_error)
  129. else
  130. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64compreal(round(value_real)));
  131. else
  132. internalerror(2005092401);
  133. end;
  134. end;
  135. location.reference.symbol:=lab_real;
  136. location.reference.base:=NR_R15;
  137. end;
  138. end;
  139. begin
  140. crealconstnode:=tarmrealconstnode;
  141. end.