-
Notifications
You must be signed in to change notification settings - Fork 1
/
ghelper.h
65 lines (52 loc) · 804 Bytes
/
ghelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
static inline u8 get_u8(void *vp)
{
u8 *p = (u8*)vp;
return *p;
}
static inline u16 get_u16(void *vp)
{
u8 *p = (u8*)vp;
u16 a;
a = p[0] << 8;
a |= p[1];
return a;
}
static inline u32 get_u32(void *vp)
{
u8 *p = (u8*)vp;
u32 a;
a = p[0] << 24;
a |= p[1] << 16;
a |= p[2] << 8;
a |= p[3] << 0;
return a;
}
static inline u64 get_u64(void *vp)
{
u8 *p = (u8*)vp;
u32 a, b;
a = get_u32(p);
b = get_u32(p + 4);
return ((u64)a<<32) | b;
}
static inline void set_u16(void *vp, u16 v)
{
u8 *p = (u8*)vp;
p[0] = v >> 8;
p[1] = v;
}
static inline void set_u32(void *vp, u32 v)
{
u8 *p = (u8*)vp;
p[0] = v >> 24;
p[1] = v >> 16;
p[2] = v >> 8;
p[3] = v;
}
static inline void set_u64(void *vp, u64 v)
{
u8 *p = (u8*)vp;
set_u32(p + 4, v);
v >>= 32;
set_u32(p, v);
}