Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
15553 Discussions

Best way to dynamically select static length part of a bus

Honored Contributor II



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]; 




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