0

The MIPS ISA supports DIV, having the quotient stored in $LO and the remainder in $HI. However, WinMIPS64 does not appear to support the DIV operation, and instead has (for example) DDIV.

From the documentation it remains unclear if DDIV only calculates the quotient, but when I output the result to the terminal I only get the integer part of it, and nowhere in the WinMIPS64 GUI can I find a register or a segment of data memory where the quotient is stored.

I considered just performing the division by using consecutive subtractions, but I would like to know if there is an easy way in WinMIPS64 to compute the remainder of a division.

I will appreciate any help you can provide.

David
  • 453
  • 3
  • 7
  • 20
  • Given the quotient, you can easily get remainder with a multiply and subtract: `a mod n = a - (a/n)*n` where `/` is integer division (truncating towards 0). This is how compilers normally implement modulo with a multiplicative inverse: [Why does GCC use multiplication by a strange number in implementing integer division?](//stackoverflow.com/q/41183935). – Peter Cordes May 11 '18 at 07:00
  • 1
    I don't know if WinMIPS64 simulates `DDIV` incorrectly, but Imagination's documentation states that _"The 64-bit quotient is placed into special register LO **and the 64-bit remainder is placed into special register HI**"_ – Michael May 11 '18 at 08:13

1 Answers1

1

I don't have enough XP to write a comment so I write here:

If you're in the same class as me and you need to get the remainder for loop unrolling, you can just check if (i+x) > ITERATIONS-1 with SLT where x is your loop unrolling factor. Since you need to calculate (i+x) in any case, this won't cost you any additional cycles.

  • Yup, if you need to do repeated subtraction anyway for a loop counter, you definitely don't want to be using a `div` instruction. Just add or sub the unroll factor, like `for( int i=0 ; i < (total-3) ; i+=4 ) { iter1; iter2; iter3; iter4; }` – Peter Cordes May 11 '18 at 19:23