There's no MSVC equivalent for compiler extension __builtin_constant_p,
but the same result can be obtained though a clever expression using
_Generic.

This patch redefines the macro __rte_constant when msvc is used and uses
it as a replacement for __builtin_constant_p.

Signed-off-by: Andre Muezerie <andre...@linux.microsoft.com>
Signed-off-by: Chengwen Feng <fengcheng...@huawei.com>
---
 lib/eal/include/generic/rte_pause.h | 2 +-
 lib/eal/include/rte_common.h        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/eal/include/generic/rte_pause.h 
b/lib/eal/include/generic/rte_pause.h
index 968c0886d3..9515caadbb 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(memorder));                     \
        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..0a20b6a3e3 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -45,7 +45,7 @@ extern "C" {
 #endif
 
 #ifdef RTE_TOOLCHAIN_MSVC
-#define __rte_constant(e) 0
+#define __rte_constant(e) _Generic((1 ? (void *) ((e) * 0ll) : (int *) 0), int 
* : 1, void * : 0)
 #else
 #define __rte_constant(e) __extension__(__builtin_constant_p(e))
 #endif
-- 
2.48.1.vfs.0.0

Reply via email to