| 1 |
6 |
robfinch |
`timescale 1ns / 1ps
|
| 2 |
|
|
// ============================================================================
|
| 3 |
|
|
// __
|
| 4 |
|
|
// \\__/ o\ (C) 2007,2014,2015 Robert Finch, Stratford
|
| 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 |
|
|
`include "..\Thor_defines.v"
|
| 41 |
|
|
|
| 42 |
|
|
module fpZLUnit
|
| 43 |
|
|
#(parameter WID=32)
|
| 44 |
|
|
(
|
| 45 |
|
|
input [7:0] op,
|
| 46 |
|
|
input [5:0] fn,
|
| 47 |
|
|
input [WID:1] a,
|
| 48 |
|
|
input [WID:1] b, // for fcmp
|
| 49 |
|
|
output reg [WID:1] o,
|
| 50 |
|
|
output nanx
|
| 51 |
|
|
);
|
| 52 |
|
|
localparam MSB = WID-1;
|
| 53 |
|
|
localparam EMSB = WID==80 ? 14 :
|
| 54 |
|
|
WID==64 ? 10 :
|
| 55 |
|
|
WID==52 ? 10 :
|
| 56 |
|
|
WID==48 ? 10 :
|
| 57 |
|
|
WID==44 ? 10 :
|
| 58 |
|
|
WID==42 ? 10 :
|
| 59 |
|
|
WID==40 ? 9 :
|
| 60 |
|
|
WID==32 ? 7 :
|
| 61 |
|
|
WID==24 ? 6 : 4;
|
| 62 |
|
|
localparam FMSB = WID==80 ? 63 :
|
| 63 |
|
|
WID==64 ? 51 :
|
| 64 |
|
|
WID==52 ? 39 :
|
| 65 |
|
|
WID==48 ? 35 :
|
| 66 |
|
|
WID==44 ? 31 :
|
| 67 |
|
|
WID==42 ? 29 :
|
| 68 |
|
|
WID==40 ? 28 :
|
| 69 |
|
|
WID==32 ? 22 :
|
| 70 |
|
|
WID==24 ? 15 : 9;
|
| 71 |
|
|
|
| 72 |
|
|
wire nanxd,nanxs;
|
| 73 |
|
|
wire single = op==`SINGLE_R;
|
| 74 |
|
|
wire az = single ? a[31:1]==0 : WID==64 ? a[63:1]==0 : 0;
|
| 75 |
|
|
wire [3:0] cmp_o,cmps_o;
|
| 76 |
|
|
assign nanx = op==`FLOAT && fn==`FCMPS ? nanxs : nanxd;
|
| 77 |
|
|
|
| 78 |
|
|
fp_cmp_unit #(64) u1 (.a(a), .b(b), .o(cmp_o), .nanx(nanxd) );
|
| 79 |
|
|
fp_cmp_unit #(32) u2 (.a(a[32:1]), .b(b[32:1]), .o(cmps_o), .nanx(nanxs) );
|
| 80 |
|
|
|
| 81 |
|
|
always @(op,a,cmp_o,az,cmps_o)
|
| 82 |
|
|
case (op)
|
| 83 |
|
|
`DOUBLE_R:
|
| 84 |
|
|
if (WID==64)
|
| 85 |
|
|
case(fn)
|
| 86 |
|
|
`FABS: o <= {1'b0,a[63:1]}; // fabs
|
| 87 |
|
|
`FNABS: o <= {1'b1,a[63:1]}; // fnabs
|
| 88 |
|
|
`FNEG: o <= {~a[64],a[63:1]}; // fneg
|
| 89 |
|
|
`FMOV: o <= a; // fmov
|
| 90 |
|
|
`FSIGN: o <= az ? 0 : {a[64],1'b0,{10{1'b1}},{52{1'b0}}}; // fsign
|
| 91 |
|
|
`FMAN: o <= {a[64],1'b0,{10{1'b1}},a[51:1]}; // fman
|
| 92 |
|
|
default: o <= 0;
|
| 93 |
|
|
endcase
|
| 94 |
|
|
`SINGLE_R:
|
| 95 |
|
|
case(fn)
|
| 96 |
|
|
`FABSS: o <= {1'b0,a[31:1]}; // fabs
|
| 97 |
|
|
`FNABSS: o <= {1'b1,a[31:1]}; // fnabs
|
| 98 |
|
|
`FNEGS: o <= {~a[32],a[31:1]}; // fneg
|
| 99 |
|
|
`FMOVS: o <= a; // fmov
|
| 100 |
|
|
`FSIGNS: o <= az ? 0 : {a[32],1'b0,{7{1'b1}},{23{1'b0}}}; // fsign
|
| 101 |
|
|
`FMANS: o <= {a[32],1'b0,{7{1'b1}},a[23:1]}; // fman
|
| 102 |
|
|
default: o <= 0;
|
| 103 |
|
|
endcase
|
| 104 |
|
|
`FLOAT:
|
| 105 |
|
|
case(fn)
|
| 106 |
|
|
`FCMP: o <= cmp_o;
|
| 107 |
|
|
`FCMPS: o <= cmps_o;
|
| 108 |
|
|
default: o <= 0;
|
| 109 |
|
|
endcase
|
| 110 |
|
|
default: o <= 0;
|
| 111 |
|
|
endcase
|
| 112 |
|
|
|
| 113 |
|
|
endmodule
|