nrv32mat.pas 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate Risc-V32 assembler for math 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 nrv32mat;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nmat, ncgmat,
  22. cgbase;
  23. type
  24. trv32moddivnode = class(tcgmoddivnode)
  25. procedure emit_div_reg_reg(signed: boolean; denum, num: tregister); override;
  26. procedure emit_mod_reg_reg(signed: boolean; denum, num: tregister); override;
  27. function first_moddivint: tnode; override;
  28. end;
  29. trv32shlshrnode = class(tcgshlshrnode)
  30. end;
  31. trv32unaryminusnode = class(tcgunaryminusnode)
  32. end;
  33. trv32notnode = class(tcgnotnode)
  34. procedure second_boolean; override;
  35. end;
  36. implementation
  37. uses
  38. globtype,systems,constexp,
  39. cutils,verbose,globals,
  40. symconst,symdef,
  41. aasmbase,aasmcpu,aasmtai,aasmdata,
  42. defutil,
  43. cgutils,cgobj,hlcgobj,pass_2,
  44. cpubase,cpuinfo,
  45. ncon,procinfo,
  46. ncgutil,cgcpu;
  47. procedure trv32notnode.second_boolean;
  48. var
  49. tlabel, flabel: tasmlabel;
  50. begin
  51. secondpass(left);
  52. if not handle_locjump then
  53. begin
  54. case left.location.loc of
  55. LOC_FLAGS :
  56. begin
  57. Internalerror(2016060601);
  58. //location_copy(location,left.location);
  59. //inverse_flags(location.resflags);
  60. end;
  61. LOC_REGISTER, LOC_CREGISTER,
  62. LOC_REFERENCE, LOC_CREFERENCE,
  63. LOC_SUBSETREG, LOC_CSUBSETREG,
  64. LOC_SUBSETREF, LOC_CSUBSETREF:
  65. begin
  66. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  67. location_reset(location,LOC_REGISTER,OS_INT);
  68. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,s32inttype);
  69. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg_const(A_SLTIU,location.register,left.location.register,1));
  70. end;
  71. else
  72. internalerror(2003042401);
  73. end;
  74. end;
  75. end;
  76. procedure trv32moddivnode.emit_div_reg_reg(signed: boolean; denum, num: tregister);
  77. var
  78. op: TAsmOp;
  79. begin
  80. if signed then
  81. op:=A_DIV
  82. else
  83. op:=A_DIVU;
  84. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg_reg(op,num,num,denum));
  85. end;
  86. procedure trv32moddivnode.emit_mod_reg_reg(signed: boolean; denum, num: tregister);
  87. var
  88. op: TAsmOp;
  89. begin
  90. if signed then
  91. op:=A_REM
  92. else
  93. op:=A_REMU;
  94. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg_reg(op,num,num,denum));
  95. end;
  96. function trv32moddivnode.first_moddivint: tnode;
  97. begin
  98. if (not is_64bitint(resultdef)) and
  99. (CPURV_HAS_MUL in cpu_capabilities[current_settings.cputype]) then
  100. Result:=nil
  101. else
  102. result:=inherited;
  103. end;
  104. begin
  105. cmoddivnode:=trv32moddivnode;
  106. cshlshrnode:=trv32shlshrnode;
  107. cunaryminusnode:=trv32unaryminusnode;
  108. cnotnode:=trv32notnode;
  109. end.