nrv64cnv.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate RiscV64 assembler for type converting nodes
  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 nrv64cnv;
  18. {$I fpcdefs.inc}
  19. interface
  20. uses
  21. node, ncnv, ncgcnv, nrvcnv;
  22. type
  23. trv64typeconvnode = class(trvtypeconvnode)
  24. protected
  25. { procedure second_int_to_int;override; }
  26. { procedure second_string_to_string;override; }
  27. { procedure second_cstring_to_pchar;override; }
  28. { procedure second_string_to_chararray;override; }
  29. { procedure second_array_to_pointer;override; }
  30. function first_int_to_real: tnode; override;
  31. { procedure second_pointer_to_array;override; }
  32. { procedure second_chararray_to_string;override; }
  33. { procedure second_char_to_string;override; }
  34. procedure second_int_to_real; override;
  35. { procedure second_real_to_real; override;}
  36. { procedure second_cord_to_pointer;override; }
  37. { procedure second_proc_to_procvar;override; }
  38. { procedure second_bool_to_int;override; }
  39. { procedure second_int_to_bool; override; }
  40. { procedure second_load_smallset;override; }
  41. { procedure second_ansistring_to_pchar;override; }
  42. { procedure second_pchar_to_string;override; }
  43. { procedure second_class_to_intf;override; }
  44. { procedure second_char_to_char;override; }
  45. end;
  46. implementation
  47. uses
  48. verbose, globtype, globals, systems,
  49. symconst, symdef, aasmbase, aasmtai,aasmdata,
  50. defutil, symcpu,
  51. cgbase, cgutils, pass_1, pass_2,
  52. ncon, ncal,procinfo,
  53. ncgutil,
  54. cpubase, aasmcpu,
  55. rgobj, tgobj, cgobj, hlcgobj;
  56. {*****************************************************************************
  57. FirstTypeConv
  58. *****************************************************************************}
  59. function trv64typeconvnode.first_int_to_real: tnode;
  60. begin
  61. if (cs_fp_emulation in current_settings.moduleswitches) then
  62. result:=inherited first_int_to_real
  63. { converting a 64bit integer to a float requires a helper }
  64. else
  65. begin
  66. if (is_currency(left.resultdef)) then begin
  67. // hack to avoid double division by 10000, as it's
  68. // already done by typecheckpass.resultdef_int_to_real
  69. left.resultdef := s64inttype;
  70. end else begin
  71. // everything that is less than 64 bits is converted to a 64 bit signed
  72. // integer - because the int_to_real conversion is faster for 64 bit
  73. // signed ints compared to 64 bit unsigned ints.
  74. if (not (torddef(left.resultdef).ordtype in [s64bit, u64bit, scurrency])) then begin
  75. inserttypeconv(left, s64inttype);
  76. end;
  77. end;
  78. firstpass(left);
  79. result := nil;
  80. expectloc := LOC_FPUREGISTER;
  81. end;
  82. end;
  83. {*****************************************************************************
  84. SecondTypeConv
  85. *****************************************************************************}
  86. procedure trv64typeconvnode.second_int_to_real;
  87. const
  88. ops: array[boolean,boolean,s32real..s64real] of TAsmOp = (
  89. ((A_FCVT_S_WU,A_FCVT_D_WU),
  90. (A_FCVT_S_W,A_FCVT_D_W)),
  91. ((A_FCVT_S_LU,A_FCVT_D_LU),
  92. (A_FCVT_S_L,A_FCVT_D_L)));
  93. var
  94. restype: tfloattype;
  95. begin
  96. location_reset(location, LOC_FPUREGISTER, def_cgsize(resultdef));
  97. restype:=tfloatdef(resultdef).floattype;
  98. location.Register := cg.getfpuregister(current_asmdata.CurrAsmList, tfloat2tcgsize[restype]);
  99. if not(left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  100. hlcg.location_force_reg(current_asmdata.CurrAsmList, left.location, left.resultdef, left.resultdef, true);
  101. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(ops[is_64bit(left.resultdef),is_signed(left.resultdef),restype], location.register, left.location.register));
  102. end;
  103. begin
  104. ctypeconvnode := trv64typeconvnode;
  105. end.