There's no MSVC equivalent for compiler extension __builtin_constant_p. EAL already had __rte_constant which was used as a first attempt to workaround __builtin_constant_p when using MSVC. However, there are pieces of code that would benefit from being able to provide a default value to be used instead of it being always 0 like how it was done by __rte_constant.
A new macro is added here allowing such default to be provided by the caller. Signed-off-by: Andre Muezerie <andre...@linux.microsoft.com> --- lib/eal/include/generic/rte_pause.h | 2 +- lib/eal/include/rte_common.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/eal/include/generic/rte_pause.h b/lib/eal/include/generic/rte_pause.h index 968c0886d3..57e13807ea 100644 --- a/lib/eal/include/generic/rte_pause.h +++ b/lib/eal/include/generic/rte_pause.h @@ -130,7 +130,7 @@ rte_wait_until_equal_64(volatile uint64_t *addr, uint64_t expected, * rte_memory_order_acquire and rte_memory_order_relaxed. */ #define RTE_WAIT_UNTIL_MASKED(addr, mask, cond, expected, memorder) do { \ - RTE_BUILD_BUG_ON(!__builtin_constant_p(memorder)); \ + RTE_BUILD_BUG_ON(!__rte_constant_with_default(memorder, 1)); \ RTE_BUILD_BUG_ON((memorder) != rte_memory_order_acquire && \ (memorder) != rte_memory_order_relaxed); \ typeof(*(addr)) expected_value = (expected); \ diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index 3f77b7624e..6bdce70551 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -50,6 +50,18 @@ extern "C" { #define __rte_constant(e) __extension__(__builtin_constant_p(e)) #endif +/** + * Determine if an expression's value is constant at compile time. + * All compilers except MSVC will return 1 if the first argument is a + * compile-time constant, and 0 otherwise. MSVC will just return the second + * argument as a default value. + */ +#ifdef RTE_TOOLCHAIN_MSVC +#define __rte_constant_with_default(e, def) def +#else +#define __rte_constant_with_default(e, def) __extension__(__builtin_constant_p(e)) +#endif + /* * RTE_TOOLCHAIN_GCC is defined if the target is built with GCC, * while a host application (like pmdinfogen) may have another compiler. -- 2.47.2.vfs.0.1