GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
include
core
gp_get_set_bits.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: LGPL-2.1-or-later
2
/*
3
* Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz>
4
* Copyright (C) 2011-2024 Cyril Hrubis <metan@ucw.cz>
5
*/
6
22
#ifndef CORE_GP_GET_SET_BITS_H
23
#define CORE_GP_GET_SET_BITS_H
24
34
#define GP_GET_BITS(offset, len, val) \
35
(sizeof(val) * 8 <= len ? \
36
(val)>>(offset) : \
37
((val)>>(offset)) & (((((typeof(val))1)<<(len)) - 1)))
38
48
#define GP_GET_BITS4_ALIGNED(offset, len, buf) ({ \
49
uint32_t v; \
50
v = ((uint8_t *)buf)[0]; \
51
v |= ((uint8_t *)buf)[1]<<8; \
52
v |= ((uint8_t *)buf)[2]<<16; \
53
v |= ((uint8_t *)buf)[3]<<24; \
54
\
55
GP_GET_BITS(offset, len, v); \
56
})
57
67
#define GP_GET_BITS3_ALIGNED(offset, len, buf) ({ \
68
uint32_t v; \
69
v = ((uint8_t *)buf)[0]; \
70
v |= ((uint8_t *)buf)[1]<<8; \
71
v |= ((uint8_t *)buf)[2]<<16; \
72
\
73
GP_GET_BITS(offset, len, v); \
74
})
75
85
#define GP_GET_BITS2_ALIGNED(offset, len, buf) ({ \
86
uint16_t v; \
87
v = ((uint8_t *)buf)[0]; \
88
v |= ((uint8_t *)buf)[1]<<8; \
89
\
90
GP_GET_BITS(offset, len, v); \
91
})
92
102
#define GP_GET_BITS1_ALIGNED(offset, len, buf) ({ \
103
uint8_t v; \
104
v = ((uint8_t *)buf)[0]; \
105
\
106
GP_GET_BITS(offset, len, v); \
107
})
108
119
#define GP_CLEAR_BITS(offset, len, dest) \
120
((dest) &= ~(((((typeof(dest))1) << (len)) - 1) << (offset)))
121
133
#define GP_SET_BITS(offset, len, dest, val) do { \
134
GP_CLEAR_BITS(offset, len, dest); \
135
((dest) |= ((val)<<(offset))); \
136
} while (0)
137
149
#define GP_SET_BITS1_ALIGNED(offset, len, dest, val) do { \
150
uint8_t v = ((uint8_t *)dest)[0]; \
151
GP_SET_BITS(offset, len, v, val); \
152
((uint8_t *)dest)[0] = v; \
153
} while (0)
154
166
#define GP_SET_BITS2_ALIGNED(offset, len, dest, val) do { \
167
uint16_t v; \
168
v = ((uint8_t *)dest)[0]; \
169
v |= ((uint8_t *)dest)[1]<<8; \
170
\
171
GP_SET_BITS(offset, len, v, val); \
172
\
173
((uint8_t *)dest)[0] = 0xff & v; \
174
((uint8_t *)dest)[1] = 0xff & (v >> 8); \
175
} while (0)
176
188
#define GP_SET_BITS3_ALIGNED(offset, len, dest, val) do { \
189
uint32_t v; \
190
v = ((uint8_t *)dest)[0]; \
191
v |= ((uint8_t *)dest)[1]<<8; \
192
v |= ((uint8_t *)dest)[2]<<16; \
193
\
194
GP_SET_BITS(offset, len, v, val); \
195
\
196
((uint8_t *)dest)[0] = 0xff & v; \
197
((uint8_t *)dest)[1] = 0xff & (v >> 8); \
198
((uint8_t *)dest)[2] = 0xff & (v >> 16); \
199
} while (0)
200
212
#define GP_SET_BITS4_ALIGNED(offset, len, dest, val) do { \
213
uint32_t v; \
214
v = ((uint8_t *)dest)[0]; \
215
v |= ((uint8_t *)dest)[2]<<16; \
216
v |= ((uint8_t *)dest)[3]<<24; \
217
\
218
GP_SET_BITS(offset, len, v, val); \
219
\
220
((uint8_t *)dest)[0] = 0xff & v; \
221
((uint8_t *)dest)[1] = 0xff & (v >> 8); \
222
((uint8_t *)dest)[2] = 0xff & (v >> 16); \
223
((uint8_t *)dest)[3] = 0xff & (v >> 24); \
224
} while (0)
225
226
227
#endif
/* CORE_GP_GET_SET_BITS_H */
Generated by
1.9.8