From af6f094420ed14879988f06cbc1c3bf77357fddf Mon Sep 17 00:00:00 2001 From: svenbarth Date: Wed, 20 Jun 2018 21:10:19 +0000 Subject: [PATCH] + add reverse_longword() function that reverses the bit pattern for a longword, just like reverse_byte() and reverse_word() do for Byte and Word respectively git-svn-id: trunk@39264 - --- compiler/cutils.pas | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/compiler/cutils.pas b/compiler/cutils.pas index 72fd71ddad..db195ce61c 100644 --- a/compiler/cutils.pas +++ b/compiler/cutils.pas @@ -69,6 +69,8 @@ interface function reverse_byte(b: byte): byte; {# Return @var(w) with the bit order reversed } function reverse_word(w: word): word; + {# Return @var(l) with the bit order reversed } + function reverse_longword(l: longword): longword; function next_prime(l: longint): longint; @@ -292,6 +294,21 @@ implementation TWordRec(reverse_word).lo := reverse_byte(TWordRec(w).hi); end; + + function reverse_longword(l: longword): longword; + type + TLongWordRec = packed record + b: array[0..3] of Byte; + end; + + begin + TLongWordRec(reverse_longword).b[0] := reverse_byte(TLongWordRec(l).b[3]); + TLongWordRec(reverse_longword).b[1] := reverse_byte(TLongWordRec(l).b[2]); + TLongWordRec(reverse_longword).b[2] := reverse_byte(TLongWordRec(l).b[1]); + TLongWordRec(reverse_longword).b[3] := reverse_byte(TLongWordRec(l).b[0]); + end; + + function align(i,a:longint):longint;{$ifdef USEINLINE}inline;{$endif} { return value aligned boundary