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

Subversion Repositories versatile_library

[/] [versatile_library/] [trunk/] [rtl/] [verilog/] [logic.v] - Blame information for rev 36

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

Line No. Rev Author Line
1 32 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Logic functions                                             ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Logic functions such as multiplexers                        ////
7
////                                                              ////
8
////                                                              ////
9
////  To Do:                                                      ////
10
////   -                                                          ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - Michael Unneback, unneback@opencores.org              ////
14
////        ORSoC AB                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42 36 unneback
module vl_mux_andor ( a, sel, dout);
43
 
44
parameter width = 32;
45
parameter nr_of_ports = 4;
46
 
47
input [nr_of_ports*width-1:0] a;
48
input [nr_of_ports-1:0] sel;
49
output reg [width-1:0] dout;
50
 
51
always @ (a, sel)
52
begin
53
    dout = a[width-1:0] & {width{sel[0]}};
54
    for (i=nr_of_ports-2;i<nr_of_ports;i=i+1)
55
        dout = (a[i*width-1:(i-1)*width] & {width{sel[i]}}) | dout;
56
end
57
 
58
endmodule
59
 
60 34 unneback
module vl_mux2_andor ( a1, a0, sel, dout);
61 32 unneback
 
62 34 unneback
parameter width = 32;
63 35 unneback
localparam nr_of_ports = 2;
64 34 unneback
input [width-1:0] a1, a0;
65
input [nr_of_ports-1:0] sel;
66
output [width-1:0] dout;
67
 
68 36 unneback
vl_mux_andor
69
    # ( .width(width), .nr_of_ports(nr_of_ports)
70
    mux0( .a({a1,a0}), .sel(sel), .dout(dout));
71
/*
72 34 unneback
wire [width-1:0] tmp [nr_of_ports-1:0];
73
integer i;
74
 
75
// and
76
assign tmp[0] = {width{sel[0]}} & a0;
77
assign tmp[1] = {width{sel[1]}} & a1;
78
 
79
// or
80
assign dout = tmp[1] | tmp[0];
81 36 unneback
*/
82 34 unneback
endmodule
83
 
84
module vl_mux3_andor ( a2, a1, a0, sel, dout);
85
 
86
parameter width = 32;
87 35 unneback
localparam nr_of_ports = 3;
88 34 unneback
input [width-1:0] a2, a1, a0;
89
input [nr_of_ports-1:0] sel;
90
output [width-1:0] dout;
91
 
92 36 unneback
vl_mux_andor
93
    # ( .width(width), .nr_of_ports(nr_of_ports)
94
    mux0( .a({a2,a1,a0}), .sel(sel), .dout(dout));
95
/*
96
 
97 34 unneback
wire [width-1:0] tmp [nr_of_ports-1:0];
98
integer i;
99
 
100
// and
101
assign tmp[0] = {width{sel[0]}} & a0;
102
assign tmp[1] = {width{sel[1]}} & a1;
103
assign tmp[2] = {width{sel[2]}} & a2;
104
 
105
// or
106
assign dout = tmp[2] | tmp[1] | tmp[0];
107 36 unneback
*/
108 34 unneback
endmodule
109
 
110 32 unneback
module vl_mux4_andor ( a3, a2, a1, a0, sel, dout);
111
 
112
parameter width = 32;
113 35 unneback
localparam nr_of_ports = 4;
114 32 unneback
input [width-1:0] a3, a2, a1, a0;
115
input [nr_of_ports-1:0] sel;
116
output [width-1:0] dout;
117
 
118 36 unneback
vl_mux_andor
119
    # ( .width(width), .nr_of_ports(nr_of_ports)
120
    mux0( .a({a3,a2,a1,a0}), .sel(sel), .dout(dout));
121
/*
122 32 unneback
wire [width-1:0] tmp [nr_of_ports-1:0];
123
integer i;
124
 
125
// and
126
assign tmp[0] = {width{sel[0]}} & a0;
127
assign tmp[1] = {width{sel[1]}} & a1;
128
assign tmp[2] = {width{sel[2]}} & a2;
129
assign tmp[3] = {width{sel[3]}} & a3;
130
 
131
// or
132
assign dout = tmp[3] | tmp[2] | tmp[1] | tmp[0];
133 36 unneback
*/
134 32 unneback
endmodule
135
 
136
module vl_mux5_andor ( a4, a3, a2, a1, a0, sel, dout);
137
 
138
parameter width = 32;
139 35 unneback
localparam nr_of_ports = 5;
140 32 unneback
input [width-1:0] a4, a3, a2, a1, a0;
141
input [nr_of_ports-1:0] sel;
142
output [width-1:0] dout;
143
 
144 36 unneback
vl_mux_andor
145
    # ( .width(width), .nr_of_ports(nr_of_ports)
146
    mux0( .a({a4,a3,a2,a1,a0}), .sel(sel), .dout(dout));
147
/*
148 32 unneback
wire [width-1:0] tmp [nr_of_ports-1:0];
149
integer i;
150
 
151
// and
152
assign tmp[0] = {width{sel[0]}} & a0;
153
assign tmp[1] = {width{sel[1]}} & a1;
154
assign tmp[2] = {width{sel[2]}} & a2;
155
assign tmp[3] = {width{sel[3]}} & a3;
156
assign tmp[4] = {width{sel[4]}} & a4;
157
 
158
// or
159
assign dout = tmp[4] | tmp[3] | tmp[2] | tmp[1] | tmp[0];
160 36 unneback
*/
161 32 unneback
endmodule
162
 
163
module vl_mux6_andor ( a5, a4, a3, a2, a1, a0, sel, dout);
164
 
165
parameter width = 32;
166 35 unneback
localparam nr_of_ports = 6;
167 32 unneback
input [width-1:0] a5, a4, a3, a2, a1, a0;
168
input [nr_of_ports-1:0] sel;
169
output [width-1:0] dout;
170
 
171 36 unneback
vl_mux_andor
172
    # ( .width(width), .nr_of_ports(nr_of_ports)
173
    mux0( .a({a5,a4,a3,a2,a1,a0}), .sel(sel), .dout(dout));
174
/*
175 32 unneback
wire [width-1:0] tmp [nr_of_ports-1:0];
176
integer i;
177
 
178
// and
179
assign tmp[0] = {width{sel[0]}} & a0;
180
assign tmp[1] = {width{sel[1]}} & a1;
181
assign tmp[2] = {width{sel[2]}} & a2;
182
assign tmp[3] = {width{sel[3]}} & a3;
183
assign tmp[4] = {width{sel[4]}} & a4;
184
assign tmp[5] = {width{sel[5]}} & a5;
185
 
186
// or
187
assign dout = tmp[5] | tmp[4] | tmp[3] | tmp[2] | tmp[1] | tmp[0];
188 36 unneback
*/
189 32 unneback
endmodule

powered by: WebSVN 2.1.0

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