Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17268 Discussions

Best way to dynamically select static length part of a bus

Altera_Forum
Honored Contributor II
1,379 Views

Hello, 

 

I am trying to figure out how to select a w-bit(w is some parameter, shorter than the bus) part of a bus based on an incoming variable x with the smallest resource footprint possible, in one clock tick. I have tried two methods so far. 

The first uses a shifter: 

 

... 

parameter bw=96 

parameter w=8 

... 

input wire [$clog2(bw):0] x, 

input wire [bw-1:0] inputWire, 

output reg [w-1:0] out 

... 

always@(posedge clk) out=inputWire>>x;  

 

At the second I use a for loop and multiplexers: 

 

 

integer i; 

always@(posedge clk)begin 

for (i =0; i<bw-w;i=i+1) begin:myforloop 

if(x==i) out=inputWire[i+:w]; 

end 

end  

 

I was quite surprised that the second method used much less resources(about half) than the first. Is there any reason for this? The only one I can come up with is that the second one covers a smaller range, but it still does not explain why the difference is this large. Also a single instance of the shifter used around 110 ALMs which is much more than I anticipated. Simpler adders take up like 4; even if the input is large like 96 it shouldn't take up so much space, should it? 

Is there any better/more compact method to dynamically select part of a bus?
0 Kudos
0 Replies
Reply