D.gnu - Extended Assembler gets goto support
- Iain Buclaw (54/54) Sep 27 2014 I've been promising myself to get round to adding support for
- Daniel N (2/5) Sep 27 2014 Kick Ass! I recently had this exact problem, thank you so much!
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.
Sep 27 2014
On Saturday, 27 September 2014 at 18:29:44 UTC, Iain Buclaw wrote: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.Kick Ass! I recently had this exact problem, thank you so much!
Sep 27 2014