Browse Source

+ RiscV: support for real constants in assembler

florian 2 weeks ago
parent
commit
a73dda69b4
3 changed files with 30 additions and 1 deletions
  1. 2 0
      compiler/aasmtai.pas
  2. 26 1
      compiler/riscv/aasmcpu.pas
  3. 2 0
      compiler/riscv/cpubase.pas

+ 2 - 0
compiler/aasmtai.pas

@@ -311,6 +311,7 @@ interface
 {$if defined(riscv32) or defined(riscv64)}
 {$if defined(riscv32) or defined(riscv64)}
        ,top_fenceflags
        ,top_fenceflags
        ,top_roundingmode
        ,top_roundingmode
+       ,top_realconst
 {$endif defined(riscv32) or defined(riscv64)}
 {$endif defined(riscv32) or defined(riscv64)}
 {$ifdef wasm}
 {$ifdef wasm}
        ,top_functype
        ,top_functype
@@ -564,6 +565,7 @@ interface
         {$if defined(riscv32) or defined(riscv64)}
         {$if defined(riscv32) or defined(riscv64)}
             top_fenceflags : (fenceflags : TFenceFlags);
             top_fenceflags : (fenceflags : TFenceFlags);
             top_roundingmode : (roundingmode : TRoundingMode);
             top_roundingmode : (roundingmode : TRoundingMode);
+            top_realconst : (val_real:bestreal;special_value : TAsmRealSpecialValue);
         {$endif defined(riscv32) or defined(riscv64)}
         {$endif defined(riscv32) or defined(riscv64)}
         {$ifdef wasm}
         {$ifdef wasm}
             top_functype : (functype: TWasmFuncType);
             top_functype : (functype: TWasmFuncType);

+ 26 - 1
compiler/riscv/aasmcpu.pas

@@ -28,7 +28,7 @@ interface
 uses
 uses
   globtype,verbose,
   globtype,verbose,
   aasmbase,aasmtai,aasmdata,aasmsym,
   aasmbase,aasmtai,aasmdata,aasmsym,
-  cpubase,cgbase,cgutils;
+  cpubase,cpuinfo,cgbase,cgutils;
 
 
     const
     const
       { "mov reg,reg" source operand number }
       { "mov reg,reg" source operand number }
@@ -53,6 +53,7 @@ uses
          constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
          constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
          constructor op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
          constructor op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
          constructor op_const_reg(op:tasmop; _op1: aint; _op2: tregister);
          constructor op_const_reg(op:tasmop; _op1: aint; _op2: tregister);
+         constructor op_reg_realconst(op:tasmop; _op1: tregister; _op2: bestreal;special_value: TAsmRealSpecialValue);
 
 
          constructor op_const_const(op : tasmop;_op1,_op2 : aint);
          constructor op_const_const(op : tasmop;_op1,_op2 : aint);
 
 
@@ -91,6 +92,7 @@ uses
          procedure loadroundingmode(opidx:aint;_roundmode:TRoundingMode);
          procedure loadroundingmode(opidx:aint;_roundmode:TRoundingMode);
          procedure loadfenceflags(opidx:aint;_flags:TFenceFlags);
          procedure loadfenceflags(opidx:aint;_flags:TFenceFlags);
          procedure loadbool(opidx:aint;_b:boolean);
          procedure loadbool(opidx:aint;_b:boolean);
+         procedure loadrealconst(opidx:longint;const _value:bestreal;_special_value:TAsmRealSpecialValue);
 
 
          function is_same_reg_move(regtype: Tregistertype):boolean; override;
          function is_same_reg_move(regtype: Tregistertype):boolean; override;
 
 
@@ -132,6 +134,20 @@ uses cutils, cclasses;
       end;
       end;
 
 
 
 
+    procedure taicpu.loadrealconst(opidx:longint;const _value:bestreal;_special_value:TAsmRealSpecialValue);
+      begin
+        allocate_oper(opidx+1);
+        with oper[opidx]^ do
+          begin
+            if typ<>top_realconst then
+              clearop(opidx);
+            special_value:=special_value;
+            val_real:=_value;
+            typ:=top_realconst;
+          end;
+      end;
+
+
     constructor taicpu.op_none(op : tasmop);
     constructor taicpu.op_none(op : tasmop);
       begin
       begin
          inherited create(op);
          inherited create(op);
@@ -187,6 +203,15 @@ uses cutils, cclasses;
       end;
       end;
 
 
 
 
+     constructor taicpu.op_reg_realconst(op: tasmop; _op1: tregister; _op2: bestreal; special_value: TAsmRealSpecialValue);
+       begin
+         inherited create(op);
+         ops:=2;
+         loadreg(0,_op1);
+         loadrealconst(1,_op2,special_value);
+       end;
+
+
     constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
     constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
       begin
       begin
          inherited create(op);
          inherited create(op);

+ 2 - 0
compiler/riscv/cpubase.pas

@@ -329,6 +329,8 @@ uses
       TFenceFlag = (ffI, ffO, ffR, ffW);
       TFenceFlag = (ffI, ffO, ffR, ffW);
       TFenceFlags = set of TFenceFlag;
       TFenceFlags = set of TFenceFlag;
 
 
+      TAsmRealSpecialValue = (ARSV_None,ARSV_Nan,ARSV_Min,ARSV_Inf);
+
       TRoundingMode = (RM_Default,
       TRoundingMode = (RM_Default,
                        RM_RNE,
                        RM_RNE,
                        RM_RTZ,
                        RM_RTZ,