Stream: project-inline-asm

Topic: Implicit arguments


Amanieu (Feb 11 2020 at 18:47, on Zulip):

Format strings have a rule that positional arguments ({3}) must appear before named arguments ({foo}) in the argument list of the macro.

Amanieu (Feb 11 2020 at 18:49, on Zulip):

However in asm it is quite common to have operands that are in a fixed register (e.g. eax) and don't actually appear in the asm string itself. This can happen when performing a syscall or a function call.

Amanieu (Feb 11 2020 at 18:49, on Zulip):

How should we represent these arguments?

Amanieu (Feb 11 2020 at 18:50, on Zulip):

Option 1: require implicit argument to be named _: asm!("foo", _ = in("eax") bar)

Amanieu (Feb 11 2020 at 18:52, on Zulip):

Option 2: allow positional arguments to not appear in the template string. We still issue a warning if this is done with a register class rather than a fixed register.

Lokathor (Feb 11 2020 at 19:03, on Zulip):

I think implicit inputs should simply disallow positional arguments.

Amanieu (Feb 11 2020 at 19:13, on Zulip):

@Lokathor I don't understand, can you explain what you mean by that?

Lokathor (Feb 11 2020 at 19:17, on Zulip):

If there are any implicit arguments, all other arguments must be named arguments only.

Amanieu (Feb 11 2020 at 19:22, on Zulip):

But there's nothing explicitly identifying an implicit argument, they look just like a positional argument.

Amanieu (Feb 11 2020 at 19:22, on Zulip):

(i.e. there's no name = in front of it)

Lokathor (Feb 11 2020 at 20:04, on Zulip):

I see what you mean now.

Lokathor (Feb 11 2020 at 20:06, on Zulip):

Option 1 seems best then

Josh Triplett (Feb 13 2020 at 16:44, on Zulip):

I think it'd be acceptable to allow positional arguments that are explicit registers to not appear in the format string, as long as they're the only positional arguments. Mixing implicit arguments with explicit arguments where both are positional seems problematic and error-prone.

Amanieu (Feb 13 2020 at 17:00, on Zulip):

In the end I just decided to require all implicit arguments to start with _ =

Amanieu (Feb 13 2020 at 17:01, on Zulip):

It makes the implementation simpler too.

Josh Triplett (Feb 13 2020 at 19:55, on Zulip):

That's certainly simpler in implementation, and we can always relax that restriction later.

Josh Triplett (Feb 13 2020 at 19:55, on Zulip):

I do suspect it might prove slightly onerous, or perhaps just hard to explain.

Amanieu (Feb 15 2020 at 22:00, on Zulip):

Actually I've just had an even better idea: we could simply ban any operands with explicit registers from appearing in the template string. So you would have to explicitly write eax in your asm code instead of using placeholders.

Amanieu (Feb 15 2020 at 22:01, on Zulip):

This leaves only register class operands, which are pretty useless if not used in the template string so we can enforce that.

Amanieu (Feb 15 2020 at 22:11, on Zulip):

For niche cases like black_box, you can just put the {} in a comment:

fn black_box<T>(mut val: T) {
    asm!("# {}", in(reg) &mut val);
    val
}
Josh Triplett (Feb 16 2020 at 02:58, on Zulip):

That feels unfortunate. I would rather not repeat a register name.

Amanieu (Feb 16 2020 at 08:02, on Zulip):

99% of the time if you use an explicit register you're not going to use it in the template string anyways.

Amanieu (Feb 16 2020 at 08:02, on Zulip):

And even if you do, it's 3 (eax) characters instead of 2 ({})

Josh Triplett (Feb 16 2020 at 18:28, on Zulip):

It's not that it's longer.

Josh Triplett (Feb 16 2020 at 18:28, on Zulip):

It's that you have to repeat yourself, rather than naming the register only once.

Josh Triplett (Feb 16 2020 at 18:45, on Zulip):

I wouldn't have a problem with prohibiting positional references to explicit registers.

Josh Triplett (Feb 16 2020 at 18:45, on Zulip):

But I'd like named references.

Last update: Jun 07 2020 at 09:45UTC