Browse Source

+ added the WebAssembly saturating truncation instructions to the internal assembler

Nikolay Nikolov 3 years ago
parent
commit
d378240134

+ 48 - 0
compiler/wasm32/aasmcpu.pas

@@ -539,6 +539,14 @@ uses
           a_end_try,
           a_end_try,
           a_catch_all:
           a_catch_all:
             result:=1;
             result:=1;
+          a_i32_trunc_sat_f32_s,
+          a_i32_trunc_sat_f32_u,
+          a_i32_trunc_sat_f64_s,
+          a_i32_trunc_sat_f64_u,
+          a_i64_trunc_sat_f32_s,
+          a_i64_trunc_sat_f32_u,
+          a_i64_trunc_sat_f64_s,
+          a_i64_trunc_sat_f64_u,
           a_memory_size,
           a_memory_size,
           a_memory_grow:
           a_memory_grow:
             result:=2;
             result:=2;
@@ -1910,6 +1918,46 @@ uses
                     internalerror(2022052809);
                     internalerror(2022052809);
                 end;
                 end;
             end;
             end;
+          a_i32_trunc_sat_f32_s:
+            begin
+              WriteByte($FC);
+              WriteByte($00);
+            end;
+          a_i32_trunc_sat_f32_u:
+            begin
+              WriteByte($FC);
+              WriteByte($01);
+            end;
+          a_i32_trunc_sat_f64_s:
+            begin
+              WriteByte($FC);
+              WriteByte($02);
+            end;
+          a_i32_trunc_sat_f64_u:
+            begin
+              WriteByte($FC);
+              WriteByte($03);
+            end;
+          a_i64_trunc_sat_f32_s:
+            begin
+              WriteByte($FC);
+              WriteByte($04);
+            end;
+          a_i64_trunc_sat_f32_u:
+            begin
+              WriteByte($FC);
+              WriteByte($05);
+            end;
+          a_i64_trunc_sat_f64_s:
+            begin
+              WriteByte($FC);
+              WriteByte($06);
+            end;
+          a_i64_trunc_sat_f64_u:
+            begin
+              WriteByte($FC);
+              WriteByte($07);
+            end;
           else
           else
             internalerror(2021092624);
             internalerror(2021092624);
         end;
         end;

+ 9 - 0
compiler/wasm32/cpubase.pas

@@ -90,6 +90,15 @@ uses
       a_ref_null, a_ref_is_null, a_ref_func,
       a_ref_null, a_ref_is_null, a_ref_func,
       // table instructions
       // table instructions
       a_table_get, a_table_set, a_table_size, a_table_grow, a_table_fill, a_table_copy, a_table_init, a_elem_drop,
       a_table_get, a_table_set, a_table_size, a_table_grow, a_table_fill, a_table_copy, a_table_init, a_elem_drop,
+      // saturating truncation instructions
+      a_i32_trunc_sat_f32_s,
+      a_i32_trunc_sat_f32_u,
+      a_i32_trunc_sat_f64_s,
+      a_i32_trunc_sat_f64_u,
+      a_i64_trunc_sat_f32_s,
+      a_i64_trunc_sat_f32_u,
+      a_i64_trunc_sat_f64_s,
+      a_i64_trunc_sat_f64_u,
       // exceptions
       // exceptions
       a_try,a_catch,a_catch_all,a_delegate,a_throw,a_rethrow,a_end_try,
       a_try,a_catch,a_catch_all,a_delegate,a_throw,a_rethrow,a_end_try,
       // atomic memory accesses - load/store
       // atomic memory accesses - load/store

+ 9 - 0
compiler/wasm32/itcpugas.pas

@@ -89,6 +89,15 @@ interface
       'ref.null', 'ref.is_null', 'ref.func',
       'ref.null', 'ref.is_null', 'ref.func',
       // table instructions
       // table instructions
       'table.get', 'table.set', 'table.size', 'table.grow', 'table.fill', 'table.copy', 'table.init', 'elem.drop',
       'table.get', 'table.set', 'table.size', 'table.grow', 'table.fill', 'table.copy', 'table.init', 'elem.drop',
+      // saturating truncation instructions
+      'i32.trunc_sat_f32_s',
+      'i32.trunc_sat_f32_u',
+      'i32.trunc_sat_f64_s',
+      'i32.trunc_sat_f64_u',
+      'i64.trunc_sat_f32_s',
+      'i64.trunc_sat_f32_u',
+      'i64.trunc_sat_f64_s',
+      'i64.trunc_sat_f64_u',
       // exceptions
       // exceptions
       'try','catch','catch_all','delegate','throw','rethrow','end_try',
       'try','catch','catch_all','delegate','throw','rethrow','end_try',
       // atomic memory accesses - load/store
       // atomic memory accesses - load/store

+ 9 - 0
compiler/wasm32/strinst.inc

@@ -73,6 +73,15 @@
         'ref.null', 'ref.is_null', 'ref.func',
         'ref.null', 'ref.is_null', 'ref.func',
         // table instructions
         // table instructions
         'table.get', 'table.set', 'table.size', 'table.grow', 'table.fill', 'table.copy', 'table.init', 'elem.drop',
         'table.get', 'table.set', 'table.size', 'table.grow', 'table.fill', 'table.copy', 'table.init', 'elem.drop',
+        // saturating truncation instructions
+        'i32.trunc_sat_f32_s',
+        'i32.trunc_sat_f32_u',
+        'i32.trunc_sat_f64_s',
+        'i32.trunc_sat_f64_u',
+        'i64.trunc_sat_f32_s',
+        'i64.trunc_sat_f32_u',
+        'i64.trunc_sat_f64_s',
+        'i64.trunc_sat_f64_u',
         // exceptions
         // exceptions
         'try','catch','catch_all','delegate','throw','rethrow','end',
         'try','catch','catch_all','delegate','throw','rethrow','end',
         // atomic memory accesses - load/store
         // atomic memory accesses - load/store