0
int get_wtime(int pcount, int tcount)//calculate expected wtime from equation
{
    int wtime = 0;
    /*
    * Wtime (Pcount = 0) = 0,
    * Wtime (Pcount  0,Tcount) = 3*(Pcount+Tcount-1)/Tcount
    */
    if (pcount == 0 || tcount == 0)
        wtime = 0;
    else
        wtime = 3 * (pcount + tcount - 1) / tcount;
    return wtime;
}

i have a task that i can use shl or shr or add or addi to represent this equation in mips assimply 32 bit but i didn't find solution for that i try to use other instruction i tied with just these instruction

  • Multiply by 3 is pretty trivially with sll and add; compilers will already do that for you. Signed integer division by a runtime-variable is non-trivial and slower to do yourself than let the hardware do it, but see njuffa's answer on [How can I multiply and divide using only bit shifting and adding?](https://stackoverflow.com/a/32443307) – Peter Cordes May 20 '22 at 17:41

0 Answers0