2
0

narmcon.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. 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. end;
  103. aitrealconst_s80bit :
  104. begin
  105. current_procinfo.aktlocaldata.concat(tai_realconst.create_s80real(value_real,tfloatdef(resultdef).size));
  106. end;
  107. {$ifdef cpufloat128}
  108. aitrealconst_s128bit :
  109. begin
  110. current_procinfo.aktlocaldata.concat(tai_realconst.create_s128real(value_real));
  111. end;
  112. {$endif cpufloat128}
  113. { the round is necessary for native compilers where comp isn't a float }
  114. aitrealconst_s64comp :
  115. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  116. message(parser_e_range_check_error)
  117. else
  118. current_procinfo.aktlocaldata.concat(tai_realconst.create_s64compreal(round(value_real)));
  119. else
  120. internalerror(2005092401);
  121. end;
  122. end;
  123. location.reference.symbol:=lab_real;
  124. location.reference.base:=NR_R15;
  125. end;
  126. end;
  127. begin
  128. crealconstnode:=tarmrealconstnode;
  129. end.