Add __BIT and __BITS macros from NetBSD to help support new testcases

MFC after:	1 week
This commit is contained in:
ngie 2017-01-12 09:01:14 +00:00
parent dec64e48c6
commit 2b62be0b79

View File

@ -71,4 +71,13 @@
*/
#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
/* __BIT(n): nth bit, where __BIT(0) == 0x1. */
#define __BIT(__n) \
(((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \
((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1))))
/* __BITS(m, n): bits m through n, m < n. */
#define __BITS(__m, __n) \
((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1))
#endif /* _LIBNETBSD_SYS_CDEFS_H_ */