2
0

narmcon.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 (FPUARM_HAS_VMOV_CONST in fpu_capabilities[current_settings.fputype]) and
  45. IsVFPFloatImmediate(tfloatdef(resultdef).floattype,value_real) and
  46. ((tfloatdef(resultdef).floattype=s32real) or
  47. (FPUARM_HAS_VFP_DOUBLE in fpu_capabilities[init_settings.fputype])) then
  48. expectloc:=LOC_MMREGISTER
  49. else
  50. expectloc:=LOC_CREFERENCE;
  51. end;
  52. procedure tarmrealconstnode.pass_generate_code;
  53. { I suppose the parser/pass_1 must make sure the generated real }
  54. { constants are actually supported by the target processor? (JM) }
  55. const
  56. floattype2ait:array[tfloattype] of tairealconsttype=
  57. (aitrealconst_s32bit,aitrealconst_s64bit,aitrealconst_s80bit,aitrealconst_s80bit,aitrealconst_s64comp,aitrealconst_s64comp,aitrealconst_s128bit);
  58. var
  59. lastlabel : tasmlabel;
  60. realait : tairealconsttype;
  61. hiloswapped : boolean;
  62. pf : TOpPostfix;
  63. begin
  64. if (FPUARM_HAS_VMOV_CONST in fpu_capabilities[current_settings.fputype]) and
  65. IsVFPFloatImmediate(tfloatdef(resultdef).floattype,value_real) and
  66. ((tfloatdef(resultdef).floattype=s32real) or
  67. (FPUARM_HAS_VFP_DOUBLE in fpu_capabilities[init_settings.fputype])) then
  68. begin
  69. location_reset(location,LOC_MMREGISTER,def_cgsize(resultdef));
  70. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  71. if tfloatdef(resultdef).floattype=s32real then
  72. pf:=PF_F32
  73. else
  74. pf:=PF_F64;
  75. current_asmdata.CurrAsmList.concat(setoppostfix(taicpu.op_reg_realconst(A_VMOV,
  76. location.register,value_real),pf));
  77. end
  78. else
  79. begin
  80. location_reset_ref(location,LOC_CREFERENCE,def_cgsize(resultdef),4,[]);
  81. lastlabel:=nil;
  82. realait:=floattype2ait[tfloatdef(resultdef).floattype];
  83. hiloswapped:=is_double_hilo_swapped;
  84. { const already used ? }
  85. if not assigned(lab_real) then
  86. begin
  87. current_asmdata.getjumplabel(lastlabel);
  88. lab_real:=lastlabel;
  89. current_procinfo.aktlocaldata.concat(Tai_label.Create(lastlabel));
  90. location.reference.symboldata:=current_procinfo.aktlocaldata.last;
  91. case realait of
  92. aitrealconst_s32bit :
  93. begin
  94. current_procinfo.aktlocaldata.concat(tai_realconst.create_s32real(ts32real(value_real)));
  95. { range checking? }
  96. if floating_point_range_check_error and
  97. (tai_realconst(current_procinfo.aktlocaldata.last).value.s32val=MathInf.Value) then
  98. Message(parser_e_range_check_error);
  99. end;
  100. aitrealconst_s64bit :
  101. begin
  102. if hiloswapped then
  103. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64real_hiloswapped(ts64real(value_real)))
  104. else
  105. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64real(ts64real(value_real)));
  106. { range checking? }
  107. if floating_point_range_check_error and
  108. (tai_realconst(current_procinfo.aktlocaldata.last).value.s64val=MathInf.Value) then
  109. Message(parser_e_range_check_error);
  110. end;
  111. aitrealconst_s80bit :
  112. begin
  113. current_procinfo.aktlocaldata.concat(tai_realconst.create_s80real(value_real,tfloatdef(resultdef).size));
  114. { range checking? }
  115. if floating_point_range_check_error and
  116. (tai_realconst(current_procinfo.aktlocaldata.last).value.s80val=MathInf.Value) then
  117. Message(parser_e_range_check_error);
  118. end;
  119. {$ifdef cpufloat128}
  120. aitrealconst_s128bit :
  121. begin
  122. current_procinfo.aktlocaldata.concat(tai_realconst.create_s128real(value_real));
  123. { range checking? }
  124. if floating_point_range_check_error and
  125. (tai_realconst(current_procinfo.aktlocaldata.last).value.s128val=MathInf.Value) then
  126. Message(parser_e_range_check_error);
  127. end;
  128. {$endif cpufloat128}
  129. { the round is necessary for native compilers where comp isn't a float }
  130. aitrealconst_s64comp :
  131. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  132. message(parser_e_range_check_error)
  133. else
  134. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64compreal(round(value_real)));
  135. else
  136. internalerror(2005092401);
  137. end;
  138. end;
  139. location.reference.symbol:=lab_real;
  140. location.reference.base:=NR_R15;
  141. end;
  142. end;
  143. begin
  144. crealconstnode:=tarmrealconstnode;
  145. end.