瀏覽代碼

+ implemented sqr(real) for the WebAssembly target

git-svn-id: trunk@49430 -
nickysn 4 年之前
父節點
當前提交
c42e297bc6
共有 1 個文件被更改,包括 34 次插入0 次删除
  1. 34 0
      compiler/wasm32/nwasminl.pas

+ 34 - 0
compiler/wasm32/nwasminl.pas

@@ -38,11 +38,14 @@ interface
         procedure second_memory_size;
         procedure second_memory_size;
         procedure second_memory_grow;
         procedure second_memory_grow;
         procedure second_unreachable;
         procedure second_unreachable;
+      protected
+        function first_sqr_real: tnode; override;
       public
       public
         function pass_typecheck_cpu: tnode; override;
         function pass_typecheck_cpu: tnode; override;
         function first_cpu: tnode; override;
         function first_cpu: tnode; override;
         procedure pass_generate_code_cpu; override;
         procedure pass_generate_code_cpu; override;
         procedure second_length;override;
         procedure second_length;override;
+        procedure second_sqr_real; override;
       end;
       end;
 
 
 implementation
 implementation
@@ -152,6 +155,13 @@ implementation
       end;
       end;
 
 
 
 
+    function twasminlinenode.first_sqr_real: tnode;
+      begin
+        expectloc:=LOC_FPUREGISTER;
+        first_sqr_real:=nil;
+      end;
+
+
     function twasminlinenode.pass_typecheck_cpu: tnode;
     function twasminlinenode.pass_typecheck_cpu: tnode;
       begin
       begin
         Result:=nil;
         Result:=nil;
@@ -268,6 +278,30 @@ implementation
           end;
           end;
       end;
       end;
 
 
+
+    procedure twasminlinenode.second_sqr_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);
+        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_f32_mul));
+          OS_F64:
+            current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_f64_mul));
+          else
+            internalerror(2021060102);
+        end;
+        thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
+
+        location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
+        location.register:=hlcg.getregisterfordef(current_asmdata.CurrAsmList,resultdef);
+        thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
+      end;
+
 begin
 begin
   cinlinenode:=twasminlinenode;
   cinlinenode:=twasminlinenode;
 end.
 end.