Constant Soft-Coding in Verilog - Synethesizable

Status
Not open for further replies.

Merton

Newbie level 2
Joined
Jul 29, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
28
Hi everyone,

I am looking for a way to code my constant in a "soft-coded" way instead of a "hard-coded" way.

let's say I have:
wire [31:0] constant [0:5]

I want to be able to write:

assign constant[0] <= 2*2;

instead of

assign constant[0] <= 4; or assign constant [0] <= {29'b0,4'b100};

Correct me if I am wrong, but the first would generate 2 wire of 2'b10 with a multiplier (what a waste), which may or may not be synthesizable. The later is simply the usual constant assignment everyone seems to be using.

My actual code:


real rot_rad_angle[0:5]; //I don't want this to be synthesize... maybe I am using the wrong type? Parameters cannot be used in arrays
wire [31:0] rot_cos_arr[0:5];
wire [31:0] rot_cos2_arr[0:5];
wire [31:0] rot_sin_arr[0:5];
wire [31:0] rot_sin2_arr[0:5];
wire [31:0] rot_sincos_arr[0:5];
initial
begin //transform degrees to radian, want it to be done at COMPILE/ELABORATION time and not at Runtime
rot_rad_angle[0] = 0.0 *2.0*3.14159/360.0;
rot_rad_angle[1] = 29.0 *2.0*3.14159/360.0;
rot_rad_angle[2] = 16.8 *2.0*3.14159/360.0;
rot_rad_angle[3] = 8.6 *2.0*3.14159/360.0;
rot_rad_angle[4] = 3.57633437 *2.0*3.14159/360.0;
end

genvar i;
generate
for (i=0;i<5;i=i+1)
begin
assign rot_cos_arr = $cos(rot_rad_angle); //those function return a fixed point of the right size
assign rot_sin_arr = $sin(rot_rad_angle);
assign rot_cos2_arr = $cos2(rot_rad_angle);
assign rot_sin2_arr = $sin2(rot_rad_angle);
assign rot_sincos_arr = $sincos(rot_rad_angle);
end
endgenerate

Note that in my code, in hardware, only rot_***_arr[0:5] should actually exist as wire connected to vdd/gnd depending on their bit.

I've search the internet for days on how to do this without avail. Of course, I know it would be possible to hard-code all those constant using a script, but this is highly error prone over time (as the script is run once, and after developer may assume that the constant are correct, while they can be wrong). ie 0x89D does not say as much as (3*4*20+5)*9.

I want to use to constant to do runtime computation later one. They will be connected to a mux to select which constant, and a mult to do the actual run-time multiplication.

Thank you!
 



it is hard to beleive that any tool will not optimise constant multiplection of 2*2. so you can write 2*2 althought it is clear it's 4.
 

In which case, would the initial block be synthesizable? Or should I just do assign statement instead?
 

Dumb question: what's the purpose of this?

At any rate, if you want it to not optimize it but put that constant value in real hardware, then plonk it in registers and initialize it to your chosen constant non-constant value.

Oh wait, just noticed you probably don't want to synthesize it, in which case you can do whatever you like. Registers like I said should cover it then.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…