2
0
Эх сурвалжийг харах

* fixes in thlcgwasm.resize_stack_int_val

git-svn-id: branches/wasm@47974 -
nickysn 4 жил өмнө
parent
commit
fc95e7f22d

+ 1 - 0
compiler/wasm32/cpubase.pas

@@ -69,6 +69,7 @@ uses
       a_f32_le, a_f64_le, a_f32_gt, a_f64_gt, a_f32_ge, a_f64_ge,
       // conversion
       a_i32_wrap_i64, a_i64_extend_s_i32, a_i64_extend_u_i32,
+      a_i32_extend_s_8,a_i32_extend_s_16,a_i64_extend_s_8,a_i64_extend_s_16,a_i64_extend_s_32,
       a_i32_trunc_s_f32, a_i32_trunc_s_f64, a_i64_trunc_s_f32, a_i64_trunc_s_f64,
       a_i32_trunc_u_f32, a_i32_trunc_u_f64, a_i64_trunc_u_f32, a_i64_trunc_u_f64,
       a_f32_demote_f64, a_f64_promote_f32,

+ 30 - 41
compiler/wasm32/hlcgcpu.pas

@@ -2245,13 +2245,26 @@ implementation
       else if tocgsize in [OS_S64,OS_64] then
         begin
           { extend }
-          if tocgsize = OS_S64 then
-            list.concat(taicpu.op_none(a_i64_extend_s_i32))
-          else
-            list.concat(taicpu.op_none(a_i64_extend_u_i32));
-          { if it was an unsigned 32 bit value, remove sign extension }
-          if fromcgsize=OS_32 then
-            a_op_const_stack(list,OP_AND,s64inttype,cardinal($ffffffff));
+          case fromcgsize of
+            OS_8:
+              begin
+                a_op_const_stack(list,OP_AND,s32inttype,255);
+                list.concat(taicpu.op_none(a_i64_extend_u_i32));
+              end;
+            OS_S8:
+              list.concat(taicpu.op_none(a_i64_extend_s_8));
+            OS_16:
+              begin
+                a_op_const_stack(list,OP_AND,s32inttype,65535);
+                list.concat(taicpu.op_none(a_i64_extend_u_i32));
+              end;
+            OS_S16:
+              list.concat(taicpu.op_none(a_i64_extend_s_16));
+            OS_32:
+              list.concat(taicpu.op_none(a_i64_extend_u_i32));
+            OS_S32:
+              list.concat(taicpu.op_none(a_i64_extend_s_i32))
+          end;
         end;
       { Conversions between 32 and 64 bit types have been completely handled
         above. We still may have to truncate or sign extend in case the
@@ -2259,40 +2272,16 @@ implementation
         sign. In case the destination is a widechar and the source is not, we
         also have to insert a conversion to widechar.
        }
-      if (not(fromcgsize in [OS_S64,OS_64,OS_32,OS_S32]) or
-          not(tocgsize in [OS_S64,OS_64,OS_32,OS_S32])) and
-         ((tcgsize2size[fromcgsize]>tcgsize2size[tocgsize]) or
-          ((tcgsize2size[fromcgsize]=tcgsize2size[tocgsize]) and
-           (fromcgsize<>tocgsize)) or
-          { needs to mask out the sign in the top 16 bits }
-          ((fromcgsize=OS_S8) and
-           (tocgsize=OS_16)) or
-          ((tosize=cwidechartype) and
-           (fromsize<>cwidechartype))) then
-        case tocgsize of
-          OS_8:
-            //todo: conversion
-            //a_op_const_stack(list,OP_AND,s32inttype,255);
-            ;
-          OS_S8:
-            //todo: conversion
-            //list.concat(taicpu.op_none(a_i2b));
-            ;
-          OS_16:
-            //todo: conversion
-            //if (tosize.typ=orddef) and
-            //   (torddef(tosize).ordtype=uwidechar) then
-            //  list.concat(taicpu.op_none(a_i2c))
-            //else
-            //  a_op_const_stack(list,OP_AND,s32inttype,65535);
-            ;
-          OS_S16:
-            //todo: conversion
-            //list.concat(taicpu.op_none(a_i2s));
-            ;
-          else
-            ;
-        end;
+      case fromcgsize of
+        OS_8:
+          a_op_const_stack(list,OP_AND,s32inttype,255);
+        OS_S8:
+          list.concat(taicpu.op_none(a_i32_extend_s_8));
+        OS_16:
+          a_op_const_stack(list,OP_AND,s32inttype,65535);
+        OS_S16:
+          list.concat(taicpu.op_none(a_i32_extend_s_16));
+      end;
     end;
 
     procedure thlcgwasm.maybe_resize_stack_para_val(list: TAsmList; retdef: tdef; callside: boolean);

+ 2 - 1
compiler/wasm32/itcpugas.pas

@@ -67,7 +67,8 @@ interface
       'f32.eq', 'f64.eq', 'f32.ne', 'f64.ne', 'f32.lt', 'f64.lt',
       'f32.le', 'f64.le', 'f32.gt', 'f64.gt', 'f32.ge', 'f64.gt',
       // conversion
-      'i32.wrap/i64', 'i64.extend_s/i32', 'i64.extend_u/i32',
+      'i32.wrap_i64', 'i64.extend_i32_s', 'i64.extend_i32_u',
+      'i32.extend8_s','i32.extend16_s','i64.extend8_s','i64.extend16_s','i64.extend32_s',
       'i32.trunc_s/f32', 'i32.trunc_s/f64', 'i64.trunc_s/f32', 'i64.trunc_s/f64',
       'i32.trunc_u/f32', 'i32.trunc_u/f64', 'i64.trunc_u/f32', 'i64.trunc_u/f64',
       'f32.demote/f64', 'f64.promote/f32',

+ 1 - 1
compiler/wasm32/nwasmmat.pas

@@ -130,7 +130,7 @@ implementation
                (torddef(resultdef).ordtype=s64bit) then
               begin
                 current_asmdata.CurrAsmList.concat(taicpu.op_none(a_i64_rem_s));
-                thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,2);
+                thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
               end
             else
               begin

+ 1 - 0
compiler/wasm32/strinst.inc

@@ -52,6 +52,7 @@
         'f32.le', 'f64.le', 'f32.gt', 'f64.gt', 'f32.ge', 'f64.gt',
         // conversion
         'i32.wrap/i64', 'i64.extend_s/i32', 'i64.extend_u/i32',
+        'i32.extend_s/8','i32.extend_s/16','i64.extend_s/8','i64.extend_s/16','i64.extend_s/32',
         'i32.trunc_s/f32', 'i32.trunc_s/f64', 'i64.trunc_s/f32', 'i64.trunc_s/f64',
         'i32.trunc_u/f32', 'i32.trunc_u/f64', 'i64.trunc_u/f32', 'i64.trunc_u/f64',
         'f32.demote/f64', 'f64.promote/f32',