[v6,19/39] regexdev: use C11 alignas

Message ID 1708971946-18231-20-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Series use C11 alignas |


Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff Feb. 26, 2024, 6:25 p.m. UTC
  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:

* 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 <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
 lib/regexdev/rte_regexdev_core.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)


diff --git a/lib/regexdev/rte_regexdev_core.h b/lib/regexdev/rte_regexdev_core.h
index 15ba712..32eef6e 100644
--- a/lib/regexdev/rte_regexdev_core.h
+++ b/lib/regexdev/rte_regexdev_core.h
@@ -144,13 +144,13 @@  enum rte_regexdev_state {
  * This structure is safe to place in shared memory to be common among different
  * processes in a multi-process configuration.
-struct rte_regexdev_data {
+struct __rte_cache_aligned rte_regexdev_data {
 	void *dev_private; /**< PMD-specific private data. */
 	char dev_name[RTE_REGEXDEV_NAME_MAX_LEN]; /**< Unique identifier name */
 	uint16_t dev_id; /**< Device [external]  identifier. */
 	struct rte_regexdev_config dev_conf; /**< RegEx configuration. */
 	uint8_t dev_started : 1; /**< Device started to work. */
-} __rte_cache_aligned;
  * @internal
@@ -162,7 +162,7 @@  struct rte_regexdev_data {
  * memory. This split allows the function pointer and driver data to be per-
  * process, while the actual configuration data for the device is shared.
-struct rte_regexdev {
+struct __rte_cache_aligned rte_regexdev {
 	regexdev_enqueue_t enqueue;
 	regexdev_dequeue_t dequeue;
 	const struct rte_regexdev_ops *dev_ops;
@@ -170,7 +170,7 @@  struct rte_regexdev {
 	struct rte_device *device; /**< Backing device */
 	enum rte_regexdev_state state; /**< The device state. */
 	struct rte_regexdev_data *data;  /**< Pointer to device data. */
-} __rte_cache_aligned;
  * @internal