Conversation
- declare mem_len as size_t - remove useless operations separating even & odd parts - remove useless set operation that
A vector of `n` DATA buffers (array of T) and an OPTIONAL vector of `n` META buffers (array of `uint8_t`). A meta buffer corresponds to a data buffer. Every `s`-byte data element of a data buffer corresponds to a `s`-bit element of the meta buffer. A pair of data and meta elements can represent an integer of `8*s + s`-bits Each data element points to a buffer of size `m * sizeof(T)` bytes. Hence, each meta element points to a buffer of size `bsize = m * sizeof(T) / 8` bytes that should be an integer, i.e. `m * sizeof(T) % 8 = 0`. This condition is not difficult to achieved as a convenient `size` can be always chosen with a negligible impact on its application.
- use vector to store reversed bit numbers - use Buffer's function for the prepare step of FFT and inverse FFT
- Add `set_meta(buf_id, ele_id, val)` setting meta of a given element - Add `set(buf_id, ele_id, lo, hi)` setting both of data and meta at the `ele_id`th of the `buf_id`th buffer/meta, according to a given unpacked value represented by its two half parts `hi` and `lo`.
| template <typename T> | ||
| inline T mask(size_t len) | ||
| { | ||
| return ((static_cast<T>(1) << len) - 1); |
There was a problem hiding this comment.
Could have an assert to ensure that len is not greater than the number of bit in T.
Optional: We may also want to check that T is an unsigned type
| template <typename T> | ||
| bool operator==(const Buffers<T>& lhs, const Buffers<T>& rhs); | ||
|
|
||
| // Return a mask of `len` ones |
There was a problem hiding this comment.
Could be a proper Doxygen comment, same for set_bits.
| return ((static_cast<T>(1) << len) - 1); | ||
| } | ||
|
|
||
| // Set a range of bits of `dest` according to bits of `src` |
There was a problem hiding this comment.
Not so clear, could be written as Copy bits_nbbits starting atd_beginfromsrcintodst`.
Also each parameter could be documented, using Doxygen (and bits_nb could be renamed len and d_begin to offset).
| // reset dest | ||
| dest &= ~(m << d_begin); | ||
| // set dest | ||
| dest |= (static_cast<uint8_t>(src & m) << d_begin); |
There was a problem hiding this comment.
Why casting to uint8_t? this looks buggy to me.
In any case, lossy cast like here should use narrow_cast instead of static_cast.
| T* get(int i); | ||
| const T* get(int i) const; | ||
| void get(int buf_id, size_t ele_id, T& hi, T& lo) const; | ||
| void set(int buf_id, size_t ele_id, T hi, T lo); |
There was a problem hiding this comment.
ele_id could be called index or idx, no? (same for set_meta).
|
|
||
| const size_t bytes = s * sizeof(T); | ||
| size_t r = bytes / CHAR_BIT; | ||
| while (r * CHAR_BIT < bytes) { |
There was a problem hiding this comment.
see my previous comment on that while.
|
|
||
| const size_t bytes = m_size * CHAR_BIT; | ||
| size_t r = bytes / sizeof(T); | ||
| while (r * sizeof(T) < bytes) { |
There was a problem hiding this comment.
ditto about the while
| * @param m_size - given meta size, in bytes | ||
| * @return meta size | ||
| */ | ||
| static size_t compute_size(size_t m_size) |
There was a problem hiding this comment.
compute_size and compute_meta_size are too similar, you should have a single function instead of copy/pasting.
| }; | ||
|
|
||
| /** Calculate conventional size of buffers | ||
| * Conentional size is the lowest number of words that is at least a given |
There was a problem hiding this comment.
s/Conentional/conventional/
Also, skip a line between the short description (the first line) and the detailed one (the rest).
| * @param size_alignment - alignment number of output size, in bytes | ||
| * @param meta_size_alignment - alignment number of meta size according to | ||
| * the out size, in byte | ||
| * @return conventional size, in words |
There was a problem hiding this comment.
What's the size of word? is it 32-bit or is it sizeof(T)?
Buffersconsists of a vector ofnDATA buffers (array of T) and an OPTIONAL vector ofnMETA buffers (array ofuint8_t). A meta buffer corresponds to a data buffer. Everys-byte data element of a data buffer corresponds to ans-bit element of the meta buffer. A pair of data and meta elements canrepresent an integer of
8*s + s-bits Each data element points to a buffer of sizem * sizeof(T)bytes.Hence, each meta element points to a buffer of size
bsize = m * sizeof(T) / 8bytes that should be an integer, i.e.m * sizeof(T) % 8 = 0. This condition is not difficult to achieve as a convenientsizecan be always chosen with a negligible impact on its application.