Browse Source

+ implemented round(real) for WebAssembly via the fXX.nearest and i64.trunc_fXX_s instructions

Nikolay Nikolov 3 years ago
parent
commit
91d8009b53
1 changed files with 37 additions and 0 deletions
  1. 37 0
      compiler/wasm32/nwasminl.pas

+ 37 - 0
compiler/wasm32/nwasminl.pas

@@ -38,10 +38,12 @@ interface
         function first_int_real:tnode;override;
         function first_sqrt_real:tnode;override;
         function first_trunc_real:tnode;override;
+        function first_round_real:tnode;override;
         procedure second_abs_real;override;
         procedure second_int_real;override;
         procedure second_sqrt_real;override;
         procedure second_trunc_real;override;
+        procedure second_round_real;override;
         procedure second_high; override;
         procedure second_memory_size;
         procedure second_memory_grow;
@@ -100,6 +102,13 @@ implementation
       end;
 
 
+    function twasminlinenode.first_round_real: tnode;
+      begin
+        expectloc:=LOC_REGISTER;
+        result:=nil;
+      end;
+
+
     procedure twasminlinenode.second_abs_real;
       begin
         secondpass(left);
@@ -188,6 +197,34 @@ implementation
       end;
 
 
+    procedure twasminlinenode.second_round_real;
+      begin
+        secondpass(left);
+        hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
+
+        thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
+
+        case left.location.size of
+          OS_F32:
+            begin
+              current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f32_nearest));
+              current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f32_s));
+            end;
+          OS_F64:
+            begin
+              current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f64_nearest));
+              current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f64_s));
+            end
+          else
+            internalerror(2021092905);
+        end;
+
+        location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
+        location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
+        thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
+      end;
+
+
     procedure twasminlinenode.second_high;
       var
         hightype: TWasmBasicType;