瀏覽代碼

* avoid unnecessary sign/zero-extensions in genlinearlist() when generating
code on a platform that doesn't have subregisters of the same size as
the "case" value

git-svn-id: trunk@30031 -

Jonas Maebe 10 年之前
父節點
當前提交
33b1732ca2
共有 1 個文件被更改,包括 19 次插入0 次删除
  1. 19 0
      compiler/ncgset.pas

+ 19 - 0
compiler/ncgset.pas

@@ -538,6 +538,8 @@ implementation
          first : boolean;
          last : TConstExprInt;
          scratch_reg: tregister;
+         newsize: tcgsize;
+         newdef: tdef;
 
       procedure genitem(t : pcaselabel);
 
@@ -603,6 +605,23 @@ implementation
            genlinearcmplist(hp)
          else
            begin
+              { sign/zero extend the value to a full register before starting to
+                subtract values, so that on platforms that don't have
+                subregisters of the same size as the value we don't generate
+                sign/zero-extensions after every subtraction
+
+                make newsize always signed, since we only do this if the size in
+                bytes of the register is larger than the original opsize, so
+                the value can always be represented by a larger signed type }
+              newsize:=tcgsize2signed[reg_cgsize(hregister)];
+              if tcgsize2size[newsize]>opsize.size then
+                begin
+                  newdef:=cgsize_orddef(newsize);
+                  scratch_reg:=hlcg.getintregister(current_asmdata.CurrAsmList,newdef);
+                  hlcg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,newdef,hregister,scratch_reg);
+                  hregister:=scratch_reg;
+                  opsize:=newdef;
+                end;
               last:=0;
               first:=true;
               scratch_reg:=hlcg.getintregister(current_asmdata.CurrAsmList,opsize);