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

Reply

VHDL - AND or OR function across a vector

 
Thread Tools Search this Thread
Old 09-16-2005, 12:31 AM   #1
Default AND or OR function across a vector


I want to implement an OR function across a STD_LOGIC_VECTOR. For
exampe the equivalent of;

signal bus : std_logic_vector(3 downto 0);
signal result : std_logic;

result <= bus(3) or bus(2) or bus(1) or bus(0);

rather than typing all the input signals one by one, is there a
shorthand notation, or is there a standard package to do so?

for example something like "result <= Or(bus);"

I have done something like the following but I am not sure if this is
the best way to do it. I need to do this since the bus width is a
generic parameter and not known before hand.

process (bus)
begin
result <= '0';
for I in bus'Range loop
if bus(I) = '1' Or bus(I) = 'H' then
result <= '1';
exit;
elsif bus(I) = 'X' then
result <= 'X';
else
null;
end if;
end loop;
end process;


Thanks in advance



Hitchkas
  Reply With Quote
Old 09-16-2005, 02:29 AM   #2
SKeffect
 
Posts: n/a
Default Re: AND or OR function across a vector
I guess you can very simply do it like this


result <= '1' when bus /= ALL_ZEROS else '0' ;

put this declaration in the signal declaration section

CONSTANT ALL_ZEROS : std_logic_vector(GENERIC_WIDTH-1 downto 0) :=
(others => '0') ;

Cheers,
SK

Hitchkas wrote:
> I want to implement an OR function across a STD_LOGIC_VECTOR. For
> exampe the equivalent of;
>
> signal bus : std_logic_vector(3 downto 0);
> signal result : std_logic;
>
> result <= bus(3) or bus(2) or bus(1) or bus(0);
>
> rather than typing all the input signals one by one, is there a
> shorthand notation, or is there a standard package to do so?
>
> for example something like "result <= Or(bus);"
>
> I have done something like the following but I am not sure if this is
> the best way to do it. I need to do this since the bus width is a
> generic parameter and not known before hand.
>
> process (bus)
> begin
> result <= '0';
> for I in bus'Range loop
> if bus(I) = '1' Or bus(I) = 'H' then
> result <= '1';
> exit;
> elsif bus(I) = 'X' then
> result <= 'X';
> else
> null;
> end if;
> end loop;
> end process;
>
>
> Thanks in advance
>



SKeffect
  Reply With Quote
Old 09-16-2005, 10:08 AM   #3
Peter
 
Posts: n/a
Default Re: AND or OR function across a vector
Or:

result <= '0' when bus = (bus'range => '0') else '1';

/Peter



Peter
  Reply With Quote
Old 09-16-2005, 08:08 PM   #4
Andy Peters
 
Posts: n/a
Default Re: AND or OR function across a vector
Hitchkas wrote:
> I want to implement an OR function across a STD_LOGIC_VECTOR. For
> exampe the equivalent of;
>
> signal bus : std_logic_vector(3 downto 0);
> signal result : std_logic;
>
> result <= bus(3) or bus(2) or bus(1) or bus(0);
>
> rather than typing all the input signals one by one, is there a
> shorthand notation, or is there a standard package to do so?
>
> for example something like "result <= Or(bus);"


Ah, the reduction-OR operator. One of the few areas where Verilog does
something VHDL doesn't.

google for "reduction-OR VHDL" -- there's a few examples.

-a



Andy Peters
  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

Similar Threads
Thread Thread Starter Forum Replies Last Post
equivalent function for itoa in Linux gcc compiler suse Software 0 03-06-2009 05:30 AM
How to assign a returns value of a javascript function to a hiddenfield in a webpart Chander Software 0 12-20-2007 09:14 AM
How to call C# function in javascript visj4u Software 2 04-23-2007 03:24 PM
MS Access not recognising Date() function tessythampan Software 0 08-28-2006 11:51 AM
I lost the "Help and Support" function from my start menu Keith A+ Certification 1 03-14-2005 03:05 PM




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