Skip to content

Commit

Permalink
Fixed alignment functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Sep 27, 2023
1 parent fd920fc commit 11155eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 14 additions & 3 deletions include/etl/alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,24 @@ namespace etl
{
public:

#if ETL_NOT_USING_64BIT_TYPES
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, float, double, void*>::type type;
#if ETL_USING_CPP11
typedef struct { alignas(Alignment) char dummy; } type;
#else
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, int64_t, float, double, void*>::type type;
#if ETL_NOT_USING_64BIT_TYPES
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, float, double, void*>::type type;
#else
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, int64_t, float, double, void*>::type type;
#endif
#endif

ETL_STATIC_ASSERT(etl::alignment_of<type>::value == Alignment, "Unable to create the type with the specified alignment");
};

#if ETL_USING_CPP11
template <size_t Alignment>
using type_with_alignment_t = typename type_with_alignment<Alignment>::type;
#endif

//***************************************************************************
/// Aligned storage
/// Length should be determined in terms of sizeof()
Expand Down
12 changes: 12 additions & 0 deletions test/test_alignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,17 @@ namespace
CHECK_FALSE(etl::is_aligned<alignof(uint32_t)>(p));
CHECK_FALSE(etl::is_aligned<uint32_t>(p));
}

//*************************************************************************
TEST(test_type_with_alignment)
{
CHECK_EQUAL(1, alignof(etl::type_with_alignment_t<1>));
CHECK_EQUAL(2, alignof(etl::type_with_alignment_t<2>));
CHECK_EQUAL(4, alignof(etl::type_with_alignment_t<4>));
CHECK_EQUAL(8, alignof(etl::type_with_alignment_t<8>));
CHECK_EQUAL(16, alignof(etl::type_with_alignment_t<16>));
CHECK_EQUAL(32, alignof(etl::type_with_alignment_t<32>));
CHECK_EQUAL(64, alignof(etl::type_with_alignment_t<64>));
}
};
}

0 comments on commit 11155eb

Please sign in to comment.