Rust assembly of Option<i32>

97 views Asked by At

enter image description hereThis code compiled with -C opt-level=3 in https://gcc.godbolt.org/z/jqEjasPTW

#[no_mangle]
pub fn match1(num: i32) -> i32 {
   if num == 10 {99} else {11}
}

#[no_mangle]
pub fn match2(num: Option<i32>) -> i32 {
    match num {
        Some(a) => a,
        _ => 11
    }
}
 

produces this assembly code:

match1:
        cmp     edi, 10
        mov     ecx, 99
        mov     eax, 11
        cmove   eax, ecx
        ret

match2:
        cmp     edi, 1
        mov     eax, 11
        cmove   eax, esi
        ret

why in match2 compares the register edi with 1 ?

0

There are 0 answers