[Issue 20594] New: [GCC ASM] Should the asm { } syntax be modernized for D2?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Feb 22 12:57:18 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20594
Issue ID: 20594
Summary: [GCC ASM] Should the asm { } syntax be modernized for
D2?
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ibuclaw at gdcproject.org
The current syntax of the `asm { }` body follows the gcc extended style as
documented in https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
This has been the case in gdc long before D1 v1.001 was released.
This has been argued that it rather counters what is considered tasteful D
style code.
Consider the existing style:
asm pure nothrow @nogc {
"cmoveq %1, %2, %[result]" // insn
: [result] "=r" (result) // outputs
: "r" (test), "r" (newvalue), // inputs
"[result]" (oldvalue)
: "memory"; // clobbers
}
Then consider what that would look like if output/inputs were a hash, and
clobbers an array:
asm pure nothrow @nogc {
"cmoveq %1, %2, %[result]" // insn
: [result = "=r": result] // outputs
: ["r": test, "r": newvalue, // inputs
"[result]": oldvalue]
: ["memory"]; // clobbers
}
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
}
---
Some examples of what this might look like in other cases:
asm nothrow @nogc {
"xchg %h0, %b0", ["+a": num];
}
asm nothrow @nogc {
"mtfsf 255,%1", ["=X": sum], ["f": fpenv];
}
asm nothrow @nogc {
"", [], [], ["memory"]; // volatile barrier.
}
asm pure nothrow @nogc {
"bsfl %1,%0", ["=r": dwRes], ["r": dwSomeValue], ["cc"];
}
asm nothrow @nogc {
"rdtsc\n\t"
"shl $32, %%rdx\n\t"
"or %%rdx, %0",
["=a": msr], [], ["rdx"];
}
asm nothrow @nogc {
/* lots of asm here */
"#n=%1 ap=%8=%12 lda=%13 x=%7=%10 y=%0=%2 alpha=%9 o16=%11\n"
"#a0=%3 a1=%4 a2=%5 a3=%6",
[ // outputs
"+m": *cast(double[10]*) y,
"+&r": n, // 1
"+b": y, // 2
"=b": a0, // 3
"=&b": a1, // 4
"=&b": a2, // 5
"=&b": a3, // 6
],
[ // inputs
"m": *cast(double[10]*) x,
"m": *cast(double*) ap,
"d": alpha, // 9
"r": x, // 10
"b": 16, // 11
"3": ap, // 12
"4": lda, // 13
],
[ // clobbers
"cr0",
"vs32","vs33","vs34","vs35","vs36","vs37",
"vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47"
];
}
int frob(int x)
{
int y;
asm {
"frob %%r5, %1; jc %l[error]; mov (%2), %%r5",
[/* No outputs. */],
["r": x, "r": &y],
["r5", "memory"],
[Lerror];
}
return y;
Lerror:
return -1;
}
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];
}
}
--
More information about the Digitalmars-d-bugs
mailing list