Extended Assembler gets goto support
Iain Buclaw via D.gnu
d.gnu at puremagic.com
Sat Sep 27 11:29:43 PDT 2014
I've been promising myself to get round to adding support for
this, well now it is very close to hitting the master repos.
Say hello to GCC's "asm goto" support in GDC.
---
int main()
{
asm { "jmp %l[MyLabel]" : : : : MyLabel; }
return 0;
MyLabel:
return 1;
}
---
The added fourth section tells the GCC optimizer that this asm
statement may jump to the label 'MyLabel', so the block following
doesn't get marked as unreachable code.
Also hooked into this, are the same D language front-end
heuristics for goto statements. Meaning the following is an
error:
---
int main()
{
asm { // goto skips initialization of 'skipme'
"jmp %l[Lerror]" : : : : Lerror;
}
return 0;
int skipme = 1;
Lerror:
return skipme;
}
---
This doesn't say that the compiler actually checks that a jump
actually happens, it assumes the worst based on the information
you've provided it.
See the GCC's documentation on Extended Assembler for more
details[1], but these are the sort of things you could do with it.
---
int btl(int a, int b)
{
asm {
"btl %1, %0;"
"jc %l2"
: /* No outputs. */
: "r" (a), "r" (b)
: "cc"
: carry;
}
return 0;
carry:
return 1;
}
---
[1]: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
Enjoy...
Iain.
More information about the D.gnu
mailing list