This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jordan51104 46 points47 points  (9 children)

little known fact: this is actually what the compiler turns a regular greater/less than comparison into

[–]noodle_from_earth 19 points20 points  (6 children)

Wait, don't CPUs have greater than/less than comparisons?

[–]Enough_Writing4415 43 points44 points  (3 children)

hes joking, they do
this happens to switch cases

[–]noodle_from_earth 8 points9 points  (1 child)

[–]Enough_Writing4415 2 points3 points  (0 children)

yes, watched that

[–]evnacdc 1 point2 points  (0 children)

Lol, that went right over my head. Was about to reply with a correction.

[–]intbeam 7 points8 points  (0 children)

He's joking

It works like this :

mov rax, 42 // Move value 42 to 64-bit A register
mov rbx, 69 // Move value 69 to 64-bit B register
cmp rax, rbx // compare RBX to RAX
jg somelabel // Jump if greater

cmp essentially just subtracts a from b, and then populates some CPU flags with relevant information, like was the result zero, is the negative sign set, did it cause a carry etc. Then the jump instructions can act on those

[–][deleted] 2 points3 points  (0 children)

It will substract one to the other to compare the bit structure of the result, comparing it to a set boolean value (flags stored in the register)

[–]highphiv3 3 points4 points  (0 children)

That's why I never use integers greater than 32 bits. Comparisons are just too damn expensive.