On Fri, Feb 23, 2024 at 11:03:36AM -0800, Tyler Retzlaff wrote:
> The current location used for __rte_aligned(a) for alignment of types
> and variables is not compatible with MSVC. There is only a single
> location accepted by both toolchains.
> 
> For variables standard C11 offers alignas(a) supported by conformant
> compilers i.e. both MSVC and GCC.
> 
> For types the standard offers no alignment facility that compatibly
> interoperates with C and C++ but may be achieved by relocating the
> placement of __rte_aligned(a) to the aforementioned location accepted
> by all currently supported toolchains.
> 
> To allow alignment for both compilers do the following:
> 
> * Expand __rte_aligned(a) to __declspec(align(a)) when building
>   with MSVC.
> 
> * Move __rte_aligned from the end of {struct,union} definitions to
>   be between {struct,union} and tag.
> 
>   The placement between {struct,union} and the tag allows the desired
>   alignment to be imparted on the type regardless of the toolchain being
>   used for all of GCC, LLVM, MSVC compilers building both C and C++.
> 
> * Replace use of __rte_aligned(a) on variables/fields with alignas(a).
> 
> Signed-off-by: Tyler Retzlaff <roret...@linux.microsoft.com>
> Acked-by: Morten Brørup <m...@smartsharesystems.com>
> ---
>  lib/eal/arm/include/rte_vect.h       |  4 ++--
>  lib/eal/common/malloc_elem.h         |  4 ++--
>  lib/eal/common/malloc_heap.h         |  4 ++--
>  lib/eal/common/rte_keepalive.c       |  3 ++-
>  lib/eal/common/rte_random.c          |  4 ++--
>  lib/eal/common/rte_service.c         |  8 ++++----
>  lib/eal/include/generic/rte_atomic.h |  4 ++--
>  lib/eal/include/rte_common.h         | 23 +++++++++++++++--------
>  lib/eal/loongarch/include/rte_vect.h |  8 ++++----
>  lib/eal/ppc/include/rte_vect.h       |  4 ++--
>  lib/eal/riscv/include/rte_vect.h     |  4 ++--
>  lib/eal/x86/include/rte_vect.h       |  4 ++--
>  lib/eal/x86/rte_power_intrinsics.c   | 10 ++++++----
>  13 files changed, 47 insertions(+), 37 deletions(-)
> 
Just to chime in with one additional benefit of this change - it will
prevent static analysers, IDEs and doxygen[1] from ever mistaking the
__rte_aligned tag at the end of a struct define as being a variable
definition. In the absence of a macro definition from our DPDK header files
this defines a variable called __rte_cache_aligned (as in [1]!):

   struct xyz {
   } __rte_cache_aligned;

while this just gives an error to let you know the definiton is missing:

  struct __rte_cache_aligned xyz {
  };

Acked-by: Bruce Richardson <bruce.richard...@intel.com>

[1] 
http://doc.dpdk.org/api/structrte__ring.html#a43d0b019eced25dc6c357f3b4f0f47e5

Reply via email to