nrvcon.pas 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. globals,
  31. aasmcpu,aasmdata,
  32. defutil,
  33. cpuinfo,
  34. cgbase,cgobj,cgutils,
  35. ncon;
  36. {*****************************************************************************
  37. TARMREALCONSTNODE
  38. *****************************************************************************}
  39. function trvrealconstnode.pass_1 : tnode;
  40. begin
  41. result:=nil;
  42. if is_number_float(value_real) and (value_real=0.0) and (get_real_sign(value_real)=1) and
  43. (
  44. ((CPURV_HAS_F in cpu_capabilities[current_settings.cputype]) and is_single(resultdef))
  45. {$ifdef RISCV64}
  46. or ((CPURV_HAS_D in cpu_capabilities[current_settings.cputype]) and is_double(resultdef))
  47. {$endif RISCV64}
  48. ) then
  49. expectloc:=LOC_FPUREGISTER
  50. else
  51. expectloc:=LOC_CREFERENCE;
  52. end;
  53. procedure trvrealconstnode.pass_generate_code;
  54. begin
  55. if is_number_float(value_real) and (value_real=0.0) and (get_real_sign(value_real)=1) and
  56. (
  57. ((CPURV_HAS_F in cpu_capabilities[current_settings.cputype]) and is_single(resultdef))
  58. {$ifdef RISCV64}
  59. or ((CPURV_HAS_D in cpu_capabilities[current_settings.cputype]) and is_double(resultdef))
  60. {$endif RISCV64}
  61. ) 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.