Re: MSEC_TO_JIFFIES is messed up...

From: William Lee Irwin III
Date: Wed May 12 2004 - 16:09:55 EST


William Lee Irwin III <wli@xxxxxxxxxxxxxx> wrote:
>> How about this?
>> #if HZ <= 1000 && !(1000 % HZ)
>> #define MSEC_TO_JIFFIES(m) ((1000/HZ)*(m))
>> #define JIFFIES_TO_MSEC(j) ((j)/(1000/HZ))
>> #elif HZ > 1000 && !(HZ % 1000)
>> #define MSEC_TO_JIFFIES(m) ((m)/(HZ/1000))
>> #define JIFFIES_TO_MSEC(j) ((HZ/1000)*(j))
>> #else
>> #define MSEC_TO_JIFFIES(m) ((HZ*(m) + 999)/1000)
>> #define JIFFIES_TO_MSEC(j) ((1000*(j) + HZ - 1)/HZ)
>> #endif

On Wed, May 12, 2004 at 01:47:18PM -0700, Andrew Morton wrote:
> You promise it's correct and generates good code?

Yes. Changelog:

Optimize the cases where HZ is a divisor of 1000 or vice-versa in
JIFFIES_TO_MSEC() and MSEC_TO_JIFFIES() by allowing the nonvanishing(!)
integral ratios to appear as a parenthesized expressions eligible for
constant folding optimizations.

I'll resend the #ifdef logic against Ingo's latest, which is orthogonal.


-- wli
-
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/