On Wed, Oct 19, 2016 at 8:00 AM, Maxim Uvarov <maxim.uva...@linaro.org> wrote:
> On 10/19/16 15:09, Petri Savolainen wrote: > >> Added a macro to round up a value to the next power of two, >> if it's not already a power of two. Also removed duplicated >> code from the same file. >> >> Signed-off-by: Petri Savolainen <petri.savolai...@nokia.com> >> --- >> .../linux-generic/include/odp_align_internal.h | 34 >> +++++----------------- >> 1 file changed, 7 insertions(+), 27 deletions(-) >> >> diff --git a/platform/linux-generic/include/odp_align_internal.h >> b/platform/linux-generic/include/odp_align_internal.h >> index 9ccde53..d2e9f4f 100644 >> --- a/platform/linux-generic/include/odp_align_internal.h >> +++ b/platform/linux-generic/include/odp_align_internal.h >> @@ -29,24 +29,18 @@ extern "C" { >> /** >> * @internal >> - * Round up pointer 'x' to alignment 'align' >> - */ >> -#define ODP_ALIGN_ROUNDUP_PTR(x, align)\ >> - ((void *)ODP_ALIGN_ROUNDUP((uintptr_t)(x), (uintptr_t)(align))) >> - >> -/** >> - * @internal >> - * Round up pointer 'x' to cache line size alignment >> + * Round up 'x' to alignment 'align' >> */ >> -#define ODP_CACHE_LINE_SIZE_ROUNDUP_PTR(x)\ >> - ((void *)ODP_CACHE_LINE_SIZE_ROUNDUP((uintptr_t)(x))) >> +#define ODP_ALIGN_ROUNDUP(x, align)\ >> + ((align) * (((x) + align - 1) / (align))) >> > Missing parens around 2nd instance of align here. should be ((align) * (((x) + (align) - 1) / (align))) > >> > > name has to be _ODP_ALIGN_ROUNDUP as it's not public API. This patch is > easy to review, > but it will be good to change naming also. > > Maxim. > > > > /** >> * @internal >> - * Round up 'x' to alignment 'align' >> + * When 'x' is not already a power of two, round it up to the next >> + * power of two value. Zero is not supported as an input value. >> */ >> -#define ODP_ALIGN_ROUNDUP(x, align)\ >> - ((align) * (((x) + align - 1) / (align))) >> +#define ODP_ROUNDUP_POWER_2(x)\ >> + (1 << (((int)(8 * sizeof(x))) - __builtin_clz(x - 1))) >> /** >> * @internal >> @@ -82,20 +76,6 @@ extern "C" { >> /** >> * @internal >> - * Round down pointer 'x' to 'align' alignment, which is a power of two >> - */ >> -#define ODP_ALIGN_ROUNDDOWN_PTR_POWER_2(x, align)\ >> -((void *)ODP_ALIGN_ROUNDDOWN_POWER_2((uintptr_t)(x), >> (uintptr_t)(align))) >> - >> -/** >> - * @internal >> - * Round down pointer 'x' to cache line size alignment >> - */ >> -#define ODP_CACHE_LINE_SIZE_ROUNDDOWN_PTR(x)\ >> - ((void *)ODP_CACHE_LINE_SIZE_ROUNDDOWN((uintptr_t)(x))) >> - >> -/** >> - * @internal >> * Round down 'x' to 'align' alignment, which is a power of two >> */ >> #define ODP_ALIGN_ROUNDDOWN_POWER_2(x, align)\ >> > >