MOVZX with bit-fields

Viewed 70

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 adds 0s at the beginning. As you can see in the next line it ANDs the value with 1. The question is: does MOVZX provide any value here? I mean wouldn't it work with a normal MOV? I need only the first bit there right?
  • I sadly couldn't find a "speed comparison" between MOV vs MOVZX. Can someone tell me does one perform better than the other (I'm assuming that MOVZX is slower, because it has to go and "clear out" the bits. If I'm not wrong)?
0 Answers
Related