RE: [PATCH net-next 1/7] timecounter: provide a macro to initialize the cyclecounter mask field.
From: David Laight
Date: Mon Jan 05 2015 - 09:27:52 EST
> There is no need for users of the timecounter/cyclecounter code to include
> clocksource.h just for a single macro.
>
> Signed-off-by: Richard Cochran <richardcochran@xxxxxxxxx>
> ---
> include/linux/timecounter.h | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/timecounter.h b/include/linux/timecounter.h
> index 74f4549..4382035 100644
> --- a/include/linux/timecounter.h
> +++ b/include/linux/timecounter.h
> @@ -19,6 +19,9 @@
>
> #include <linux/types.h>
>
> +/* 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?
David
--
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/