util: Replace the usage of ALIGN16 with alignas(16) and them remove ALIGN16 macro

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19565>
This commit is contained in:
Yonggang Luo
2022-11-07 11:34:26 +08:00
committed by Marge Bot
parent 956935abaf
commit f6ed016fe9
5 changed files with 38 additions and 15 deletions

View File

@@ -184,7 +184,7 @@ struct tu6_global
uint32_t pad[7]; uint32_t pad[7];
} flush_base[4]; } flush_base[4];
ALIGN16 uint32_t cs_indirect_xyz[3]; alignas(16) uint32_t cs_indirect_xyz[3];
volatile uint32_t vtx_stats_query_not_running; volatile uint32_t vtx_stats_query_not_running;

View File

@@ -73,18 +73,27 @@
#define TILE_BOTTOM_LEFT 2 #define TILE_BOTTOM_LEFT 2
#define TILE_BOTTOM_RIGHT 3 #define TILE_BOTTOM_RIGHT 3
static_assert(alignof(union tgsi_exec_channel) == 16, "");
static_assert(alignof(struct tgsi_exec_vector) == 16, "");
static_assert(alignof(struct tgsi_exec_machine) == 16, "");
union tgsi_double_channel { union tgsi_double_channel {
alignas(16)
double d[TGSI_QUAD_SIZE]; double d[TGSI_QUAD_SIZE];
unsigned u[TGSI_QUAD_SIZE][2]; unsigned u[TGSI_QUAD_SIZE][2];
uint64_t u64[TGSI_QUAD_SIZE]; uint64_t u64[TGSI_QUAD_SIZE];
int64_t i64[TGSI_QUAD_SIZE]; int64_t i64[TGSI_QUAD_SIZE];
} ALIGN16; };
struct ALIGN16 tgsi_double_vector { struct tgsi_double_vector {
alignas(16)
union tgsi_double_channel xy; union tgsi_double_channel xy;
union tgsi_double_channel zw; union tgsi_double_channel zw;
}; };
static_assert(alignof(union tgsi_double_channel) == 16, "");
static_assert(alignof(struct tgsi_double_vector) == 16, "");
static void static void
micro_abs(union tgsi_exec_channel *dst, micro_abs(union tgsi_exec_channel *dst,
const union tgsi_exec_channel *src) const union tgsi_exec_channel *src)

View File

@@ -73,17 +73,18 @@ extern "C" {
*/ */
union tgsi_exec_channel union tgsi_exec_channel
{ {
alignas(16)
float f[TGSI_QUAD_SIZE]; float f[TGSI_QUAD_SIZE];
int i[TGSI_QUAD_SIZE]; int i[TGSI_QUAD_SIZE];
unsigned u[TGSI_QUAD_SIZE]; unsigned u[TGSI_QUAD_SIZE];
} ALIGN16; };
/** /**
* A vector[RGBA] of channels[4 pixels] * A vector[RGBA] of channels[4 pixels]
*/ */
struct ALIGN16 tgsi_exec_vector struct tgsi_exec_vector
{ {
union tgsi_exec_channel xyzw[TGSI_NUM_CHANNELS]; alignas(16) union tgsi_exec_channel xyzw[TGSI_NUM_CHANNELS];
}; };
/** /**
@@ -286,10 +287,11 @@ typedef void (* apply_sample_offset_func)(
/** /**
* Run-time virtual machine state for executing TGSI shader. * Run-time virtual machine state for executing TGSI shader.
*/ */
struct ALIGN16 tgsi_exec_machine struct tgsi_exec_machine
{ {
/* Total = program temporaries + internal temporaries /* Total = program temporaries + internal temporaries
*/ */
alignas(16)
struct tgsi_exec_vector Temps[TGSI_EXEC_NUM_TEMPS]; struct tgsi_exec_vector Temps[TGSI_EXEC_NUM_TEMPS];
unsigned ImmsReserved; unsigned ImmsReserved;

View File

@@ -79,8 +79,8 @@ enum GLmatrixtype {
* Matrix type to represent 4x4 transformation matrices. * Matrix type to represent 4x4 transformation matrices.
*/ */
typedef struct { typedef struct {
ALIGN16 GLfloat m[16]; /**< 16 matrix elements (16-byte aligned) */ alignas(16) GLfloat m[16]; /**< 16 matrix elements (16-byte aligned) */
ALIGN16 GLfloat inv[16]; /**< 16-element inverse (16-byte aligned) */ alignas(16) GLfloat inv[16]; /**< 16-element inverse (16-byte aligned) */
GLuint flags; /**< possible values determined by (of \link GLuint flags; /**< possible values determined by (of \link
* MatFlags MAT_FLAG_* flags\endlink) * MatFlags MAT_FLAG_* flags\endlink)
*/ */

View File

@@ -215,12 +215,6 @@ do { \
# endif # endif
#endif #endif
#ifdef _MSC_VER
#define ALIGN16 __declspec(align(16))
#else
#define ALIGN16 __attribute__((aligned(16)))
#endif
#ifdef __cplusplus #ifdef __cplusplus
/** /**
* Macro function that evaluates to true if T is a trivially * Macro function that evaluates to true if T is a trivially
@@ -413,6 +407,24 @@ u_uintN_max(unsigned bit_size)
return UINT64_MAX >> (64 - bit_size); return UINT64_MAX >> (64 - bit_size);
} }
/* alignas usage
* For struct or union, use alignas(align_size) on any member
* of it will make it aligned to align_size.
* See https://en.cppreference.com/w/c/language/_Alignas for
* details. We can use static_assert and alignof to check if
* the alignment result of alignas(align_size) on struct or
* union is valid.
* For example:
* static_assert(alignof(struct tgsi_exec_machine) == 16, "")
* Also, we can use special code to see the size of the aligned
* struct or union at the compile time with GCC, Clang or MSVC.
* So we can see if the size of union or struct are as expected
* when using alignas(align_size) on its member.
* For example:
* char (*__kaboom)[sizeof(struct tgsi_exec_machine)] = 1;
* can show us the size of struct tgsi_exec_machine at compile
* time.
*/
#ifndef __cplusplus #ifndef __cplusplus
#ifdef _MSC_VER #ifdef _MSC_VER
#define alignof _Alignof #define alignof _Alignof