public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <i@maskray.me>
To: Nick Clifton <nickc@redhat.com>
Cc: binutils@sourceware.org
Subject: Re: RFC: Maintaining a per-macro invocation count
Date: Tue, 14 May 2024 22:59:23 -0700	[thread overview]
Message-ID: <20240515055923.7jlccxxbl574bf5w@google.com> (raw)
In-Reply-To: <87pltw9qku.fsf@redhat.com>

On 2024-05-08, Nick Clifton wrote:
>Hi Guys,
>
>  The attached patch implements a extension to the assembler's macro
>  syntax, allowing a macro to access a count of the number of times that
>  it has been executed via the \+ pseudo-variable.  ie like this:
>
>    .macro foo
>      .print "I have been invoked \+ times"
>    .endm
>
>  This syntax is similar to the already supported \@ pseudo-variable,
>  except that the count is maintained on a per-macro basis.
>
>  The drive for this extension is that I want to be able to generate
>  N references to unique symbols in file A and then N definitions of
>  those symbols in file B.  Using assembler macros makes this easy,
>  providing that I can ensure that the names in file A will match those
>  in file B.  ie:
>
>  fileA.s:
>    .macro gen_refs count
>    .dc.a ref_\+
>    .if \count > 1
>    gen_refs \count-1
>    .endif
>    .endm
>
>    gen_refs 1000
>
>  fileB.s:
>    .macro gen_defs count
>    .global ref_\+
>    ref_\+ :
>    .if \count > 1
>    gen_defs \count-1
>    .endif
>    .endm
>
>    gen_defs 1000
>
>  (This is part of a larger exercise to generate some micro benchmarks
>  for the assembler that exercise various different features.  In this
>  case I am looking into relocation processing).

    (
    I am curious how intrusive it would be to support a new relocation
    format
    https://maskray.me/blog/2024-03-09-a-compact-relocation-format-for-elf#crel-relocation-format
    )

>  Comments, suggestions ?
>
>Cheers
>  Nick
>
>PS. In the course of creating this patch I noticed that the altmacto
>test (gas/testsuite/gas/macros/altmacro.d) does not appear to be run.
>So I have fixed that as well.
>


Thanks for the patch https://sourceware.org/cgit/binutils-gdb/commit/?id=83b972fc272db31ab48aa5cde84f47c98868d7c8
and the test fix!
This feature looks very useful, which resembles
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Special-format-strings

> ‘%=’
>
> Outputs a number that is unique to each instance of the asm statement in
> the entire compilation. This option is useful when creating local labels
> and referring to them multiple times in a single template that generates
> multiple assembler instructions.

  parent reply	other threads:[~2024-05-15  5:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 17:11 Nick Clifton
2024-05-14  1:12 ` Hans-Peter Nilsson
2024-05-15  9:42   ` Nick Clifton
2024-05-15  5:59 ` Fangrui Song [this message]
2024-05-15  9:45   ` Nick Clifton
2024-05-17 17:54     ` Fangrui Song

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=20240515055923.7jlccxxbl574bf5w@google.com \
    --to=i@maskray.me \
    --cc=binutils@sourceware.org \
    --cc=nickc@redhat.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).