* [PATCH] log2.h: Define order_base_2() macro for convenience.
@ 2007-11-11 3:53 Robert P. J. Day
2007-11-11 18:28 ` Randy Dunlap
0 siblings, 1 reply; 4+ messages in thread
From: Robert P. J. Day @ 2007-11-11 3:53 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: Andrew Morton
Given a number of places in the tree that need to calculate this value
explicitly, might as well just create a macro for it.
Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
---
run-time tested for the first several values. note that this macro
is defined strictly in terms of rounding *up* -- i've seen no places
in the tree that require this expression to be rounded down, so i'm
not drawing that distinction.
diff --git a/include/linux/log2.h b/include/linux/log2.h
index c8cf5e8..ed121c0 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -190,4 +190,20 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
__rounddown_pow_of_two(n) \
)
+/**
+ * order_base_2 - calculate the (rounded up) base 2 order of the argument
+ * @n - parameter
+ *
+ * The first few values calculated by this routine:
+ * ob2(0) = 0
+ * ob2(1) = 0
+ * ob2(2) = 1
+ * ob2(3) = 2
+ * ob2(4) = 2
+ * ob2(5) = 3
+ * ... and so on.
+ */
+
+#define order_base_2(n) ilog2(roundup_pow_of_two(n))
+
#endif /* _LINUX_LOG2_H */
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://crashcourse.ca
========================================================================
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] log2.h: Define order_base_2() macro for convenience.
2007-11-11 3:53 [PATCH] log2.h: Define order_base_2() macro for convenience Robert P. J. Day
@ 2007-11-11 18:28 ` Randy Dunlap
2007-11-12 7:27 ` Robert P. J. Day
0 siblings, 1 reply; 4+ messages in thread
From: Randy Dunlap @ 2007-11-11 18:28 UTC (permalink / raw)
To: Robert P. J. Day; +Cc: Linux Kernel Mailing List, Andrew Morton
On Sat, 10 Nov 2007 22:53:36 -0500 (EST) Robert P. J. Day wrote:
>
> Given a number of places in the tree that need to calculate this value
> explicitly, might as well just create a macro for it.
>
> Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
>
> ---
>
> run-time tested for the first several values. note that this macro
> is defined strictly in terms of rounding *up* -- i've seen no places
> in the tree that require this expression to be rounded down, so i'm
> not drawing that distinction.
>
> diff --git a/include/linux/log2.h b/include/linux/log2.h
> index c8cf5e8..ed121c0 100644
> --- a/include/linux/log2.h
> +++ b/include/linux/log2.h
> @@ -190,4 +190,20 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
> __rounddown_pow_of_two(n) \
> )
>
> +/**
> + * order_base_2 - calculate the (rounded up) base 2 order of the argument
> + * @n - parameter
* @n: argument
(mostly changing - to :)
> + *
> + * The first few values calculated by this routine:
> + * ob2(0) = 0
> + * ob2(1) = 0
> + * ob2(2) = 1
> + * ob2(3) = 2
> + * ob2(4) = 2
> + * ob2(5) = 3
> + * ... and so on.
> + */
> +
> +#define order_base_2(n) ilog2(roundup_pow_of_two(n))
> +
> #endif /* _LINUX_LOG2_H */
>
> --
---
~Randy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] log2.h: Define order_base_2() macro for convenience.
2007-11-11 18:28 ` Randy Dunlap
@ 2007-11-12 7:27 ` Robert P. J. Day
0 siblings, 0 replies; 4+ messages in thread
From: Robert P. J. Day @ 2007-11-12 7:27 UTC (permalink / raw)
To: Randy Dunlap; +Cc: Linux Kernel Mailing List, Andrew Morton
On Sun, 11 Nov 2007, Randy Dunlap wrote:
> On Sat, 10 Nov 2007 22:53:36 -0500 (EST) Robert P. J. Day wrote:
> >
> > +/**
> > + * order_base_2 - calculate the (rounded up) base 2 order of the argument
> > + * @n - parameter
>
> * @n: argument
>
> (mostly changing - to :)
ah, yes, fix coming shortly.
rday
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] log2.h: Define order_base_2() macro for convenience.
@ 2007-11-12 7:32 Robert P. J. Day
0 siblings, 0 replies; 4+ messages in thread
From: Robert P. J. Day @ 2007-11-12 7:32 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: Andrew Morton
Given a number of places in the tree that need to calculate this value
explicitly, might as well just create a macro for it.
Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
---
run-time tested for the first several values. note that this macro
is defined strictly in terms of rounding *up* -- i've seen no places
in the tree that require this expression to be rounded down, so i'm
not drawing that distinction.
diff --git a/include/linux/log2.h b/include/linux/log2.h
index c8cf5e8..ed121c0 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -190,4 +190,20 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
__rounddown_pow_of_two(n) \
)
+/**
+ * order_base_2 - calculate the (rounded up) base 2 order of the argument
+ * @n: parameter
+ *
+ * The first few values calculated by this routine:
+ * ob2(0) = 0
+ * ob2(1) = 0
+ * ob2(2) = 1
+ * ob2(3) = 2
+ * ob2(4) = 2
+ * ob2(5) = 3
+ * ... and so on.
+ */
+
+#define order_base_2(n) ilog2(roundup_pow_of_two(n))
+
#endif /* _LINUX_LOG2_H */
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA
http://crashcourse.ca
========================================================================
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-11-12 7:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-11 3:53 [PATCH] log2.h: Define order_base_2() macro for convenience Robert P. J. Day
2007-11-11 18:28 ` Randy Dunlap
2007-11-12 7:27 ` Robert P. J. Day
-- strict thread matches above, loose matches on Subject: below --
2007-11-12 7:32 Robert P. J. Day
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox