Przeglądaj źródła

+ implemented trunc(real) for WebAssembly via the i64.trunc_f32_s and i64.trunc_f64_s instructions

Nikolay Nikolov 3 lat temu
rodzic
commit
835bc62e2a
1 zmienionych plików z 31 dodań i 0 usunięć
  1. 31 0
      compiler/wasm32/nwasminl.pas

+ 31 - 0
compiler/wasm32/nwasminl.pas

@@ -37,9 +37,11 @@ interface
         function first_abs_real:tnode;override;
         function first_int_real:tnode;override;
         function first_sqrt_real:tnode;override;
+        function first_trunc_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_high; override;
         procedure second_memory_size;
         procedure second_memory_grow;
@@ -91,6 +93,13 @@ implementation
       end;
 
 
+    function twasminlinenode.first_trunc_real: tnode;
+      begin
+        expectloc:=LOC_REGISTER;
+        result:=nil;
+      end;
+
+
     procedure twasminlinenode.second_abs_real;
       begin
         secondpass(left);
@@ -157,6 +166,28 @@ implementation
       end;
 
 
+    procedure twasminlinenode.second_trunc_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:
+            current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f32_s));
+          OS_F64:
+            current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f64_s));
+          else
+            internalerror(2021092904);
+        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;