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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fpDiv.v] - Diff between revs 29 and 32

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 29 Rev 32
Line 5... Line 5...
//     \/_//     robfinch<remove>@finitron.ca
//     \/_//     robfinch<remove>@finitron.ca
//       ||
//       ||
//
//
//      fpDiv.v
//      fpDiv.v
//    - floating point divider
//    - floating point divider
//    - parameterized FPWIDth
//    - parameterized width
//    - IEEE 754 representation
//    - IEEE 754 representation
//
//
//
//
// This source file is free software: you can redistribute it and/or modify 
// This source file is free software: you can redistribute it and/or modify 
// it under the terms of the GNU Lesser General Public License as published 
// it under the terms of the GNU Lesser General Public License as published 
Line 36... Line 36...
`include "fp_defines.v"
`include "fp_defines.v"
//`define GOLDSCHMIDT   1'b1
//`define GOLDSCHMIDT   1'b1
 
 
module fpDiv(rst, clk, clk4x, ce, ld, op, a, b, o, done, sign_exe, overflow, underflow);
module fpDiv(rst, clk, clk4x, ce, ld, op, a, b, o, done, sign_exe, overflow, underflow);
 
 
parameter FPWID = 128;
parameter FPWID = 64;
`include "fpSize.sv"
`include "fpSize.sv"
// FADD is a constant that makes the divider FPWIDth a multiple of four and includes eight extra bits.                  
// FADD is a constant that makes the divider width a multiple of four and includes eight extra bits.                    
localparam FADD = FPWID+`EXTRA_BITS==128 ? 9 :
localparam FADD = FPWID==128 ? 9 :
                                  FPWID+`EXTRA_BITS==96 ? 9 :
                                  FPWID==96 ? 9 :
                                  FPWID+`EXTRA_BITS==84 ? 9 :
                                  FPWID==84 ? 9 :
                                  FPWID+`EXTRA_BITS==80 ? 9 :
                                  FPWID==80 ? 9 :
                                  FPWID+`EXTRA_BITS==64 ? 13 :
                                  FPWID==64 ? 13 :
                                  FPWID+`EXTRA_BITS==52 ? 9 :
                                  FPWID==52 ? 9 :
                                  FPWID+`EXTRA_BITS==48 ? 10 :
                                  FPWID==48 ? 10 :
                                  FPWID+`EXTRA_BITS==44 ? 9 :
                                  FPWID==44 ? 9 :
                                  FPWID+`EXTRA_BITS==42 ? 11 :
                                  FPWID==42 ? 11 :
                                  FPWID+`EXTRA_BITS==40 ? 8 :
                                  FPWID==40 ? 8 :
                                  FPWID+`EXTRA_BITS==32 ? 10 :
                                  FPWID==32 ? 10 :
                                  FPWID+`EXTRA_BITS==24 ? 9 : 11;
                                  FPWID==24 ? 9 : 11;
 
 
input rst;
input rst;
input clk;
input clk;
input clk4x;
input clk4x;
input ce;
input ce;
Line 128... Line 128...
// check for exponent underflow/overflow
// check for exponent underflow/overflow
wire under = ex1[EMSB+2];       // MSB set = negative exponent
wire under = ex1[EMSB+2];       // MSB set = negative exponent
wire over = (&ex1[EMSB:0] | ex1[EMSB+1]) & !ex1[EMSB+2];
wire over = (&ex1[EMSB:0] | ex1[EMSB+1]) & !ex1[EMSB+2];
 
 
// Perform divide
// Perform divide
// Divider FPWIDth must be a multiple of four
// Divider width must be a multiple of four
`ifndef GOLDSCHMIDT
`ifndef GOLDSCHMIDT
fpdivr16 #(FMSB+FADD) u2 (.clk(clk), .ld(ld), .a({3'b0,fracta,8'b0}), .b({3'b0,fractb,8'b0}), .q(divo), .r(), .done(done1), .lzcnt(lzcnt));
fpdivr16 #(FMSB+FADD) u2 (.clk(clk), .ld(ld), .a({3'b0,fracta,8'b0}), .b({3'b0,fractb,8'b0}), .q(divo), .r(), .done(done1), .lzcnt(lzcnt));
//fpdivr2 #(FMSB+FADD) u2 (.clk4x(clk4x), .ld(ld), .a({3'b0,fracta,8'b0}), .b({3'b0,fractb,8'b0}), .q(divo), .r(), .done(done1), .lzcnt(lzcnt));
//fpdivr2 #(FMSB+FADD) u2 (.clk4x(clk4x), .ld(ld), .a({3'b0,fracta,8'b0}), .b({3'b0,fractb,8'b0}), .q(divo), .r(), .done(done1), .lzcnt(lzcnt));
wire [(FMSB+FADD)*2-1:0] divo1 = divo[(FMSB+FADD)*2-1:0] << (lzcnt-2);
wire [(FMSB+FADD)*2-1:0] divo1 = divo[(FMSB+FADD)*2-1:0] << (lzcnt-2);
`else
`else
DivGoldschmidt #(.FPWID(FMSB+6),.WHOLE(1),.POINTS(FMSB+5))
DivGoldschmidt #(.WID(FMSB+6),.WHOLE(1),.POINTS(FMSB+5))
        u2 (.rst(rst), .clk(clk), .ld(ld), .a({fracta,4'b0}), .b({fractb,4'b0}), .q(divo), .done(done1), .lzcnt(lzcnt));
        u2 (.rst(rst), .clk(clk), .ld(ld), .a({fracta,4'b0}), .b({fractb,4'b0}), .q(divo), .done(done1), .lzcnt(lzcnt));
wire [(FMSB+6)*2+1:0] divo1 =
wire [(FMSB+6)*2+1:0] divo1 =
        lzcnt > 8'd5 ? divo << (lzcnt-8'd6) :
        lzcnt > 8'd5 ? divo << (lzcnt-8'd6) :
        divo >> (8'd6-lzcnt);
        divo >> (8'd6-lzcnt);
        ;
        ;
Line 170... Line 170...
                        5'b00001:               xo <= 1'd0;             // underflow
                        5'b00001:               xo <= 1'd0;             // underflow
                        default:                xo <= ex1;      // normal or underflow: passthru neg. exp. for normalization
                        default:                xo <= ex1;      // normal or underflow: passthru neg. exp. for normalization
                        endcase
                        endcase
 
 
                        casez({aNan,bNan,qNaNOut,bInf,bz,over,aInf&bInf,az&bz})
                        casez({aNan,bNan,qNaNOut,bInf,bz,over,aInf&bInf,az&bz})
                        8'b1???????:  mo <= {1'b1,1'b1,a[FMSB-1:0],{FMSB+1{1'b0}}};
                        8'b1???????:    mo <= {1'b1,a[FMSB:0],{FMSB+1{1'b0}}};
                        8'b01??????:  mo <= {1'b1,1'b1,b[FMSB-1:0],{FMSB+1{1'b0}}};
                        8'b01??????:    mo <= {1'b1,b[FMSB:0],{FMSB+1{1'b0}}};
                        8'b001?????:    mo <= {1'b1,qNaN[FMSB:0]|{aInf,1'b0}|{az,bz},{FMSB+1{1'b0}}};
                        8'b001?????:    mo <= {1'b1,qNaN[FMSB:0]|{aInf,1'b0}|{az,bz},{FMSB+1{1'b0}}};
                        8'b0001????:    mo <= 1'd0;     // div by inf
                        8'b0001????:    mo <= 1'd0;     // div by inf
                        8'b00001???:    mo <= 1'd0;     // div by zero
                        8'b00001???:    mo <= 1'd0;     // div by zero
                        8'b000001??:    mo <= 1'd0;     // Inf exponent
                        8'b000001??:    mo <= 1'd0;     // Inf exponent
                        8'b0000001?:    mo <= {1'b1,qNaN|`QINFDIV,{FMSB+1{1'b0}}};      // infinity / infinity
                        8'b0000001?:    mo <= {1'b1,qNaN|`QINFDIV,{FMSB+1{1'b0}}};      // infinity / infinity
Line 195... Line 195...
        end
        end
 
 
endmodule
endmodule
 
 
module fpDivnr(rst, clk, clk4x, ce, ld, op, a, b, o, rm, done, sign_exe, inf, overflow, underflow);
module fpDivnr(rst, clk, clk4x, ce, ld, op, a, b, o, rm, done, sign_exe, inf, overflow, underflow);
parameter FPWID=32;
parameter FPWID=64;
`include "fpSize.sv"
`include "fpSize.sv"
 
 
input rst;
input rst;
input clk;
input clk;
input clk4x;
input clk4x;
Line 219... Line 219...
wire sign_exe1, inf1, overflow1, underflow1;
wire sign_exe1, inf1, overflow1, underflow1;
wire [MSB+3:0] fpn0;
wire [MSB+3:0] fpn0;
wire done1;
wire done1;
 
 
fpDiv       #(FPWID) u1 (rst, clk, clk4x, ce, ld, op, a, b, o1, done1, sign_exe1, overflow1, underflow1);
fpDiv       #(FPWID) u1 (rst, clk, clk4x, ce, ld, op, a, b, o1, done1, sign_exe1, overflow1, underflow1);
fpNormalize #(FPWID) u2(.clk(clk), .ce(ce), .under(underflow1), .i(o1), .o(fpn0) );
fpNormalize #(FPWID) u2(.clk(clk), .ce(ce), .under_i(underflow1), .i(o1), .o(fpn0) );
fpRound                 #(FPWID) u3(.clk(clk), .ce(ce), .rm(rm), .i(fpn0), .o(o) );
fpRound                 #(FPWID) u3(.clk(clk), .ce(ce), .rm(rm), .i(fpn0), .o(o) );
delay2      #(1)   u4(.clk(clk), .ce(ce), .i(sign_exe1), .o(sign_exe));
delay2      #(1)   u4(.clk(clk), .ce(ce), .i(sign_exe1), .o(sign_exe));
delay2      #(1)   u5(.clk(clk), .ce(ce), .i(inf1), .o(inf));
delay2      #(1)   u5(.clk(clk), .ce(ce), .i(inf1), .o(inf));
delay2      #(1)   u6(.clk(clk), .ce(ce), .i(overflow1), .o(overflow));
delay2      #(1)   u6(.clk(clk), .ce(ce), .i(overflow1), .o(overflow));
delay2      #(1)   u7(.clk(clk), .ce(ce), .i(underflow1), .o(underflow));
delay2      #(1)   u7(.clk(clk), .ce(ce), .i(underflow1), .o(underflow));
delay2            #(1)   u8(.clk(clk), .ce(ce), .i(done1), .o(done));
vtdl                    #(1)   u8(.clk(clk), .ce(ce), .a(4'd13), .d(done1), .q(done));
endmodule
endmodule
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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