2
0

nrv32mat.pas 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. ncon,procinfo,
  45. cpubase,
  46. ncgutil,cgcpu;
  47. procedure trv32notnode.second_boolean;
  48. var
  49. tlabel, flabel: tasmlabel;
  50. begin
  51. if not handle_locjump then
  52. begin
  53. secondpass(left);
  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. current_asmdata.getjumplabel(tlabel);
  68. current_asmdata.getjumplabel(flabel);
  69. location_reset_jump(location,tlabel,flabel);
  70. hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,left.resultdef,OC_EQ,0,left.location.register,tlabel);
  71. hlcg.a_jmp_always(current_asmdata.CurrAsmList,flabel);
  72. end;
  73. else
  74. internalerror(2003042401);
  75. end;
  76. end;
  77. end;
  78. procedure trv32moddivnode.emit_div_reg_reg(signed: boolean; denum, num: tregister);
  79. var
  80. op: TAsmOp;
  81. begin
  82. if signed then
  83. op:=A_DIV
  84. else
  85. op:=A_DIVU;
  86. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg_reg(op,denum,num,denum));
  87. end;
  88. procedure trv32moddivnode.emit_mod_reg_reg(signed: boolean; denum, num: tregister);
  89. var
  90. op: TAsmOp;
  91. begin
  92. if signed then
  93. op:=A_REM
  94. else
  95. op:=A_REMU;
  96. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg_reg(op,denum,num,denum));
  97. end;
  98. function trv32moddivnode.first_moddivint: tnode;
  99. begin
  100. if (not is_64bitint(resultdef)) then
  101. Result:=nil
  102. else
  103. result:=inherited;
  104. end;
  105. begin
  106. cmoddivnode:=trv32moddivnode;
  107. cshlshrnode:=trv32shlshrnode;
  108. cunaryminusnode:=trv32unaryminusnode;
  109. cnotnode:=trv32notnode;
  110. end.