vendredi 30 novembre 2018

Why did a large comparison become 1 line of assembler code?

Following a suggestion in a comment here, I'm trying to understand how does Compiler Explorer work. My input is the following piece of code:

int main() {
    double x,y,x0,y0,x1,y1;
    x = 10;
    y = 10;
    x0 = 5;
    y0 = 5;
    x1 = 15;
    y1 = 15;
    if (x > x0 && x < x1 && y > y0 && y < y1)
        return 1;
    return 0;
}

The result is:

    mov     eax, 1
    ret

I have learned the basics of assembler many years ago, but I don't know if, or how, this makes any sense. Does it? (What I was trying to find is if adding an "else" between the two returns would have any difference in performance. According to this site, it doesn't. But am I getting it right?)

Aucun commentaire:

Enregistrer un commentaire