http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45434
--- Comment #7 from Adam Warner <adam at consulting dot net.nz> 2012-01-18
03:35:24 UTC ---
It does not appear to be possible to generate inline asm that leaves GCC to
choose the {ah, bh, ch, dh} register:
#include <stdint.h>
uint64_t u8l(uint64_t in) {
uint64_t out;
asm ("movzbl %b1, %k0" : "=q" (out) : "r" (in));
return out;
}
uint64_t u8h(uint64_t in) {
uint64_t out;
asm ("movzbl %h1, %k0" : "=Q" (out) : "r" (in)); //line number 11
return out;
}
int main(void) {
return 0;
}
$ gcc -O3 ah_bh_ch_dh.c
ah_bh_ch_dh.c: Assembler messages:
ah_bh_ch_dh.c:11: Error: operand type mismatch for `movzbl'
I found the "h" qualifier by reading:
<www.cs.virginia.edu/~clc5q/gcc-inline-asm.pdf>
"%b0 prints the 8-bit form of an operand. %al, etc.
"%h0 prints the high 8-bit form of a register. %ah, etc."
Q is the x86 machine constraint which means "Any register accessible as rh: a,
b, c, and d."
<http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html>
Additionally, this inline assembly instruction causes LLVM-based clang to
segfault and request a bug submission report.
I haven't located the primary documentation for these %b, %h, %k, etc.
qualifiers. Is my usage of %h correct/is this actually a bug in GCC?