Re: [PATCH] document optimizing macro for translating PROT_ to VM_ bits

From: Muli Ben-Yehuda
Date: Thu Oct 02 2003 - 06:40:58 EST


On Tue, Sep 30, 2003 at 07:00:53PM +0900, Miles Bader wrote:
> Muli Ben-Yehuda <mulix@xxxxxxxxx> writes:
> > I like code that is "future proof", especially when it doesn't cost
> > anything.
>
> Sure, it's not always worth the trouble/pain to do so unless you've
> actually got some reason to think it will be mis-used.
>
> This is seeming more and more like such a case: it's a very special
> purpose macro which is only used by two other small functions, both of
> which are located immediately adjacent to the macro's definition.

After taking the time to cool down from the testosterone rush commonly
induced by micro optimizations, I recon you're right. Andrew, please
apply this documentation only patch against 2.6.0-t6-mm2:

--- linux-2.5/include/linux/mman.h Sun Sep 7 10:05:18 2003
+++ optimizing-macro-2.6.0-t6/include/linux/mman.h Tue Sep 30 09:47:19 2003
@@ -28,8 +28,13 @@
vm_acct_memory(-pages);
}

-/* Optimisation macro. */
-#define _calc_vm_trans(x,bit1,bit2) \
+/*
+ * Optimisation macro. It is equivalent to:
+ * (x & bit1) ? bit2 : 0
+ * but this version is faster.
+ * ("bit1" and "bit2" must be single bits).
+ */
+#define _calc_vm_trans(x, bit1, bit2) \
((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
: ((x) & (bit1)) / ((bit1) / (bit2)))


--
Muli Ben-Yehuda
http://www.mulix.org

Attachment: signature.asc
Description: Digital signature