[v11,10/16] eal: expand most macros to empty when using MSVC

Message ID 1691781658-32520-11-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series msvc integration changes |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Tyler Retzlaff Aug. 11, 2023, 7:20 p.m. UTC
  For now expand a lot of common rte macros empty. The catch here is we
need to test that most of the macros do what they should but at the same
time they are blocking work needed to bootstrap of the unit tests.

Later we will return and provide (where possible) expansions that work
correctly for msvc and where not possible provide some alternate macros
to achieve the same outcome.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 lib/eal/include/rte_branch_prediction.h |  8 +++++
 lib/eal/include/rte_common.h            | 54 +++++++++++++++++++++++++++++++++
 lib/eal/include/rte_compat.h            | 20 ++++++++++++
 3 files changed, 82 insertions(+)
  

Patch

diff --git a/lib/eal/include/rte_branch_prediction.h b/lib/eal/include/rte_branch_prediction.h
index 414cd92..c0356ca 100644
--- a/lib/eal/include/rte_branch_prediction.h
+++ b/lib/eal/include/rte_branch_prediction.h
@@ -24,7 +24,11 @@ 
  *      do_stuff();
  */
 #ifndef likely
+#ifdef RTE_TOOLCHAIN_MSVC
+#define likely(x)	(!!(x))
+#else
 #define likely(x)	__builtin_expect(!!(x), 1)
+#endif
 #endif /* likely */
 
 /**
@@ -37,7 +41,11 @@ 
  *      do_stuff();
  */
 #ifndef unlikely
+#ifdef RTE_TOOLCHAIN_MSVC
+#define unlikely(x)	(!!(x))
+#else
 #define unlikely(x)	__builtin_expect(!!(x), 0)
+#endif
 #endif /* unlikely */
 
 #ifdef __cplusplus
diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index 2f464e3..b087532 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -41,6 +41,10 @@ 
 #define RTE_STD_C11
 #endif
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __extension__
+#endif
+
 /*
  * RTE_TOOLCHAIN_GCC is defined if the target is built with GCC,
  * while a host application (like pmdinfogen) may have another compiler.
@@ -65,7 +69,11 @@ 
 /**
  * Force alignment
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_aligned(a)
+#else
 #define __rte_aligned(a) __attribute__((__aligned__(a)))
+#endif
 
 #ifdef RTE_ARCH_STRICT_ALIGN
 typedef uint64_t unaligned_uint64_t __rte_aligned(1);
@@ -80,16 +88,29 @@ 
 /**
  * Force a structure to be packed
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_packed
+#else
 #define __rte_packed __attribute__((__packed__))
+#endif
 
 /**
  * Macro to mark a type that is not subject to type-based aliasing rules
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_may_alias
+#else
 #define __rte_may_alias __attribute__((__may_alias__))
+#endif
 
 /******* Macro to mark functions and fields scheduled for removal *****/
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_deprecated
+#define __rte_deprecated_msg(msg)
+#else
 #define __rte_deprecated	__attribute__((__deprecated__))
 #define __rte_deprecated_msg(msg)	__attribute__((__deprecated__(msg)))
+#endif
 
 /**
  *  Macro to mark macros and defines scheduled for removal
@@ -110,14 +131,22 @@ 
 /**
  * Force symbol to be generated even if it appears to be unused.
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_used
+#else
 #define __rte_used __attribute__((used))
+#endif
 
 /*********** Macros to eliminate unused variable warnings ********/
 
 /**
  * short definition to mark a function parameter unused
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_unused
+#else
 #define __rte_unused __attribute__((__unused__))
+#endif
 
 /**
  * Mark pointer as restricted with regard to pointer aliasing.
@@ -141,6 +170,9 @@ 
  * even if the underlying stdio implementation is ANSI-compliant,
  * so this must be overridden.
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_format_printf(format_index, first_arg)
+#else
 #if RTE_CC_IS_GNU
 #define __rte_format_printf(format_index, first_arg) \
 	__attribute__((format(gnu_printf, format_index, first_arg)))
@@ -148,6 +180,7 @@ 
 #define __rte_format_printf(format_index, first_arg) \
 	__attribute__((format(printf, format_index, first_arg)))
 #endif
+#endif
 
 /**
  * Tells compiler that the function returns a value that points to
@@ -222,7 +255,11 @@  static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 /**
  * Hint never returning function
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_noreturn
+#else
 #define __rte_noreturn __attribute__((noreturn))
+#endif
 
 /**
  * Issue a warning in case the function's return value is ignored.
@@ -247,12 +284,20 @@  static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  *  }
  * @endcode
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_warn_unused_result
+#else
 #define __rte_warn_unused_result __attribute__((warn_unused_result))
+#endif
 
 /**
  * Force a function to be inlined
  */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_always_inline
+#else
 #define __rte_always_inline inline __attribute__((always_inline))
+#endif
 
 /**
  * Force a function to be noinlined
@@ -437,7 +482,11 @@  static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 #define RTE_CACHE_LINE_MIN_SIZE 64
 
 /** Force alignment to cache line. */
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_cache_aligned
+#else
 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
+#endif
 
 /** Force minimum cache line alignment. */
 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
@@ -812,6 +861,10 @@  static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
  *  struct wrapper *w = container_of(x, struct wrapper, c);
  */
 #ifndef container_of
+#ifdef RTE_TOOLCHAIN_MSVC
+#define container_of(ptr, type, member) \
+			((type *)((uintptr_t)(ptr) - offsetof(type, member)))
+#else
 #define container_of(ptr, type, member)	__extension__ ({		\
 			const typeof(((type *)0)->member) *_ptr = (ptr); \
 			__rte_unused type *_target_ptr =	\
@@ -819,6 +872,7 @@  static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void)
 			(type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
 		})
 #endif
+#endif
 
 /** Swap two variables. */
 #define RTE_SWAP(a, b) \
diff --git a/lib/eal/include/rte_compat.h b/lib/eal/include/rte_compat.h
index fc9fbaa..716bc03 100644
--- a/lib/eal/include/rte_compat.h
+++ b/lib/eal/include/rte_compat.h
@@ -12,14 +12,22 @@ 
 
 #ifndef ALLOW_EXPERIMENTAL_API
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_experimental
+#else
 #define __rte_experimental \
 __attribute__((deprecated("Symbol is not yet part of stable ABI"), \
 section(".text.experimental")))
+#endif
 
 #else
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_experimental
+#else
 #define __rte_experimental \
 __attribute__((section(".text.experimental")))
+#endif
 
 #endif
 
@@ -30,23 +38,35 @@ 
 
 #if !defined ALLOW_INTERNAL_API && __has_attribute(error) /* For GCC */
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_internal
+#else
 #define __rte_internal \
 __attribute__((error("Symbol is not public ABI"), \
 section(".text.internal")))
+#endif
 
 #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /* For clang */
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_internal
+#else
 #define __rte_internal \
 _Pragma("GCC diagnostic push") \
 _Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
 __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \
 section(".text.internal"))) \
 _Pragma("GCC diagnostic pop")
+#endif
 
 #else
 
+#ifdef RTE_TOOLCHAIN_MSVC
+#define __rte_internal
+#else
 #define __rte_internal \
 __attribute__((section(".text.internal")))
+#endif
 
 #endif