lkml.org 
[lkml]   [2015]   [Apr]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 2/3 V2] time: allow gcc to fold constants when using
On Sun, 12 Apr 2015, Nicholas Mc Guire wrote:
> +extern unsigned long __msecs_to_jiffies(const unsigned int m);
> +#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
> +static inline unsigned long _msecs_to_jiffies(const unsigned int m)
> +{

This should move the comments explaining the logic for each variant as
well.

> + return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
> +}
> +#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
> +static inline unsigned long _msecs_to_jiffies(const unsigned int m)
> +{
> + if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
> + return MAX_JIFFY_OFFSET;
> + return m * (HZ / MSEC_PER_SEC);
> +}
> +#else
> +static inline unsigned long _msecs_to_jiffies(const unsigned int m)
> +{
> + if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
> + return MAX_JIFFY_OFFSET;
> +
> + return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32)
> + >> MSEC_TO_HZ_SHR32;
> +}
> +#endif
> +static inline unsigned long msecs_to_jiffies(const unsigned int m)
> +{
> + if (__builtin_constant_p(m)) {
> + if ((int)m < 0)
> + return MAX_JIFFY_OFFSET;
> + return _msecs_to_jiffies(m);
> + } else
> + return __msecs_to_jiffies(m);

It'd be nice to have this as two patches:

1) Factor out the code into inline helpers w/o adding anything

2) Add the __builtin_constant_p() check

Thanks,

tglx


\
 
 \ /
  Last update: 2015-04-22 14:21    [W:0.028 / U:0.280 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site