Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Synplify doesn't like it...

 
Thread Tools Search this Thread
Old 10-03-2003, 03:55 PM   #1
Default Synplify doesn't like it...


The code below compiles fine in Active HDL and synthesizes by XST, however
Synplify says
that the sig_num((sig_num'Left - 1) downto 0) slice is out of range. How
should I write it so it will understand?

/Mikhail

---------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_UNSIGNED.all;

package num_convert is
function two_cmplt ( sig_num : std_logic_vector )
return std_logic_vector;
end package num_convert ;


package body num_convert is

function two_cmplt ( sig_num : std_logic_vector )
return std_logic_vector is
variable result : std_logic_vector (sig_num'LENGTH-1 downto 0);
begin
if sig_num(sig_num'Left)='1' then
result := '1' & ((not sig_num((sig_num'Left - 1) downto 0)) + 1);
else
result := sig_num;
end if;

return result;
end two_cmplt;

end package body num_convert;
---------------------------------------------------------------------------




MM
  Reply With Quote
Old 10-03-2003, 04:41 PM   #2
Renaud Pacalet
 
Posts: n/a
Default Re: Synplify doesn't like it...
MM a écrit :
> The code below compiles fine in Active HDL and synthesizes by XST, however
> Synplify says
> that the sig_num((sig_num'Left - 1) downto 0) slice is out of range. How
> should I write it so it will understand?
>
> /Mikhail
>
> ---------------------------------------------------------------------------
> library IEEE;
> use IEEE.std_logic_1164.all;
> use IEEE.std_logic_UNSIGNED.all;
>
> package num_convert is
> function two_cmplt ( sig_num : std_logic_vector )
> return std_logic_vector;
> end package num_convert ;
>
>
> package body num_convert is
>
> function two_cmplt ( sig_num : std_logic_vector )
> return std_logic_vector is
> variable result : std_logic_vector (sig_num'LENGTH-1 downto 0);
> begin
> if sig_num(sig_num'Left)='1' then
> result := '1' & ((not sig_num((sig_num'Left - 1) downto 0)) + 1);
> else
> result := sig_num;
> end if;
>
> return result;
> end two_cmplt;
>
> end package body num_convert;
> ---------------------------------------------------------------------------
>
>


Very common problem: as you know nothing about the argument that will be
passed to your function you can't decide that:
sig_num((sig_num'Left - 1) downto 0)
is in range. Example:

variable A: std_logic_vector(8 to 16);
...
two_cmplt(A);

then you'll have:
sig_num'Left = 8
and
sig_num((sig_num'Left - 1) downto 0) = A(7 downto 0) -- out of range

Solution: renormalize the argument:

function two_cmplt ( sig_num : std_logic_vector )
return std_logic_vector is
variable v, result : std_logic_vector (sig_num'LENGTH-1 downto 0);
begin
v := sig_num;
if v(v'LENGTH - 1) = '1' then
result := '1' & ((not v(v'LENGTH - 2 downto 0) + 1);
else
result := v;
end if;
return result;
end two_cmplt;

But if your function is supposed to compute the absolute value of its
argument then you'll be disapointed ; with argument -1 on 4 bits
("1111") it will return "1001" (-7) instead of "0001" (1). Moreover
there are much more efficient, elegant, readable, ways:

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all; -- this one is a standard one!

function TWO_CMPLT(SIG_NUM: STD_LOGIC_VECTOR) return STD_LOGIC_VECTOR is
begin
return STD_LOGIC_VECTOR(abs(SIGNED(SIG_NUM)));
end TWO_CMPLT;

Best regards,
--
Renaud Pacalet, GET/ENST/COMELEC/LabSoC
Institut Eurecom BP 193, 2229 route des Cretes
F-06904 Sophia-Antipolis Cedex
Tel : +33 (0) 4 9300 2770
Fax : +33 (0) 4 9300 2627
Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/



Renaud Pacalet
  Reply With Quote
Old 10-03-2003, 05:21 PM   #3
Renaud Pacalet
 
Posts: n/a
Default Re: Synplify doesn't like it...
Renaud Pacalet a écrit :
> ...
> But if your function is supposed to compute the absolute value of its
> argument then you'll be disapointed ; with argument -1 on 4 bits
> ("1111") it will return "1001" (-7) instead of "0001" (1). Moreover
> there are much more efficient, elegant, readable, ways:
>
> library IEEE;
> use IEEE.STD_LOGIC_1164.all;
> use IEEE.NUMERIC_STD.all; -- this one is a standard one!
>
> function TWO_CMPLT(SIG_NUM: STD_LOGIC_VECTOR) return STD_LOGIC_VECTOR is
> begin
> return STD_LOGIC_VECTOR(abs(SIGNED(SIG_NUM)));
> end TWO_CMPLT;
>


I just understood that your argument representation was probably sign
and magnitude and not 2's complement as I first thought. Sorry. My first
remark above is nonsense. But the second one remains true:

function TWO_CMPLT(SIG_NUM: STD_LOGIC_VECTOR) return STD_LOGIC_VECTOR is
variable V: SIGNED(SIG_NUM'length - 1 downto 0) := SIG_NUM;
begin
if V(V'left) = '1' then
V(V'left) := '0';
V := -V;
end if;
return STD_LOGIC_VECTOR(V);
end TWO_CMPLT;

Best regards,
--
Renaud Pacalet, GET/ENST/COMELEC/LabSoC
Institut Eurecom BP 193, 2229 route des Cretes
F-06904 Sophia-Antipolis Cedex
Tel : +33 (0) 4 9300 2770
Fax : +33 (0) 4 9300 2627
Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/



Renaud Pacalet
  Reply With Quote
Old 10-03-2003, 05:46 PM   #4
MM
 
Posts: n/a
Default Re: Synplify doesn't like it...
Thanks a lot, Renaud.

> But if your function is supposed to compute the absolute value of its
> argument then you'll be disapointed ; with argument -1 on 4 bits
> ("1111") it will return "1001" (-7) instead of "0001" (1).


No, it is supposed to do two's complement...

/Mikhail




MM
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46