nrvcon.pas 2.8 KB

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