Re: [PATCH net-next 1/7] timecounter: provide a macro to initialize the cyclecounter mask field.

From: Richard Cochran
Date: Mon Jan 05 2015 - 08:43:39 EST


On Mon, Jan 05, 2015 at 01:20:57PM +0000, David Laight wrote:
> > +/* simplify initialization of mask field */
> > +#define CYCLECOUNTER_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
>
> That has me chasing through the C integer promotion rules.
> Better might be:
> ((bits) < 64 ? (1ULL << (bits)) - 1 : (((1ULL << 63) - 1) << 1) + 1)
> I actually suspect there is a standard definition somewhere?

This is an exact copy of CLOCKSOURCE_MASK, and if wrong, then both are
wrong. In any case, I can't see any issue here. Is not

(some_int_type) -1

always equal to

0xf...(width of type)

for all integer types, when using 2s compliment?

Thanks
Richard




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/