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
MOVZXadds0s at the beginning. As you can see in the next line itANDs the value with1. The question is: doesMOVZXprovide 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
MOVvsMOVZX. Can someone tell me does one perform better than the other (I'm assuming thatMOVZXis slower, because it has to go and "clear out" the bits. If I'm not wrong)?