1

C language:

if(a < b) {
   b += a;
}

Assume $t1 = 1, $t2 = b.

MIPS assembly:

       SLT $t0, $t1, $t2
       BEQ $t0, $0, Label
       ADD $t2, $t2, $t1
Label: ...

But, it can be reached different way:

       SUB $t0, $t1, $t2
       BGEZ $t0, Label
       ADD $t2, $t2, $t1
Label: ...

My question:

It can be proved that every SLT instruction can be replaced by some form of ADD/SUB instructions. So, what's the key usage of instruction SLT? Can it be carry out detection as shown here or something else that I missed?

Sorry for my English.

Community
  • 1
  • 1
Nik Novák
  • 569
  • 1
  • 9
  • 24
  • You can use `slt` to do carry *without* branches. Considering that deeply pipelined processors can have tens of cycles of branch-misprediction penalty, avoiding the branch can produce a considerable performance benefit. – EOF Jan 24 '16 at 20:25
  • @EOF Thank you for your answer. Okay, I thought it. But, is there any other usage of SLT instruction that you know? – Nik Novák Jan 24 '16 at 20:27
  • MIPS32R2 also adds conditional moves `MOVZ`, `MOVN` which can be used in combination with `SLT` to implement your C code without any branches. – markgz Jan 25 '16 at 21:48
  • @markgz Thank you for your answer. Also, isn't be better to perform `SUB` and then conditional jump or conditional skip following instruction (for implement C code without branches and for avoid break pipeline), that will be comparing only with zero (equal, not equal, less, less or equal, greater, greater or equal)? – Nik Novák Jan 25 '16 at 22:07

0 Answers0