I am working on a small design with SystemC for a systolic array. For that I have implemented a templated shift register class where the data type and the delay are the templates. For every row of the array I need to attach a shift register with a different delay, e.g. the first row has no delay at all, the second one has one cylce delay, the third one has two cycles etc. For this I have constructed a loop inside the constructor that initializes the shift registers. The constructor then looks like this:
template<unsigned int HEIGHT, unsigned int WIDTH>
class SystolicArray : public sc_module{
sc_module shift_registers[HEIGHT];
SC_CTOR(SystolicArray){
for(int h = 1; h < HEIGHT; h++){
shift_registers[h-1] = new ShiftRegister<type, h>
//Do connections here...
}
}
};
Now the problem I am facing is that the compiler complains that I can't use h here in the way I did:
# Error: systolic_array.h(61): error: the value of ‘h’ is not usable in a constant expression
and I do understand why that is the case. But, all the information I need to construct this thing is available at compile time since it is all derived from the HEIGHT and WIDTH templates of the array.
Is there a smarter way to do this than what I have tried here? I am working with C++11 and can only use the synthesizable subset of SystemC.
You basically want "run this code with different values of
hat compile time." Perfect for a template. You can do it with a pair of overloads like this:With some precautions or possibly written some other way if
Hcan equal0.