RE: [PATCH v4 19/35] eal: add macro for marking assumed alignment

Morten Brørup
2026-02-09T22:35:32Z

> From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> Sent: Monday, 9 February 2026 17.45
>
> Provide a common DPDK macro for the gcc/clang builtin
> __rte_assume_aligned to mark pointers as pointing to something with
> known minimum alignment.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
> lib/eal/include/rte_common.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/lib/eal/include/rte_common.h
> b/lib/eal/include/rte_common.h
> index 573bf4f2ce..51a2eaf8b4 100644
> --- a/lib/eal/include/rte_common.h
> +++ b/lib/eal/include/rte_common.h
> @@ -121,6 +121,12 @@ extern "C" {
> #define __rte_aligned(a) __attribute__((__aligned__(a)))
> #endif
>
> +#ifdef RTE_TOOLCHAIN_MSVC
> +#define __rte_assume_aligned(ptr, align) (ptr)
> +#else
> +#define __rte_assume_aligned __builtin_assume_aligned
> +#endif

The GCC/Clang macro supports the optional 3rd parameter (offset), but the MSVC doesn't.
Maybe it's better to pass (ptr, align) to the GCC/Clang variant, so the API consistently only supports two parameters.

If the 3rd parameter ever becomes needed, it can be implemented as a new macro.

Also, a short description of the macro would be nice.

Did you look into using e.g. __rte_assume((ptr % 16) == 0) instead?
It's relevant if it has the desired effect for MSVC, which the macro in this patch doesn't.