|
发表于 2008-8-5 11:10:57
|
显示全部楼层
浮点数乘法
module floatmul(clk,reset,oz,ost);
//input[31:0] ix,iy;
input clk,reset;
output[31:0] oz;
output ost;
reg[31:0] oz;
reg[24:0] xm, ym, zm;
reg[22:0] zm1;
reg[7:0] xe, ye, ze;
reg p;
reg[31:0] ix,iy;
reg[2:0] state;
parameter start = 3'b000;
parameter mulm = 3'b011;
parameter infifl = 3'b101;
parameter over = 3'b110;
assign ost = (state == over) ? 1 : 0;
[email=always@(posedge]always@(posedge[/email] clk)
begin
if(!reset)
begin
state<= start;
ix=32'b01000000001101000111100110010110;
iy=32'b10111111000111110101001110110010;
oz=0;
end
else
case(state)
start: begin
xe <= ix[30:23];
xm <= {1'b0,1'b1,ix[22:0]};
ye <= iy[30:23];
ym <= {1'b0,1'b1,iy[22:0]};
state<= mulm;
end
mulm: begin
p=ix[31]^iy[31];
ze=xe+ye-8'b01111111;
{zm,zm1}=xm*ym;
state <= infifl;
end
infifl:begin
if(zm[24])
begin
ze=ze+1;
oz={p,ze,zm[23:1]};
state <= over;
end
else
begin
oz={p,ze,zm[22:0]};
state <= over;
end
end
over: state <= over;
default: state <= start;
endcase
end
endmodule
32位浮点数分为三部分:
31 符号位 30~23 阶码 22~0 尾数 |
|