I’m struggling to get some x86 assembly to compile on a Core 2 Duo Mac. Using clang returns an invalid operand error for statements like the following:
asm volatile ("subl %0,%%esp" :: "r"(foobar) : "cc", "sp");
Where foobar is a long. I was wondering what the sp keyword means in the clobber list as neither the GCC / llvm doc nor Google can shed much light on them. Does anybody know of a comprehensive list of clobber keywords?
Looking at gcc-4.4.3/gcc/config/i386/i386.h :2036 file I conclude that “sp” is gcc-specific alias of “esp”:
Both “sp” and “esp” (and “rsp” too) will code register number 7.
So, this code is legal for GCC; but is you want to make it portable (compilable by clang), change “sp” to “esp”. This patch will not change gcc logic and will enable you to build this with clang.
== Update==
there is a possibility that gcc stores size of register access for clobbers too. Here is the the checker function of asm registers – clobbers conflict (gcc/stmt.c):
The conflict (overlap) is checked via HARD_REG_SET, which has size 52 bits:
gcc/hard-reg-set.h :50. Hard_reg_set has length of FIRST_PSEUDO bits, rounded up to fill fastint fully.
i386/i386.h :865:
#define FIRST_PSEUDO_REGISTER 53:882 same file has a list of registers in the HARD_REG_SET:
So register-clobber conflict is checked without size field check (for non-mm/xmm regs).