mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gabriel Paubert <paubert@iram.es>
To: Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
Cc: insecure <insecure@mail.od.ua>,
	"J.A. Magallon" <jamagallon@able.es>,
	Lista Linux-Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [2.4] gcc3 warns about type-punned pointers ?
Date: Sat, 30 Aug 2003 13:09:14 +0000	[thread overview]
Message-ID: <20030830130914.A3041@mrt-lx1.iram.es> (raw)
In-Reply-To: <Pine.LNX.4.44.0308301427320.3338-100000@artax.karlin.mff.cuni.cz>

On Sat, Aug 30, 2003 at 02:33:08PM +0200, Mikulas Patocka wrote:
> > > A collateral question: why is the reason for this function ?
> > > long long assignments are not atomic in gcc ?
> >
> > Another question: why do we do _double_ store here?
> >
> > static inline void __set_64bit (unsigned long long * ptr,
> >                 unsigned int low, unsigned int high)
> > {
> >         __asm__ __volatile__ (
> >                 "\n1:\t"
> >                 "movl (%0), %%eax\n\t"
> >                 "movl 4(%0), %%edx\n\t"
> >                 "lock cmpxchg8b (%0)\n\t"
> >                 "jnz 1b"
> >                 : /* no outputs */
> >                 :       "D"(ptr),
> >                         "b"(low),
> >                         "c"(high)
> >                 :       "ax","dx","memory");
> > }
> >
> > This will execute expensive locked load-compare-store operation twice
> > almost always (unless previous value was already equal
> > to the value we are about to store)
> 
> It doesn't double store. cmpxchg8b does:
> compare memory with edx:eax
> 	if equal, copy copy ecx:ebx into memory, set zf = 1
> 	else copy memory into edx:eax, set zf = 0
> 
> > AFAIK we can safely drop that loop (jnz instruction)
> 
> No. The only possible optimization would be to move 1: label directly at
> cmpxgch8b. But it won't bring much, because loop is executed only if value
> was changed after read and before cmpxchg.

Indeed.

> 
> There is another worse problem --- jump instructions are predicted as
> taken when they point backwards, so it gets mispredicted. jnz should
> really point to some other section, that is linked after .text, where
> unconditional jump backwards would be.

On Pentium IV, you can prefix the jump instruction to alter the default 
prediction (the encoding reuses one of the segment overides prefixes).

	Regards,
	Gabriel

  reply	other threads:[~2003-08-30 13:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-28 22:35 J.A. Magallon
2003-08-29 15:24 ` Antonio Vargas
2003-08-29 18:48   ` J.A. Magallon
2003-08-29 19:41     ` Richard B. Johnson
2003-08-30  6:27       ` Antonio Vargas
2003-08-30  9:56         ` Willy Tarreau
2003-08-30 11:31           ` Jamie Lokier
2003-08-30  2:37 ` insecure
2003-08-30 12:33   ` Mikulas Patocka
2003-08-30 13:09     ` Gabriel Paubert [this message]
2003-08-30 23:27     ` insecure
2003-08-31  1:27 ` J.A. Magallon

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=20030830130914.A3041@mrt-lx1.iram.es \
    --to=paubert@iram.es \
    --cc=insecure@mail.od.ua \
    --cc=jamagallon@able.es \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikulas@artax.karlin.mff.cuni.cz \
    /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

all inboxes | Powered by JetHome®