public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <rdsandiford@googlemail.com>
To: Mark Mitchell <mark@codesourcery.com>
Cc: "Weddington\, Eric" <eweddington@cso.atmel.com>,
	 gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] MIPS function attributes for interrupt handlers
Date: Wed, 22 Oct 2008 10:03:00 -0000	[thread overview]
Message-ID: <87vdvlhyv6.fsf@firetop.home> (raw)
In-Reply-To: <48FE5091.4000406@codesourcery.com> (Mark Mitchell's message of 	"Tue\, 21 Oct 2008 14\:58\:41 -0700")

Mark Mitchell <mark@codesourcery.com> writes:
> Richard Sandiford wrote:
>> I still disagree, for the reasons given before.  MIPS assembly coders
>> already have preprocessor macros to prettify the assembly function
>> declaration syntax.  If the only point of the attribute is to write
>> out that syntax, I don't think the attribute is a win.
>
> I disagree on that point.  Assembly function declaration syntax is
> complex, and varies from OS to OS, and depends on things like whether
> the function is hidden, static, etc.  Making this an
> architecture-independent attribute seems beneficial, as one of GCC's
> core advantages is cross-platform consistency.
>
> For example, writing:
>
>   void mylock()
>     __attribute__((hidden))
>     __attribute__((naked)) {
>     ARCH_MYLOCK;
>   }
>
> where ARCH_MYLOCK is a macro that expands to the CPU-specific assembly
> implementation of a locking primitive seems likely to be useful.  Much
> better than lots of #ifdef __linux__ and #ifdef __mips__ goo in a pure
> assembler file.

I'm not convinced by this example.  GCC already provides a much
more powerful way of doing this: extended asms.  Such an extended
asm has many benefits over naked functions:

  - It can be inlined into bigger functions.  That way, locks don't
    need to be function calls.

  - Other GCC features like function profiling continue to work correctly.

  - There is no need for an attribute.  GCC can tell what resources the
    asm needs, so when optimisation is enabled, GCC won't generate a
    prologue unless the asm needs one.

  - GCC can emit asm directives that depend on the code itself.
    Take the MIPS .frame pseudo-op as an example.  GCC doesn't
    know how much stack space a naked asm uses (if any), or what
    GPRs it uses, so it can't output a correct .frame for it.
    It _can_ (and does) output correct .frames for functions
    containing extended asms.

  - The extended-asm approach is _genuinely_ consistent across platforms.
    All ports support extended asms, and have done for many GCC releases.

    On the other hand, if we did decide to extend the naked attribute to
    other ports, it's likely to be several releases at least before it
    is genuinely consistent.  People would need to know which version of
    GCC first supported the attribute on the targets they care about.

AIUI, the only "advantage" of naked asms over extended asms is that they
allow you to do things that you wouldn't normally be allowed to do, like
write directly to the result register.  But why not simply bind the
return value to an output operand in an extended asm?  Is that
really much uglier than writing "__attribute__((naked))"?

Also, because naked functions cannot refer to their arguments, you will
get a warning for C unless you write:

  void __attribute__((naked))
  foo (int arg1 __attribute__((unused)), 
       int arg2 __attribute__((unused)))
  {
    ...;
  }

The macro definitions themselves would presumably look like:

  #define LOAD_AND_ADD_1 asm ("\
     lw $2,($4)\
     addiu $2,$2,1\
  ")

The combination of these two doesn't seem any prettier or easier
to me than having a source code file:

  FUNC_START(foo)
    lw $2,($4)
    addiu $2,$2,1
  FUNC_END(foo)

(which among other things avoids those infernal backslashes).

I agree with what Thiemo said about defining these assembly macros.
You said in reply that they were hard to write, but the point is that,
for the ports we're talking about, you don't need to.  Other people
already have.  (And most of the architectural differences between
these macros are historical.  GAS itself is much more consistent.)

It just seems to me that we're trying to introduce a feature in the name
of cross-platform consistency in cases where (a) in the foreseeable
future, "cross-platform" will mean "across a handful of targets" and
(b) we already have a better feature that is genuinely cross-platform.
(I say "foreseeable future" because we can't of course predict what
people will contribute.)

Richard

  parent reply	other threads:[~2008-10-22  7:30 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-14 20:29 Fu, Chao-Ying
2008-10-15 23:47 ` Richard Sandiford
2008-10-20 23:03   ` Mark Mitchell
2008-10-20 23:24     ` Adam Nemet
2008-10-21 16:15     ` Weddington, Eric
2008-10-21 17:01       ` Mark Mitchell
2008-10-21 23:11         ` Richard Sandiford
2008-10-21 23:49           ` Mark Mitchell
2008-10-22  0:16             ` Thiemo Seufer
2008-10-22  1:05               ` Mark Mitchell
2008-10-22  6:36                 ` Thiemo Seufer
2008-10-22  6:54                   ` Mark Mitchell
2008-10-22  7:30                     ` Weddington, Eric
2008-10-22 10:03             ` Richard Sandiford [this message]
2008-10-22 17:43               ` Mark Mitchell
2008-10-22 20:28                 ` Richard Sandiford
2008-10-28  5:07   ` Fu, Chao-Ying
2008-10-29  8:05     ` Richard Sandiford
2008-10-16 22:34 ` Adam Nemet
2009-02-25  7:01 ` Fu, Chao-Ying
2009-02-25  9:35   ` Adam Nemet
2009-02-25 17:51   ` Daniel Jacobowitz
2009-02-26  9:48     ` Fu, Chao-Ying
2009-02-27 20:46       ` Maciej W. Rozycki
2009-02-28 10:15         ` Fu, Chao-Ying
2009-02-28 18:39           ` Maciej W. Rozycki
2008-10-17 11:40 Fu, Chao-Ying
2008-10-23  9:06 Ross Ridge

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=87vdvlhyv6.fsf@firetop.home \
    --to=rdsandiford@googlemail.com \
    --cc=eweddington@cso.atmel.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mark@codesourcery.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).