1
$\begingroup$

I'm trying to find out which operation is fast, evaluating a comparison vs doing an arithmetic option on a single word (e.g subtract, add). Can anyone point me in the right direction with some blogs, books and other material?

$\endgroup$
2
$\begingroup$

It principle it could depend on the processor. However, I imagine that comparison are done using the same circuitry as subtraction, so the complexity should be comparable. I'm assuming that by comparison you mean an instruction comparing two registers and setting some flags (or another register). A conditional jump might interfere with pipelining and so would be costlier.

$\endgroup$
  • $\begingroup$ +1 SPARC actually uses a subtraction instruction with the zero register as a destination for comparison. In theory, an equality check is modestly easier than less-than/greater-than and comparison to zero is slightly easier than that, which along with commonness is why some RISCs support them for branch instructions. ISAs with condition codes typically allow a version of subtraction to set those codes, so treating compare as flag-only subtraction is simpler. Providing special hardware would often add complexity without benefit. $\endgroup$ – Paul A. Clayton May 15 '14 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.