Преглед изворни кода

+ utility function to reverse the bit pattern of a Word

git-svn-id: trunk@35266 -
svenbarth пре 8 година
родитељ
комит
62fc960e63
1 измењених фајлова са 13 додато и 0 уклоњено
  1. 13 0
      compiler/cutils.pas

+ 13 - 0
compiler/cutils.pas

@@ -65,6 +65,8 @@ interface
     function newalignment(oldalignment: longint; offset: int64): longint;
     {# Return @var(b) with the bit order reversed }
     function reverse_byte(b: byte): byte;
+    {# Return @var(w) with the bit order reversed }
+    function reverse_word(w: word): word;
 
     function next_prime(l: longint): longint;
 
@@ -273,6 +275,17 @@ implementation
         reverse_byte:=(reverse_nible[b and $f] shl 4) or reverse_nible[b shr 4];
       end;
 
+    function reverse_word(w: word): word;
+      type
+        TWordRec = packed record
+          hi, lo: Byte;
+        end;
+
+      begin
+        TWordRec(reverse_word).hi := reverse_byte(TWordRec(w).lo);
+        TWordRec(reverse_word).lo := reverse_byte(TWordRec(w).hi);
+      end;
+
     function align(i,a:longint):longint;{$ifdef USEINLINE}inline;{$endif}
     {
       return value <i> aligned <a> boundary