356 #define DECL_BITFIELD3(_a, _b, _c) \
357 uint8_t _c, _b, _a
358 #define DECL_BITFIELD4(_a, _b, _c, _d) \
359 uint8_t _d, _c, _b, _a
360 #define DECL_BITFIELD5(_a, _b, _c, _d, _e) \
361 uint8_t _e, _d, _c, _b, _a
362 #define DECL_BITFIELD6(_a, _b, _c, _d, _e, _f) \
363 uint8_t _f, _e, _d, _c, _b, _a
364 #define DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g) \
365 uint8_t _g, _f, _e, _d, _c, _b, _a
366 #define DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h) \
367 uint8_t _h, _g, _f, _e, _d, _c, _b, _a
368 #else
369 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
370 #endif /* _BIT_FIELDS_LTOH */
371
372 #if !defined(ARRAY_SIZE)
373 #define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0]))
374 #endif
375
376 #ifdef __cplusplus
377 }
378 #endif
379
380 #endif /* _SYS_SYSMACROS_H */
|
356 #define DECL_BITFIELD3(_a, _b, _c) \
357 uint8_t _c, _b, _a
358 #define DECL_BITFIELD4(_a, _b, _c, _d) \
359 uint8_t _d, _c, _b, _a
360 #define DECL_BITFIELD5(_a, _b, _c, _d, _e) \
361 uint8_t _e, _d, _c, _b, _a
362 #define DECL_BITFIELD6(_a, _b, _c, _d, _e, _f) \
363 uint8_t _f, _e, _d, _c, _b, _a
364 #define DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g) \
365 uint8_t _g, _f, _e, _d, _c, _b, _a
366 #define DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h) \
367 uint8_t _h, _g, _f, _e, _d, _c, _b, _a
368 #else
369 #error One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
370 #endif /* _BIT_FIELDS_LTOH */
371
372 #if !defined(ARRAY_SIZE)
373 #define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0]))
374 #endif
375
376 /*
377 * Add a value to a uint64_t that saturates at UINT64_MAX instead of wrapping
378 * around.
379 */
380 #define UINT64_OVERFLOW_ADD(val, add) \
381 ((val) > ((val) + (add)) ? (UINT64_MAX) : ((val) + (add)))
382
383 /*
384 * Convert to an int64, saturating at INT64_MAX.
385 */
386 #define UINT64_OVERFLOW_TO_INT64(uval) \
387 (((uval) > INT64_MAX) ? INT64_MAX : (int64_t)(uval))
388
389 #ifdef __cplusplus
390 }
391 #endif
392
393 #endif /* _SYS_SYSMACROS_H */
|