Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Multiplication by 0,6

Hi i have an input of 8 bits and i need to make a

multiplication by 0,6. I doesn't has to be precise so

i thaught to do :

INPUT * 19 /32

This is not a working code but is displays what i wanna do:

array_amp_to_find(column_counter) <= std_logic_vector (to_unsigned ((to_integer(CAM_DATA)*19/32), 8));

Both input (CAM_DATA) and output (array_amp_to_find) are

std_logic_vectors (7 downto 0).

Q: How to make it work in one cycle? Or first the calculation then take the 8 LSB's?

15 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    the complier nicely inferred two adders to do the job. If you try to write the * 19 in one go, it infers a multiplier ...

    --- Quote End ---

    You're apparently describing the RTL netlist. To see, how it's synthesized, you have to examine the gate level. I also guessed, that a hardware multiplier would be inferred. If you have plenty of them, there's nothing against it, I think. Otherwise you would specify multstyle "logic" for the respective node.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    You're apparently describing the RTL netlist. To see, how it's synthesized, you have to examine the gate level. I also guessed, that a hardware multiplier would be inferred. If you have plenty of them, there's nothing against it, I think. Otherwise you would specify multstyle "logic" for the respective node.

    --- Quote End ---

    I did go down to the Technology map viewer, they are different, but in the end there is no hardware multiplier used (as witnessed in de Flow Summary). I guess the mapping and fitting are able to deal quite well with the 'one operand' being a fixed value.

    --- Quote Start ---

    If it was me I will also add a further 16 to the list of addition, so I get rounding up at truncation

    --- Quote End ---

    We have to make a choice here:

    floor (== truncate) : what is in the example code

    ceil : should add 31 (and then truncated), or better said add 2^n - 1

    financial rounding : like kaz proposes adding 16 or 2^(n-1). This looks interesting ...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    My rounding based on adding 2^(n-1) is the most common rounding used in hardware computations but is now termed (dc biased rounding) Vs dc unbiassed rounding. The difference is really trivial.

    The biassed rounding(adding 16 in our case) goes wrong at so called ties i.e. exact (.5) points if the values are negative otherwise it is identical to "round" function.

    Matlab has now functions like convergent, nearest, round, to give better performance mostly for bit accurate testbenching
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    My rounding based on adding 2^(n-1) is the most common rounding used in hardware computations but is now termed (dc biased rounding) Vs dc unbiassed rounding. The difference is really trivial.

    The biassed rounding(adding 16 in our case) goes wrong at so called ties i.e. exact (.5) points if the values are negative otherwise it is identical to "round" function.

    Matlab has now functions like convergent, nearest, round, to give better performance mostly for bit accurate testbenching

    --- Quote End ---

    Thanks, Kaz.

    Like I said interesting! I will take that into account in my future work. I probably will have no issue with rounding negative numbers as I favour using sign-magnitude representations where truncation goes toward zero in contrast to 2's complement numbers where truncation goes towards -infinity. Unfortunately sign-magnitude is not so efficient to implement.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I use the * 16 + * 2 + *1 code and no multiplyers were used.

    I also add the +16 or 2^(n-1) for rounding but with that i was familiar with.

    Thx all!