Search code examples
verilogxilinx

verilog 16b barrel circular shift why it doesn't work?


module Rotator(shift,lr,in,out);

input [3:0]  shift;
input [15:0] in;
input   [15:0] out;
input lr;

wire [15:0] la, ra, lb,rb, lc,rc, ld,rd;

//left shift:2^n

assign la = shift[0] ? { in[14:0],in[15]} : in; //<<1
assign lb = shift[1] ? { la[13:0],la[15:14]} : la; //<<2
assign lc = shift[2] ? { lb[11:0],lb[15:12]}: lb; //<<4
assign ld = shift[3] ? { lc[7:0], lc[15:8]}:lc; //<<8

//right shift:2^n

assign ra = shift[0]? { in[0], in[15:1]}: in;  //>>1
assign rb = shift[1]? { ra[1:0], in[15:2]}: ra; //>>2
assign rc = shift[2]? { rb[3:0], in[15:4]}: rb; //>>4
assign rd = shift[3]? { rc[7:0], in[15:8]}:rc; //>>8

assign out = lr? ld : rd;

endmodule

i'm tring to make 16b barrel rotator. but the result does not change along with shift value i think the parts that i emphasize are issue. please give me advice


Solution

  • out needs to be defined as output, currently at input. Some simulators/fpgas can be very strict on the enforcing the direction of the port, most will give a warning.

    FYI, there is a bug in the assignments for rb, rc and rd. They are referencing in and should be using ra, rb and rc respectively.

    Working fixed example: http://www.edaplayground.com/s/6/332