Richard Molgner wrote:
> Hi again,
>
> I updated the routine now, and it looks as follows. Although it
> compiles fine, the output
> of the computation is ALWAYS ZERO. It seems with this software-like
> implementation I wont
> be able to describe the hardware circuit I want to. Or does anyone see
> a problem with my
> VHDL description?
>
> procedure main
> (
> signal a : in std_logic_vector(31 downto 0);
> signal b : in std_logic_vector(31 downto 0);
> signal r : out std_logic_vector(31 downto 0)
> )
> is
> variable res : std_logic_vector(31 downto 0);
> variable t0, t1 : std_logic_vector(31 downto 0);
> constant c : std_logic_vector(31 downto 0) := X"fedcba90";
> constant d : std_logic_vector(31 downto 0) :=
> X"7654321f";
> begin
>
> t0 := (others => '0');
> t1 := (others => '0');
>
> for i in 0 to 31 loop
> if ( (c(i) = '0') and (d(i) = '1') ) then
> for j in 0 to 31 loop
> t0(j) := (a(j) xor b(j)) and (t0(j) xor t1(j));
> t1(j) := (a(j) xor b(j)) or ((t1(j) xor t0(j)) xor
> b(j));
> end loop;
> end if;
> end loop;
>
> r <= t0;
> end;
With the given values of constants c and d, the only bits for which the 'if'
holds true are 0 to 3. Is that what you intended?
As you have rewritten your code, you now modify t0 and then use it in the
computation of t1. That is not what was intended in the original code, as
far as I can see.
It seems you messed up in an attempt to transform the original code.
Let me try to modify that code so it will compile. No guarantees on
functionality, I'll probably mess up as well!
procedure subproc
(
a : inout std_logic_vector(31 downto 0);
b : inout std_logic_vector(31 downto 0);
c : in std_logic_vector(31 downto 0);
d : in std_logic_vector(31 downto 0)
)
is
variable x : std_logic_vector(31 downto 0);
variable y : std_logic_vector(31 downto 0);
begin
x := (a xor b) and (c xor d);
y := (a xor b) or ((d xor c) xor b);
a := x;
b := y;
end;
procedure main
(
constant a : in std_logic_vector(31 downto 0);
constant b : in std_logic_vector(31 downto 0);
signal r : out std_logic_vector(31 downto 0)
)
is
variable t0, t1 : std_logic_vector(31 downto 0);
constant c : std_logic_vector(31 downto 0) := X"fedcba90";
constant d : std_logic_vector(31 downto 0) := X"7654321f";
begin
t0 := (others => '0');
t1 := (others => '0');
for i in c'range loop
if (c(i) = '0') and (d(i) = '1') then
subproc(t0, t1, a, b);
end if;
end loop;
r <= t0;
end;
Remarks:
1) No need to always use separate bits. Operators like and, or,
xor also work on vectors. No loop needed.
2) If you want to use the complete vector, there is no need to
specify the range. So these are all equivalent:
a := x;
a := x(31 downto 0);
a(31 downto 0) := x;
a(31 downto 0) := x(31 downto 0);
3) Parameters of procedures need not always be of class signal.
Depends on where they are used.
4) Parenthesis around the condition in an 'if' statement are not
needed (style issue). VHDL is not C.
5) There is no operator &&: it is 'and'. VHDL is not C.
6) Variable res in procedure main was never used.
7) If you want to loop over all bits in a vector, use the 'range
attribute. In my opinion it is clearer and it is more robust
against code changes (like changing the vector length).

The class of parameters c and d of procedure subproc and
parameters a and b of main all are constant. For input parameters
that is the default. I have the habit to only actually specify
the class of subprogram parameters if one of the parameters has
a non-default class, such as parameter r of main in this case.
9) Simulate before synthesize. That also means: make a testbench.
--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.