ソースを参照

+ WebAssembly: added support for using saturating (non-trapping) float-to-int conversion instructions via the new target switch SATURATINGFLOATINGTOINT

Nikolay Nikolov 5 ヶ月 前
コミット
0c939ac6c6
3 ファイル変更24 行追加6 行削除
  1. 6 2
      compiler/globtype.pas
  2. 1 0
      compiler/msg/errore.msg
  3. 17 4
      compiler/wasm32/nwasminl.pas

+ 6 - 2
compiler/globtype.pas

@@ -329,7 +329,10 @@ interface
          ts_wasm_native_exceptions,
          { support multithreading via the WebAssembly threading proposal:
            https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md }
-         ts_wasm_threads
+         ts_wasm_threads,
+         { use saturating (nontrapping) float to int conversion instructions:
+           https://github.com/WebAssembly/spec/blob/main/proposals/nontrapping-float-to-int-conversion/Overview.md }
+         ts_wasm_saturating_float_to_int
        );
        ttargetswitches = set of ttargetswitch;
 
@@ -469,7 +472,8 @@ interface
          (name: 'BFEXCEPTIONS';        hasvalue: false; isglobal: true ; define: 'FPC_WASM_BRANCHFUL_EXCEPTIONS'),
          (name: 'JSEXCEPTIONS';        hasvalue: false; isglobal: true ; define: 'FPC_WASM_JS_EXCEPTIONS'),
          (name: 'WASMEXCEPTIONS';      hasvalue: false; isglobal: true ; define: 'FPC_WASM_NATIVE_EXCEPTIONS'),
-         (name: 'WASMTHREADS';         hasvalue: false; isglobal: true ; define: 'FPC_WASM_THREADS')
+         (name: 'WASMTHREADS';         hasvalue: false; isglobal: true ; define: 'FPC_WASM_THREADS'),
+         (name: 'SATURATINGFLOATTOINT';hasvalue: false; isglobal: false; define: 'FPC_WASM_SATURATING_FLOAT_TO_INT_CONVERSIONS')
        );
 
        { switches being applied to all CPUs at the given level }

+ 1 - 0
compiler/msg/errore.msg

@@ -4135,6 +4135,7 @@ W*3CTbfexceptions_        Enable the branchful exception support for WebAssembly
 W*3CTjsexceptions_        Enable the JavaScript-based exception support for WebAssembly (experimental)
 W*3CTwasmexceptions_      Enable the native WebAssembly exceptions support
 W*3CTwasmthreads_         Enable WebAssembly threads support (experimental)
+W*3CTsaturatingfloattoint_ Use saturating (non-trapping) float-to-int conversion instructions
 J*2Cv_Var/out parameter copy-out checking
 A*2CV<x>_Set section threadvar model to <x>
 **2CX_Create also smartlinked library

+ 17 - 4
compiler/wasm32/nwasminl.pas

@@ -73,6 +73,7 @@ interface
 implementation
 
     uses
+      globtype,globals,
       procinfo,
       ninl,ncal,compinnr,
       aasmbase,aasmdata,aasmcpu,
@@ -203,9 +204,15 @@ implementation
 
         case left.location.size of
           OS_F32:
-            current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f32_s));
+            if ts_wasm_saturating_float_to_int in current_settings.targetswitches then
+              current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_sat_f32_s))
+            else
+              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));
+            if ts_wasm_saturating_float_to_int in current_settings.targetswitches then
+              current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_sat_f64_s))
+            else
+              current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f64_s));
           else
             internalerror(2021092904);
         end;
@@ -227,12 +234,18 @@ implementation
           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));
+              if ts_wasm_saturating_float_to_int in current_settings.targetswitches then
+                current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_sat_f32_s))
+              else
+                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));
+              if ts_wasm_saturating_float_to_int in current_settings.targetswitches then
+                current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_sat_f64_s))
+              else
+                current_asmdata.CurrAsmList.Concat(taicpu.op_none(a_i64_trunc_f64_s));
             end
           else
             internalerror(2021092905);