Signed multiplication in Verilog

Status
Not open for further replies.

Aimerbhat

Newbie level 5 Hi ,

I have 8 numbers like -398.1234 , -14.1898 etc and I have 8 signals generated in the design .
I need to compute

y = c1* x1 + c2 * x2 .... + c8 *x8 ,
where c1 , c2 etc are the constants and x1 , x2 are the signals to the block .

What is the best way to code this ?
since these are floating point numbers , should I multiply them by10, 000 ,
to convert them to integer, do the computation and then again divide by10, 000 ?
If so , dividing by10,000 will not be easy in binary .

Can we declare floating point numbers in verilog, and will the synthesis tool take care of it ?

Thanks ,
Aimer

FvM

Super Moderator
Staff member The topic of fixed point numbers has been frequently discussed at Edaboard, you may want to review the respective discussions. Generally, you have to decide about the intended precision and choose a suitable signal bitwidth. Scaling should be done by powers of two, which is nothing but a shift operation with binary numbers. I'm sure, you can figure it out yourself.

yanzixuan

Member level 3 Aimerbhat said:
Hi ,

I have 8 numbers like -398.1234 , -14.1898 etc and I have 8 signals generated in the design .
I need to compute

y = c1* x1 + c2 * x2 .... + c8 *x8 ,
where c1 , c2 etc are the constants and x1 , x2 are the signals to the block .

What is the best way to code this ?
since these are floating point numbers , should I multiply them by10, 000 ,
to convert them to integer, do the computation and then again divide by10, 000 ?
If so , dividing by10,000 will not be easy in binary .

Can we declare floating point numbers in verilog, and will the synthesis tool take care of it ?

Thanks ,
Aimer

Hi, seems you want to design a FIR filter.
follow the binary rule, you can multiply then by 2^n(such as 1024) to convert them to integer. after computation, divide it by 2^n.

also, you can declare floating point number in verilog, but only just for simulation.
Synthesis tool can not modify it automatically. if you want implement it on FPGA, i suggest you use the float module from "opencore" or FPGA vendor such as xilinx.
but I thought it's not necessary.

these is anther way to convert real number to binary number: example:
6.125 = 6 + 0.125
6 = 110(binary),

0.125 * 2
0 0.250 * 2
0 0.500 * 2
1 1.000

0.125 = 0.001(binary)

6.125 = 110.001(binary)

Status
Not open for further replies.