Electronic – Dividing numbers on an FPGA

arithmetic-divisionfpgaprogrammable-logic

I wrote a program for a Cyclone II FPGA that divides 2 64 bit numbers and returns if the remainder is 0 using the modulus (%) operation.

When I compiled the program with 64 bit numbers for the divisor and dividend it used almost all of the logic cells in the device.

Is there a way to do division, or modulus, or [if modulus==0] in a way that uses less logic cells?

Best Answer

Our Open-Source PoC-Library has a multi-cycle division IP core, which can be synthesized as a pipeline. The bit count of the dividend and divisor as well as the radix can be configured to the users needs. This module returns the quotient as well as the remainder.

entity arith_div is
  generic (
    A_BITS             : positive;          -- Dividend Width
    D_BITS             : positive;          -- Divisor Width
    RAPOW              : positive := 1;     -- Power of Compute Radix (2**RAPOW)
    PIPELINED          : boolean  := false  -- Computation Pipeline
  );
  port (
    -- Global Reset/Clock
    clk : in std_logic;
    rst : in std_logic;

    -- Ready / Start
    start : in  std_logic;
    ready : out std_logic;

    -- Arguments / Result (2's complement)
    A : in  std_logic_vector(A_BITS-1 downto 0);  -- Dividend
    D : in  std_logic_vector(D_BITS-1 downto 0);  -- Divisor
    Q : out std_logic_vector(A_BITS-1 downto 0);  -- Quotient
    R : out std_logic_vector(D_BITS-1 downto 0);  -- Remainder
    Z : out std_logic  -- Division by Zero
  );
end arith_div;

See the source of PoC.arith.div for the full implementation (it's too long to post it here).