Browse Source

+ implemented the f32.const and f64.const instructions in the wasm
internal asm

Nikolay Nikolov 3 years ago
parent
commit
6133affad6
1 changed files with 60 additions and 0 deletions
  1. 60 0
      compiler/wasm32/aasmcpu.pas

+ 60 - 0
compiler/wasm32/aasmcpu.pas

@@ -555,6 +555,10 @@ uses
                     internalerror(2021092615);
                     internalerror(2021092615);
                 end;
                 end;
             end;
             end;
+          a_f32_const:
+            result:=5;
+          a_f64_const:
+            result:=9;
           a_local_get,
           a_local_get,
           a_local_set,
           a_local_set,
           a_local_tee:
           a_local_tee:
@@ -705,6 +709,36 @@ uses
             objdata.writebytes(b,1);
             objdata.writebytes(b,1);
           end;
           end;
 
 
+{$ifdef FPC_LITTLE_ENDIAN}
+        procedure WriteSingle(s: single);
+          begin
+            objdata.writebytes(s,4);
+          end;
+
+        procedure WriteDouble(d: double);
+          begin
+            objdata.writebytes(d,8);
+          end;
+{$else FPC_LITTLE_ENDIAN}
+        procedure WriteSingle(s: single);
+          var
+            l: longword;
+          begin
+            Move(s,l,4);
+            l:=SwapEndian(l);
+            objdata.writebytes(l,4);
+          end;
+
+        procedure WriteDouble(d: double);
+          var
+            q: qword;
+          begin
+            Move(d,q,8);
+            q:=SwapEndian(q);
+            objdata.writebytes(q,8);
+          end;
+{$endif FPC_LITTLE_ENDIAN}
+
         procedure WriteSleb(v: tcgint);
         procedure WriteSleb(v: tcgint);
           var
           var
             b: byte;
             b: byte;
@@ -1049,6 +1083,32 @@ uses
                     internalerror(2021092615);
                     internalerror(2021092615);
                 end;
                 end;
             end;
             end;
+          a_f32_const:
+            begin
+              if ops<>1 then
+                internalerror(2021092619);
+              WriteByte($44);
+              with oper[0]^ do
+                case typ of
+                  top_single:
+                    WriteSingle(sval);
+                  else
+                    internalerror(2021092618);
+                end;
+            end;
+          a_f64_const:
+            begin
+              if ops<>1 then
+                internalerror(2021092616);
+              WriteByte($44);
+              with oper[0]^ do
+                case typ of
+                  top_double:
+                    WriteDouble(dval);
+                  else
+                    internalerror(2021092617);
+                end;
+            end;
           a_local_get,
           a_local_get,
           a_local_set,
           a_local_set,
           a_local_tee:
           a_local_tee: