public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Dmytro Tarasiuk <tadmytro@gmail.com>
Cc: Binutils <binutils@sourceware.org>
Subject: Re: Paired Nested Macroses Support
Date: Thu, 16 Feb 2023 17:31:50 +0100	[thread overview]
Message-ID: <f12a0881-8489-3c25-7e4a-ca9cddc37205@suse.com> (raw)
In-Reply-To: <CAEk2QZN7aQ26PANUY-ua3sBuGZhPL9fA9Q=k4V3mAsV2R+heGA@mail.gmail.com>

(re-sending with the list added back - please don't drop the list when
replying to earlier list communication, unless there's a very specific
reason to do so)

On 16.02.2023 16:06, Dmytro Tarasiuk wrote:
> on, 16.02.2023 10:04 Jan Beulich <jbeulich@suse.com> wrote:
>> On 16.02.2023 00:37, Dmytro Tarasiuk via Binutils wrote:
>>> Writing paired nested macros is not possible in the gas macro assembler.
>>> For example, BEGIN/WHILE macros for loops, etc.  This is important to me
>>> for writing portable pseudocode between different architectures that
>>> supports gas.
>>
>> Without explaining (perhaps by way of providing an example) it's unclear
>> what you mean here.
>>
> 
> Excuse me. Here is an example of the macroses for nested cycles:

Thanks for the example. My first conclusion is - there's no nesting
of macros here. Instead you want multiple macros to interact with
one another in a certain way. I think this can be achieved without
patching the assembler, using alternative macro mode (.altmacro) and
the special unary % operator that this mode supports. That may
require helper macros, yes, so the set of macros overall may end up
bigger (and uglier), but that's still not necessarily a reason to
extend gas.

Furthermore ...

>     .macro DO
>         LABEL_DO\(++DO)_start:

... while this syntax may indeed have a low chance of colliding with
anything people already use (simply because it is pretty unlikely
for anyone to use two + in a row), ...

>     .endm
> 
>     .macro DO_WHILE cond
>             j\cond LABEL_DO_WHILE\@continue
>             jmp LABEL_DONE\(DO)_end

... this is a problem: There's nothing wrong with somebody having a
construct like this in an existing macro, while at the same time
also having a macro somewhere with the name DO. If you wanted to
extend the language, you would need to make sure that this cannot
break existing code.

Irrespective of the ++ being not as much of a problem syntax-wise, I
hope you're aware that without further changes elsewhere \(+ +DO)
may end up being seen as \(++DO) by the time the (scrubbed) input
reaches the parsing logic here. That's because unlike in C ++ (and
-- as well) do not form a "token"; they're always two separate +,
and hence whitespace between them may be dropped by the scrubber.

>         LABEL_DO_WHILE\@continue:
>     .endm
> 
>     .macro DONE_WHEN cond
>             j\cond LABEL_DONE\(DO)_end
>             jmp LABEL_DO\(DO)_start
>         LABEL_DONE\(DO--)_end:
>     .endm
> 
>     .macro DONE
>             jmp LABEL_DO\(DO)_start
>         LABEL_DONE\(DO--)_end:
>     .endm
> 
> Using macroses above (which is not translated without patching) I able to
> write program like below:
> 
>                 DO
>                     xor %rax, %rax
>                     mov counter, %eax

Just as an aside: The "xor" here is pointless.

Jan

  parent reply	other threads:[~2023-02-16 16:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-15 23:37 Dmytro Tarasiuk
2023-02-16  8:04 ` Jan Beulich
     [not found]   ` <CAEk2QZN7aQ26PANUY-ua3sBuGZhPL9fA9Q=k4V3mAsV2R+heGA@mail.gmail.com>
2023-02-16 16:31     ` Jan Beulich [this message]
     [not found]       ` <CAEk2QZPYg+Q=EXAcR98AUHsGOT8c4GSFpPndjsB+ZC7ukzkG0g@mail.gmail.com>
2023-02-17  8:01         ` Jan Beulich
2023-02-16  8:29 ` Ulf Samuelsson

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=f12a0881-8489-3c25-7e4a-ca9cddc37205@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=tadmytro@gmail.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).