I am getting my head around the process of multiplying two Qm.n numbers, and producing an answer of the same width.
As an example, I will pretend I have an 8 bit Q2.5 number. I understand that this format can represent a number in the range -4 to 3.96875.
I understand that multiplying two 8 bit SLVs results in a 16 bit SLV, I'm just not sure what each bit means in this 16 bit result.
Here is my algorithm:
- multiply the two 8 bit SLVs, to get one 16 bit result
- shift the result left by the number of fractional bits, 5 in this case
- assign the lower 8 bits as the result
Is there anything more to it than this? Why do the number of integer bits not come into it? Here is a function I've written to try do this:
function qmult(a : signed; b : signed; n : integer) return signed is variable tmp0 : signed(a'length * 2 - 1 downto 0); variable tmp1 : signed(a'length * 2 - 1 downto 0); variable ret_val : signed(a'length - 1 downto 0); begin tmp0 := a * b; tmp1 := tmp0 srl n; ret_val := tmp1(a'length - 1 downto 0); return ret_val; end qmult;
Two main questions to conclude:
Why is there no such function in numeric_std if it is this simple?
From my understanding, if you are unsure of the Q format of two numbers, then is is impossible to get a proper multiplication result (you don't know the fractional bits, so step  of the above algorithm won't work) or is there a hole in my understanding?