Forum Discussion

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

Adding and resizing in one step

Hi,

Is there a way to add two unsigned numbers and extract only the x most significant bits from it in one step?

I want something like this:

sum <= resize(number1 + number2,4)

Instead of:

temp <= number1 + number2

sum <= temp(7 downto 4)

The existing resize function in numeric_std drops the msb's, I want the lsb's dropped.

Thanks in advance!

11 Replies

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

    If your tool understands and supports the following:

    sum = (num1 + num2)/2**4;

    Then it is equivalent to discarding 4 bits from result unless it goes silly and creates a division module.

    alternatively if you can accept truncation errors then:

    sum <= num1(6 downto 4) + num2(6 downto 4);

    is almost equivalent but division is done on operands.