toolchain: add Z_POW2_CEIL()

Helper macro for rounding up to next power of two.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2020-03-23 14:48:37 -07:00 committed by Anas Nashif
commit 79728eccca
2 changed files with 18 additions and 1 deletions

View file

@ -462,5 +462,21 @@ do { \
_value_a_ < _value_b_ ? _value_a_ : _value_b_; \
})
/**
* @brief Calculate power of two ceiling for some nonzero value
*
* @param x Nonzero unsigned long value
* @return X rounded up to the next power of two
*/
#ifdef CONFIG_64BIT
#define Z_POW2_CEIL(x) ((1UL << (63U - __builtin_clzl(x))) < x ? \
1UL << (63U - __builtin_clzl(x) + 1U) : \
1UL << (63U - __builtin_clzl(x)))
#else
#define Z_POW2_CEIL(x) ((1UL << (31U - __builtin_clzl(x))) < x ? \
1UL << (31U - __builtin_clzl(x) + 1U) : \
1UL << (31U - __builtin_clzl(x)))
#endif
#endif /* !_LINKER */
#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_ */

View file

@ -7,6 +7,7 @@
#include <ztest.h>
#include <linker/linker-defs.h>
#include <syscall_handler.h>
#include <toolchain.h>
#include <arch/arm/aarch32/cortex_m/cmsis.h>
@ -42,7 +43,7 @@ void test_arm_sw_vector_relay(void)
* interrupt vector table respect the VTOR.TBLOFF alignment
* requirements.
*/
uint32_t mask = MAX(128, POW2_CEIL(4 * (16 + CONFIG_NUM_IRQS))) - 1;
uint32_t mask = MAX(128, Z_POW2_CEIL(4 * (16 + CONFIG_NUM_IRQS))) - 1;
zassert_true(((vector_table_addr) & mask) == 0,
"vector table not properly aligned: 0x%x\n",