mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jens Gustedt <jens.gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: Re: Optimized C memset
Date: Tue, 27 Aug 2013 11:50:40 +0200	[thread overview]
Message-ID: <1377597040.25996.295.camel@eris.loria.fr> (raw)
In-Reply-To: <20130827091730.GN20515@brightrain.aerifal.cx>

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

Am Dienstag, den 27.08.2013, 05:17 -0400 schrieb Rich Felker:
> So far, my experience is that compilers which advertise themseleves as
> "GNU C" compilers have all the semantic features of GCC 3 at the very
> least. Is this an invalid assumption?

for gcc versions less than 4, probably, I don't remember an exception
for that. For version in the 4, there are several such examples.

> > To make this easier to maintain, I'd suggest to introduce a special
> > feature test macro, something like __has_may_alias__, and have that
> > set at the beginning of the file in a section that is clearly
> > dedicated to compile time feature detection. Other compilers may have
> > different syntax for such a feature (a _Pragma comes in mind) and may
> > be detected quite differently than by gcc version numbering.
> 
> Where would you suggest it be added? The result of the check is only
> used in one place, so I don't see how


I'd wouldn't have an #else case to the detection but do

#ifndef may_alias
# if 100*__GNUC__+__GNUC_MINOR__ >= 302
#  define may_alias __attribute__((__may_alias__))
# endif
#endif

#ifdef may_alias
# define __has_may_alias__
#else
# define may_alias
#endif

This is not much more complicated than what you have and makes it easy
to add other cases, without having to maintain the __has_may_alias__
feature macro itself.


> If on the other hand you're suggesting that I should be more
> conservative and check not just for __GNUC__, but also for the
> availability of __may_alias__, in the actual code body (rather than
> just the typedefs), then it may make more sense.

yes, I thought in these lines. that code should be handled well by any
modern compiler that you can convince to not playing games with
aliasing, here. So the fact that you tested it with gcc-like compilers
is merely an artefact.

> > Such specific feature test macros is the way that clang goes, and from
> > my experience this is much easier to maintain and to understand when
> > you stumble on such #ifdef'ed code. You not only know that this needs
> > a special version of a compiler, but also for what reason.
> 
> Oh, I agree it's much cleaner. Sadly, though, GCC doesn't seem to give
> us that information...

yes, for gcc you'd always have to detect features in the way you are
doing it know. But I'd think that feature detection should be
separated from the use of the features. The uses might be spread over
several places, but the detection should be done in one well
detectable spot in the source code.

Jens

-- 
:: INRIA Nancy Grand Est :: http://www.loria.fr/~gustedt/   ::
:: AlGorille ::::::::::::::: office Nancy : +33 383593090   ::
:: ICube :::::::::::::: office Strasbourg : +33 368854536   ::
:: ::::::::::::::::::::::::::: gsm France : +33 651400183   ::
:: :::::::::::::::::::: gsm international : +49 15737185122 ::



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2013-08-27  9:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-27  8:30 Rich Felker
2013-08-27  8:52 ` Jens Gustedt
2013-08-27  9:17   ` Rich Felker
2013-08-27  9:50     ` Jens Gustedt [this message]
2013-08-27 14:21       ` Rich Felker
2013-08-27 14:34         ` Luca Barbato
2013-08-27 14:39           ` Rich Felker
2013-08-27 15:20         ` John Spencer
2013-08-27 15:34           ` Rich Felker
2013-08-27 16:22 ` Optimized C memset [v2] Rich Felker
2013-08-27 17:28   ` Jeremy Huntwork
2013-08-27 21:27     ` Rich Felker
2013-08-28  0:05   ` Andre Renaud
2013-08-28  1:24     ` 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=1377597040.25996.295.camel@eris.loria.fr \
    --to=jens.gustedt@inria.fr \
    --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).