How to simulate a 5-stage pipeline line in C ++?

I am trying to simulate 5 stages of a pipeline. I saved all the instructions in the structure. (mainly done with the stage of lycal 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 stages of the pipeline and ( p[1] can be pc=pc+1 ; I[i] are the instructions, ( I[1] can 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 it goes, I use C ++. how can anyone represent this loop in c ++?

+4
source share
1 answer

It looks like you just want to add an element at the beginning of the array for each time interval, thereby moving the existing elements of the array 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) already == I[1] )
  • at t = 3: p_at_time (1,3) = i [3], (p_at_time (2,3) and p_at_time (3,3) mean i [2] and i [1] respectively)
+3
source

Source: https://habr.com/ru/post/1479204/


All Articles