Browse Source

[PATCH 73/83] copied over jvm implementation of second_addfloat

From ded21da2dd4e20db39426ba904974484c5b04fd8 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Tue, 29 Oct 2019 09:46:46 -0400

git-svn-id: branches/wasm@45950 -
nickysn 5 years ago
parent
commit
3ae2ce9a28
1 changed files with 68 additions and 1 deletions
  1. 68 1
      compiler/wasm/nwasmadd.pas

+ 68 - 1
compiler/wasm/nwasmadd.pas

@@ -38,7 +38,7 @@ interface
           procedure second_generic_compare(unsigned: boolean);
 
           procedure pass_left_right;override;
-          //procedure second_addfloat;override;
+          procedure second_addfloat;override;
           procedure second_cmpfloat;override;
           procedure second_cmpboolean;override;
           procedure second_cmp64bit;override;
@@ -76,6 +76,73 @@ interface
         inherited pass_left_right;
       end;
 
+    procedure twasmaddnode.second_addfloat;
+      var
+        op : TAsmOp;
+        commutative : boolean;
+      begin
+        pass_left_right;
+
+        location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
+        location.register:=hlcg.getfpuregister(current_asmdata.CurrAsmList,resultdef);
+
+        commutative:=false;
+        case nodetype of
+          addn :
+            begin
+              if location.size=OS_F64 then
+                op:=a_f64_add
+              else
+                op:=a_f32_add;
+              commutative:=true;
+            end;
+          muln :
+            begin
+              if location.size=OS_F64 then
+                op:=a_f64_mul
+              else
+                op:=a_f32_mul;
+              commutative:=true;
+            end;
+          subn :
+            begin
+              if location.size=OS_F64 then
+                op:=a_f64_sub
+              else
+                op:=a_f32_sub;
+            end;
+          slashn :
+            begin
+              if location.size=OS_F64 then
+                op:=a_f64_div
+              else
+                op:=a_f32_div;
+            end;
+          else
+            internalerror(2011010402);
+        end;
+
+        { swap the operands to make it easier for the optimizer to optimize
+          the operand stack slot reloading (non-commutative operations must
+          always be in the correct order though) }
+        if (commutative and
+            (left.location.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) and
+            (right.location.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER])) or
+           (not commutative and
+            (nf_swapped in flags)) then
+          swapleftright;
+
+        thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
+        thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,right.resultdef,right.location);
+
+        current_asmdata.CurrAsmList.concat(taicpu.op_none(op));
+        thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1+ord(location.size=OS_F64));
+        { could be optimized in the future by keeping the results on the stack,
+          if we add code to swap the operands when necessary (a_swap for
+          singles, store/load/load for doubles since there is no swap for
+          2-slot elements -- also adjust expectloc in that case! }
+        thlcgwasm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,resultdef,location.register);
+      end;
 
     procedure twasmaddnode.second_cmpfloat;
       //var