Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Is signed binary multiplication done differently than unsigned binary multiplication

Status
Not open for further replies.

matrixofdynamism

Advanced Member level 2
Joined
Apr 17, 2011
Messages
593
Helped
24
Reputation
48
Reaction score
23
Trophy points
1,298
Activity points
7,681
In long multiplication we take one digit at a time from the multiplier and multiply it with all digits of the multiplied. One all digits are multiplied we sum the intermediate shifted products to get final result.

If the numbers are negative we just multiply the signs together.

However, in binary we usually use 2's complement. Is 2's complement multiplication done differently to how normal multiplication is done?
 

Yes it is. Unlike adding and subtracting numbers, a different method has to be used for multiplying and dividing numbers depending on whether the two numbers are signed or unsigned. 2's or 1's complement representatiopn is irrelevant.

Ratch
 

The lpm_add_sub and lpm_mult both have option to select input type as signed/unsigned

The same binary value 1100 could be interpreted as -4 or 12.

Therefore in Altera Quartus II, when the lpm_adder and lpm_mult gives us option to select input type as signed or unsigned, what does it mean by that? Does the way we do the addition/subtraction or multiplication actually change if we select signed or unsigned?
 

Re: The lpm_add_sub and lpm_mult both have option to select input type as signed/unsi

Hi,

4 bit values:
signed: -8 ... 0 ... +7
unsigned: 0...15 ("-4" is not allowed)

addition and subtraction of signed and unsigend values are the same.

But multiplication and division takes care of signed/unsigned.

Klaus
 

Re: The lpm_add_sub and lpm_mult both have option to select input type as signed/unsi

The SIGNED/UNSIGNED setting of lpm_add_sub actually matters, but only for the optional overflow output.
 

Re: The lpm_add_sub and lpm_mult both have option to select input type as signed/unsi

What if there is multiplication of a signed number with an unsigned number?

If I have std_logic_vectors say 100101010 and 001101111 and they are port mapped to the lpm_add or lpm_mult, they are just bits. If we add them we add them per bit, if we subtract them we take 2's complement of the other. If we multiply them, we multiply them per bit and then sum all the per bit multiplication results. I am not sure where exactly it makes a difference whether we select signed or unsigned.
 

Re: The lpm_add_sub and lpm_mult both have option to select input type as signed/unsi

Hi,

What if there is multiplication of a signed number with an unsigned number?

Then you need to use the MUL_signed_x_unsigned function.

Klaus
 

If I have std_logic_vectors say 100101010 and 001101111 and they are port mapped to the lpm_add or lpm_mult, they are just bits. If we add them we add them per bit, if we subtract them we take 2's complement of the other. If we multiply them, we multiply them per bit and then sum all the per bit multiplication results. I am not sure where exactly it makes a difference whether we select signed or unsigned.
Ratch did already answer the question in your previous thread. Signed multiply in two's complement and unsigned multiply are different operations, the signed multiply needs a different handling of sign extension, resulting in (slightly) different bit operations. https://en.wikipedia.org/wiki/Two's_complement#Multiplication

Signed and unsigned addition or substraction are only different regarding the interpretation of involved bit vectors, the actual bit operation is the same.

You can review the implementation differences in synthesized hardware.
 
Ratch did already answer the question in your previous thread. Signed multiply in two's complement and unsigned multiply are different operations, the signed multiply needs a different handling of sign extension, resulting in (slightly) different bit operations. https://en.wikipedia.org/wiki/Two's_complement#Multiplication

Signed and unsigned addition or substraction are only different regarding the interpretation of involved bit vectors, the actual bit operation is the same.

You can review the implementation differences in synthesized hardware.

OK this answers my question, now I understand that they are infact different when we multiply them.
 

I have used this code to confirm what was expected:

Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity signed_unsigned_tb is
end entity;

architecture tb of signed_unsigned_tb is
	
	signal clk: std_logic := '0';
begin

	p_main: process(clk)
		variable s1: signed(4 downto 0) := (others=>'0');
		variable s2: signed(4 downto 0) := (others=>'1');
		variable qs: signed(9 downto 0) := (others=>'0');
		variable u1: unsigned(4 downto 0) := (others=>'0');
		variable u2: unsigned(4 downto 0) := (others=>'1');
		variable qu: unsigned(9 downto 0) := (others=>'0');
		variable flag: std_logic:= '0';

	begin
		if rising_edge(clk) then
			s1 := s1+1;
			if flag = '0' then
				s2 := s2-1;
			end if;
			qs := s1*s2;
			u1 := u1+1;
			if flag = '0' then
				u2 := u2-1;
			end if;
			flag := not flag;
			qu := u1*u2;
		end if;
	end process;

	p_clk: process
	begin
		wait for 10 ns;
		clk <= not clk;	
	end process;

end architecture;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top