Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > and bitwise operation on std_logic_vector bits

Reply
Thread Tools

and bitwise operation on std_logic_vector bits

 
 
Hannes
Guest
Posts: n/a
 
      02-14-2011
Hello,

I am relatively new to VHDL.

I search for a command to realize a Boolean OR operation on all bits of
a std_logic_vector in a compact way.

example:

signal a : std_logic vector (3 downto 0);
signal b : std_logic;

b <= a(0) or a(1) or a(2) or a(3);



this solution works fine with four bits, but with larger vectors it is
not very comfortable.
Do somebody have an idea?

Regards

Hannes


 
Reply With Quote
 
 
 
 
HT-Lab
Guest
Posts: n/a
 
      02-14-2011
VHDL2008 supports reduction operators,

b<= OR a;

Hans
www.ht-lab.com


"Hannes" wrote in message news:...

Hello,

I am relatively new to VHDL.

I search for a command to realize a Boolean OR operation on all bits of
a std_logic_vector in a compact way.

example:

signal a : std_logic vector (3 downto 0);
signal b : std_logic;

b <= a(0) or a(1) or a(2) or a(3);



this solution works fine with four bits, but with larger vectors it is
not very comfortable.
Do somebody have an idea?

Regards

Hannes

 
Reply With Quote
 
 
 
 
Hannes
Guest
Posts: n/a
 
      02-14-2011
Thank you,

regards

Hannes

On 02/14/2011 05:43 PM, HT-Lab wrote:
> VHDL2008 supports reduction operators,
>
> b<= OR a;
>
> Hans
> www.ht-lab.com
>
>
> "Hannes" wrote in message news:...
> Hello,
>
> I am relatively new to VHDL.
>
> I search for a command to realize a Boolean OR operation on all bits of
> a std_logic_vector in a compact way.
>
> example:
>
> signal a : std_logic vector (3 downto 0);
> signal b : std_logic;
>
> b <= a(0) or a(1) or a(2) or a(3);
>
>
>
> this solution works fine with four bits, but with larger vectors it is
> not very comfortable.
> Do somebody have an idea?
>
> Regards
>
> Hannes
>


 
Reply With Quote
 
backhus
Guest
Posts: n/a
 
      02-15-2011
On 14 Feb., 18:51, Hannes <"h.mcchoc"@gmx.de> wrote:
> Thank you,
>
> regards
>
> Hannes
>
> On 02/14/2011 05:43 PM, HT-Lab wrote:
>
> > VHDL2008 supports reduction operators,

>
> > b<= OR a;

>
> > Hans
> >www.ht-lab.com

>
> > "Hannes" *wrote in messagenews:...
> > Hello,

>
> > I am relatively new to VHDL.

>
> > I search for a command to realize a Boolean OR operation on all bits of
> > a std_logic_vector in a compact way.

>
> > example:

>
> > signal a : std_logic vector (3 downto 0);
> > signal b : std_logic;

>
> > b <= a(0) or a(1) or a(2) or a(3);

>
> > this solution works fine with four bits, but with larger vectors it is
> > not very comfortable.
> > Do somebody have an idea?

>
> > Regards

>
> > Hannes

>
>


Hi,
nice tip for the future, when all tools finally support VHDL 2008.
For now, you can find reduce-functions in std_logic_misc.
e.g.
function AND_REDUCE(ARG: STD_LOGIC_VECTOR) return UX01;
function NAND_REDUCE(ARG: STD_LOGIC_VECTOR) return UX01;
function OR_REDUCE(ARG: STD_LOGIC_VECTOR) return UX01;
function NOR_REDUCE(ARG: STD_LOGIC_VECTOR) return UX01;
function XOR_REDUCE(ARG: STD_LOGIC_VECTOR) return UX01;
function XNOR_REDUCE(ARG: STD_LOGIC_VECTOR) return UX01;

function AND_REDUCE(ARG: STD_ULOGIC_VECTOR) return UX01;
function NAND_REDUCE(ARG: STD_ULOGIC_VECTOR) return UX01;
function OR_REDUCE(ARG: STD_ULOGIC_VECTOR) return UX01;
function NOR_REDUCE(ARG: STD_ULOGIC_VECTOR) return UX01;
function XOR_REDUCE(ARG: STD_ULOGIC_VECTOR) return UX01;
function XNOR_REDUCE(ARG: STD_ULOGIC_VECTOR) return UX01;

Have a nice synthesis
Eilert
 
Reply With Quote
 
Thomas Stanka
Guest
Posts: n/a
 
      02-15-2011
On 14 Feb., 16:50, Hannes <"h.mcchoc"@gmx.de> wrote:

> signal a : std_logic vector (3 downto 0);
> signal b : std_logic;
>
> b <= a(0) or a(1) or a(2) or a(3);


beside the defined reduce functions(see other post in this thread) you
could use a for-loop as generic solution to do bitwise reduction for
any function.

for i in a'range loop
b_var := b_var or a(i);
c_var := my_function(c_var, a(i));
end loop

bye Thomas
 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      02-15-2011
On Feb 15, 8:59*am, Thomas Stanka <usenet_nospam_va...@stanka-web.de>
wrote:
> On 14 Feb., 16:50, Hannes <"h.mcchoc"@gmx.de> wrote:
>
> > signal a : std_logic vector (3 downto 0);
> > signal b : std_logic;

>
> > b <= a(0) or a(1) or a(2) or a(3);

>
> beside the defined reduce functions(see other post in this thread) you
> could use a for-loop as generic solution to do bitwise reduction for
> any function.
>
> for i in a'range loop
> * b_var := b_var or a(i);
> * c_var := my_function(c_var, a(i));
> end loop
>
> bye Thomas


Don't forget to initialize b_var before entering the loop!

Depending on the arbitrary function, the initialization value may
differ. Hint: initialize it to first bit of a() and skip that bit in
the loop.

Andy
 
Reply With Quote
 
Paul Uiterlinden
Guest
Posts: n/a
 
      02-16-2011
Hannes wrote:

> Hello,
>
> I am relatively new to VHDL.
>
> I search for a command to realize a Boolean OR operation on all bits of
> a std_logic_vector in a compact way.
>
> example:
>
> signal a : std_logic vector (3 downto 0);
> signal b : std_logic;
>
> b <= a(0) or a(1) or a(2) or a(3);


b <= '0' WHEN a = (a'range => '0') ELSE '1';

Caveat: it does not handle weak values such as 'L' and 'H'. If that is a
concern, you can use:

b <= '0' WHEN to_x01(a) = (a'range => '0') ELSE '1';

Function to_x01 is defined in ieee.std_logic_1164.

--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access individual bits of std_logic_vector Daku VHDL 6 11-20-2009 11:39 AM
How to assign a hex or decimal value to a std_logic_vector of length19 bits? gabor VHDL 5 12-06-2008 02:14 PM
inout std_logic_vector to array of std_logic_vector of generic length conversion... Thomas Rouam VHDL 6 11-09-2007 11:49 AM
std_logic_vector 64bits with data 8 bits picnanard VHDL 0 03-15-2007 08:40 PM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM



Advertisments
 



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 47 48 49 50 51 52 53 54 55 56 57