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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog/] [fpSqrt.v] - Diff between revs 12 and 26

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

Rev 12 Rev 26
Line 1... Line 1...
`timescale 1ns / 1ps
`timescale 1ns / 1ps
// ============================================================================
// ============================================================================
//        __
//        __
//   \\__/ o\    (C) 2018  Robert Finch, Waterloo
//   \\__/ o\    (C) 2018-2019  Robert Finch, Waterloo
//    \  __ /    All rights reserved.
//    \  __ /    All rights reserved.
//     \/_//     robfinch<remove>@finitron.ca
//     \/_//     robfinch<remove>@finitron.ca
//       ||
//       ||
//
//
//      fpSqrt.v
//      fpSqrt.v
Line 27... Line 27...
//                                                                          
//                                                                          
//      Floating Point Multiplier / Divider
//      Floating Point Multiplier / Divider
//
//
// ============================================================================
// ============================================================================
 
 
module fpSqrt(rst, clk, ce, ld, a, o, done);
`include "fp_defines.v"
parameter WID = 128;
 
localparam MSB = WID-1;
 
localparam EMSB = WID==128 ? 14 :
 
                  WID==96 ? 14 :
 
                  WID==80 ? 14 :
 
                  WID==64 ? 10 :
 
                                  WID==52 ? 10 :
 
                                  WID==48 ? 11 :
 
                                  WID==44 ? 10 :
 
                                  WID==42 ? 10 :
 
                                  WID==40 ?  9 :
 
                                  WID==32 ?  7 :
 
                                  WID==24 ?  6 : 4;
 
localparam FMSB = WID==128 ? 111 :
 
                  WID==96 ? 79 :
 
                  WID==80 ? 63 :
 
                  WID==64 ? 51 :
 
                                  WID==52 ? 39 :
 
                                  WID==48 ? 34 :
 
                                  WID==44 ? 31 :
 
                                  WID==42 ? 29 :
 
                                  WID==40 ? 28 :
 
                                  WID==32 ? 22 :
 
                                  WID==24 ? 15 : 9;
 
 
 
localparam FX = (FMSB+2)*2-1;   // the MSB of the expanded fraction
module fpSqrt(rst, clk, ce, ld, a, o, done, sqrinf, sqrneg);
localparam EX = FX + 1 + EMSB + 1 + 1 - 1;
parameter WID = 128;
 
`include "fpSize.sv"
 
 
input rst;
input rst;
input clk;
input clk;
input ce;
input ce;
input ld;
input ld;
input [MSB:0] a;
input [MSB:0] a;
output [EX:0] o;
output reg [EX:0] o;
output done;
output done;
 
output sqrinf;
 
output sqrneg;
 
 
// registered outputs
// registered outputs
reg sign_exe;
reg sign_exe;
reg inf;
reg inf;
reg     overflow;
reg     overflow;
Line 120... Line 99...
 
 
assign ex1 = xa + 8'd1;
assign ex1 = xa + 8'd1;
assign so = 1'b0;                               // square root of positive numbers only
assign so = 1'b0;                               // square root of positive numbers only
assign xo = (ex1 >> 1) + (bias >> 1);   // divide by 2 cuts the bias in half, so 1/2 of it is added back in.
assign xo = (ex1 >> 1) + (bias >> 1);   // divide by 2 cuts the bias in half, so 1/2 of it is added back in.
assign mo = aNan ? {1'b1,a[FMSB:0],{FMSB+1{1'b0}}} : (sqrto << 36);
assign mo = aNan ? {1'b1,a[FMSB:0],{FMSB+1{1'b0}}} : (sqrto << 36);
 
assign sqrinf = aInf;
 
assign sqrneg = !az & so;
 
 
wire [FMSB+2:0] fracta1 = ex1[0] ? {1'b0,fracta} << 1 : {2'b0,fracta};
wire [FMSB+2:0] fracta1 = ex1[0] ? {1'b0,fracta} << 1 : {2'b0,fracta};
 
 
isqrt #(FX+1) u2
isqrt #(FX+1) u2
(
(
Line 134... Line 115...
        .a({fracta1,{FMSB+1{1'b0}}}),
        .a({fracta1,{FMSB+1{1'b0}}}),
        .o(sqrto),
        .o(sqrto),
        .done(done)
        .done(done)
);
);
 
 
assign o = aNan ? {sa,xa,mo} : {so,xo,mo};
always @*
 
casez({aNan,sqrinf,sqrneg})
 
3'b1??: o <= {sa,xa,mo};
 
3'b01?: o <= {sa,1'b1,qNaN|`QSQRTINF,{FMSB+1{1'b0}}};
 
3'b001: o <= {sa,1'b1,qNaN|`QSQRTNEG,{FMSB+1{1'b0}}};
 
default:        o <= {so,xo,mo};
 
endcase
 
 
 
 
endmodule
endmodule
 
 
module fpSqrtnr(rst, clk, ce, ld, a, o, rm, done, inf);
module fpSqrtnr(rst, clk, ce, ld, a, o, rm, done, inf, sqrinf, sqrneg);
parameter WID=32;
parameter WID=32;
localparam MSB = WID-1;
`include "fpSize.sv"
localparam EMSB = WID==128 ? 14 :
 
                  WID==96 ? 14 :
 
                  WID==80 ? 14 :
 
                  WID==64 ? 10 :
 
                                  WID==52 ? 10 :
 
                                  WID==48 ? 11 :
 
                                  WID==44 ? 10 :
 
                                  WID==42 ? 10 :
 
                                  WID==40 ?  9 :
 
                                  WID==32 ?  7 :
 
                                  WID==24 ?  6 : 4;
 
localparam FMSB = WID==128 ? 111 :
 
                  WID==96 ? 79 :
 
                  WID==80 ? 63 :
 
                  WID==64 ? 51 :
 
                                  WID==52 ? 39 :
 
                                  WID==48 ? 34 :
 
                                  WID==44 ? 31 :
 
                                  WID==42 ? 29 :
 
                                  WID==40 ? 28 :
 
                                  WID==32 ? 22 :
 
                                  WID==24 ? 15 : 9;
 
 
 
localparam FX = (FMSB+2)*2-1;   // the MSB of the expanded fraction
 
localparam EX = FX + 1 + EMSB + 1 + 1 - 1;
 
input rst;
input rst;
input clk;
input clk;
input ce;
input ce;
input ld;
input ld;
input  [MSB:0] a;
input  [MSB:0] a;
output [MSB:0] o;
output [MSB:0] o;
input [2:0] rm;
input [2:0] rm;
output done;
output done;
output inf;
output inf;
 
output sqrinf;
 
output sqrneg;
 
 
wire [EX:0] o1;
wire [EX:0] o1;
wire inf1;
wire inf1;
wire [MSB+3:0] fpn0;
wire [MSB+3:0] fpn0;
wire done1;
wire done1;
 
 
fpSqrt      #(WID) u1 (rst, clk, ce, ld, a, o1, done1);
fpSqrt      #(WID) u1 (rst, clk, ce, ld, a, o1, done1, sqrinf, sqrneg);
fpNormalize #(WID) u2(.clk(clk), .ce(ce), .under(1'b0), .i(o1), .o(fpn0) );
fpNormalize #(WID) u2(.clk(clk), .ce(ce), .under(1'b0), .i(o1), .o(fpn0) );
fpRoundReg  #(WID) u3(.clk(clk), .ce(ce), .rm(rm), .i(fpn0), .o(o) );
fpRoundReg  #(WID) u3(.clk(clk), .ce(ce), .rm(rm), .i(fpn0), .o(o) );
delay2      #(1)   u5(.clk(clk), .ce(ce), .i(inf1), .o(inf));
delay2      #(1)   u5(.clk(clk), .ce(ce), .i(inf1), .o(inf));
delay2          #(1)   u8(.clk(clk), .ce(ce), .i(done1), .o(done));
delay2          #(1)   u8(.clk(clk), .ce(ce), .i(done1), .o(done));
endmodule
endmodule

powered by: WebSVN 2.1.0

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