Floating Point Unit - multiplier block
prepared by P. Bakowski (designer G. Ramstein)
back
to main text
note : non synthetisable
MULTIPLIER ENTITY
entity Multiplier_Nty is
port(Ck : in Bit; -- Horloge
Hldb : in Bit; -- Hold
Abort : in Bit; -- Abort
RF_MUSD2F : in Bit; -- Multiplier Instructed
RF_T5D2F : in Bit; -- MR register Read/Write
RF_MFOPD2F : in Bit_vector(7 downto 0); -- Code instruction
PS_TRUNC1F : in Bit; -- Mode arrondi 0=Plus pret, 1= Troncature
PS_RND321F : in Bit; -- Format 0/1= 40/32 bits
PS_SRCU1F : in Bit; -- Alternance Foreground/Background
MFX2F, MFY2F : in bit_vector(39 downto 0); -- operandes X et Y
MFR2F : out bit_vector(39 downto 0); -- resultat Stat2F : out bit_vector(1
to 5) --
MN, MI, MV, MU, MF );
end Multiplier_Nty;
-- MULTIPLIER ARCHITECTURE
use WORK.FLOAT40_pkg.all;
use WORK.bitvector_pkg.all;
use WORK.signvector_pkg.all;
architecture Multiplier_a of Multiplier_Nty is
signal Muphi1, Muphi2 : Bit;
begin
process(Ck)
variable Inste : bit_vector(7 downto 0); -- Instruction Pipeline
a executer
variable Instructede : Bit; -- Pipeline a executer RF_MUSD2F
variable Transfere : Bit; -- RF_T5D2F
variable Trunc, Rnd32, Srcu : Bit;
variable mrf2, mrf1, mrf0 : bit_vector(31 downto 0); -- Foreground
MR2,MR1,MR0, phase 1
variable mrb2, mrb1, mrb0 : bit_vector(31 downto 0); -- Background
MR2,MR1,MR0, phase 1
variable temp2, temp1, temp0 : bit_vector(31 downto 0); -- Variables
temporaires
variable X, Y, Rs0, Rs1, Rs2 : Fix_Typ;
variable XF, YF, RF : Float_Typ;
variable MN, MI, MV, MU, MF : Bit; -- Negatif, Invalide, Underflow,
oVerflow, Flottant
begin
if Ck='1' then
Trunc:=PS_TRUNC1F; Rnd32:=PS_RND321F; Srcu:=PS_SRCU1F; X :=Fix_Typ(MFX2F(39
downto 8)); Y :=Fix_Typ(MFY2F(39 downto 8)); XF:=Float_Typ(MFX2F); YF:=Float_Typ(MFY2F);
if Rnd32='1' then
- XF(7 downto 0):=X"00"; YF(7 downto 0):=X"00";
end if;
Inste:=RF_MFOPD2F; Transfere:=RF_T5D2F; Instructede:=RF_MUSD2F;
-- INSTRUCTION DE TRANSFERT
if Abort='0' and Instructede='1' and Transfere='1' then
if Inste(4)='0' then
- -------- LECTURE MR -------------------------
- MFR2F(7 downto 0)<=X"00"; if (Inste(2) xor Srcu)='0'
then
- ---- FOREGROUND -------
- if Inste(1)='0' and Inste(0)='0' then
- ---- MR0 --------------
- MFR2F(39 downto 8) <= mrf0;
- end if;
- if Inste(1)='0' and Inste(0)='1' then
- ---- MR1 --------------
- MFR2F(39 downto 8) <= mrf1;
- end if;
- if Inste(1)='1' and Inste(0)='0' then
- ---- MR2 --------------
- MFR2F(39 downto 24) <= (others=> mrf2(15)); -- etendu au
signe
- MFR2F(23 downto 8) <= mrf2(15 downto 0);
- end if;
else
--------------------------------- BACKGROUND -------------
- if Inste(1)='0' and Inste(0)='0' then
- ---- MR0 --------------
- MFR2F(39 downto 8) <= mrb0;
- end if;
- if Inste(1)='0' and Inste(0)='1' then
- ---- MR1 --------------
- MFR2F(39 downto 8) <= mrb1;
- end if;
- if Inste(1)='1' and Inste(0)='0' then
- ---- MR2 --------------
- MFR2F(39 downto 24) <= (others=> mrb2(15));
- -- etendu au signe
- MFR2F(23 downto 8) <= mrb2(15 downto 0);
- end if;
end if;
else
-- ECRITURE MR
if (Inste(2) xor Srcu)='0' then
-- FOREGROUND
- if Inste(1)='0' and Inste(0)='0' then
- ---- MR0
- mrf0:=bit_vector(Y);
- end if;
- if Inste(1)='0' and Inste(0)='1' then
- ---- MR1 --------------
- mrf1:=bit_vector(Y); if Y(31)='1' then
- mrf2:=X"0000FFFF";
- else mrf2:=X"00000000";
- end if;
end if;
if Inste(1)='1' and Inste(0)='0' then
---- MR2 --------------
mrf2:=bit_vector(Y) and X"0000FFFF";
end if;
else
--------------------------------- BACKGROUND ---------------
if Inste(1)='0' and Inste(0)='0' then
---- MR0 --------------
mrb0:=bit_vector(Y);
end if;
if Inste(1)='0' and Inste(0)='1' then
---- MR1 --------------
mrb1:=bit_vector(Y);
- if Y(31)='1' then
- mrb2:=X"0000FFFF";
- else mrb2:=X"00000000";
- end if;
end if;
if Inste(1)='1' and Inste(0)='0' then
---- MR2 --------------
mrb2:=bit_vector(Y) and X"0000FFFF"; end if; end if;
end if; end if;
-- Transfert
-- INSTRUCTION DE TYPE CALCUL
if Abort='0' and Instructede='1' and Transfere='0' then
-- INSTRUCTIONS SUR LES REGISTRES MR
if Inste(7)='0' and inste(6)='0' and inste(5)='0' then
------------------ Clear MR ----------------
-- 00 010 xmx ---
if inste(4)='1' and inste(3)='0' then
- if (inste(1) xor srcu) ='0' then
- -- Foreground 00 010 xX"
- mrf2 :=X"00000000"; mrf1 :=X"00000000"; mrf0
:=X"00000000";
- else
- -- Background 00 010 x1x
- mrb2 :=X"00000000"; mrb1 :=X"00000000"; mrb0
:=X"00000000";
- end if; MN :='0'; MI :='0'; MV :='0'; MU :='0'; MF :='0';
end if;
-- end Clear ---------------------
-- Saturate MR --------------- 00 00m mmm ----
if inste(4)='0' then
- if (inste(1) xor srcu) ='0' then
- --Foreground 00 00m 0mm --
- temp2:= mrf2; temp1:= mrf1; temp0:= mrf0;
- else
- -- Background 00 00m 100 --
- temp2:= mrb2; temp1:= mrb1; temp0:= mrb0; end if; if inste(3)='0'
then
- -- Integer 00 000 mmm --
- if inste(0)='0' then
- -- Unsigned 00 000 mm0
- if temp2(15 downto 0) /= X"0000" or temp1 /=X"00000000"
then
- temp2:= X"00000000"; temp1:= X"00000000"; temp0:=
X"FFFFFFFF";
- end if;
- else
- -- Signed 00 000 mm1 --
- if temp2(15)='0'then
- -- Positive --
- if temp2(15 downto 0) /= X"0000" or temp1 /= X"00000000"
or temp0(31)='1' then
- temp2:= X"00000000"; temp1:= X"00000000"; temp0:=
X"7FFFFFFF";
- end if;
- else
- -- Negative --
- if temp2(15 downto 0) /= X"FFFF" or temp1 /= X"FFFFFFFF"
or temp0(31)='0' then
- temp2:= X"FFFFFFFF"; temp1:= X"FFFFFFFF"; temp0:=
X"80000000";
- end if;
- end if;
- end if;
- -- signe ou non else -- Fractional 00 001 mmm --
- if inste(0)='0' then
- -- Unsigned 00 001 mm0 --
- if temp2(15 downto 0) /= X"0000" then
- temp2:= X"00000000"; temp1:= X"FFFFFFFF"; temp0:=
X"FFFFFFFF";
- end if;
- else
- -- Signed 00 001 mm1 --
- if temp2(15)='0' then
- -- Positive --
- if temp2(15 downto 0) /= X"0000" or temp1(31) = '1' then
- temp2:= X"00000000"; temp1:= X"7FFFFFFF"; temp0:=
X"FFFFFFFF";
- end if;
- else
- -- Negative --
- if temp2 /= X"0000FFFF" or temp1(31)= '0' then
- temp2:= X"FFFFFFFF"; temp1:= X"80000000"; temp0:=
X"00000000";
- end if;
- end if;
- end if;
- end if;
-- fractionnaire
--- Underflow Flag ---
- if inste(3)='0' then
- -- Integer --
- MU := '0';
- else
- -- Fractional --
- if inste(0)='1' and temp2(15)='1' then
- -- Negative --
- if temp2(15 downto 0)=X"FFFF" and temp1=X"FFFFFFFF"
and temp0 /= X"00000000" then
- MU :='1';
- else MU :='0';
- end if;
- else
- -- Positive --
- if temp2(15 downto 0)=X"00000000" and temp1=X"00000000"
and temp0 /= X"00000000" then
- MU :='1';
- else MU :='0';
- end if;
- end if;
- end if;
-- underflow
- if inste(2)='0' then
- -- Resultat vers Reg File 00 00m 0xx
- if inste(3)='0' then
- -- Integer Data 00 000 0xx
- MFR2F(7 downto 0) <= X"00"; MFR2F(39 downto 8)<=
temp0;
- else
- -- Fractional Data 00 001 0xx
- MFR2F(7 downto 0) <= X"00"; MFR2F(39 downto 8)<=
temp1;
- end if;
- else
- -- Resultat vers registres MR 00 00x 1mx
- if (inste(1) xor srcu) ='0' then
- -- Foreground 00 0X" 10x
- mrf2 := temp2; mrf1 := temp1; mrf0 := temp0;
- else
- -- Background 00 0X" 11x
- mrb2 := temp2; mrb1 := temp1; mrb0 := temp0;
- end if;
- end if;
- if inste(0)='0' then
- -- Unsigned --
- MN :='0';
- else
- -- Signed --
- MN := temp2(15); MI :='0'; MV :='0'; MF :='0';
- end if;
end if;
-- end saturate ---------------------
-- Round MR ------------------ 00 011 mmx ----
- if inste(4)='1' and inste(3)='1' then
- if (inste(1) xor srcu) ='0' then
- -- Foreground 00 011 00x
- if mrf0>X"80000000" or (mrf1(0)='1' and mrf0=X"80000000")
then
- if mrf1=X"FFFFFFFF" then
- temp0 := X"00000000"; temp1 := X"00000000";
temp2 := mrf2 + '1';
- else temp0 := X"00000000"; temp1 := mrf1 + '1'; temp2
:= mrf2;
- end if;
- else temp0 := X"00000000"; temp1 := mrf1; temp2 := mrf2;
- end if;
- else
- -- Background 00 011 01x
- if mrb0>X"80000000" or (mrb1(0)='1' and mrb0=X"80000000")
then
- if mrb1=X"FFFFFFFF" then
- temp0 := X"00000000"; temp1 := X"00000000";
temp2 := mrb2 + '1';
- else temp0 := X"00000000"; temp1 := mrb1 + '1'; temp2
:= mrb2;
- end if;
- else temp0 := X"00000000"; temp1 := mrb1; temp2 := mrb2;
- end if;
- end if;
- -- Foreground/Background
- if inste(2)='0' then
- -- Result to Register File --
- MFR2F(7 downto 0) <= X"00"; MFR2F(39 downto 8) <=
temp1;
- else
- -- Result to MR --
- if (inste(1) xor srcu) ='0' then
- -- Foreground --
- mrf0 := temp0; mrf1 := temp1; mrf2 := temp2;
- else
- -- Background --
- mrb0 := temp0; mrb1 := temp1; mrb2 := temp2;
- end if;
- end if;
- --- Overflow flag ---
- if inste(0)='1'and temp1(31)='1' then
- -- Negative --
- if temp2(15 downto 0)=X"FFFF" then
- MV := '0';
- else MV := '1';
- end if;
- else
- -- Positive --
- if temp2(15 downto 0)=X"0000"then
- MV := '0'; else MV := '1';
- end if;
- end if;
- MN := temp2(15); MU := '0'; MI := '0'; MF := '0';
- end if;
- -- end Round
- end if; -- calcul sur registres MR
-- MULTIPLICATION FLOTTANT
- if Inste(7)='0' and inste(6)='0' and inste(5)='1' and inste(4)='1'
then
- Mulf(XF, YF, PS_RND321F , PS_TRUNC1F, RF, MN, MI, MU, MV, MF);
MFR2F <= RF;
- end if;
-- MULTIPLICATION FIX
- if Inste(7)='1' or inste(6)='1' then if inste(7)='1' then
- ----------- Accumulation
- if (inste(1) xor srcu)='0' then
- ---- Foreground
- temp0 :=mrf0; temp1 :=mrf1; temp2 :=mrf2;
- else
- ---- Background
- temp0 :=mrb0; temp1 :=mrb1; temp2 :=mrb2;
- end if;
- else temp0 :=X"00000000"; temp1 :=X"00000000";
temp2 :=X"00000000";
- end if;
Mul(X,Y, Inste, temp0, temp1, temp2, MN, MI, MU, MV, MF);
- if inste(2)='0' then
- -- Resultat vers Reg File
- if inste(3)='0' then
- -- Integer Data
- MFR2F(7 downto 0) <= X"00"; MFR2F(39 downto 8)<=
temp0;
- else -- Fractional Data
- MFR2F(7 downto 0) <= X"00"; MFR2F(39 downto 8)<=
temp1;
- end if;
- else
- -- Resultat vers registres MR
- if (inste(1) xor srcu) ='0' then
- -- Foreground 00 0X" 10x
- mrf2 := temp2; mrf1 := temp1; mrf0 := temp0;
- else
- -- Background 00 0X" 11x
- mrb2 := temp2; mrb1 := temp1; mrb0 := temp0;
- end if;
- end if;
end if;
-- Multiplication Fix
end if;
---instructions de calcul
Stat2F<=(MN, MI, MU, MV, MF);
end if; -- Ck
end process;
end Multiplier_a;
back
to main text