Browse Source

+ utility function to reverse the bit pattern of a Word

git-svn-id: trunk@35266 -
svenbarth 8 years ago
parent
commit
62fc960e63
1 changed files with 13 additions and 0 deletions
  1. 13 0
      compiler/cutils.pas

+ 13 - 0
compiler/cutils.pas

@@ -65,6 +65,8 @@ interface
     function newalignment(oldalignment: longint; offset: int64): longint;
     function newalignment(oldalignment: longint; offset: int64): longint;
     {# Return @var(b) with the bit order reversed }
     {# Return @var(b) with the bit order reversed }
     function reverse_byte(b: byte): byte;
     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;
     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];
         reverse_byte:=(reverse_nible[b and $f] shl 4) or reverse_nible[b shr 4];
       end;
       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}
     function align(i,a:longint):longint;{$ifdef USEINLINE}inline;{$endif}
     {
     {
       return value <i> aligned <a> boundary
       return value <i> aligned <a> boundary