Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how optimize this logic circuit?

Status
Not open for further replies.

lty

Junior Member level 3
Joined
May 24, 2004
Messages
28
Helped
7
Reputation
14
Reaction score
4
Trophy points
1,283
Activity points
214
input clk, rst;
input [255:0] din; //input data;
input vld_in; //input data valid flag;
input sop_in; //input data packet start flag
input eop_in; //input data packet end flag
input [4:0] num_in; //the valid byte number of input data;such as 1:din[255:248] is valid, 2:din[255:240]is valid;32:din[255:0]is valid;
output [255:0] dout; //output data
output vld_out; //output data valid falg
output sop_out; //ouput data packet start flag
output eop_out; //output data packet end flag
output [4:0] mod_out; //output data valid byte number of the packet, it is valid when eop =1;

As it is showed in the upper, every clock, the valid data(the valid number is 0~32) enter, we need pack the input data into 32 byte data and output them.

My idea is the following:

reg [4:0] num_res;

always@(posedge clk)
if(rst==1)
num_res<=0;
else if( vld_in==1 )
num_res<= num_res+num_in;

always@(posedge clk)
if(rst==1)
data_res <= 0;
else if( num_res+num_in<=32 )
for(i=0;i<32;i=i+1)begin
if( num_res==i)
data_res <= {data_res[(256-1-8*i)+:8*i], din[(256-1-8*(32-i))+:8*(32-i)]};
else //if( num_res+num_in>32 )
for(i=0;i<32;i=i+1)begin
if( num_res==i)
data_res <= {din[0+:i*8], {(32-i){8'h0}} };

always@(*)
if( num_res+num_in>32 )
for(i=0;i<32;i=i+1)begin
if( num_res==i)
dout = {data_res[(256-1-8*i)+:8*i], din[(256-1-8*(32-i))+:8*(32-i)]};

always@(*)
if( num_res+num_in<32 )
vld_out = 1;
else
vld_out = 0;

Three questions:
1. Now the combination logic is too large, it is a 64 in 1 mux. Can we optimize it and use two or more clock to implement it?
2. Now the code can not be synthesized, because its operator data's width is not constant. Can we keep the code is concise and synthesized?
3. Can we make the code is parameterized, and implement the data pack for 16byte or 32byte or 64byte width input data?
Thank you, Welcome all suggestion!
 

Wait, Anyone could give some suggestion
 
Yes, I could probably optimize it, but as it would take a significant amount of time and effort (definitely more than the 5 min maximum I usually spend on a post) I won't even try.

Of course you could pay me my consulting fee.... :-D

You should really try doing this yourself. Part of engineering is being creative and coming up with different solutions to a problem and optimizing a design. :)
 

:p, Thank you for your reply, I will keep my thinking. I believe there will be a better solution.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top