Reputation: 21
I'm preparing for a university exam, the course talks about Calculator, specifically the MIPS 64, I'll get to the point, an exercise ask me the use the loop unrolling using multidimensional arrays, however, I'm able to handle the exercise as long as exercis ask me to use simple array.
So, I need your help.
Example, the matrix is squared:
for (i=0;i<n; i++)
{ for(y=0;y<n;y++)
{
g[i][y] = g[i][y] + a;
}}
So, I want use an loop unrolling factor equal to 4, so my code becomes:
for (i=0; i<n; i++)
{for (y=0; y+4-1<n; y=y+4)
{ g[i][y]= g[i][y] + a;
g[i][y+1]= g[i][y+1] + a;
g[i][y+2]= g[i][y+2] + a;
g[i][y+3]= g[i][y+3] + a;
}}
Using MIPS 64 Assembly, how can I write my code?
Upvotes: 0
Views: 88
Reputation: 21
so, for the the following examination test: Z[i]=A[i]*⅀B[i,j] where ⅀ is used to sum all the elements of a row.
My pointers are linked to the last element of array:
A starts from 1000, B starts from 3000 and Z starts from 2000
R3 is used to scroll A and Z, R2 for scrolling B
Code:
DSLL R3 R1 3
Loop1:
DSLL R2 R1 3 // R2=R1*8 where R1 is N; this istruction is used to reset the j-index for scrolling the row of the matrix
Loop2:
LD F0 R2 3000 // F0 is used to sum the elements of a row
LD F6 R2 2992
LD F8 R2 2984
LD F10 R2 2976
DADD F2 F0 F2
DADD F2 F6 F2
DADD F2 F8 F2
DADD F2 F10 F2
DADDI R2 R2 -32
BNEZ R2 loop2
LD F2 R3 1000 // Load A element
DMUL F2 F4 F2 // A[i]*⅀B[i,j]
SD F4 R3 2000 // Store in Z the result above
DADDI R3 R3 -8
BGEZ R3 loop1
Upvotes: 1