31#ifndef ETL_ALIGNMENT_INCLUDED
32#define ETL_ALIGNMENT_INCLUDED
36#include "static_assert.h"
56 :
exception(reason_, file_name_, line_number_)
69 :
alignment_exception(ETL_ERROR_TEXT(
"alignment:error", ETL_ALIGNMENT_FILE_ID
"A"), file_name_, line_number_)
77 inline bool is_aligned(
void* p,
size_t required_alignment)
79 uintptr_t alignment =
static_cast<uintptr_t
>(required_alignment);
80 uintptr_t address =
reinterpret_cast<uintptr_t
>(p);
81 return (address % alignment) == 0U;
87 template <
size_t Alignment>
90 uintptr_t address =
reinterpret_cast<uintptr_t
>(p);
91 return (address %
static_cast<uintptr_t
>(Alignment)) == 0U;
100 return is_aligned<etl::alignment_of<T>::value>(p);
103 namespace private_alignment
109 template <
bool Is_Match,
size_t Alignment,
typename... TRest>
110 class type_with_alignment_matcher;
113 template <
size_t Alignment,
typename T1,
typename... TRest>
114 class type_with_alignment_matcher<true, Alignment, T1, TRest...>
122 template <
size_t Alignment,
typename T1,
typename T2,
typename... TRest>
123 class type_with_alignment_matcher <false, Alignment, T1, T2, TRest...>
127 typedef typename type_with_alignment_matcher < Alignment <= etl::alignment_of<T2>::value , Alignment, T2, TRest... > ::type type;
131 template <
size_t Alignment,
typename T1>
132 class type_with_alignment_matcher <false, Alignment, T1>
142 template <
size_t Alignment,
typename T1,
typename... T>
143 class type_with_alignment_helper
147 typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T...>::type type;
153 template <
bool Is_Match,
const size_t Alignment,
typename T1 = void,
typename T2 = void,
typename T3 = void,
typename T4 = void,
154 typename T5 = void,
typename T6 = void,
typename T7 = void,
typename T8 =
void>
158 template <
size_t Alignment,
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8>
167 template <
size_t Alignment,
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8>
176 template <
size_t Alignment>
187 template <
size_t Alignment,
typename T1,
typename T2 = void,
typename T3 = void,
typename T4 = void,
188 typename T5 = void,
typename T6 = void,
typename T7 = void,
typename T8 =
void>
202 template <
size_t Alignment>
207#if ETL_NOT_USING_64BIT_TYPES
219 template <
size_t Length, const
size_t Alignment>
230 template <
typename T>
239 template <
typename T>
240 operator const T& ()
const
248 template <
typename T>
252 return reinterpret_cast<T*
>(data);
256 template <
typename T>
257 operator const T* ()
const
260 return reinterpret_cast<const T*
>(data);
264 template <
typename T>
273 template <
typename T>
282 template <
typename T>
286 return reinterpret_cast<T*
>(data);
290 template <
typename T>
294 return reinterpret_cast<const T*
>(data);
297#if ETL_USING_CPP11 && !defined(ETL_COMPILER_ARM5)
298 alignas(Alignment)
char data[Length];
303 typename etl::type_with_alignment<Alignment>::type etl_alignment_type;
310 template <
size_t Length, const
size_t Alignment>
311 using aligned_storage_t =
typename aligned_storage<Length, Alignment>::type;
318 template <
size_t Length,
typename T>
324 template <
size_t Length,
typename T>
Memory misalignment exception.
Definition: alignment.h:65
Exception base for alignment.
Definition: alignment.h:52
Definition: alignment.h:190
Definition: alignment.h:155
Definition: alignment.h:204
Definition: alignment.h:221
Definition: alignment.h:320
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition: exception.h:69
Definition: exception.h:47
add_rvalue_reference
Definition: type_traits_generator.h:1327
is_same
Definition: type_traits_generator.h:1041
bitset_ext
Definition: absolute.h:38
bool is_aligned(void *p, size_t required_alignment)
Check that 'p' has 'required_alignment'.
Definition: alignment.h:77
Definition: alignment.h:223
const T * get_address() const
Get address as const T pointer.
Definition: alignment.h:291
T * get_address()
Get address as T pointer.
Definition: alignment.h:283
const T & get_reference() const
Get address as const T reference.
Definition: alignment.h:274
T & get_reference()
Get address as T reference.
Definition: alignment.h:265