iPXE
rotate.h
Go to the documentation of this file.
00001 #ifndef _IPXE_ROTATE_H
00002 #define _IPXE_ROTATE_H
00003 
00004 /** @file
00005  *
00006  * Bit operations
00007  */
00008 
00009 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00010 
00011 #include <stdint.h>
00012 
00013 static inline __attribute__ (( always_inline )) uint8_t
00014 rol8 ( uint8_t data, unsigned int rotation ) {
00015         return ( ( data << rotation ) | ( data >> ( 8 - rotation ) ) );
00016 }
00017 
00018 static inline __attribute__ (( always_inline )) uint8_t
00019 ror8 ( uint8_t data, unsigned int rotation ) {
00020         return ( ( data >> rotation ) | ( data << ( 8 - rotation ) ) );
00021 }
00022 
00023 static inline __attribute__ (( always_inline )) uint16_t
00024 rol16 ( uint16_t data, unsigned int rotation ) {
00025         return ( ( data << rotation ) | ( data >> ( 16 - rotation ) ) );
00026 }
00027 
00028 static inline __attribute__ (( always_inline )) uint16_t
00029 ror16 ( uint16_t data, unsigned int rotation ) {
00030         return ( ( data >> rotation ) | ( data << ( 16 - rotation ) ) );
00031 }
00032 
00033 static inline __attribute__ (( always_inline )) uint32_t
00034 rol32 ( uint32_t data, unsigned int rotation ) {
00035         return ( ( data << rotation ) | ( data >> ( 32 - rotation ) ) );
00036 }
00037 
00038 static inline __attribute__ (( always_inline )) uint32_t
00039 ror32 ( uint32_t data, unsigned int rotation ) {
00040         return ( ( data >> rotation ) | ( data << ( 32 - rotation ) ) );
00041 }
00042 
00043 static inline __attribute__ (( always_inline )) uint64_t
00044 rol64 ( uint64_t data, unsigned int rotation ) {
00045         return ( ( data << rotation ) | ( data >> ( 64 - rotation ) ) );
00046 }
00047 
00048 static inline __attribute__ (( always_inline )) uint64_t
00049 ror64 ( uint64_t data, unsigned int rotation ) {
00050         return ( ( data >> rotation ) | ( data << ( 64 - rotation ) ) );
00051 }
00052 
00053 #endif /* _IPXE_ROTATE_H */