Messages in this thread | | | Subject | Re: [PATCH] document optimizing macro for translating PROT_ to VM_ bits | From | Valdis.Kletnieks@vt ... | Date | Mon, 29 Sep 2003 11:51:35 -0400 |
| |
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] | |