Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21592 Discussions

Multiplier and Divider

Altera_Forum
Honored Contributor II
3,108 Views

I am new to the forum, but not VHDL. I am a student at RIT and have taken classes and am very familiar with the language. The questions I have are more of what should my hardware multiplier and divider include? 

 

I am designing an 32-bit arithmetic logic unit that can add, subtract, multiply and divide twos compliment signed numbers and one that does unsigned (two separate units). This is part of a larger system that includes a status word.  

 

I do know that for an adder/subtractor there is an overflow and carry bit for a status register.  

 

What do you need for a multiplier and divider, or better yet, what is typically found? I know there are conditions specified by the IEEE for floating point.
0 Kudos
19 Replies
Altera_Forum
Honored Contributor II
1,905 Views

 

--- Quote Start ---  

I am new to the forum, but not VHDL. I am a student at RIT and have taken classes and am very familiar with the language. The questions I have are more of what should my hardware multiplier and divider include? 

 

I am designing an 32-bit arithmetic logic unit that can add, subtract, multiply and divide twos compliment signed numbers and one that does unsigned (two separate units). This is part of a larger system that includes a status word.  

 

I do know that for an adder/subtractor there is an overflow and carry bit for a status register.  

 

What do you need for a multiplier and divider, or better yet, what is typically found? I know there are conditions specified by the IEEE for floating point. 

--- Quote End ---  

 

 

Hi, 

 

it is not necessary to develop your own divider or multiplier. Have a look to the Quartus 

build-in Megawizard. I'm pretty sure you will find most of the things you need. 

 

Kind regards 

 

GPK
0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

I did look at the megawizard but the divider and multiplier do not have carry, overflow, etc outputs you can specify, only the adder.

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

building a multiplier is as simple as writing: 

 

output <= a * b; 

 

a divider has to be pipelined to run at any useful speed, but if you dont mind a slow clock rate, you can write: 

 

output <= a / b; 

 

I dont know why you are looking for carry on multiplier and divider, they have no meaning.
0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

The alu output is 32 bits. The multiplier, if it is to have no overflow would require 64 bits. The inputs are 32 bits as well. The wizard has no overflow, even if the output is restricted to 32 bits.

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

Thats no problem. Embedded multipliers allow inputs up to 36 bits, with 72 bit output.

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

The output of the ALU goes to a 32 bit bus. The wizard has no overflow, even if the output is restricted to 32 bits. So if you multiply FFFFFFFF * FFFFFFFF what happens?

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

I agree, that depending on the multiplier/divider usage, overflow detection and/or handling (saturation logic) may be reasonable. But it's not provided by the Altera MegaFunctions, you have to add the feature by writing behavioral code.

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

I suppose could make an overflow like this (syntax not guaranteed): 

 

product <= a * b; -- product is 64 bits. 

overflow <= NOT product(63 downto 32) AND x"0"; --No overflow when zeros.
0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

 

--- Quote Start ---  

I suppose could make an overflow like this (syntax not guaranteed): 

 

product <= a * b; -- product is 64 bits. 

overflow <= NOT product(63 downto 32) AND x"0"; --No overflow when zeros. 

--- Quote End ---  

 

 

overflow will always be zero. A and 0 = 0.
0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

Yeah, careless mistake I'm half asleep here in the us. figure it out tomorrow.

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

What megawizard are you looking at to create a multiplier btw? my one allows inputs up to 256 bits, no overflow problems. 

 

Also, you can just write behavioural VHDL and it will use the correct number of embedded multipliers. 

 

32bit * 32bit doesnt need an overflow.
0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

The LPM_Mult is what I looked at. If you are multiplying two 32 bit numbers, and the output is restricted to 32 bits, all numbers that have bits above the 32 bit limit will require an overflow detection. For example if you multiply FFFFFFFF * FFFFFFFF, the result will be FFFFFFFE00000001, which exceeds the limit and will not fit on a 32 bit output bus.

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

dont use the LPM mult 

 

Use behavioural code. 

 

What FPGA are you targetting?
0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

Cyclone II

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

For me, Quartus 10, The megawizard lets me create an LPM_MULT for a cyclone two that has 2x 256bit inputs and 512 bit output. So no need for any overflow. 

 

Basically, 32 bit multiply is trivial in even the most basic of FPGAs. overflow is never needed.
0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

And if you understand VHDL, why are you using the megawizard anyway for multiply. What wrong with the * function?

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

Yes, I agree that you need no overflow when the output is twice the width of the inputs. That is not the case with me. I do not have a 64 bit output bus, only a 32. Are you misunderstanding something?

0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

In that case, all you need for a single overflow but is to or the top 32 bits of the output of the multuplier (because you connect the least significant 32 bits of the multiplier to your output) for your unsigned ALU. 

 

for the signed, the output becomes and overflow/underflow. first check is to see if the top 32 bit are all 1 or all 0. If this fails, there is an overflow (in the case of MSB = '1') or underflow (MSB = '0'). Then you compare MSB with bit 31. MSB = '1' and bit31 = '0' means underflow, MSB = '0' and bit31 = '1' mean overflow. You can of course combine all this for a single bit "error".
0 Kudos
Altera_Forum
Honored Contributor II
1,905 Views

How are divide by zero conditions handled in the MegaWizard divider, the LPM_DIVIDER?

0 Kudos
Reply