byteops.h
Go to the documentation of this file.
00001 /*
00002  *  RoboPeak Project
00003  *  Copyright 2009 - 2013
00004  *  
00005  *  RPOS - Byte Operations
00006  *
00007  */
00008 
00009 #pragma once
00010 
00011 // byte swapping operations for compiling time
00012 
00013 #define __static_byteswap_16(x)  ((_u16)(                               \
00014         (((_u16)(x) & (_u16)0x00FFU) << 8) |                    \
00015         (((_u16)(x) & (_u16)0xFF00U) >> 8)))
00016 
00017 #define __static_byteswap_32(x) ((_u32)(                                \
00018         (((_u32)(x) & (_u32)0x000000FFUL) << 24) |              \
00019         (((_u32)(x) & (_u32)0x0000FF00UL) <<  8) |              \
00020         (((_u32)(x) & (_u32)0x00FF0000UL) >>  8) |              \
00021         (((_u32)(x) & (_u32)0xFF000000UL) >> 24)))
00022 
00023 #define __static_byteswap_64(x) ((_u64)(                                \
00024         (((_u64)(x) & (_u64)0x00000000000000ffULL) << 56) |     \
00025         (((_u64)(x) & (_u64)0x000000000000ff00ULL) << 40) |     \
00026         (((_u64)(x) & (_u64)0x0000000000ff0000ULL) << 24) |     \
00027         (((_u64)(x) & (_u64)0x00000000ff000000ULL) <<  8) |     \
00028         (((_u64)(x) & (_u64)0x000000ff00000000ULL) >>  8) |     \
00029         (((_u64)(x) & (_u64)0x0000ff0000000000ULL) >> 24) |     \
00030         (((_u64)(x) & (_u64)0x00ff000000000000ULL) >> 40) |     \
00031         (((_u64)(x) & (_u64)0xff00000000000000ULL) >> 56)))
00032 
00033 
00034 #define __fast_swap(a, b) do { (a) ^= (b); (b) ^= (a); (a) ^= (b); } while(0)
00035 
00036 
00037 static inline _u16 __byteswap_16(_u16 x)
00038 {
00039 #ifdef __arch_byteswap_16
00040     return __arch_byteswap_16(x);
00041 #else
00042     return __static_byteswap_16(x);
00043 #endif
00044 }
00045 
00046 static inline _u32 __byteswap_32(_u32 x)
00047 {
00048 #ifdef __arch_byteswap_32
00049     return __arch_byteswap_32(x);
00050 #else
00051     return __static_byteswap_32(x);
00052 #endif
00053 }
00054 
00055 static inline _u64 __byteswap_64(_u64 x)
00056 {
00057 #ifdef __arch_byteswap_64
00058     return __arch_byteswap_64(x);
00059 #else
00060     return __static_byteswap_64(x);
00061 #endif
00062 }
00063 
00064 
00065 #ifdef float
00066 static inline float __byteswap_float(float x)
00067 {
00068 #ifdef __arch_byteswap_float
00069     return __arch_byteswap_float(x);
00070 #else
00071     _u8 * raw = (_u8 *)&x;
00072     __fast_swap(raw[0], raw[3]);
00073     __fast_swap(raw[1], raw[2]);
00074     return x;
00075 #endif
00076 }
00077 #endif
00078 
00079 
00080 #ifdef double
00081 static inline double __byteswap_double(double x)
00082 {
00083 #ifdef __arch_byteswap_double
00084     return __arch_byteswap_double(x);
00085 #else
00086     _u8 * raw = (_u8 *)&x;
00087     __fast_swap(raw[0], raw[7]);
00088     __fast_swap(raw[1], raw[6]);
00089     __fast_swap(raw[2], raw[5]);
00090     __fast_swap(raw[3], raw[4]);
00091     return x;
00092 #endif
00093 }
00094 #endif


rplidar_ros
Author(s):
autogenerated on Mon Mar 18 2019 02:34:23