nrvcon.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Code generation for const nodes on the Risc-V
  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 nrvcon;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgcon,cpubase;
  22. type
  23. trvrealconstnode = 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,aasmcpu,aasmdata,
  33. symdef,
  34. defutil,
  35. cgbase,cgobj,cgutils,
  36. procinfo,
  37. ncon;
  38. {*****************************************************************************
  39. TARMREALCONSTNODE
  40. *****************************************************************************}
  41. function trvrealconstnode.pass_1 : tnode;
  42. begin
  43. result:=nil;
  44. if is_number_float(value_real) and (value_real=0.0) and (get_real_sign(value_real)=1) and
  45. (
  46. is_single(resultdef)
  47. {$ifdef RISCV64}
  48. or is_double(resultdef)
  49. {$endif RISCV64}
  50. ) then
  51. expectloc:=LOC_FPUREGISTER
  52. else
  53. expectloc:=LOC_CREFERENCE;
  54. end;
  55. procedure trvrealconstnode.pass_generate_code;
  56. { I suppose the parser/pass_1 must make sure the generated real }
  57. { constants are actually supported by the target processor? (JM) }
  58. const
  59. floattype2ait:array[tfloattype] of tairealconsttype=
  60. (aitrealconst_s32bit,aitrealconst_s64bit,aitrealconst_s80bit,aitrealconst_s80bit,aitrealconst_s64comp,aitrealconst_s64comp,aitrealconst_s128bit);
  61. var
  62. lastlabel : tasmlabel;
  63. realait : tairealconsttype;
  64. begin
  65. if is_number_float(value_real) and (value_real=0.0) and (get_real_sign(value_real)=1) and
  66. (
  67. is_single(resultdef)
  68. {$ifdef RISCV64}
  69. or is_double(resultdef)
  70. {$endif RISCV64}
  71. ) then
  72. begin
  73. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  74. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  75. if is_single(resultdef) then
  76. current_asmdata.CurrAsmList.concat(Taicpu.op_reg_reg(A_FMV_W_X,location.register,NR_X0))
  77. {$ifdef RISCV64}
  78. else if is_double(resultdef) then
  79. current_asmdata.CurrAsmList.concat(Taicpu.op_reg_reg(A_FMV_D_X,location.register,NR_X0))
  80. {$endif RISCV64}
  81. else
  82. Internalerror(2025011103);
  83. end
  84. else
  85. inherited pass_generate_code;
  86. end;
  87. begin
  88. crealconstnode:=trvrealconstnode;
  89. end.