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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64/] [rtl/] [fpUnit/] [fpZLUnit.v] - Blame information for rev 43

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 43 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 VECTOR  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
 
65
module fpZLUnit
66
#(parameter WID=32)
67
(
68
    input [31:0] ir,
69
        input [WID-1:0] a,
70
        input [WID-1:0] b,       // for fcmp
71
        output reg [WID-1:0] o,
72
        output nanx
73
);
74
localparam MSB = WID-1;
75
localparam EMSB = WID==128 ? 14 :
76
                  WID==96 ? 14 :
77
                  WID==80 ? 14 :
78
                  WID==64 ? 10 :
79
                                  WID==52 ? 10 :
80
                                  WID==48 ? 11 :
81
                                  WID==44 ? 10 :
82
                                  WID==42 ? 10 :
83
                                  WID==40 ?  9 :
84
                                  WID==32 ?  7 :
85
                                  WID==24 ?  6 : 4;
86
localparam FMSB = WID==128 ? 111 :
87
                  WID==96 ? 79 :
88
                  WID==80 ? 63 :
89
                  WID==64 ? 51 :
90
                                  WID==52 ? 39 :
91
                                  WID==48 ? 34 :
92
                                  WID==44 ? 31 :
93
                                  WID==42 ? 29 :
94
                                  WID==40 ? 28 :
95
                                  WID==32 ? 22 :
96
                                  WID==24 ? 15 : 9;
97
 
98
wire [5:0] op = ir[5:0];
99
wire [1:0] prec = ir[25:24];
100
wire [5:0] fn = ir[31:26];
101
wire [2:0] sxx = {ir[25],ir[20:19]};
102
 
103
wire [4:0] cmp_o;
104
 
105
fp_cmp_unit #(WID) u1 (.a(a), .b(b), .o(cmp_o), .nanx(nanx) );
106
wire [127:0] sq_o;
107
//fcvtsq u2 (a[31:0], sq_o);
108
wire [63:0] sdo;
109
fs2d u3 (a[31:0], sdo);
110
wire [31:0] dso;
111
fd2s u4 (a, dso);
112
 
113
always @*
114
    case(op)
115
    `FLOAT:
116
        case(fn)
117
        `FABS:   o <= {1'b0,a[WID-2:0]};        // fabs
118
        `FNABS:  o <= {1'b1,a[WID-2:0]};        // fnabs
119
        `FNEG:   o <= {~a[WID-1],a[WID-2:0]};   // fneg
120
        `FMOV:   o <= a;                        // fmov
121
        `FSIGN:  o <= (a[WID-2:0]==0) ? 0 : {a[WID-1],1'b0,{EMSB{1'b1}},{FMSB+1{1'b0}}};    // fsign
122
        `FMAN:   o <= {a[WID-1],1'b0,{EMSB{1'b1}},a[FMSB:0]};    // fman
123
        //`FCVTSQ:    o <= sq_o;
124
        `FCVTSD: o <= sdo;
125
        `FCVTDS: o <= {{32{dso[31]}},dso};
126
        `FCMP:   o <= cmp_o;
127
        default: o <= 0;
128
        endcase
129
    `VECTOR:
130
        case(fn)
131
        `VFABS:  o <= {1'b0,a[WID-2:0]};        // fabs
132
        `VFSIGN: o <= (a[WID-2:0]==0) ? 0 : {a[WID-1],1'b0,{EMSB{1'b1}},{FMSB+1{1'b0}}};    // fsign
133
        `VFNEG:  o <= {~a[WID-1],a[WID-2:0]};   // fneg
134
        `VFSxx,`VFSxxS:
135
            case(sxx)
136
            `VSEQ:  o <=  cmp_o[0];
137
            `VSNE:  o <= ~cmp_o[0];
138
            `VSLT:  o <=  cmp_o[1];
139
            `VSGE:  o <= ~cmp_o[1];
140
            `VSLE:  o <=  cmp_o[2];
141
            `VSGT:  o <= ~cmp_o[2];
142
            `VSUN:  o <=  cmp_o[4];
143
            default:    o <= cmp_o[2];
144
            endcase
145
        default:    o <= 0;
146
        endcase
147
        default:        o <= 0;
148
        endcase
149
 
150
endmodule

powered by: WebSVN 2.1.0

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