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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [common/] [FT64_bitfield.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2016-2018  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8
//
9
//      FT64_bitfield.v
10
//              
11
//
12
// This source file is free software: you can redistribute it and/or modify 
13
// it under the terms of the GNU Lesser General Public License as published 
14
// by the Free Software Foundation, either version 3 of the License, or     
15
// (at your option) any later version.                                      
16
//                                                                          
17
// This source file is distributed in the hope that it will be useful,      
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
20
// GNU General Public License for more details.                             
21
//                                                                          
22
// You should have received a copy of the GNU General Public License        
23
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
24
//                                                                          
25
//
26
// ============================================================================
27
//
28
`ifndef BFSET
29
`define BFSET     4'd0
30
`define BFCLR     4'd1
31
`define BFCHG     4'd2
32
`define BFINS     4'd3
33
`define BFINSI    4'd4
34
`define BFEXT     4'd5
35
`define BFEXTU    4'd6
36
`define BFFFO     4'd8
37
`endif
38
 
39
module FT64_bitfield(inst, a, b, c, o, masko);
40
parameter DWIDTH=64;
41
input [47:0] inst;
42
input [DWIDTH-1:0] a;
43
input [DWIDTH-1:0] b;
44
input [DWIDTH-1:0] c;
45
output [DWIDTH-1:0] o;
46
reg [DWIDTH-1:0] o;
47
output [DWIDTH-1:0] masko;
48
 
49
reg [DWIDTH-1:0] o1;
50
reg [DWIDTH-1:0] o2;
51
wire [6:0] ffoo;
52
 
53
// generate mask
54
reg [DWIDTH-1:0] mask;
55
assign masko = mask;
56
wire [3:0] op = inst[31:28];
57
wire [5:0] mb = inst[30] ? a[5:0] : {inst[28],inst[12:8]};
58
wire [5:0] mw = inst[31] ? b[5:0] : {inst[29],inst[17:13]};
59
wire [63:0] da = inst[32] ? c : {inst[43:33],inst[22:18]};
60
wire [5:0] me = mb + mw;
61
wire [5:0] ml = mw;              // mask length-1
62
wire [63:0] imm = {59'd0,inst[10:6]};
63
 
64
integer nn,n;
65
always @(mb or me or nn)
66
        for (nn = 0; nn < DWIDTH; nn = nn + 1)
67
                mask[nn] <= (nn >= mb) ^ (nn <= me) ^ (me >= mb);
68
 
69
ffo96 u1 ({32'h0,o1},ffoo);
70
 
71
always @(op,mask,b,a,da,imm,mb,ml)
72
case (op)
73
// ToDo: Fix bitfield inserts
74
`BFINS:         begin
75
                                o2 = a << mb;
76
                                for (n = 0; n < DWIDTH; n = n + 1) o[n] = (mask[n] ? o2[n] : b[n]);
77
                        end
78
`BFINSI:        begin
79
                                o2 = imm << mb;
80
                                for (n = 0; n < DWIDTH; n = n + 1) o[n] = (mask[n] ? o2[n] : b[n]);
81
                        end
82
`BFSET:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? 1'b1 : da[n]; end
83
`BFCLR:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? 1'b0 : da[n]; end
84
`BFCHG:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? ~da[n] : da[n]; end
85
`BFEXTU:        begin
86
                                for (n = 0; n < DWIDTH; n = n + 1)
87
                                        o1[n] = mask[n] ? da[n] : 1'b0;
88
                                o = o1 >> mb;
89
                        end
90
`BFEXT:         begin
91
                                for (n = 0; n < DWIDTH; n = n + 1)
92
                                        o1[n] = mask[n] ? da[n] : 1'b0;
93
                                o2 = o1 >> mb;
94
                                for (n = 0; n < DWIDTH; n = n + 1)
95
                                        o[n] = n > ml ? o2[ml] : o2[n];
96
                        end
97
`BFFFO:
98
                        begin
99
                                for (n = 0; n < DWIDTH; n = n + 1)
100
                                        o1[n] = mask[n] ? da[n] : 1'b0;
101
                                o = (ffoo==7'd127) ? -64'd1 : ffoo;     // ffoo returns 127 if no one was found
102
                        end
103
`ifdef I_SEXT
104
`SEXT:          begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? da[mb] : da[n]; end
105
`endif
106
default:        o = {DWIDTH{1'b0}};
107
endcase
108
 
109
endmodule
110
 

powered by: WebSVN 2.1.0

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