Verilog - floating point multiplication

We have a problem with Verilog. We should use multiplication with two floating points (binary), but it does not work 100% perfectly.

We have Req m [31: 0]. The first numbers (before the decimal point) are m [31:16] and the numbers after the decimal point m [15: 0], so we have:

m [31:16] = 1000000000000000; m [15: 0] = 1000000000000000;

m [31: 0] = 10000000000000000 (.) 1000000000000000;

The problem is that we want to multiply numbers with decimal places, but we do not know how to do this. For example: m = 2.5 in binary format. The result of m * m is 6.25.

+3
source share
1 answer

, , , OP.

( 2) , 4 :

2^3  2^2  2^1  2^0 (Base 2)
  8    4    2    1

, . 4 hex :

16^3  16^2  16^1  16^0
4096   256    16     1

2, , , MSB ( ) .

-2^3  2^2  2^1  2^0 (Base 2, Twos complement)
  -8    4    2    1

, . 4 4 .

Base 2: Twos complement 4 integer, 4 bit frational
-2^3  2^2  2^1  2^0  .  2^-1    2^-2    2^-3    2^-4
  -8    4    2    1  .   0.5    0.25   0.125  0.0625

, Verilog , . . verilog, reg logic, . verilog _ , . .

2.5 8'b0010_1000, 16 , 16 _, .

A B, A * B :

Integer bits    = A.integer_bits    + B.integer_bits.
Fractional bits = A.fractional_bits + B.fractional_bits.

[4 Int, 4 Frac] * [4 Int, 4 Frac] = > [8 Int, 8 Frac]

reg [7:0] a = 0010_1000;
reg [7:0] b = 0010_1000;
reg [15:0] sum;

always @* begin
  sum = a * b ;
  $displayb(sum); //Binary
  $display(sum);  //Decimal
end

// sum == 00000110_01000000; //Decimal->6.25

EDA.

. 16 Int 16 . , , .

Q & A, 22 .

+6

All Articles