ok, thanx you all , the problem is that iam beginner in vhdl , i wrote some programs which deals with matrices , i will post some of these codes because i need your help to tell me if my code is optimal or there is better ways to write it , i need the smallest area and least execution time in my design
this function calculates the addition of two matrices
package mat_add is
type t11 is array (0 to 9) of unsigned(7 downto 0);
type t1 is array (0 to 9) of t11;
function matadd ( a:t1; b:t1 ) return t1;
end mat_add;
package body mat_add is
function matadd ( a : t1; b:t1 ) return t1 is
variable i,j,k : integer:=0;
variable prod : t1:=(others => (others => (others => '0')));
begin
for i in 0 to 9 loop --(number of rows in the first matrix - 1)
for j in 0 to 9 loop --(number of columns in the second matrix - 1)
prod(i)(j) := (a(i)(j) + b(i)(j));
end loop;
end loop;
return prod;
end matadd;
end mat_add;
-------------------------------------------
i used the same code for subtraction too , and the below codes for matrix multiplication, transpose
package mat_ply is
type t11 is array (0 to 9) of unsigned(7 downto 0);
type t1 is array (0 to 9) of t11; --10*10 matrix
type t22 is array (0 to 9) of unsigned(15 downto 0);
type t2 is array (0 to 9) of t22;
function matmul ( a : t1; b:t1 ) return t2;
end mat_ply;
package body mat_ply is
function matmul ( a : t1; b:t1 ) return t2 is
variable i,j,k : integer:=0;
variable prod : t2:=(others => (others => (others => '0')));
begin
for i in 0 to 9 loop --(number of rows in the first matrix - 1)
for j in 0 to 9 loop --(number of columns in the second matrix - 1)
for k in 0 to 9 loop --(number of rows in the second matrix - 1)
prod(i)(j) := prod(i)(j) + (a(i)(k) * b(k)(j));
end loop;
end loop;
end loop;
return prod;
end matmul;
end mat_ply;
---------------------------------------------------
matrix transpose
package mat_transpose is
type t11 is array (0 to 9) of unsigned(7 downto 0);
type t1 is array (0 to 9) of t11;
function mat_trans( a : t1) return t1;
end mat_transpose;
package body mat_transpose is
function mat_trans ( a : t1) return t1 is
variable i,j : integer range 0 to 11:=0;
variable prod : t1:=(others => (others => (others => '0')));
begin
for i in 0 to 9 loop --(number of rows in the first matrix - 1)
for j in 0 to 9 loop --(number of columns in the second matrix - 1)
prod(i)(j) := a(j)(i);
end loop;
end loop;
return prod;
end mat_trans;
end mat_transpose;
-------------------------------------
now i have this program in matlab , it has a lot of for loops and i want to convert it in vhdl , but i don't know if this is possible , or it is better to use the FSM
for j = 1 : r
for i = j : r
if a(i,j) ~= 0
for k = 1 : r
s = a(j,k); a(j,k) = a(i,k); a(i,k) = s;
s = b(j,k); b(j,k) = b(i,k); b(i,k) = s;
end
t = 1/a(j,j);
for k = 1 : r
a(j,k) = t * a(j,k);
b(j,k) = t * b(j,k);
end
for L = 1 : r
if L ~= j
t = -a(L,j);
for k = 1 : r
a(L,k) = a(L,k) + t * a(j,k);
b(L,k) = b(L,k) + t * b(j,k);
end
end
end
end
break
end
% Display warning if a row full of zeros is found
if a(i,j) == 0
disp('Warning: Singular Matrix')
b = 'error';
return
end
end