Попросили написать на верилоге конвертер инт во флоат.
Собственно, написал, но есть проблемы:
1й вариант:
module int2float(
input_data,
output_data
);
//---Input pins---
input [15:0] input_data;
//---Output pins---
output [31:0] output_data;
//---Registers---
reg [31:0] out_data_reg;
integer exponent;
assign output_data = out_data_reg;
always @ (input_data)
begin
out_data_reg = 0;
out_data_reg[31] = input_data[15];
for(exponent=15; exponent<0; exponent=exponent-1)
begin
if(out_data_reg[exponent] == 0)
continue;
else
break;
end
out_data_reg[30:23] = exponent + 127;
out_data_reg[22:22-1-exponent] = input_data[exponent-1:0];
end
endmodule
2й вариант(говнокод):
module int2float(
input_data,
output_data
);
//---Input pins---
input [15:0] input_data;
//---Output pins---
output [31:0] output_data;
//---Registers---
reg [31:0] out_data_reg;
//reg [3:0] exponent;
reg [15:0] buffer;
integer index;
integer found_one;
integer exponent;
assign output_data = out_data_reg;
always @ (input_data or output_data)
begin
out_data_reg = 0;
found_one = 0;
index = 15;
buffer = 0;
exponent = 15;
out_data_reg[31] = input_data[15];
for(exponent=15; exponent<0; exponent=exponent-1)
begin
if(input_data[exponent] == 0 && found_one == 0)
continue;
else if(input_data[exponent] == 1 && found_one == 0)
begin
found_one = 1;
buffer[index] = input_data[exponent];
index = index - 1;
end
else if(input_data[exponent] == 1 && found_one == 1)
begin
buffer[index] = input_data[exponent];
index = index - 1;
end
else if(input_data[exponent] == 0 && found_one == 1)
begin
buffer[index] = input_data[exponent];
index = index - 1;
end
end
out_data_reg[30:23] = exponent + 127;
out_data_reg[22:7] = buffer[15:0];
end
endmodule