Browse Source

* write elements of bitpacked arrays grouped per the number of bits that
will be used to load them afterwards instead of always per byte so we
can use that loadsize as the array element type in llvm declarations
(-> less casting required)

git-svn-id: branches/hlcgllvm@26977 -

Jonas Maebe 11 years ago
parent
commit
672c96a811
1 changed files with 18 additions and 12 deletions
  1. 18 12
      compiler/ngtcon.pas

+ 18 - 12
compiler/ngtcon.pas

@@ -350,12 +350,10 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
         inc(bp.curbitoffset,bp.packedbitsize);
         inc(bp.curbitoffset,bp.packedbitsize);
       end;
       end;
 
 
-{$pop}
-
     procedure flush_packed_value(list: tasmlist; var bp: tbitpackedval);
     procedure flush_packed_value(list: tasmlist; var bp: tbitpackedval);
       var
       var
         bitstowrite: longint;
         bitstowrite: longint;
-        writeval : byte;
+        writeval : AInt;
       begin
       begin
         if (bp.curbitoffset < AIntBits) then
         if (bp.curbitoffset < AIntBits) then
           begin
           begin
@@ -368,27 +366,35 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
             bitstowrite:=AIntBits;
             bitstowrite:=AIntBits;
             dec(bp.curbitoffset,AIntBits);
             dec(bp.curbitoffset,AIntBits);
           end;
           end;
-        while (bitstowrite>=8) do
+        while (bitstowrite>=bp.loadbitsize) do
           begin
           begin
             if (target_info.endian=endian_little) then
             if (target_info.endian=endian_little) then
               begin
               begin
-                { write lowest byte }
-                writeval:=byte(bp.curval);
-                bp.curval:=bp.curval shr 8;
+                { write lowest "loadbitsize" bits }
+                writeval:=bp.curval and (aint(-1) shr ((sizeof(aint)*8)-bp.loadbitsize));
+                bp.curval:=bp.curval shr bp.loadbitsize;
               end
               end
             else
             else
               begin
               begin
-                { write highest byte }
-                writeval:=bp.curval shr (AIntBits-8);
-                bp.curval:=(bp.curval and (not($ff shl (AIntBits-8)))) shl 8;
+                { write highest "loadbitsize" bits }
+                writeval:=bp.curval shr (AIntBits-bp.loadbitsize);
+                bp.curval:=bp.curval shl bp.loadbitsize;
               end;
               end;
-            list.concat(tai_const.create_8bit(writeval));
-            dec(bitstowrite,8);
+            case bp.loadbitsize of
+              8: list.concat(tai_const.create_8bit(writeval));
+              16: list.concat(tai_const.create_16bit(writeval));
+              32: list.concat(tai_const.create_32bit(writeval));
+              64: list.concat(tai_const.create_64bit(writeval));
+              else
+                internalerror(2013111101);
+            end;
+            dec(bitstowrite,bp.loadbitsize);
           end;
           end;
         bp.curval:=bp.nextval;
         bp.curval:=bp.nextval;
         bp.nextval:=0;
         bp.nextval:=0;
       end;
       end;
 
 
+    {$pop}
 
 
 
 
     { parses a packed array constant }
     { parses a packed array constant }