mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: Model specific optimizations?
Date: Thu, 29 Sep 2016 19:08:01 +0200	[thread overview]
Message-ID: <20160929170801.GC22343@voyager> (raw)
In-Reply-To: <20160929152354.GK19318@brightrain.aerifal.cx>

On Thu, Sep 29, 2016 at 11:23:54AM -0400, Rich Felker wrote:
> What kind of version-checking? Not all systems even give you a way to
> version-check.
> 

To the extent that they don't, they also don't give you a way to check
for features (again, except for executing the instructions and seeing if
you get SIGILL). PowerPC (sorry, but that's where I spent a lot of time
on recently) for instance only has the PVR (Processor Version Register).
No software I could find online uses another way to detect the features
of the CPU.

And for systems to not give you a way of detecting system version at
runtime and then define optional parts of the ISA would be very dickish,
in my opinion. That basically guarentees optional functions won't be
used at all.

> This code contains data races. In order to be safe under musl's memory
> model, sqrtfn would have to be volatile and should probably be written
> via a_cas_p. It also then has to have type void* and be cast to/from
> function pointer type. See clock_gettime.c.
> 

Well, yes, I was just throwing shit at a wall to see what sticks. We
could also move the function pointer dispatch into a pthread_once block
or something. I don't know if any caches need to be cleared then or not.

But yes, there are better examples.

> For some archs, gas produces an error or tags the .o file as needing a
> certain ISA level if you use an instruction that's not present in the
> baseline ISA. I'm not sure if this is an issue here or not.
> 

As I said, fsqrt is defined in the baseline ISA, just marked as
optional. So any PowerPC implementation is free to include it or not.
There are a lot of optional features, and if the gas people made a
different subarch for each combination of them, they'd be here all day.

Not just instructions, too. Sometimes the optional thing is a register,
and sometimes just bits in a register.


> I think it's the #define sqrt soft_sqrt that's a hack. The inclusion
> itself is okay and would be the right way to do this for sure if it
> were just a compile-time check and not a runtime one.
> 

I meant the define. While it is hacky, it does mean no code duplication
and only one externally facing symbol regarding sqrt(), which is the one
defined by the standard. Although I am abusing the little known rule
about C that if a function is declared as static in its prototype, and
the function definition doesn't have an explicit storage class
specifier, then the function will be static. Most style guides (rightly)
say to have the storage class specifier in the prototype and the
definition be the same, because otherwise this gets confusing fast.

I guess it goes to show that you should know your language even in the
parts you barely ever use (because forbidden), because they might come
in handy at some point.

> Rich

Ciao,
Markus


  reply	other threads:[~2016-09-29 17:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-29 14:21 Markus Wichmann
2016-09-29 14:57 ` Szabolcs Nagy
2016-09-29 15:23 ` Rich Felker
2016-09-29 17:08   ` Markus Wichmann [this message]
2016-09-29 18:13     ` Rich Felker
2016-09-29 18:52       ` Adhemerval Zanella
2016-09-29 22:05         ` Szabolcs Nagy
2016-09-29 23:14           ` Adhemerval Zanella
2016-09-30  4:56       ` Markus Wichmann
2016-10-01  5:50         ` Rich Felker
2016-10-01  8:52           ` Markus Wichmann
2016-10-01 15:10             ` Rich Felker
2016-10-01 19:53               ` Markus Wichmann
2016-10-02 13:59                 ` Adhemerval Zanella

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=20160929170801.GC22343@voyager \
    --to=nullplan@gmx.net \
    --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).