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

Subversion Repositories thor

[/] [thor/] [trunk/] [rtl/] [verilog/] [Thor_bitfield.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 robfinch
`include "Thor_defines.v"
2
`timescale 1ns / 1ps
3
//=============================================================================
4
//        __
5
//   \\__/ o\    (C) 2012,2013  Robert Finch
6
//    \  __ /    All rights reserved.
7
//     \/_//     robfinch<remove>@opencores.org
8
//       ||
9
//  
10
//      Thor_bitfield.v
11
//  - bitfield datapath operations
12
//
13
//  
14
// This source file is free software: you can redistribute it and/or modify 
15
// it under the terms of the GNU Lesser General Public License as published 
16
// by the Free Software Foundation, either version 3 of the License, or     
17
// (at your option) any later version.                                      
18
//                                                                          
19
// This source file is distributed in the hope that it will be useful,      
20
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
21
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
22
// GNU General Public License for more details.                             
23
//                                                                          
24
// You should have received a copy of the GNU General Public License        
25
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
26
//                                                                          
27
//
28
//=============================================================================
29
//
30
//`define I_BFEXTS      1
31
//`define I_SEXT                1
32
 
33
module Thor_bitfield(op, a, b, m, o, masko);
34
parameter DWIDTH=64;
35
input [3:0] op;
36
input [DWIDTH-1:0] a;
37
input [DWIDTH-1:0] b;
38
input [15:0] m;
39
output [DWIDTH-1:0] o;
40
reg [DWIDTH-1:0] o;
41
output [DWIDTH-1:0] masko;
42
 
43
reg [DWIDTH-1:0] o1;
44
reg [DWIDTH-1:0] o2;
45
 
46
// generate mask
47
reg [DWIDTH-1:0] mask;
48
assign masko = mask;
49
wire [5:0] mb = m[ 5:0];
50
wire [5:0] me = m[11:6];
51
wire [5:0] ml = me-mb;           // mask length-1
52
 
53
integer nn,n;
54
always @(mb or me or nn)
55
        for (nn = 0; nn < DWIDTH; nn = nn + 1)
56
                mask[nn] <= (nn >= mb) ^ (nn <= me) ^ (me >= mb);
57
 
58
always @(op,mask,b,a,mb)
59
case (op)
60
`BFINS:         begin
61
                                o2 = a << mb;
62
                                for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? o2[n] : b[n];
63
                        end
64
`BFSET:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? 1'b1 : a[n]; end
65
`BFCLR:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? 1'b0 : a[n]; end
66
`BFCHG:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? ~a[n] : a[n]; end
67
`BFEXTU:        begin
68
                                for (n = 0; n < DWIDTH; n = n + 1)
69
                                        o1[n] = mask[n] ? a[n] : 1'b0;
70
                                o = o1 >> mb;
71
                        end
72
`BFEXT:         begin
73
                                for (n = 0; n < DWIDTH; n = n + 1)
74
                                        o1[n] = mask[n] ? a[n] : 1'b0;
75
                                o2 = o1 >> mb;
76
                                for (n = 0; n < DWIDTH; n = n + 1)
77
                                        o[n] = n > ml ? o2[ml] : o2[n];
78
                        end
79
`ifdef I_SEXT
80
`SEXT:          begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? a[mb] : a[n]; end
81
`endif
82
default:        o = {DWIDTH{1'b0}};
83
endcase
84
 
85
endmodule

powered by: WebSVN 2.1.0

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