Forum Discussion

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

LPM_DIVIDER [More than 64 bits necessary]

Greetings,

Simple background/story:

Here I am implementing a pipelined version of double-precision floating point arithmetics with the format:

So far I've managed to implement addition, subtraction and multiplication using the LPM megafunctions. Right now I'm implementing the division by simply taking the reciprocal of the "denominator" and then multiplying the reciprocal with the "nominator".

A/B -> A*1/B

LPM_div only accepts a maximum of 64bits, hence leaving me with the fractional/mantissa bits in the remainder. This is a huge problem for me because I'd normally need to divide the remainder with B and in turn lose the purpose with the reciprocal part.

For example (Only accounting for 1/B):

constant 1: contains 64 bits, where MSB is one and the rest zeroes.

NOMINATOR : std_logic_vector(63 downto 0) := (63 => '1', others => '0');

b: 53 bits, hidden bit included.

1.1001111110011001100110011001100110011001100110011010
(the dot isn't there in practic, just to show you where the hidden bit is).

The problem is that a big part of the fraction ends up in the remainder. Is there someway I can process the remainder without having to divide it by B to get the rest of the fraction?

Has anyone encountered the same issue, or maybe have some tips of what I could do ?

Cheers!

4 Replies

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

    The LPM library components are for fixed point, not floating point arithmatic.

    you need the alt_fp library.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    alt_fp needs the whole floating point, with the sign, exp and mantissa bits. I just want to process the mantissa.

    Actually, when I'm calculating the reciprocal I'm not assuming that there are any fractional bits. They are all assumed to be normal "std_logic". Dont really know how to express myself here.

    Let me illustrate an example:

    1000000000000000000000000000000000000000000000000000000000000000
    /
    11001100110011001100110011001100110011001100110011011
    =
    QUOTIENT = 00000000000000000000000000000000000000000000000000001|00111111110 <--- (|) illustrates binary point
    REMAIN   = 11001100110011001100110011001100110011001001010011011

    Now the question is, can I somehow process the remainder and get the rest of the fraction without having to do another division?

    I tried to take a look into the altfp_div code, but there was so many wires and everything was hardcoded which made it very unreadable ..

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

    Why not directly use one of the iterative algorithms (for example see http://en.wikipedia.org/wiki/division_algorithm), taking the initial estimate from a direct array lookup of the first few mantissa bits.

    If you can guarantee a fixed number of iterations, then you can pipeline it isnstead.

    The early iterations can probably drop some of the least significant bits.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I'd prefer to transfer to fixed point and use a pipelined divider. I once worked on that here in the forum. You can resize it easily according to your needs.