Bug 1325771 - mfbt: Reorder parameters for MOZ_ALIGNED_DECL r=jwalden

Currently, MOZ_ALIGNED_DECL uses the order (_type, _align) for its
parameters. However, this order makes the code less readable when
_type is a larger object like a struct because the value for _align
would be at the end of the struct definition. By swapping the order
of _type and _align, the alignment value will always be next to
the type name, regardless how far the definition of _type extends.

Differential Revision: https://phabricator.services.mozilla.com/D77288
This commit is contained in:
John Paul Adrian Glaubitz 2020-06-03 18:31:06 +00:00
parent 0d3f9839aa
commit 319d3205ce
3 changed files with 12 additions and 12 deletions

View file

@ -85,8 +85,8 @@ END_TEST(testAtomicFence)
// Memory for testing atomics. This must be aligned to the natural alignment of // Memory for testing atomics. This must be aligned to the natural alignment of
// the type we're testing; for now, use 8-byte alignment for all. // the type we're testing; for now, use 8-byte alignment for all.
MOZ_ALIGNED_DECL(static uint8_t atomicMem[8], 8); MOZ_ALIGNED_DECL(8, static uint8_t atomicMem[8]);
MOZ_ALIGNED_DECL(static uint8_t atomicMem2[8], 8); MOZ_ALIGNED_DECL(8, static uint8_t atomicMem2[8]);
// T is the primitive type we're testing, and A and B are references to constant // T is the primitive type we're testing, and A and B are references to constant
// bindings holding values of that type. // bindings holding values of that type.

View file

@ -2874,7 +2874,7 @@ struct TlsData {
// The globalArea must be the last field. Globals for the module start here // The globalArea must be the last field. Globals for the module start here
// and are inline in this structure. 16-byte alignment is required for SIMD // and are inline in this structure. 16-byte alignment is required for SIMD
// data. // data.
MOZ_ALIGNED_DECL(char globalArea, 16); MOZ_ALIGNED_DECL(16, char globalArea);
}; };
static const size_t TlsDataAlign = 16; // = Simd128DataSize static const size_t TlsDataAlign = 16; // = Simd128DataSize

View file

@ -62,18 +62,18 @@ struct AlignasHelper {
* *
* For instance, * For instance,
* *
* MOZ_ALIGNED_DECL(char arr[2], 8); * MOZ_ALIGNED_DECL(8, char arr[2]);
* *
* will declare a two-character array |arr| aligned to 8 bytes. * will declare a two-character array |arr| aligned to 8 bytes.
*/ */
#if defined(__GNUC__) #if defined(__GNUC__)
# define MOZ_ALIGNED_DECL(_type, _align) _type __attribute__((aligned(_align))) # define MOZ_ALIGNED_DECL(_align, _type) _type __attribute__((aligned(_align)))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
# define MOZ_ALIGNED_DECL(_type, _align) __declspec(align(_align)) _type # define MOZ_ALIGNED_DECL(_align, _type) __declspec(align(_align)) _type
#else #else
# warning "We don't know how to align variables on this compiler." # warning "We don't know how to align variables on this compiler."
# define MOZ_ALIGNED_DECL(_type, _align) _type # define MOZ_ALIGNED_DECL(_align, _type) _type
#endif #endif
/* /*
@ -92,27 +92,27 @@ struct AlignedElem;
template <> template <>
struct AlignedElem<1> { struct AlignedElem<1> {
MOZ_ALIGNED_DECL(uint8_t elem, 1); MOZ_ALIGNED_DECL(1, uint8_t elem);
}; };
template <> template <>
struct AlignedElem<2> { struct AlignedElem<2> {
MOZ_ALIGNED_DECL(uint8_t elem, 2); MOZ_ALIGNED_DECL(2, uint8_t elem);
}; };
template <> template <>
struct AlignedElem<4> { struct AlignedElem<4> {
MOZ_ALIGNED_DECL(uint8_t elem, 4); MOZ_ALIGNED_DECL(4, uint8_t elem);
}; };
template <> template <>
struct AlignedElem<8> { struct AlignedElem<8> {
MOZ_ALIGNED_DECL(uint8_t elem, 8); MOZ_ALIGNED_DECL(8, uint8_t elem);
}; };
template <> template <>
struct AlignedElem<16> { struct AlignedElem<16> {
MOZ_ALIGNED_DECL(uint8_t elem, 16); MOZ_ALIGNED_DECL(16, uint8_t elem);
}; };
template <typename T> template <typename T>