OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [basal/] [src/] [misc/] [barrel_shifter.v] - Blame information for rev 50

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 50 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2019 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
module
29
  barrel_shifter
30
  #(
31
    parameter W = 32,
32
    parameter D = W,
33
    parameter UB = $clog2(D)
34
  )
35
  (
36
    input  direction,       // right = 0, left = 1
37
    input  op,              // logical = 0, arithmetic = 1; left arithmetic not supported
38
    input [UB-1:0] amount,  // 0 not allowed
39
    input [W-1:0] data_in,
40
    output [W-1:0] data_out,
41
 
42
    input reset,
43
    input clk
44
  );
45
 
46
  // --------------------------------------------------------------------
47
  wire [W-1:0] out [UB:0];
48
  wire shift_in = direction & op ? data_in[W-1] : 0;
49
  genvar j, k;
50
 
51
  // --------------------------------------------------------------------
52
  generate
53
    for(k = 0; k < D; k = k + 1)
54
    begin : reversal
55
      assign out[5][k] = direction ? data_in[k] : data_in[D - 1 - k];
56
      assign data_out[k] = direction ? out[0][k] : out[0][D - 1 - k];
57
    end
58
  endgenerate
59
 
60
  // --------------------------------------------------------------------
61
  generate
62
    for(j = 0; j < UB; j = j + 1)
63
      for(k = 0; k < D; k = k + 1)
64
      begin : shifter
65
        if(k > D - 1 - (2**j))
66
          assign out[j][k] = amount[j] ? shift_in : out[j+1][k];
67
        else
68
          assign out[j][k] = amount[j] ? out[j+1][k + (2**j)] : out[j+1][k];
69
      end
70
  endgenerate
71
 
72
// --------------------------------------------------------------------
73
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2020 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.