Mesa (main): util: use c11 alignas instead of rolling our own
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Jun 14 15:50:07 UTC 2022
Module: Mesa
Branch: main
Commit: e3bc78b8e398348bc1993b1c713b8917bd4d53d9
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=e3bc78b8e398348bc1993b1c713b8917bd4d53d9
Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date: Wed Jun 8 10:07:15 2022 +0200
util: use c11 alignas instead of rolling our own
Due to how alignas is defined, it itsn't allowed to use it on a struct,
it needs to be used on the first member instead. So move the declaration
in those cases.
This still leaves the ALIGN16 macro using compiler-specific directives,
because it's a lot of work to untangle the above. This probably deserves
its own MR.
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16908>
---
src/util/macros.h | 1 +
src/util/ralloc.c | 32 +++++++++++++-------------------
src/util/sparse_array.h | 10 ++--------
src/util/u_cpu_detect.c | 2 +-
4 files changed, 17 insertions(+), 28 deletions(-)
diff --git a/src/util/macros.h b/src/util/macros.h
index e0af384f7b9..e978007df6b 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -413,6 +413,7 @@ u_uintN_max(unsigned bit_size)
#ifndef __cplusplus
#ifdef _MSC_VER
#define alignof _Alignof
+#define alignas _Alignas
#else
#include <stdalign.h>
#endif
diff --git a/src/util/ralloc.c b/src/util/ralloc.c
index 5ffc91ca823..35740655613 100644
--- a/src/util/ralloc.c
+++ b/src/util/ralloc.c
@@ -41,20 +41,14 @@
* 64-bit), avoiding performance penalities on x86 and alignment faults on
* ARM.
*/
-struct
-#ifdef _MSC_VER
-#if _WIN64
-__declspec(align(16))
-#else
- __declspec(align(8))
-#endif
-#elif defined(__LP64__)
- __attribute__((aligned(16)))
+struct ralloc_header
+{
+#if defined(__LP64__) || defined(_WIN64)
+ alignas(16)
#else
- __attribute__((aligned(8)))
+ alignas(8)
#endif
- ralloc_header
-{
+
#ifndef NDEBUG
/* A canary value used to determine whether a pointer is ralloc'd. */
unsigned canary;
@@ -554,15 +548,15 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt,
#define SUBALLOC_ALIGNMENT 8
#define LMAGIC 0x87b9c7d3
-struct
-#ifdef _MSC_VER
- __declspec(align(8))
-#elif defined(__LP64__)
- __attribute__((aligned(16)))
+struct linear_header {
+
+ /* align first member to align struct */
+#if defined(__LP64__) || defined(_WIN64)
+ alignas(16)
#else
- __attribute__((aligned(8)))
+ alignas(8)
#endif
- linear_header {
+
#ifndef NDEBUG
unsigned magic; /* for debugging */
#endif
diff --git a/src/util/sparse_array.h b/src/util/sparse_array.h
index f91fe21dae2..3df45a54644 100644
--- a/src/util/sparse_array.h
+++ b/src/util/sparse_array.h
@@ -87,13 +87,7 @@ void util_sparse_array_validate(struct util_sparse_array *arr);
* "free" elements backed by a util_sparse_array. The list supports only two
* operations: push and pop both of which are thread-safe and lock-free. T
*/
-struct
-#ifdef _MSC_VER
- __declspec(align(8))
-#else
- __attribute__((aligned(8)))
-#endif
-util_sparse_array_free_list
+struct util_sparse_array_free_list
{
/** Head of the list
*
@@ -103,7 +97,7 @@ util_sparse_array_free_list
* We want this element to be 8-byte aligned. Otherwise, the performance
* of atomic operations on it will be aweful on 32-bit platforms.
*/
- uint64_t head;
+ alignas(8) uint64_t head;
/** The array backing this free list */
struct util_sparse_array *arr;
diff --git a/src/util/u_cpu_detect.c b/src/util/u_cpu_detect.c
index fb96e1042bd..4d65804561a 100644
--- a/src/util/u_cpu_detect.c
+++ b/src/util/u_cpu_detect.c
@@ -365,7 +365,7 @@ PIPE_ALIGN_STACK static inline boolean sse2_has_daz(void)
uint32_t pad1[7];
uint32_t mxcsr_mask;
uint32_t pad2[128-8];
- } PIPE_ALIGN_VAR(16) fxarea;
+ } alignas(16) fxarea;
fxarea.mxcsr_mask = 0;
#if defined(PIPE_CC_GCC)
More information about the mesa-commit
mailing list