lkml.org 
[lkml]   [2003]   [Sep]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] document optimizing macro for translating PROT_ to VM_ bits
On Mon, Sep 29, 2003 at 04:34:37PM +0100, Jamie Lokier wrote:

> I agree with the intent of that comment, but the code in it is
> unnecessarily complex. See if you like this, and if you do feel free
> to submit it as a patch:

Ah, much nicer, thank you. I'll submit it, but first, what do you
think about this version? it keeps the optimization and enforces the
"bit1 and bit2 must be single bits only" rule. It could probably be
improved to be done at build time, if bit1 and bit2 and compile time
constants. Against 2.6.0-t6-cvs, compiles and boots for me.

--- linux-2.5/include/linux/mman.h Sun Sep 7 10:05:18 2003
+++ calc-vm-bit-optimizing-macro-2.6.0-t6//include/linux/mman.h Tue Sep 30 10:02:01 2003
@@ -28,10 +28,28 @@
vm_acct_memory(-pages);
}

-/* Optimisation macro. */
-#define _calc_vm_trans(x,bit1,bit2) \
- ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
- : ((x) & (bit1)) / ((bit1) / (bit2)))
+/*
+ * assert that only a single bit is on in 'bit'
+ */
+static inline void assert_single_bit(unsigned long bit)
+{
+ BUG_ON(bit & (bit - 1));
+}
+/*
+ * Optimisation function. It is equivalent to:
+ * (x & bit1) ? bit2 : 0
+ * but this version is faster.
+ * ("bit1" and "bit2" must be single bits).
+ */
+static inline unsigned long
+_calc_vm_trans(unsigned long x, unsigned long bit1, unsigned long bit2)
+{
+ assert_single_bit(bit1);
+ assert_single_bit(bit2);
+
+ return ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1))
+ : ((x) & (bit1)) / ((bit1) / (bit2)));
+}

/*
* Combine the mmap "prot" argument into "vm_flags" used internally.
--
Muli Ben-Yehuda
http://www.mulix.org

[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 13:49    [W:1.947 / U:0.012 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site