diff options
author | Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> | 2021-06-25 07:53:57 +0100 |
---|---|---|
committer | Philippe Mathieu-Daudé <f4bug@amsat.org> | 2021-07-02 17:35:08 +0200 |
commit | db1ffc32dd0d32ef476c00637efc888ecea8466c (patch) | |
tree | 1c2d4f54a61a3b3833e3bb7da2e4830fffdd4f05 /include | |
parent | c3250c8e6b3158f9b55bfc457c4e7a940b59d2b0 (diff) | |
download | qemu-db1ffc32dd0d32ef476c00637efc888ecea8466c.zip qemu-db1ffc32dd0d32ef476c00637efc888ecea8466c.tar.gz qemu-db1ffc32dd0d32ef476c00637efc888ecea8466c.tar.bz2 |
qemu/bitops.h: add bitrev8 implementation
This will be required for an upcoming checksum calculation.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Tested-by: Finn Thain <fthain@linux-m68k.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20210625065401.30170-7-mark.cave-ayland@ilande.co.uk>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/qemu/bitops.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 03213ce..110c56e 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -618,4 +618,26 @@ static inline uint64_t half_unshuffle64(uint64_t x) return x; } +/** + * bitrev8: + * @x: 8-bit value to be reversed + * + * Given an input value with bits:: + * + * ABCDEFGH + * + * return the value with its bits reversed from left to right:: + * + * HGFEDCBA + * + * Returns: the bit-reversed value. + */ +static inline uint8_t bitrev8(uint8_t x) +{ + x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); + x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); + x = (x >> 4) | (x << 4) ; + return x; +} + #endif |