From 6ecadb03abc1211ff996bc09c8acb68223a4429f Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Wed, 26 Jun 2019 10:33:45 -0400 Subject: [PATCH] cleanup: include/: move misc/math_extras.h to sys/math_extras.h move misc/math_extras.h to sys/math_extras.h and create a shim for backward-compatibility. No functional changes to the headers. A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES. Related to #16539 Signed-off-by: Anas Nashif --- include/misc/math_extras.h | 67 ++--------------------- include/sys/math_extras.h | 72 +++++++++++++++++++++++++ kernel/include/syscall_handler.h | 2 +- kernel/mempool.c | 2 +- kernel/msg_q.c | 2 +- kernel/thread.c | 2 +- kernel/userspace.c | 2 +- lib/libc/minimal/source/stdlib/malloc.c | 2 +- subsys/net/lib/sockets/sockets.c | 2 +- tests/unit/math_extras/tests.inc | 2 +- 10 files changed, 85 insertions(+), 70 deletions(-) create mode 100644 include/sys/math_extras.h diff --git a/include/misc/math_extras.h b/include/misc/math_extras.h index 77335c9f8e7..93deb696479 100644 --- a/include/misc/math_extras.h +++ b/include/misc/math_extras.h @@ -1,72 +1,15 @@ /* - * Copyright (c) 2019 Facebook. + * Copyright (c) 2019 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ - -/** - * @file - * @brief Extra arithmetic and bitmanipulation functions. - * - * @details This header file provides portable wrapper functions for a number of - * arithmetic and bit-counting functions that are often provided by compiler - * builtins. If the compiler does not have an appropriate builtin, a portable C - * implementation is used instead. - */ - #ifndef ZEPHYR_INCLUDE_MISC_MATH_EXTRAS_H_ #define ZEPHYR_INCLUDE_MISC_MATH_EXTRAS_H_ -#include -#include -#include - -/** - * @name Unsigned integer addition with overflow detection. - * - * These functions compute `a + b` and store the result in `*result`, returning - * true if the operation overflowed. - */ -/**@{*/ -static bool u32_add_overflow(u32_t a, u32_t b, u32_t *result); -static bool u64_add_overflow(u64_t a, u64_t b, u64_t *result); -static bool size_add_overflow(size_t a, size_t b, size_t *result); -/**@}*/ - -/** - * @name Unsigned integer multiplication with overflow detection. - * - * These functions compute `a * b` and store the result in `*result`, returning - * true if the operation overflowed. - */ -/**@{*/ -static bool u32_mul_overflow(u32_t a, u32_t b, u32_t *result); -static bool u64_mul_overflow(u64_t a, u64_t b, u64_t *result); -static bool size_mul_overflow(size_t a, size_t b, size_t *result); -/**@}*/ - -/** - * @name Count leading zeros. - * - * Count the number of leading zero bits in the bitwise representation of `x`. - * When `x = 0`, this is the size of `x` in bits. - */ -/**@{*/ -static int u32_count_leading_zeros(u32_t x); -static int u64_count_leading_zeros(u64_t x); -/**@}*/ - -/** - * @name Count trailing zeros. - * - * Count the number of trailing zero bits in the bitwise representation of `x`. - * When `x = 0`, this is the size of `x` in bits. - */ -/**@{*/ -static int u32_count_trailing_zeros(u32_t x); -static int u64_count_trailing_zeros(u64_t x); -/**@}*/ +#ifndef CONFIG_COMPAT_INCLUDES +#warning "This header file has moved, include instead." +#endif -#include +#include #endif /* ZEPHYR_INCLUDE_MISC_MATH_EXTRAS_H_ */ diff --git a/include/sys/math_extras.h b/include/sys/math_extras.h new file mode 100644 index 00000000000..4f6d707cfcc --- /dev/null +++ b/include/sys/math_extras.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2019 Facebook. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief Extra arithmetic and bitmanipulation functions. + * + * @details This header file provides portable wrapper functions for a number of + * arithmetic and bit-counting functions that are often provided by compiler + * builtins. If the compiler does not have an appropriate builtin, a portable C + * implementation is used instead. + */ + +#ifndef ZEPHYR_INCLUDE_SYS_MATH_EXTRAS_H_ +#define ZEPHYR_INCLUDE_SYS_MATH_EXTRAS_H_ + +#include +#include +#include + +/** + * @name Unsigned integer addition with overflow detection. + * + * These functions compute `a + b` and store the result in `*result`, returning + * true if the operation overflowed. + */ +/**@{*/ +static bool u32_add_overflow(u32_t a, u32_t b, u32_t *result); +static bool u64_add_overflow(u64_t a, u64_t b, u64_t *result); +static bool size_add_overflow(size_t a, size_t b, size_t *result); +/**@}*/ + +/** + * @name Unsigned integer multiplication with overflow detection. + * + * These functions compute `a * b` and store the result in `*result`, returning + * true if the operation overflowed. + */ +/**@{*/ +static bool u32_mul_overflow(u32_t a, u32_t b, u32_t *result); +static bool u64_mul_overflow(u64_t a, u64_t b, u64_t *result); +static bool size_mul_overflow(size_t a, size_t b, size_t *result); +/**@}*/ + +/** + * @name Count leading zeros. + * + * Count the number of leading zero bits in the bitwise representation of `x`. + * When `x = 0`, this is the size of `x` in bits. + */ +/**@{*/ +static int u32_count_leading_zeros(u32_t x); +static int u64_count_leading_zeros(u64_t x); +/**@}*/ + +/** + * @name Count trailing zeros. + * + * Count the number of trailing zero bits in the bitwise representation of `x`. + * When `x = 0`, this is the size of `x` in bits. + */ +/**@{*/ +static int u32_count_trailing_zeros(u32_t x); +static int u64_count_trailing_zeros(u64_t x); +/**@}*/ + +#include + +#endif /* ZEPHYR_INCLUDE_SYS_MATH_EXTRAS_H_ */ diff --git a/kernel/include/syscall_handler.h b/kernel/include/syscall_handler.h index ab2449dbbc9..13fb35206d6 100644 --- a/kernel/include/syscall_handler.h +++ b/kernel/include/syscall_handler.h @@ -13,7 +13,7 @@ #ifndef _ASMLANGUAGE #include #include -#include +#include #include #include diff --git a/kernel/mempool.c b/kernel/mempool.c index ad2849f1749..35c42ddf14b 100644 --- a/kernel/mempool.c +++ b/kernel/mempool.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include static struct k_spinlock lock; diff --git a/kernel/msg_q.c b/kernel/msg_q.c index ef0bf43dbe4..2ae117a9e27 100644 --- a/kernel/msg_q.c +++ b/kernel/msg_q.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/kernel/thread.c b/kernel/thread.c index 90d0ade87b9..a3605114e39 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/kernel/userspace.c b/kernel/userspace.c index 819db64ee0a..49f8d7c32a6 100644 --- a/kernel/userspace.c +++ b/kernel/userspace.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/lib/libc/minimal/source/stdlib/malloc.c b/lib/libc/minimal/source/stdlib/malloc.c index ce7536f56bc..ce3070c1154 100644 --- a/lib/libc/minimal/source/stdlib/malloc.c +++ b/lib/libc/minimal/source/stdlib/malloc.c @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/subsys/net/lib/sockets/sockets.c b/subsys/net/lib/sockets/sockets.c index 6360c60167d..513926b60f7 100644 --- a/subsys/net/lib/sockets/sockets.c +++ b/subsys/net/lib/sockets/sockets.c @@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(net_sock, CONFIG_NET_SOCKETS_LOG_LEVEL); #include #include #include -#include +#include #include "sockets_internal.h" diff --git a/tests/unit/math_extras/tests.inc b/tests/unit/math_extras/tests.inc index 820e8cfab34..8f36852100e 100644 --- a/tests/unit/math_extras/tests.inc +++ b/tests/unit/math_extras/tests.inc @@ -5,7 +5,7 @@ */ #include -#include +#include #include static void VNAME(u32_add)(void)