Fixed alignment functionality

This commit is contained in:
John Wellbelove 2023-09-27 13:48:53 +01:00
parent fd920fcc7e
commit 11155eb9f1
2 changed files with 26 additions and 3 deletions

View File

@ -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()

View File

@ -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>));
}
};
}