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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [fpUnit/] [fpZLUnit.v] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 51 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2007-2018  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8
//
9
//      fpZLUnit.v
10
//              - zero latency floating point unit
11
//              - instructions can execute in a single cycle without
12
//                a clock
13
//              - parameterized width
14
//              - IEEE 754 representation
15
//
16
//
17
// This source file is free software: you can redistribute it and/or modify 
18
// it under the terms of the GNU Lesser General Public License as published 
19
// by the Free Software Foundation, either version 3 of the License, or     
20
// (at your option) any later version.                                      
21
//                                                                          
22
// This source file is distributed in the hope that it will be useful,      
23
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
24
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
25
// GNU General Public License for more details.                             
26
//                                                                          
27
// You should have received a copy of the GNU General Public License        
28
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
29
//                                                                          
30
//      fabs    - get absolute value of number
31
//      fnabs   - get negative absolute value of number
32
//      fneg    - negate number
33
//      fmov    - copy input to output
34
//      fsign   - get sign of number (set number to +1,0, or -1)
35
//      fman    - get mantissa (set exponent to zero)
36
//  fcmp
37
//
38
// ============================================================================
39
 
40
`define FVECTOR 6'h01
41
`define VFABS   6'h03
42
`define VFSxx   6'h06
43
`define VFSxxS  6'h07
44
`define VFNEG   6'h16
45
`define VSEQ        3'd0
46
`define VSNE        3'd1
47
`define VSLT        3'd2
48
`define VSGE        3'd3
49
`define VSLE        3'd4
50
`define VSGT        3'd5
51
`define VSUN        3'd7
52
`define VFSIGN  6'h26
53
`define FLOAT   6'h0F
54
`define FCMP    6'h06
55
`define FMOV    6'h10
56
`define FNEG    6'h14
57
`define FABS    6'h15
58
`define FSIGN   6'h16
59
`define FMAN    6'h17
60
`define FNABS   6'h18
61
`define FCVTSD  6'h19
62
`define FCVTSQ  6'h1B
63
`define FCVTDS  6'h29
64
`define FSLT            6'h38
65
`define FSGE            6'h39
66
`define FSLE            6'h3A
67
`define FSGT            6'h3B
68
`define FSEQ            6'h3C
69
`define FSNE            6'h3D
70
`define FSUN            6'h3E
71
 
72
module fpZLUnit
73
#(parameter WID=32)
74
(
75
    input [31:0] ir,
76
        input [WID-1:0] a,
77
        input [WID-1:0] b,       // for fcmp
78
        output reg [WID-1:0] o,
79
        output nanx
80
);
81
localparam MSB = WID-1;
82
localparam EMSB = WID==128 ? 14 :
83
                  WID==96 ? 14 :
84
                  WID==80 ? 14 :
85
                  WID==64 ? 10 :
86
                                  WID==52 ? 10 :
87
                                  WID==48 ? 11 :
88
                                  WID==44 ? 10 :
89
                                  WID==42 ? 10 :
90
                                  WID==40 ?  9 :
91
                                  WID==32 ?  7 :
92
                                  WID==24 ?  6 : 4;
93
localparam FMSB = WID==128 ? 111 :
94
                  WID==96 ? 79 :
95
                  WID==80 ? 63 :
96
                  WID==64 ? 51 :
97
                                  WID==52 ? 39 :
98
                                  WID==48 ? 34 :
99
                                  WID==44 ? 31 :
100
                                  WID==42 ? 29 :
101
                                  WID==40 ? 28 :
102
                                  WID==32 ? 22 :
103
                                  WID==24 ? 15 : 9;
104
 
105
wire [5:0] op = ir[5:0];
106
//wire [1:0] prec = ir[25:24];
107
wire [5:0] fn = ir[31:26];
108
wire [2:0] sxx = {ir[25],ir[20:19]};
109
 
110
wire [4:0] cmp_o;
111
 
112
fp_cmp_unit #(WID) u1 (.a(a), .b(b), .o(cmp_o), .nanx(nanx) );
113
wire [127:0] sq_o;
114
//fcvtsq u2 (a[31:0], sq_o);
115
wire [63:0] sdo;
116
fs2d u3 (a[31:0], sdo);
117
wire [31:0] dso;
118
fd2s u4 (a, dso);
119
 
120
always @*
121
    case(op)
122
    `FLOAT:
123
        case(fn)
124
        `FABS:   o <= {1'b0,a[WID-2:0]};        // fabs
125
        `FNABS:  o <= {1'b1,a[WID-2:0]};        // fnabs
126
        `FNEG:   o <= {~a[WID-1],a[WID-2:0]};   // fneg
127
        `FMOV:   o <= a;                        // fmov
128
        `FSIGN:  o <= (a[WID-2:0]==0) ? 0 : {a[WID-1],1'b0,{EMSB{1'b1}},{FMSB+1{1'b0}}};    // fsign
129
        `FMAN:   o <= {a[WID-1],1'b0,{EMSB{1'b1}},a[FMSB:0]};    // fman
130
        //`FCVTSQ:    o <= sq_o;
131
        `FCVTSD: o <= sdo;
132
        `FCVTDS: o <= {{32{dso[31]}},dso};
133
        `FCMP:   o <= cmp_o;
134
        `FSLT:   o <=  cmp_o[1];
135
        `FSGE:   o <= ~cmp_o[1];
136
        `FSLE:   o <=  cmp_o[2];
137
        `FSGT:   o <= ~cmp_o[2];
138
        `FSEQ:   o <=  cmp_o[0];
139
        `FSNE:   o <= ~cmp_o[0];
140
        `FSUN:   o <=  cmp_o[4];
141
        default: o <= 0;
142
        endcase
143
    `FVECTOR:
144
        case(fn)
145
        `VFABS:  o <= {1'b0,a[WID-2:0]};        // fabs
146
        `VFSIGN: o <= (a[WID-2:0]==0) ? 0 : {a[WID-1],1'b0,{EMSB{1'b1}},{FMSB+1{1'b0}}};    // fsign
147
        `VFNEG:  o <= {~a[WID-1],a[WID-2:0]};   // fneg
148
        `VFSxx,`VFSxxS:
149
            case(sxx)
150
            `VSEQ:  o <=  cmp_o[0];
151
            `VSNE:  o <= ~cmp_o[0];
152
            `VSLT:  o <=  cmp_o[1];
153
            `VSGE:  o <= ~cmp_o[1];
154
            `VSLE:  o <=  cmp_o[2];
155
            `VSGT:  o <= ~cmp_o[2];
156
            `VSUN:  o <=  cmp_o[4];
157
            default:    o <= cmp_o[2];
158
            endcase
159
        default:    o <= 0;
160
        endcase
161
        default:        o <= 0;
162
        endcase
163
 
164
endmodule

powered by: WebSVN 2.1.0

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