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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [rtl/] [verilog/] [Raptor64_bitfield.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 robfinch
`include "Raptor64_opcodes.v"
2
`timescale 1ns / 1ps
3
//=============================================================================
4
//        __
5 48 robfinch
//   \\__/ o\    (C) 2012,2013  Robert Finch
6 31 robfinch
//    \  __ /    All rights reserved.
7
//     \/_//     robfinch<remove>@opencores.org
8
//       ||
9
//  
10
//      Raptor64_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 48 robfinch
//`define I_BFEXTS      1
31
//`define I_SEXT                1
32
 
33 44 robfinch
module Raptor64_bitfield(xIR, a, b, o, masko);
34 48 robfinch
parameter DWIDTH=64;
35 41 robfinch
input [31:0] xIR;
36 48 robfinch
input [DWIDTH-1:0] a;
37
input [DWIDTH-1:0] b;
38
output [DWIDTH-1:0] o;
39
reg [DWIDTH-1:0] o;
40
output [DWIDTH-1:0] masko;
41 31 robfinch
 
42 48 robfinch
reg [DWIDTH-1:0] o1;
43
reg [DWIDTH-1:0] o2;
44 41 robfinch
wire [6:0] xOpcode = xIR[31:25];
45 44 robfinch
wire [2:0] xFunc3 = xIR[2:0];
46 31 robfinch
 
47
// generate mask
48 48 robfinch
reg [DWIDTH-1:0] mask;
49 31 robfinch
assign masko = mask;
50 44 robfinch
wire [5:0] mb = xIR[8:3];
51
wire [5:0] me = xIR[14:9];
52 48 robfinch
wire [5:0] ml = me-mb;           // mask length-1
53 31 robfinch
integer nn,n;
54
always @(mb or me or nn)
55 48 robfinch
        for (nn = 0; nn < DWIDTH; nn = nn + 1)
56 31 robfinch
                mask[nn] <= (nn >= mb) ^ (nn <= me) ^ (me >= mb);
57
 
58 44 robfinch
always @(xOpcode,xFunc3,mask,b,a,mb)
59 31 robfinch
case (xOpcode)
60 44 robfinch
`BITFIELD:
61
        case(xFunc3)
62
        `BFINS:         begin
63
                                        o2 = a << mb;
64 48 robfinch
                                        for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? o2[n] : b[n];
65 44 robfinch
                                end
66 48 robfinch
        `BFSET:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? 1'b1 : a[n]; end
67
        `BFCLR:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? 1'b0 : a[n]; end
68
        `BFCHG:         begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? ~a[n] : a[n]; end
69
        `BFEXTU:        begin
70
                                        for (n = 0; n < DWIDTH; n = n + 1)
71 44 robfinch
                                                o1[n] = mask[n] ? a[n] : 1'b0;
72 31 robfinch
                                        o = o1 >> mb;
73
                                end
74 48 robfinch
`ifdef I_BFEXTS
75
        `BFEXTS:        begin
76
                                        for (n = 0; n < DWIDTH; n = n + 1)
77
                                                o1[n] = mask[n] ? a[n] : 1'b0;
78
                                        o2 = o1 >> mb;
79
                                        for (n = 0; n < DWIDTH; n = n + 1)
80
                                                o[n] = n > ml ? o2[ml] : o2[n];
81
                                end
82
`endif
83
`ifdef I_SEXT
84
        `SEXT:          begin for (n = 0; n < DWIDTH; n = n + 1) o[n] = mask[n] ? a[mb] : a[n]; end
85
`endif
86
        default:        o = {DWIDTH{1'b0}};
87 31 robfinch
        endcase
88 48 robfinch
default:        o = {DWIDTH{1'b0}};
89 31 robfinch
endcase
90
 
91
endmodule

powered by: WebSVN 2.1.0

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