I have following snippet:
typedef struct {
unsigned int gender: 1;
unsigned int age: 7;
unsigned int uid: 24;
} person;
int
f(person *p) {
return p->gender;
}
which generates (gcc
-O2):
f:
movzx eax, BYTE PTR [rdi] ; this line looks interesting.
and eax, 1
ret
Questions
- If I understand correctly
MOVZX
adds0
s at the beginning. As you can see in the next line itAND
s the value with1
. The question is: doesMOVZX
provide any value here? I mean wouldn't it work with a normalMOV
? I need only the first bit there right? - I sadly couldn't find a "speed comparison" between
MOV
vsMOVZX
. Can someone tell me does one perform better than the other (I'm assuming thatMOVZX
is slower, because it has to go and "clear out" the bits. If I'm not wrong)?