I am trying to write a VHDL code on Karatsuba algorithm but facing errors in the following code regarding operator + cannot determine exact overloaded matching.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity kmulti is
Port (
A : in std_logic_vector(1 downto 0);
B : in std_logic_vector(1 downto 0);
result : out std_logic_vector(3 downto 0)
);
end kmulti;
architecture Behavioral of kmulti is
-- signal A0, A1, B0, B1: std_logic;
signal P0, P1, P2, Temp3: std_logic;
begin
-- A0 <= a(0);
-- A1 <= a(1);
-- B0 <= b(0);
-- B1 <= b(1);
P0 <= A(0) AND B(0);
P1 <= (A(0) + A(1)) AND (B(0) + B(1));
P2 <= A1 AND B1;
Temp3 <= P1 - P2 - P0;
result <= P2 & "00" + Temp3 & "0" + P0;
end Behavioral;
I tried writing the code for a 2-bit. How can I resolve this issue?


There are two errors in your code:
"+"for 3 different types -std_logic_vectorfromSTD_LOGIC_UNSIGNEDandunsignedandsignedtypes fromSTD_LOGIC_ARITH.When you do this line:
is doesnt know whether the resulting types after the "&" function are
std_logic_vector,unsignedorsigned, hence it doesnt know which"+"function to use. To fix this, you could use a qualifier to specify the type:std_logic+std_logic. That is what you are doing in these lines:There is a workaround for this, and combining with the 1st solution, you can simply concatenate a 0 length array to make it an array of length 1 and then qualify the resulting type.
This is all very long winded, so you may want to re-asses what types you are using.
Side note:
std_logic_arithandstd_logic_unsignedare not standard VHDL packages and have not been updated since 1992. You would likely be better served using the standardnumeric_stdpackage which is part of the VHDL standard. Since VHDL 2008,numeric_std_unsignedhas also been available as an alternative tostd_logic_unsigned.