compiler warning cleanup: is_signed_type: compare -1 to 1
[babeltrace.git] / src / compat / bitfield.h
CommitLineData
6dc2ca62 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
6dc2ca62 3 *
0235b0db 4 * Copyright 2010-2019 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6dc2ca62
MD
5 */
6
0235b0db
MJ
7#ifndef _BABELTRACE_BITFIELD_H
8#define _BABELTRACE_BITFIELD_H
9
6dc2ca62 10#include <stdint.h> /* C99 5.2.4.2 Numerical limits */
fd2c04ed 11#include <stdbool.h> /* C99 7.16 bool type */
578e048b
MJ
12#include "compat/limits.h" /* C99 5.2.4.2 Numerical limits */
13#include "compat/endian.h" /* Non-standard BIG_ENDIAN, LITTLE_ENDIAN, BYTE_ORDER */
6dc2ca62 14
7f140ae8
MD
15/*
16 * This header strictly follows the C99 standard, except for use of the
17 * compiler-specific __typeof__.
18 */
19
20/*
21 * This bitfield header requires the compiler representation of signed
22 * integers to be two's complement.
23 */
24#if (-1 != ~0)
25#error "bitfield.h requires the compiler representation of signed integers to be two's complement."
26#endif
08228826 27
534d93a8 28#define _bt_is_signed_type(type) ((type) -1 < (type) 1)
08228826 29
a2d16120 30/*
7f140ae8
MD
31 * Produce a build-time error if the condition `cond` is non-zero.
32 * Evaluates as a size_t expression.
33 */
f0c01bee
SM
34#ifdef __cplusplus
35#define _BT_BUILD_ASSERT(cond) ([]{static_assert((cond), "");}, 0)
36#else
7f140ae8
MD
37#define _BT_BUILD_ASSERT(cond) \
38 sizeof(struct { int f:(2 * !!(cond) - 1); })
f0c01bee 39#endif
7f140ae8
MD
40
41/*
42 * Cast value `v` to an unsigned integer of the same size as `v`.
43 */
44#define _bt_cast_value_to_unsigned(v) \
45 (sizeof(v) == sizeof(uint8_t) ? (uint8_t) (v) : \
46 sizeof(v) == sizeof(uint16_t) ? (uint16_t) (v) : \
47 sizeof(v) == sizeof(uint32_t) ? (uint32_t) (v) : \
48 sizeof(v) == sizeof(uint64_t) ? (uint64_t) (v) : \
49 _BT_BUILD_ASSERT(sizeof(v) <= sizeof(uint64_t)))
50
51/*
52 * Cast value `v` to an unsigned integer type of the size of type `type`
53 * *without* sign-extension.
54 *
55 * The unsigned cast ensures that we're not shifting a negative value,
56 * which is undefined in C. However, this limits the maximum type size
57 * of `type` to 64-bit. Generate a compile-time error if the size of
58 * `type` is larger than 64-bit.
59 */
60#define _bt_cast_value_to_unsigned_type(type, v) \
61 (sizeof(type) == sizeof(uint8_t) ? \
62 (uint8_t) _bt_cast_value_to_unsigned(v) : \
63 sizeof(type) == sizeof(uint16_t) ? \
64 (uint16_t) _bt_cast_value_to_unsigned(v) : \
65 sizeof(type) == sizeof(uint32_t) ? \
66 (uint32_t) _bt_cast_value_to_unsigned(v) : \
67 sizeof(type) == sizeof(uint64_t) ? \
68 (uint64_t) _bt_cast_value_to_unsigned(v) : \
69 _BT_BUILD_ASSERT(sizeof(v) <= sizeof(uint64_t)))
70
71/*
72 * _bt_fill_mask evaluates to a "type" integer with all bits set.
73 */
74#define _bt_fill_mask(type) ((type) ~(type) 0)
75
76/*
77 * Left shift a value `v` of `shift` bits.
78 *
79 * The type of `v` can be signed or unsigned integer.
80 * The value of `shift` must be less than the size of `v` (in bits),
81 * otherwise the behavior is undefined.
82 * Evaluates to the result of the shift operation.
83 *
84 * According to the C99 standard, left shift of a left hand-side signed
85 * type is undefined if it has a negative value or if the result cannot
86 * be represented in the result type. This bitfield header discards the
87 * bits that are left-shifted beyond the result type representation,
88 * which is the behavior of an unsigned type left shift operation.
89 * Therefore, always perform left shift on an unsigned type.
90 *
91 * This macro should not be used if `shift` can be greater or equal than
92 * the bitwidth of `v`. See `_bt_safe_lshift`.
93 */
94#define _bt_lshift(v, shift) \
95 ((__typeof__(v)) (_bt_cast_value_to_unsigned(v) << (shift)))
96
97/*
98 * Generate a mask of type `type` with the `length` least significant bits
99 * cleared, and the most significant bits set.
a2d16120 100 */
7f140ae8
MD
101#define _bt_make_mask_complement(type, length) \
102 _bt_lshift(_bt_fill_mask(type), length)
08228826 103
7f140ae8
MD
104/*
105 * Generate a mask of type `type` with the `length` least significant bits
106 * set, and the most significant bits cleared.
107 */
108#define _bt_make_mask(type, length) \
109 ((type) ~_bt_make_mask_complement(type, length))
110
111/*
112 * Right shift a value `v` of `shift` bits.
113 *
114 * The type of `v` can be signed or unsigned integer.
115 * The value of `shift` must be less than the size of `v` (in bits),
116 * otherwise the behavior is undefined.
117 * Evaluates to the result of the shift operation.
118 *
119 * According to the C99 standard, right shift of a left hand-side signed
120 * type which has a negative value is implementation defined. This
121 * bitfield header relies on the right shift implementation carrying the
122 * sign bit. If the compiler implementation has a different behavior,
123 * emulate carrying the sign bit.
124 *
125 * This macro should not be used if `shift` can be greater or equal than
126 * the bitwidth of `v`. See `_bt_safe_rshift`.
127 */
128#if ((-1 >> 1) == -1)
129#define _bt_rshift(v, shift) ((v) >> (shift))
130#else
131#define _bt_rshift(v, shift) \
132 ((__typeof__(v)) ((_bt_cast_value_to_unsigned(v) >> (shift)) | \
133 ((v) < 0 ? _bt_make_mask_complement(__typeof__(v), \
134 sizeof(v) * CHAR_BIT - (shift)) : 0)))
135#endif
136
137/*
138 * Right shift a signed or unsigned integer with `shift` value being an
139 * arbitrary number of bits. `v` is modified by this macro. The shift
140 * is transformed into a sequence of `_nr_partial_shifts` consecutive
141 * shift operations, each of a number of bits smaller than the bitwidth
142 * of `v`, ending with a shift of the number of left over bits.
143 */
144#define _bt_safe_rshift(v, shift) \
145do { \
146 unsigned long _nr_partial_shifts = (shift) / (sizeof(v) * CHAR_BIT - 1); \
147 unsigned long _leftover_bits = (shift) % (sizeof(v) * CHAR_BIT - 1); \
148 \
149 for (; _nr_partial_shifts; _nr_partial_shifts--) \
150 (v) = _bt_rshift(v, sizeof(v) * CHAR_BIT - 1); \
151 (v) = _bt_rshift(v, _leftover_bits); \
152} while (0)
153
154/*
155 * Left shift a signed or unsigned integer with `shift` value being an
156 * arbitrary number of bits. `v` is modified by this macro. The shift
157 * is transformed into a sequence of `_nr_partial_shifts` consecutive
158 * shift operations, each of a number of bits smaller than the bitwidth
159 * of `v`, ending with a shift of the number of left over bits.
160 */
161#define _bt_safe_lshift(v, shift) \
162do { \
163 unsigned long _nr_partial_shifts = (shift) / (sizeof(v) * CHAR_BIT - 1); \
164 unsigned long _leftover_bits = (shift) % (sizeof(v) * CHAR_BIT - 1); \
165 \
166 for (; _nr_partial_shifts; _nr_partial_shifts--) \
167 (v) = _bt_lshift(v, sizeof(v) * CHAR_BIT - 1); \
168 (v) = _bt_lshift(v, _leftover_bits); \
169} while (0)
a2d16120 170
6dc2ca62 171/*
d79865b9 172 * bt_bitfield_write - write integer to a bitfield in native endianness
6dc2ca62
MD
173 *
174 * Save integer to the bitfield, which starts at the "start" bit, has "len"
175 * bits.
176 * The inside of a bitfield is from high bits to low bits.
177 * Uses native endianness.
178 * For unsigned "v", pad MSB with 0 if bitfield is larger than v.
179 * For signed "v", sign-extend v if bitfield is larger than v.
180 *
181 * On little endian, bytes are placed from the less significant to the most
182 * significant. Also, consecutive bitfields are placed from lower bits to higher
183 * bits.
184 *
185 * On big endian, bytes are places from most significant to less significant.
186 * Also, consecutive bitfields are placed from higher to lower bits.
187 */
188
a1d04c73 189#define _bt_bitfield_write_le(ptr, type, start, length, v) \
6dc2ca62 190do { \
a1d04c73
MD
191 __typeof__(v) _v = (v); \
192 type *_ptr = (void *) (ptr); \
193 unsigned long _start = (start), _length = (length); \
194 type _mask, _cmask; \
195 unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \
196 unsigned long _start_unit, _end_unit, _this_unit; \
197 unsigned long _end, _cshift; /* _cshift is "complement shift" */ \
6dc2ca62 198 \
a1d04c73 199 if (!_length) \
6dc2ca62
MD
200 break; \
201 \
a1d04c73
MD
202 _end = _start + _length; \
203 _start_unit = _start / _ts; \
204 _end_unit = (_end + (_ts - 1)) / _ts; \
6dc2ca62
MD
205 \
206 /* Trim v high bits */ \
a1d04c73
MD
207 if (_length < sizeof(_v) * CHAR_BIT) \
208 _v &= _bt_make_mask(__typeof__(_v), _length); \
6dc2ca62
MD
209 \
210 /* We can now append v with a simple "or", shift it piece-wise */ \
a1d04c73
MD
211 _this_unit = _start_unit; \
212 if (_start_unit == _end_unit - 1) { \
213 _mask = _bt_make_mask(type, _start % _ts); \
214 if (_end % _ts) \
215 _mask |= _bt_make_mask_complement(type, _end % _ts); \
216 _cmask = _bt_lshift((type) (_v), _start % _ts); \
217 _cmask &= ~_mask; \
218 _ptr[_this_unit] &= _mask; \
219 _ptr[_this_unit] |= _cmask; \
6dc2ca62
MD
220 break; \
221 } \
a1d04c73
MD
222 if (_start % _ts) { \
223 _cshift = _start % _ts; \
224 _mask = _bt_make_mask(type, _cshift); \
225 _cmask = _bt_lshift((type) (_v), _cshift); \
226 _cmask &= ~_mask; \
227 _ptr[_this_unit] &= _mask; \
228 _ptr[_this_unit] |= _cmask; \
229 _bt_safe_rshift(_v, _ts - _cshift); \
230 _start += _ts - _cshift; \
231 _this_unit++; \
6dc2ca62 232 } \
a1d04c73
MD
233 for (; _this_unit < _end_unit - 1; _this_unit++) { \
234 _ptr[_this_unit] = (type) _v; \
235 _bt_safe_rshift(_v, _ts); \
236 _start += _ts; \
6dc2ca62 237 } \
a1d04c73
MD
238 if (_end % _ts) { \
239 _mask = _bt_make_mask_complement(type, _end % _ts); \
240 _cmask = (type) _v; \
241 _cmask &= ~_mask; \
242 _ptr[_this_unit] &= _mask; \
243 _ptr[_this_unit] |= _cmask; \
6dc2ca62 244 } else \
a1d04c73 245 _ptr[_this_unit] = (type) _v; \
6dc2ca62
MD
246} while (0)
247
a1d04c73 248#define _bt_bitfield_write_be(ptr, type, start, length, v) \
6dc2ca62 249do { \
a1d04c73
MD
250 __typeof__(v) _v = (v); \
251 type *_ptr = (void *) (ptr); \
252 unsigned long _start = (start), _length = (length); \
253 type _mask, _cmask; \
254 unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \
255 unsigned long _start_unit, _end_unit, _this_unit; \
256 unsigned long _end, _cshift; /* _cshift is "complement shift" */ \
6dc2ca62 257 \
a1d04c73 258 if (!_length) \
6dc2ca62
MD
259 break; \
260 \
a1d04c73
MD
261 _end = _start + _length; \
262 _start_unit = _start / _ts; \
263 _end_unit = (_end + (_ts - 1)) / _ts; \
6dc2ca62
MD
264 \
265 /* Trim v high bits */ \
a1d04c73
MD
266 if (_length < sizeof(_v) * CHAR_BIT) \
267 _v &= _bt_make_mask(__typeof__(_v), _length); \
6dc2ca62
MD
268 \
269 /* We can now append v with a simple "or", shift it piece-wise */ \
a1d04c73
MD
270 _this_unit = _end_unit - 1; \
271 if (_start_unit == _end_unit - 1) { \
272 _mask = _bt_make_mask(type, (_ts - (_end % _ts)) % _ts); \
273 if (_start % _ts) \
274 _mask |= _bt_make_mask_complement(type, _ts - (_start % _ts)); \
275 _cmask = _bt_lshift((type) (_v), (_ts - (_end % _ts)) % _ts); \
276 _cmask &= ~_mask; \
277 _ptr[_this_unit] &= _mask; \
278 _ptr[_this_unit] |= _cmask; \
6dc2ca62
MD
279 break; \
280 } \
a1d04c73
MD
281 if (_end % _ts) { \
282 _cshift = _end % _ts; \
283 _mask = _bt_make_mask(type, _ts - _cshift); \
284 _cmask = _bt_lshift((type) (_v), _ts - _cshift); \
285 _cmask &= ~_mask; \
286 _ptr[_this_unit] &= _mask; \
287 _ptr[_this_unit] |= _cmask; \
288 _bt_safe_rshift(_v, _cshift); \
289 _end -= _cshift; \
290 _this_unit--; \
6dc2ca62 291 } \
a1d04c73
MD
292 for (; (long) _this_unit >= (long) _start_unit + 1; _this_unit--) { \
293 _ptr[_this_unit] = (type) _v; \
294 _bt_safe_rshift(_v, _ts); \
295 _end -= _ts; \
6dc2ca62 296 } \
a1d04c73
MD
297 if (_start % _ts) { \
298 _mask = _bt_make_mask_complement(type, _ts - (_start % _ts)); \
299 _cmask = (type) _v; \
300 _cmask &= ~_mask; \
301 _ptr[_this_unit] &= _mask; \
302 _ptr[_this_unit] |= _cmask; \
6dc2ca62 303 } else \
a1d04c73 304 _ptr[_this_unit] = (type) _v; \
6dc2ca62
MD
305} while (0)
306
307/*
d79865b9
MD
308 * bt_bitfield_write - write integer to a bitfield in native endianness
309 * bt_bitfield_write_le - write integer to a bitfield in little endian
310 * bt_bitfield_write_be - write integer to a bitfield in big endian
6dc2ca62
MD
311 */
312
313#if (BYTE_ORDER == LITTLE_ENDIAN)
314
a1d04c73
MD
315#define bt_bitfield_write(ptr, type, start, length, v) \
316 _bt_bitfield_write_le(ptr, type, start, length, v)
6dc2ca62 317
a1d04c73
MD
318#define bt_bitfield_write_le(ptr, type, start, length, v) \
319 _bt_bitfield_write_le(ptr, type, start, length, v)
a2d16120 320
a1d04c73
MD
321#define bt_bitfield_write_be(ptr, type, start, length, v) \
322 _bt_bitfield_write_be(ptr, unsigned char, start, length, v)
6dc2ca62
MD
323
324#elif (BYTE_ORDER == BIG_ENDIAN)
325
a1d04c73
MD
326#define bt_bitfield_write(ptr, type, start, length, v) \
327 _bt_bitfield_write_be(ptr, type, start, length, v)
6dc2ca62 328
a1d04c73
MD
329#define bt_bitfield_write_le(ptr, type, start, length, v) \
330 _bt_bitfield_write_le(ptr, unsigned char, start, length, v)
a2d16120 331
a1d04c73
MD
332#define bt_bitfield_write_be(ptr, type, start, length, v) \
333 _bt_bitfield_write_be(ptr, type, start, length, v)
6dc2ca62
MD
334
335#else /* (BYTE_ORDER == PDP_ENDIAN) */
336
337#error "Byte order not supported"
338
339#endif
340
a1d04c73 341#define _bt_bitfield_read_le(ptr, type, start, length, vptr) \
6dc2ca62 342do { \
a1d04c73
MD
343 __typeof__(*(vptr)) *_vptr = (vptr); \
344 __typeof__(*_vptr) _v; \
f0c01bee 345 type *_ptr = (type *) (ptr); \
a1d04c73
MD
346 unsigned long _start = (start), _length = (length); \
347 type _mask, _cmask; \
348 unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \
349 unsigned long _start_unit, _end_unit, _this_unit; \
350 unsigned long _end, _cshift; /* _cshift is "complement shift" */ \
08228826 351 \
a1d04c73
MD
352 if (!_length) { \
353 *_vptr = 0; \
08228826
MD
354 break; \
355 } \
356 \
a1d04c73
MD
357 _end = _start + _length; \
358 _start_unit = _start / _ts; \
359 _end_unit = (_end + (_ts - 1)) / _ts; \
6a7b3345 360 \
a1d04c73 361 _this_unit = _end_unit - 1; \
534d93a8 362 if (_bt_is_signed_type(__typeof__(_v)) \
a1d04c73
MD
363 && (_ptr[_this_unit] & _bt_lshift((type) 1, (_end % _ts ? _end % _ts : _ts) - 1))) \
364 _v = ~(__typeof__(_v)) 0; \
6a7b3345 365 else \
a1d04c73
MD
366 _v = 0; \
367 if (_start_unit == _end_unit - 1) { \
368 _cmask = _ptr[_this_unit]; \
369 _cmask = _bt_rshift(_cmask, _start % _ts); \
370 if ((_end - _start) % _ts) { \
371 _mask = _bt_make_mask(type, _end - _start); \
372 _cmask &= _mask; \
6a7b3345 373 } \
a1d04c73
MD
374 _bt_safe_lshift(_v, _end - _start); \
375 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \
376 *_vptr = _v; \
6a7b3345
MD
377 break; \
378 } \
a1d04c73
MD
379 if (_end % _ts) { \
380 _cshift = _end % _ts; \
381 _mask = _bt_make_mask(type, _cshift); \
382 _cmask = _ptr[_this_unit]; \
383 _cmask &= _mask; \
384 _bt_safe_lshift(_v, _cshift); \
385 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \
386 _end -= _cshift; \
387 _this_unit--; \
6a7b3345 388 } \
a1d04c73
MD
389 for (; (long) _this_unit >= (long) _start_unit + 1; _this_unit--) { \
390 _bt_safe_lshift(_v, _ts); \
391 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \
392 _end -= _ts; \
6a7b3345 393 } \
a1d04c73
MD
394 if (_start % _ts) { \
395 _mask = _bt_make_mask(type, _ts - (_start % _ts)); \
396 _cmask = _ptr[_this_unit]; \
397 _cmask = _bt_rshift(_cmask, _start % _ts); \
398 _cmask &= _mask; \
399 _bt_safe_lshift(_v, _ts - (_start % _ts)); \
400 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \
6a7b3345 401 } else { \
a1d04c73
MD
402 _bt_safe_lshift(_v, _ts); \
403 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \
6a7b3345 404 } \
a1d04c73 405 *_vptr = _v; \
08228826
MD
406} while (0)
407
a1d04c73 408#define _bt_bitfield_read_be(ptr, type, start, length, vptr) \
08228826 409do { \
a1d04c73
MD
410 __typeof__(*(vptr)) *_vptr = (vptr); \
411 __typeof__(*_vptr) _v; \
412 type *_ptr = (void *) (ptr); \
413 unsigned long _start = (start), _length = (length); \
414 type _mask, _cmask; \
415 unsigned long _ts = sizeof(type) * CHAR_BIT; /* type size */ \
416 unsigned long _start_unit, _end_unit, _this_unit; \
417 unsigned long _end, _cshift; /* _cshift is "complement shift" */ \
6dc2ca62 418 \
a1d04c73
MD
419 if (!_length) { \
420 *_vptr = 0; \
6dc2ca62 421 break; \
08228826 422 } \
6dc2ca62 423 \
a1d04c73
MD
424 _end = _start + _length; \
425 _start_unit = _start / _ts; \
426 _end_unit = (_end + (_ts - 1)) / _ts; \
6a7b3345 427 \
a1d04c73 428 _this_unit = _start_unit; \
534d93a8 429 if (_bt_is_signed_type(__typeof__(_v)) \
a1d04c73
MD
430 && (_ptr[_this_unit] & _bt_lshift((type) 1, _ts - (_start % _ts) - 1))) \
431 _v = ~(__typeof__(_v)) 0; \
6a7b3345 432 else \
a1d04c73
MD
433 _v = 0; \
434 if (_start_unit == _end_unit - 1) { \
435 _cmask = _ptr[_this_unit]; \
436 _cmask = _bt_rshift(_cmask, (_ts - (_end % _ts)) % _ts); \
437 if ((_end - _start) % _ts) { \
438 _mask = _bt_make_mask(type, _end - _start); \
439 _cmask &= _mask; \
6a7b3345 440 } \
a1d04c73
MD
441 _bt_safe_lshift(_v, _end - _start); \
442 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \
443 *_vptr = _v; \
6a7b3345
MD
444 break; \
445 } \
a1d04c73
MD
446 if (_start % _ts) { \
447 _cshift = _start % _ts; \
448 _mask = _bt_make_mask(type, _ts - _cshift); \
449 _cmask = _ptr[_this_unit]; \
450 _cmask &= _mask; \
451 _bt_safe_lshift(_v, _ts - _cshift); \
452 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \
453 _start += _ts - _cshift; \
454 _this_unit++; \
6a7b3345 455 } \
a1d04c73
MD
456 for (; _this_unit < _end_unit - 1; _this_unit++) { \
457 _bt_safe_lshift(_v, _ts); \
458 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \
459 _start += _ts; \
6a7b3345 460 } \
a1d04c73
MD
461 if (_end % _ts) { \
462 _mask = _bt_make_mask(type, _end % _ts); \
463 _cmask = _ptr[_this_unit]; \
464 _cmask = _bt_rshift(_cmask, _ts - (_end % _ts)); \
465 _cmask &= _mask; \
466 _bt_safe_lshift(_v, _end % _ts); \
467 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _cmask); \
6a7b3345 468 } else { \
a1d04c73
MD
469 _bt_safe_lshift(_v, _ts); \
470 _v |= _bt_cast_value_to_unsigned_type(__typeof__(_v), _ptr[_this_unit]); \
6a7b3345 471 } \
a1d04c73 472 *_vptr = _v; \
6dc2ca62
MD
473} while (0)
474
6dc2ca62 475/*
d79865b9
MD
476 * bt_bitfield_read - read integer from a bitfield in native endianness
477 * bt_bitfield_read_le - read integer from a bitfield in little endian
478 * bt_bitfield_read_be - read integer from a bitfield in big endian
6dc2ca62
MD
479 */
480
08228826
MD
481#if (BYTE_ORDER == LITTLE_ENDIAN)
482
a1d04c73
MD
483#define bt_bitfield_read(ptr, type, start, length, vptr) \
484 _bt_bitfield_read_le(ptr, type, start, length, vptr)
08228826 485
a1d04c73
MD
486#define bt_bitfield_read_le(ptr, type, start, length, vptr) \
487 _bt_bitfield_read_le(ptr, type, start, length, vptr)
a2d16120 488
a1d04c73
MD
489#define bt_bitfield_read_be(ptr, type, start, length, vptr) \
490 _bt_bitfield_read_be(ptr, unsigned char, start, length, vptr)
08228826
MD
491
492#elif (BYTE_ORDER == BIG_ENDIAN)
493
a1d04c73
MD
494#define bt_bitfield_read(ptr, type, start, length, vptr) \
495 _bt_bitfield_read_be(ptr, type, start, length, vptr)
08228826 496
a1d04c73
MD
497#define bt_bitfield_read_le(ptr, type, start, length, vptr) \
498 _bt_bitfield_read_le(ptr, unsigned char, start, length, vptr)
a2d16120 499
a1d04c73
MD
500#define bt_bitfield_read_be(ptr, type, start, length, vptr) \
501 _bt_bitfield_read_be(ptr, type, start, length, vptr)
08228826
MD
502
503#else /* (BYTE_ORDER == PDP_ENDIAN) */
504
505#error "Byte order not supported"
506
507#endif
6dc2ca62 508
d79865b9 509#endif /* _BABELTRACE_BITFIELD_H */
This page took 0.116683 seconds and 4 git commands to generate.