CyberShot
CyberShot

Reputation: 2335

MIPS Loop unrolling

for (i=0, i<10000, i=i+2)
{

    A[i]=B[i]+C[i]
    A[i+1]=B[i+1]+C[i+1]

}

Given the preceding code, what does the MIPS assembly look like? I'm trying to construct assembly code where R9 = base address of A, R9 = base of B, R10 = base of C

I know this method of unrolling ONCE is supposed to be more efficient, but it's tough to see what the MIPS looks like.

Can someone please help me out?

Upvotes: 1

Views: 2720

Answers (1)

markgz
markgz

Reputation: 6266

The loop body would be something like this:

LW    r1, 0(r9)    // B[i]
LW    r2, 4(r9)    // B[i+1]
LW    r3, 0(r10)   // C[i]
LW    r4, 4(r10)   // C[i+1]
ADDU  r5, r1, r3   // B[i] + C[i]
ADDU  r6, r2, r4   // B[i+1] + C[i+1]
SW    r5, 0(r8)    // A[i] 
SW    r5, 4(r8)    // A[i+1]
ADDIU r9,  8
ADDIU r10, 8
ADDIU r8,  8

MIPS has lots of registers, so it would likely be worth unrolling the loop a few more times.

Upvotes: 3

Related Questions