Re: [PATCH] document optimizing macro for translating PROT_ to VM_ bits
From: Thomas Schlichter
Date: Tue Sep 30 2003 - 05:36:50 EST
Hi,
here just my 2 cents...
On Tuesday 30 September 2003 11:24, Muli Ben-Yehuda wrote:
~~ snip ~~
> /*
> * assert that only a single bit is on in 'bit'
> */
> #define assert_single_bit(bit) do { \
> if (__builtin_constant_p(bit)) { \
> if ((bit & (bit -1))) \
> __assert_single_bit_failed_dont_exist(); \
> } else \
> BUG_ON(!(bit & (bit - 1))); \
> } while(0)
In the BUG_ON statement the "!" looks wrong to me...
> /*
> * 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
> inline_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)));
>
> }
Why don't we do:
static inline unsigned long calc_vm_trans(const unsigned long x,
const unsigned long bit1, const unsigned long bit2) {
assert_single_bit(bit1);
assert_single_bit(bit2);
/* Optimisation function */
if (__builtin_constant_p(bit1) && __builtin_constant_p(bit2)) {
return ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1))
: ((x) & (bit1)) / ((bit1) / (bit2)));
}
return (x & bit1) ? bit2 : 0;
}
Best regards
Thomas Schlichter
Attachment:
pgp00001.pgp
Description: signature