Message ID | 20190924172503.30864-2-jacopo@jmondi.org |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Jacopo, On 24/09/2019 18:24, Jacopo Mondi wrote: I know there's not much to say, but I always fear an empty commit message :-D > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> > --- > src/libcamera/include/utils.h | 2 ++ > src/libcamera/utils.cpp | 11 +++++++++++ > 2 files changed, 13 insertions(+) > > diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h > index 52eee8ac2804..08323966b44e 100644 > --- a/src/libcamera/include/utils.h > +++ b/src/libcamera/include/utils.h > @@ -63,6 +63,8 @@ using time_point = std::chrono::steady_clock::time_point; > struct timespec duration_to_timespec(const duration &value); > std::string time_point_to_string(const time_point &time); > > +#define ALIGN(_s, _a) (((_s) + (_a - 1)) & ~(_a - 1)) > + > } /* namespace utils */ > > } /* namespace libcamera */ > diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp > index 928db254ec67..c3188bfff03d 100644 > --- a/src/libcamera/utils.cpp > +++ b/src/libcamera/utils.cpp > @@ -143,6 +143,17 @@ std::string time_point_to_string(const time_point &time) > return ossTimestamp.str(); > } > > +/** > + * \def ALIGN(_s, _a) > + * \brief Align a size to a boundary > + * \param[in] _s The size to align > + * \param[in] _a The boundary to align size to > + * > + * Align the provide size \a _s to a the provided boundary. The request > + * alignement should be a power of 2, and the aligned size is up aligned to s/alignement/alignment/ > + * the given boundary. > + */ I haven't yet seen how this macro is to be used, but C++11 has alignof() and alignas() keywords. Have you considered them? I guess it will depend on whether you are looking to reserve an area where the size is a power of 2, or if you are just trying to allocate on boundaries. I guess that might also suggest that merging this into a patch where it is used would clarify it's intended usage. > + > } /* namespace utils */ > > } /* namespace libcamera */ >
Hi Kieran, On Thu, Sep 26, 2019 at 08:58:05PM +0100, Kieran Bingham wrote: > Hi Jacopo, > > On 24/09/2019 18:24, Jacopo Mondi wrote: > > I know there's not much to say, but I always fear an empty commit > message :-D You shall fear no more! I'll add a commit message ;) > > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> > > --- > > src/libcamera/include/utils.h | 2 ++ > > src/libcamera/utils.cpp | 11 +++++++++++ > > 2 files changed, 13 insertions(+) > > > > diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h > > index 52eee8ac2804..08323966b44e 100644 > > --- a/src/libcamera/include/utils.h > > +++ b/src/libcamera/include/utils.h > > @@ -63,6 +63,8 @@ using time_point = std::chrono::steady_clock::time_point; > > struct timespec duration_to_timespec(const duration &value); > > std::string time_point_to_string(const time_point &time); > > > > +#define ALIGN(_s, _a) (((_s) + (_a - 1)) & ~(_a - 1)) > > + > > } /* namespace utils */ > > > > } /* namespace libcamera */ > > diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp > > index 928db254ec67..c3188bfff03d 100644 > > --- a/src/libcamera/utils.cpp > > +++ b/src/libcamera/utils.cpp > > @@ -143,6 +143,17 @@ std::string time_point_to_string(const time_point &time) > > return ossTimestamp.str(); > > } > > > > +/** > > + * \def ALIGN(_s, _a) > > + * \brief Align a size to a boundary > > + * \param[in] _s The size to align > > + * \param[in] _a The boundary to align size to > > + * > > + * Align the provide size \a _s to a the provided boundary. The request > > + * alignement should be a power of 2, and the aligned size is up aligned to > > s/alignement/alignment/ > > > + * the given boundary. > > + */ > > I haven't yet seen how this macro is to be used, but C++11 has alignof() > and alignas() keywords. > The macro is used in the implementation of the Serializer class ([03/21]) During the serialization of DataValue and DataInfo, it is used to align the sizes of the types a DataValue transport, and the min and max DataValue a DataInfo transports. It is also used to calulculate the size of the memory area to allocate to hold the serialized content. > Have you considered them? No, I didn't know :) > > I guess it will depend on whether you are looking to reserve an area > where the size is a power of 2, or if you are just trying to allocate on > boundaries. I mostly use it to calulate sizes, which are used in the Serializer sub-class to advance the pointer where to store data and where to fish data from... Those marcos seems to be type oriented, I'm not sure it's worth going down that path in this case.. Or actually, DataInfo DataValue could be made-sublcasses of a Serialized , defined with alignas(8).. It could actually work, as I could then use alignof() on the DataType to get the right size... I could actually get rid of the ALIGN macro maybe? Thanks j > > I guess that might also suggest that merging this into a patch where it > is used would clarify it's intended usage. > > > + > > } /* namespace utils */ > > > > } /* namespace libcamera */ > > > > -- > Regards > -- > Kieran
diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h index 52eee8ac2804..08323966b44e 100644 --- a/src/libcamera/include/utils.h +++ b/src/libcamera/include/utils.h @@ -63,6 +63,8 @@ using time_point = std::chrono::steady_clock::time_point; struct timespec duration_to_timespec(const duration &value); std::string time_point_to_string(const time_point &time); +#define ALIGN(_s, _a) (((_s) + (_a - 1)) & ~(_a - 1)) + } /* namespace utils */ } /* namespace libcamera */ diff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp index 928db254ec67..c3188bfff03d 100644 --- a/src/libcamera/utils.cpp +++ b/src/libcamera/utils.cpp @@ -143,6 +143,17 @@ std::string time_point_to_string(const time_point &time) return ossTimestamp.str(); } +/** + * \def ALIGN(_s, _a) + * \brief Align a size to a boundary + * \param[in] _s The size to align + * \param[in] _a The boundary to align size to + * + * Align the provide size \a _s to a the provided boundary. The request + * alignement should be a power of 2, and the aligned size is up aligned to + * the given boundary. + */ + } /* namespace utils */ } /* namespace libcamera */
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> --- src/libcamera/include/utils.h | 2 ++ src/libcamera/utils.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+)