mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Solar Designer <solar@openwall.com>
To: musl@lists.openwall.com
Subject: Re: tough choice on thread pointer initialization issue
Date: Fri, 10 Feb 2012 23:12:09 +0400	[thread overview]
Message-ID: <20120210191209.GA17416@openwall.com> (raw)
In-Reply-To: <20120210170015.GH146@brightrain.aerifal.cx>

On Fri, Feb 10, 2012 at 12:00:15PM -0500, Rich Felker wrote:
> On Fri, Feb 10, 2012 at 02:42:52PM +0400, Solar Designer wrote:
> > All of these execute in 1000 cycles total as well.  With "w" forms of
> > the instructions there are extra prefixes, so I think these should
> > better be avoided, even though there's no slowdown from them on this CPU.
> 
> I had no idea it was even valid to use the non-w-prefix forms with
> segment registers. Learned something new. Are the high bits just
> discarded (when writing) and zeroed (when reading)?

Yes.

Frankly, I am not sure how portable this is exactly.  The Linux kernel
uses these short forms unconditionally (although there are also a few
instances of "movw"), whereas glibc somehow uses them on 686+ only - see
nptl/sysdeps/i386/tls.h vs. nptl/sysdeps/i386/i686/tls.h.  The latter
has this comment:

/* Macros to load from and store into segment registers.  We can use
   the 32-bit instructions.  */

My guess is that this is one of those things that was always this way,
but was only documented much later - starting with Pentium Pro maybe?
We can download some PDFs from Intel to confirm when this appeared
officially.  I'd start with those for PPro.

There were several things documented at about this time - e.g., the SALC
instruction that was available since 8086 (including clones), but was
only documented by Intel starting with Pentium Pro.

glibc is probably too careful in limiting this to 686+.

Well, I wouldn't be too surprised if some pre-686 CPU did not zero out
the high bits on read from segment registers into 32-bit registers.
If we're merely copying the value into another segment register, this
does not matter, but for the non-zero test it does...

Alexander


  reply	other threads:[~2012-02-10 19:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10  2:58 Rich Felker
2012-02-10  7:40 ` Solar Designer
2012-02-10  7:58   ` Rich Felker
2012-02-10 10:42     ` Solar Designer
2012-02-10 11:22       ` Solar Designer
2012-02-10 17:00       ` Rich Felker
2012-02-10 19:12         ` Solar Designer [this message]
2012-02-25  6:56 ` Rich Felker
2012-02-25 13:32   ` Rich Felker

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=20120210191209.GA17416@openwall.com \
    --to=solar@openwall.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).