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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [basal/] [src/] [misc/] [one_hot_encoder.sv] - Blame information for rev 34

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 34 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 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
 
29
module
30
  one_hot_encoder
31
  #(
32
    A,  // encoder select width
33
    D = 2 ** A
34
  )
35
  (
36
    input   [A-1:0] select,
37
    output  [D-1:0] encoded
38
  );
39
 
40
  // --------------------------------------------------------------------
41
  //
42
  localparam W = 2 ** (A-1);
43
 
44
 
45
  // --------------------------------------------------------------------
46
  //
47
  generate
48
    if(A == 1)
49
    begin: mux_gen
50
        assign encoded[1:0] = select[0] ? 2'b10 :2'b01;
51
    end
52
    else
53
    begin: recurse_mux_gen
54
      wire [W-1:0] encoder_out;
55
 
56
      one_hot_encoder #(.A(A - 1))
57
        one_hot_encoder_i
58
        (
59
          .select(select[A-2:0]),
60
          .encoded(encoder_out)
61
        );
62
 
63
      assign encoded = select[A-1] ? {encoder_out, {W{1'b0}}} : {{W{1'b0}}, encoder_out};
64
    end
65
  endgenerate
66
 
67
 
68
// --------------------------------------------------------------------
69
//
70
endmodule
71
 

powered by: WebSVN 2.1.0

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