mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Schlichter <schlicht@uni-mannheim.de>
To: Miles Bader <miles@gnu.org>
Cc: Muli Ben-Yehuda <mulix@mulix.org>,
	Linux-Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] document optimizing macro for translating PROT_ to VM_ bits
Date: Tue, 30 Sep 2003 12:35:32 +0200	[thread overview]
Message-ID: <200309301235.37246.schlicht@uni-mannheim.de> (raw)
In-Reply-To: <20030930092403.GR29313@actcom.co.il>

[-- Attachment #1: Type: text/plain, Size: 1391 bytes --]

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 #2: signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  parent reply	other threads:[~2003-09-30 10:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-29  9:06 Muli Ben-Yehuda
2003-09-29 15:34 ` Jamie Lokier
2003-09-29 15:51   ` Valdis.Kletnieks
2003-09-29 17:11     ` Jamie Lokier
2003-09-29 17:25     ` Maciej Zenczykowski
2003-09-30  2:15       ` Miles Bader
2003-09-30  7:10   ` Muli Ben-Yehuda
2003-09-30  7:34     ` Miles Bader
2003-09-30  7:41       ` Muli Ben-Yehuda
2003-09-30  7:59         ` Miles Bader
2003-09-30  9:24           ` Muli Ben-Yehuda
2003-09-30 10:00             ` Miles Bader
2003-09-30 10:06               ` Miles Bader
2003-10-02 11:37               ` Muli Ben-Yehuda
2003-09-30 10:35             ` Thomas Schlichter [this message]
2003-09-30  8:02   ` Frédéric St-Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200309301235.37246.schlicht@uni-mannheim.de \
    --to=schlicht@uni-mannheim.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miles@gnu.org \
    --cc=mulix@mulix.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome