Skip to content

Commit

Permalink
Bug 1325771 - mfbt: Reorder parameters for MOZ_ALIGNED_DECL r=jwalden
Browse files Browse the repository at this point in the history
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
  • Loading branch information
glaubitz committed Jun 3, 2020
1 parent 9dc27a6 commit fe753ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions js/src/jsapi-tests/testAtomicOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ END_TEST(testAtomicFence)
// 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.

MOZ_ALIGNED_DECL(static uint8_t atomicMem[8], 8);
MOZ_ALIGNED_DECL(static uint8_t atomicMem2[8], 8);
MOZ_ALIGNED_DECL(8, static uint8_t atomicMem[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
// bindings holding values of that type.
Expand Down
2 changes: 1 addition & 1 deletion js/src/wasm/WasmTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2874,7 +2874,7 @@ struct TlsData {
// 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
// data.
MOZ_ALIGNED_DECL(char globalArea, 16);
MOZ_ALIGNED_DECL(16, char globalArea);
};

static const size_t TlsDataAlign = 16; // = Simd128DataSize
Expand Down
18 changes: 9 additions & 9 deletions mfbt/Alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ struct AlignasHelper {
*
* 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.
*/

#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)
# define MOZ_ALIGNED_DECL(_type, _align) __declspec(align(_align)) _type
# define MOZ_ALIGNED_DECL(_align, _type) __declspec(align(_align)) _type
#else
# 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

/*
Expand All @@ -92,27 +92,27 @@ struct AlignedElem;

template <>
struct AlignedElem<1> {
MOZ_ALIGNED_DECL(uint8_t elem, 1);
MOZ_ALIGNED_DECL(1, uint8_t elem);
};

template <>
struct AlignedElem<2> {
MOZ_ALIGNED_DECL(uint8_t elem, 2);
MOZ_ALIGNED_DECL(2, uint8_t elem);
};

template <>
struct AlignedElem<4> {
MOZ_ALIGNED_DECL(uint8_t elem, 4);
MOZ_ALIGNED_DECL(4, uint8_t elem);
};

template <>
struct AlignedElem<8> {
MOZ_ALIGNED_DECL(uint8_t elem, 8);
MOZ_ALIGNED_DECL(8, uint8_t elem);
};

template <>
struct AlignedElem<16> {
MOZ_ALIGNED_DECL(uint8_t elem, 16);
MOZ_ALIGNED_DECL(16, uint8_t elem);
};

template <typename T>
Expand Down

0 comments on commit fe753ba

Please sign in to comment.