ncpumat.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate LoongArch64 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 ncpumat;
  18. {$I fpcdefs.inc}
  19. interface
  20. uses
  21. node,nmat, ncgmat,
  22. cgbase;
  23. type
  24. tloongarch64moddivnode = class(tcgmoddivnode)
  25. function use_moddiv64bitint_helper: boolean; override;
  26. procedure emit_div_reg_reg(signed: boolean; denum, num: tregister); override;
  27. procedure emit_mod_reg_reg(signed: boolean; denum, num: tregister); override;
  28. function first_moddiv64bitint: tnode; override;
  29. end;
  30. tloongarch64shlshrnode = class(tcgshlshrnode)
  31. end;
  32. tloongarch64unaryminusnode = class(tcgunaryminusnode)
  33. end;
  34. tloongarch64notnode = class(tcgnotnode)
  35. procedure second_boolean; override;
  36. end;
  37. implementation
  38. uses
  39. nadd,ninl,ncal,ncnv,
  40. globtype,systems,constexp,
  41. cutils,verbose,globals,
  42. cpuinfo,
  43. symconst,symdef,
  44. aasmbase,aasmcpu,aasmtai,aasmdata,
  45. defutil,
  46. cgutils,cgobj,hlcgobj,
  47. pass_1,pass_2,htypechk,
  48. ncon,procinfo,
  49. cpubase,
  50. ncgutil,cgcpu;
  51. procedure tloongarch64notnode.second_boolean;
  52. var
  53. tlabel, flabel: tasmlabel;
  54. begin
  55. secondpass(left);
  56. if not handle_locjump then
  57. begin
  58. case left.location.loc of
  59. LOC_FLAGS :
  60. begin
  61. Internalerror(2022111907);
  62. end;
  63. LOC_REGISTER, LOC_CREGISTER,
  64. LOC_REFERENCE, LOC_CREFERENCE,
  65. LOC_SUBSETREG, LOC_CSUBSETREG,
  66. LOC_SUBSETREF, LOC_CSUBSETREF:
  67. begin
  68. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  69. location_reset(location,LOC_REGISTER,OS_INT);
  70. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,s64inttype);
  71. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg_const(A_SLTUI,location.register,left.location.register,1));
  72. end;
  73. else
  74. internalerror(2022111906);
  75. end;
  76. end;
  77. end;
  78. function tloongarch64moddivnode.use_moddiv64bitint_helper: boolean;
  79. begin
  80. Result:=true;
  81. end;
  82. procedure tloongarch64moddivnode.emit_div_reg_reg(signed: boolean; denum, num: tregister);
  83. var
  84. op: TAsmOp;
  85. begin
  86. if signed then
  87. op:=A_DIV_D
  88. else
  89. op:=A_DIV_DU;
  90. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg_reg(op,num,num,denum));
  91. end;
  92. procedure tloongarch64moddivnode.emit_mod_reg_reg(signed: boolean; denum, num: tregister);
  93. var
  94. op: TAsmOp;
  95. begin
  96. if signed then
  97. op:=A_MOD_D
  98. else
  99. op:=A_MOD_DU;
  100. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg_reg(op,num,num,denum));
  101. end;
  102. function tloongarch64moddivnode.first_moddiv64bitint: tnode;
  103. begin
  104. {We can handle all cases of constant division}
  105. if not(cs_check_overflow in current_settings.localswitches) and
  106. (right.nodetype=ordconstn) and
  107. (nodetype=divn) then
  108. result:=nil
  109. else if (nodetype in [divn,modn]) then
  110. result:=nil
  111. else
  112. result:=inherited;
  113. { we may not change the result type here }
  114. if assigned(result) and (torddef(result.resultdef).ordtype<>torddef(resultdef).ordtype) then
  115. inserttypeconv(result,resultdef);
  116. end;
  117. begin
  118. cmoddivnode := tloongarch64moddivnode;
  119. cshlshrnode := tloongarch64shlshrnode;
  120. cunaryminusnode := tloongarch64unaryminusnode;
  121. cnotnode := tloongarch64notnode;
  122. end.