lkml.org 
[lkml]   [2003]   [Sep]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] document optimizing macro for translating PROT_ to VM_ bits
Date
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
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 13:49    [W:0.057 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site