Best way to dynamically select static length part of a bus
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?