import byucc.jhdl.base.*; import byucc.jhdl.Logic.*; import byucc.jhdl.Xilinx.*; import byucc.jhdl.Xilinx.XC4000.*; /** * Right shifter module generator * * This module will create an variable width right shifter with * that can either do logical or arithmetic shifts */ public class VarShiftR extends Logic{ public static CellInterface[] cell_interface = { param("width",INTEGER), param("shift_amt_width",INTEGER), in("a","width"), in("shift_amt","shift_amt_width"), out("out","width") }; public VarShiftR(Node parent, /* circuit's parent */ boolean logical, /* true means logical shift false means arithmetic shift */ Wire a, /*input wire--generic width */ Wire shift_amt,/* Wire that indicates how many bits to shift. note that the width of this wire is restricted to the following equation: log2(width(shift_amt)-1) < width(a) <= log2(width(shift_amt)) */ Wire out){/* shifted output wire */ super(parent); int width = a.getWidth(); // get width of input wire int shift_amt_width = shift_amt.getWidth();/*get width of shifting wire */ /* do some error checking for invalide inputs */ if (width > (int)Math.pow(2,shift_amt_width) || width <= (int)Math.pow(2,shift_amt_width-1)) { throw new VarShiftException ("The width of the shift_amt wire must satisfy the following "+ "equation: "+ "log2(width(shift_amt)-1) < width(a) <= log2(width(shift_amt))"); } /* bind parameters and connect ports */ bind("width",width); bind("shift_amt_width",shift_amt_width); connect("a",a); connect("shift_amt",shift_amt); connect("out",out); /*create the first input wire going into the first ShiftMuxR helper module */ Wire shifted = wire(width,"shift_in"); buf_o(a,shifted); /*create first output wire from ShiftMuxR and initialize it so it will compile */ Wire shifted1=wire(width, "shifted"+(shift_amt_width-1)); /* iteratively create and place various mux banks used for the right shifter */ for (int i = shift_amt_width-1; i>=0; i--){ /*create new output wire for ShiftMuxR for all iterations except the first*/ if (i!=(shift_amt_width-1)) shifted1 = wire(width,"shifted"+i); //create a ShiftR mux new ShiftMuxR(this, logical, i, shifted, shift_amt.gw(i), shifted1); //place the output wire shifted1 from ShiftMuxR place(shifted1,(shift_amt_width-1-i),0); //assign output to input of next cell shifted = shifted1; } //buffer last output to port out buf_o(shifted1,out); } /* excecption class to catch illegal dimensions of parameters */ private class VarShiftException extends RuntimeException { public VarShiftException(String gripe){ super(gripe); } } }