byteops.h
Go to the documentation of this file.
1 /*
2  * RoboPeak Project
3  * Copyright 2009 - 2013
4  *
5  * RPOS - Byte Operations
6  *
7  */
8 
9 #pragma once
10 
11 // byte swapping operations for compiling time
12 
13 #define __static_byteswap_16(x) ((_u16)( \
14  (((_u16)(x) & (_u16)0x00FFU) << 8) | \
15  (((_u16)(x) & (_u16)0xFF00U) >> 8)))
16 
17 #define __static_byteswap_32(x) ((_u32)( \
18  (((_u32)(x) & (_u32)0x000000FFUL) << 24) | \
19  (((_u32)(x) & (_u32)0x0000FF00UL) << 8) | \
20  (((_u32)(x) & (_u32)0x00FF0000UL) >> 8) | \
21  (((_u32)(x) & (_u32)0xFF000000UL) >> 24)))
22 
23 #define __static_byteswap_64(x) ((_u64)( \
24  (((_u64)(x) & (_u64)0x00000000000000ffULL) << 56) | \
25  (((_u64)(x) & (_u64)0x000000000000ff00ULL) << 40) | \
26  (((_u64)(x) & (_u64)0x0000000000ff0000ULL) << 24) | \
27  (((_u64)(x) & (_u64)0x00000000ff000000ULL) << 8) | \
28  (((_u64)(x) & (_u64)0x000000ff00000000ULL) >> 8) | \
29  (((_u64)(x) & (_u64)0x0000ff0000000000ULL) >> 24) | \
30  (((_u64)(x) & (_u64)0x00ff000000000000ULL) >> 40) | \
31  (((_u64)(x) & (_u64)0xff00000000000000ULL) >> 56)))
32 
33 
34 #define __fast_swap(a, b) do { (a) ^= (b); (b) ^= (a); (a) ^= (b); } while(0)
35 
36 
37 static inline _u16 __byteswap_16(_u16 x)
38 {
39 #ifdef __arch_byteswap_16
40  return __arch_byteswap_16(x);
41 #else
42  return __static_byteswap_16(x);
43 #endif
44 }
45 
46 static inline _u32 __byteswap_32(_u32 x)
47 {
48 #ifdef __arch_byteswap_32
49  return __arch_byteswap_32(x);
50 #else
51  return __static_byteswap_32(x);
52 #endif
53 }
54 
55 static inline _u64 __byteswap_64(_u64 x)
56 {
57 #ifdef __arch_byteswap_64
58  return __arch_byteswap_64(x);
59 #else
60  return __static_byteswap_64(x);
61 #endif
62 }
63 
64 
65 #ifdef float
66 static inline float __byteswap_float(float x)
67 {
68 #ifdef __arch_byteswap_float
69  return __arch_byteswap_float(x);
70 #else
71  _u8 * raw = (_u8 *)&x;
72  __fast_swap(raw[0], raw[3]);
73  __fast_swap(raw[1], raw[2]);
74  return x;
75 #endif
76 }
77 #endif
78 
79 
80 #ifdef double
81 static inline double __byteswap_double(double x)
82 {
83 #ifdef __arch_byteswap_double
84  return __arch_byteswap_double(x);
85 #else
86  _u8 * raw = (_u8 *)&x;
87  __fast_swap(raw[0], raw[7]);
88  __fast_swap(raw[1], raw[6]);
89  __fast_swap(raw[2], raw[5]);
90  __fast_swap(raw[3], raw[4]);
91  return x;
92 #endif
93 }
94 #endif
static _u64 __byteswap_64(_u64 x)
Definition: byteops.h:55
#define __fast_swap(a, b)
Definition: byteops.h:34
uint8_t _u8
Definition: rptypes.h:63
#define __static_byteswap_64(x)
Definition: byteops.h:23
#define __static_byteswap_16(x)
Definition: byteops.h:13
uint32_t _u32
Definition: rptypes.h:69
static _u32 __byteswap_32(_u32 x)
Definition: byteops.h:46
#define __static_byteswap_32(x)
Definition: byteops.h:17
uint64_t _u64
Definition: rptypes.h:72
uint16_t _u16
Definition: rptypes.h:66
static _u16 __byteswap_16(_u16 x)
Definition: byteops.h:37


rplidar_ros
Author(s):
autogenerated on Wed Jan 1 2020 04:01:40