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@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16908>
This commit is contained in:
parent
2c43044507
commit
e3bc78b8e3
|
@ -413,6 +413,7 @@ u_uintN_max(unsigned bit_size)
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define alignof _Alignof
|
#define alignof _Alignof
|
||||||
|
#define alignas _Alignas
|
||||||
#else
|
#else
|
||||||
#include <stdalign.h>
|
#include <stdalign.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,20 +41,14 @@
|
||||||
* 64-bit), avoiding performance penalities on x86 and alignment faults on
|
* 64-bit), avoiding performance penalities on x86 and alignment faults on
|
||||||
* ARM.
|
* ARM.
|
||||||
*/
|
*/
|
||||||
struct
|
struct ralloc_header
|
||||||
#ifdef _MSC_VER
|
|
||||||
#if _WIN64
|
|
||||||
__declspec(align(16))
|
|
||||||
#else
|
|
||||||
__declspec(align(8))
|
|
||||||
#endif
|
|
||||||
#elif defined(__LP64__)
|
|
||||||
__attribute__((aligned(16)))
|
|
||||||
#else
|
|
||||||
__attribute__((aligned(8)))
|
|
||||||
#endif
|
|
||||||
ralloc_header
|
|
||||||
{
|
{
|
||||||
|
#if defined(__LP64__) || defined(_WIN64)
|
||||||
|
alignas(16)
|
||||||
|
#else
|
||||||
|
alignas(8)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
/* A canary value used to determine whether a pointer is ralloc'd. */
|
/* A canary value used to determine whether a pointer is ralloc'd. */
|
||||||
unsigned canary;
|
unsigned canary;
|
||||||
|
@ -554,15 +548,15 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt,
|
||||||
#define SUBALLOC_ALIGNMENT 8
|
#define SUBALLOC_ALIGNMENT 8
|
||||||
#define LMAGIC 0x87b9c7d3
|
#define LMAGIC 0x87b9c7d3
|
||||||
|
|
||||||
struct
|
struct linear_header {
|
||||||
#ifdef _MSC_VER
|
|
||||||
__declspec(align(8))
|
/* align first member to align struct */
|
||||||
#elif defined(__LP64__)
|
#if defined(__LP64__) || defined(_WIN64)
|
||||||
__attribute__((aligned(16)))
|
alignas(16)
|
||||||
#else
|
#else
|
||||||
__attribute__((aligned(8)))
|
alignas(8)
|
||||||
#endif
|
#endif
|
||||||
linear_header {
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
unsigned magic; /* for debugging */
|
unsigned magic; /* for debugging */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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
|
* "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
|
* operations: push and pop both of which are thread-safe and lock-free. T
|
||||||
*/
|
*/
|
||||||
struct
|
struct util_sparse_array_free_list
|
||||||
#ifdef _MSC_VER
|
|
||||||
__declspec(align(8))
|
|
||||||
#else
|
|
||||||
__attribute__((aligned(8)))
|
|
||||||
#endif
|
|
||||||
util_sparse_array_free_list
|
|
||||||
{
|
{
|
||||||
/** Head of the 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
|
* We want this element to be 8-byte aligned. Otherwise, the performance
|
||||||
* of atomic operations on it will be aweful on 32-bit platforms.
|
* 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 */
|
/** The array backing this free list */
|
||||||
struct util_sparse_array *arr;
|
struct util_sparse_array *arr;
|
||||||
|
|
|
@ -365,7 +365,7 @@ PIPE_ALIGN_STACK static inline boolean sse2_has_daz(void)
|
||||||
uint32_t pad1[7];
|
uint32_t pad1[7];
|
||||||
uint32_t mxcsr_mask;
|
uint32_t mxcsr_mask;
|
||||||
uint32_t pad2[128-8];
|
uint32_t pad2[128-8];
|
||||||
} PIPE_ALIGN_VAR(16) fxarea;
|
} alignas(16) fxarea;
|
||||||
|
|
||||||
fxarea.mxcsr_mask = 0;
|
fxarea.mxcsr_mask = 0;
|
||||||
#if defined(PIPE_CC_GCC)
|
#if defined(PIPE_CC_GCC)
|
||||||
|
|
Loading…
Reference in New Issue