> >  /**
> >   * @internal
> > - * 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_ROUNDUP_POWER_2(x)\
> > -       (1 << (((int)(8 * sizeof(x))) - __builtin_clz((x) - 1)))
> > + * Round up a uint32_t value 'x' to the next power of two. It's not
> round up,
> > + * if it's already a power of two. It must be larger than 0 and must
> not exceed
> 
> Macro fails and reports ODP_ROUNDUP_POWER_2(1) == 1 instead of the
> correct answer 2. Probably easier to just document that arg must be >
> 1 unless you want to special-case this endpoint.


Sent v2 which addresses this. Actually, 1 is also a power of two (2^0).


> 
> > + * 0x80000000.
> > + */
> > +#define _SHIFT_U32(x, y)  (((uint32_t)(x)) >> (y))
> > +#define _POW2_U32_R1(x)   (((uint32_t)(x)) | _SHIFT_U32(x, 1))
> > +#define _POW2_U32_R2(x)   (_POW2_U32_R1(x) |
> _SHIFT_U32(_POW2_U32_R1(x), 2))
> > +#define _POW2_U32_R3(x)   (_POW2_U32_R2(x) |
> _SHIFT_U32(_POW2_U32_R2(x), 4))
> > +#define _POW2_U32_R4(x)   (_POW2_U32_R3(x) |
> _SHIFT_U32(_POW2_U32_R3(x), 8))
> > +#define _POW2_U32_R5(x)   (_POW2_U32_R4(x) |
> _SHIFT_U32(_POW2_U32_R4(x), 16))
> > +
> > +#define ODP_ROUNDUP_POWER2_U32(x) \
> > +       (((x) > 0x80000000) ? 0 : (_POW2_U32_R5(x - 1) + 1))
> 
> Should be (((uint32_t)(x)) ... ) here otherwise fails if arg is not
> unsigned.

This is also in v2.

-Petri

Reply via email to