FastLED 3.9.15
Loading...
Searching...
No Matches

◆ FL_ALIGNAS() [5/5]

template<typename T, fl::size N>
struct fl::FL_ALIGNAS ( alignof(T) ,
alignof(fl::uptr) ? alignof(T) :alignof(fl::uptr)  )

Definition at line 1 of file vector.h.

32 : alignof(fl::uptr)) InlinedMemoryBlock {
33 // using MemoryType = uinptr_t;
34 typedef fl::uptr MemoryType;
35 enum {
36 kTotalBytes = N * sizeof(T),
37 kExtraSize =
38 (kTotalBytes % alignof(fl::max_align_t)) ? (alignof(fl::max_align_t) - (kTotalBytes % alignof(fl::max_align_t))) : 0,
39 // Fix: calculate total bytes first, then convert to MemoryType units
40 kTotalBytesAligned = kTotalBytes + kExtraSize,
41 kBlockSize = (kTotalBytesAligned + sizeof(MemoryType) - 1) / sizeof(MemoryType),
42 };
43
44 InlinedMemoryBlock() FL_NOEXCEPT {
45 fl::memset(mMemoryBlock, 0, sizeof(mMemoryBlock));
46#ifdef FASTLED_TESTING
47 __data = memory();
48#endif
49 }
50
51 InlinedMemoryBlock(const InlinedMemoryBlock &other) FL_NOEXCEPT = default;
52 InlinedMemoryBlock(InlinedMemoryBlock &&other) FL_NOEXCEPT = default;
53
54 // u32 mRaw[N * sizeof(T)/sizeof(MemoryType) + kExtraSize];
55 // align this to the size of MemoryType.
56 // u32 mMemoryBlock[kTotalSize] = {0};
57 MemoryType mMemoryBlock[kBlockSize];
58
59 T *memory() FL_NOEXCEPT {
60 MemoryType *begin = &mMemoryBlock[0];
61 fl::uptr shift_up =
62 fl::ptr_to_int(begin) & (sizeof(MemoryType) - 1);
63 MemoryType *raw = begin + shift_up;
64 return fl::bit_cast<T *>(raw);
65 }
66
67 const T *memory() const FL_NOEXCEPT {
68 const MemoryType *begin = &mMemoryBlock[0];
69 const fl::uptr shift_up =
70 fl::ptr_to_int(begin) & (sizeof(MemoryType) - 1);
71 const MemoryType *raw = begin + shift_up;
72 return fl::bit_cast<const T *>(raw);
73 }
74
75#ifdef FASTLED_TESTING
76 T *__data = nullptr;
77#endif
78};
max_align_selector<(sizeof(longdouble)>sizeof(double))>::type max_align_t
Definition s16x16x4.h:56
constexpr T * begin(T(&array)[N]) FL_NOEXCEPT
uptr ptr_to_int(T *ptr) FL_NOEXCEPT
Definition bit_cast.h:71
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
To bit_cast(const From &from) FL_NOEXCEPT
Definition bit_cast.h:48
#define FL_NOEXCEPT

References begin(), bit_cast(), FL_ALIGNAS(), FL_NOEXCEPT, memset(), and ptr_to_int().

+ Here is the call graph for this function: