[Issue 20594] [GCC ASM] Should the asm { } syntax be modernized for D2?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 16 15:22:16 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20594

--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject.org> ---
(In reply to Iain Buclaw from comment #0)
> Then going one further and replacing the colons with commas.
> 
> asm pure nothrow @nogc {
>     "cmoveq %1, %2, %[result]",   // insn
>     [result = "=r": result],      // outputs
>     ["r": test, "r": newvalue,    // inputs
>      "[result]": oldvalue],
>     ["memory"];                   // clobbers
> }
> 

Could even drop the order dependency and re-use struct literal syntax of using
labels to denote "fields" of the asm statement.

asm pure nothrow @nogc {
    insn:     "cmoveq %1, %2, %[result]",
    clobbers: ["memory"],
    inputs:   ["r": test, "r": newvalue,
               "[result]": oldvalue],
    outputs:  [result = "=r": result],
}

And so in the last example.

> int main()
> {
>     int iInt = 1;
> top:
>     asm nothrow @nogc {
>         "some assembler instructions here",
>         [/* No outputs. */],
>         ["q": iInt, "X": char.sizeof + 1, "i": 42],
>         [/* No clobbers. */],
>         [top];
>     }
> }

It can be abbreviated to:

int main()
{
    int iInt = 1;
top:
    asm nothrow @nogc {
        "some assembler instructions here",
        inputs: ["q": iInt, "X": char.sizeof + 1, "i": 42],
        labels: [top];
    }
}

--


More information about the Digitalmars-d-bugs mailing list