nrvcon.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. private
  27. function is_real_constant: boolean;
  28. end;
  29. implementation
  30. uses
  31. verbose,
  32. globals,
  33. aasmcpu,aasmdata,
  34. defutil,
  35. cpuinfo,
  36. cgbase,cgobj,cgutils,
  37. ncon;
  38. {*****************************************************************************
  39. TARMREALCONSTNODE
  40. *****************************************************************************}
  41. function trvrealconstnode.is_real_constant: boolean;
  42. begin
  43. result:=is_number_float(value_real) and (value_real=0.0) and (get_real_sign(value_real)=1) and
  44. (
  45. ((CPURV_HAS_F in cpu_capabilities[current_settings.cputype]) and is_single(resultdef))
  46. {$ifdef RISCV64}
  47. or ((CPURV_HAS_D in cpu_capabilities[current_settings.cputype]) and is_double(resultdef))
  48. {$endif RISCV64}
  49. );
  50. end;
  51. function trvrealconstnode.pass_1 : tnode;
  52. begin
  53. result:=nil;
  54. if is_real_constant then
  55. expectloc:=LOC_FPUREGISTER
  56. else
  57. expectloc:=LOC_CREFERENCE;
  58. end;
  59. procedure trvrealconstnode.pass_generate_code;
  60. begin
  61. if is_real_constant then
  62. begin
  63. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  64. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  65. if is_single(resultdef) then
  66. current_asmdata.CurrAsmList.concat(Taicpu.op_reg_reg(A_FMV_W_X,location.register,NR_X0))
  67. {$ifdef RISCV64}
  68. else if is_double(resultdef) then
  69. current_asmdata.CurrAsmList.concat(Taicpu.op_reg_reg(A_FMV_D_X,location.register,NR_X0))
  70. {$endif RISCV64}
  71. else
  72. Internalerror(2025011103);
  73. end
  74. else
  75. inherited pass_generate_code;
  76. end;
  77. begin
  78. crealconstnode:=trvrealconstnode;
  79. end.