lkml.org 
[lkml]   [2003]   [Sep]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] document optimizing macro for translating PROT_ to VM_ bits
From
Date
On Mon, 29 Sep 2003 16:34:37 BST, Jamie Lokier said:
> Muli Ben-Yehuda wrote:
> > -/* Optimisation macro. */
> > +/* Optimisation macro, used to be defined as: */
> > +/* ((bit1 == bit2) ? (x & bit1) : (x & bit1) ? bit2 : 0) */
> > +/* but this version is faster */
> > +/* "check if bit1 is on in 'x'. If it is, return bit2" */
> > #define _calc_vm_trans(x,bit1,bit2) \
> > ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
> > : ((x) & (bit1)) / ((bit1) / (bit2)))
>
> 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:
>
> /* Optimisation macro. It is equivalent to:
> (x & bit1) ? bit2 : 0
> but this version is faster. ("bit1" and "bit2" must be single bits). */

Is this supposed to return the bitmask bit2, or (x & bit2)? If the former,
then your code is right. If the latter, (x & bit1) ? (x & bit2) : 0

I'm totally failing to see why the original did the bit1 == bit2 compare,
so maybe mhyself and Jamie are both missing some subtlety?
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2005-03-22 13:48    [W:0.051 / U:0.508 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site