3 ms·
It doesn't support them for a specific kind of global, but it supports function local use like the one I gave above. Here's another example I tried just now:
by dundarious 3y ago
It doesn't support them for a specific kind of global, but it supports function local use like the one I gave above. Here's another example I tried just now:
#include <sys/syscall.h> /* for __NR_exit */
int main(void)
{
long ret;
register long nr __asm__("rax") = __NR_exit;
register long ec __asm__("rdi") = 99;
__asm__ volatile("syscall\n" : "=a"(ret) : "r"(ec), "0"(nr) : "r11", "rcx", "cc", "memory");
return 0;
}
Build: clang -s -O0 -o ./t ./t.c
Disassemble to double check: objdump -M intel -D ./t
Run: ./t || echo $?
Output: 99
The docs you link basically say that the special global "1.0" register mentioned in https://news.ycombinator.com/item?id=36551728 https://news.ycombinator.com/item?id=36551728 wouldn't be supported in clang -- so much for the only good usage!
- pm215 3y agoWhoops, thanks for the correction. My main experience with register variables is with the global kind -- QEMU used to use one to hold a CPU environment pointer, and we had to refactor to get rid of it in order to support clang. (By that point in time the register global was more of a legacy bit of design rather than something that was actively useful for performance or convenience, so it was a useful piece of cleanup to do anyway.)