Question

I am trying to simulate 5 stage of pipeline. I have saved all the instruction into a struct. ( basically done with the stage of lixcal analysis )

eg:

ADD R1 R2 R3 // R1 = R2+ R3 ... struct pipe{ int pc, string instruction , int r1, int r2....}

now if p[i] is one of the stage of pipeline and ( p[1] could be pc=pc+1; I[i] is instructions, ( I[1] could be ADD R1 R2 R3 )

what I want to do is

at t=1 : p[1] = I[1]

at t=2 :p[2] = I[1], p[1] = I[2]

at t=3 :p[3] = I[1], p[2] = I[2], p[1] = I[3]

at t=4 :p[4] = I[1], p[3] = I[2], p[2] = I[3], p[1] = I[4]

... and goes like that I am using c++ so far. how could any one represent this cycle in c++ ?

Était-ce utile?

La solution

It looks like you just want to add an element at the front of the array at each timestep, thus moving the already existant array elements one to the right. You could avoid doing O(n**2) ops like this

int& p_at_time(int index, int time_moment) {
    return &p[time_moment-index+1];
}
  • and at t=1: p_at_time(1,1) = I[1];
  • at t=2: p_at_time(1,2) = I[2], (p_at_time(2,2) is already == I[1])
  • at t=3: p_at_time(1,3) = I[3], (p_at_time(2,3) and p_at_time(3,3) have the values I[2] and I[1] respectively)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top