Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

test if set in vhdl different implementation

Status
Not open for further replies.

ghattasak

Member level 1
Joined
Dec 31, 2012
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,595
if i have a array of 0 to M ot std_logic in vhdl and i want to test if it is set having all bits 1, is it advised to use "and gate" or should i use an if statement. what is the difference in hardware?
 

And gates is like a mask, more quick than an if statement.
 

it will cost me more hardware right ? if i have lets say an array of 1000
 

Yes, in these cases it's more straightforward to mask bit a bit than an recursive if statement.
 

an if statement that just does an equality:

if a = "1111" then do something;

will probably just create an and gate anyway. and its easier to read. Unless you have some really old device where LUT count is important, readible code is better than smaller implementation.

- - - Updated - - -

if you want to just and all the bits, there is the and_reduce function in the std_logic_misc library:

op <= and_reduce(ip);

or if you have 2008 support:

op <= and ip;
 
Do that: try coding both implementations and then look at the synthetized blocks, it's more easy than just try to guess how it's implemented in hardware by the compiler.
 
done_sort <= '1' when done_arr =((others => '1')) else '0';

can i write it like this ? supposedly done_arr is an array of 0 to M and i want it to varry depending on M and not set up like a 1000 1's

- - - Updated - - -

@TrickyDicky
i am using the and_reduce now to check for the results
thank you

@rusty81
yes i will implement them but i might lose track in a big design implementation
thank you
 

done_sort <= '1' when done_arr =((others => '1')) else '0';

can i write it like this ? supposedly done_arr is an array of 0 to M and i want it to varry depending on M and not set up like a 1000 1's
No, "others" can only be used in an assignment.
You can create a constant with all ones to be used in the compare:


Code VHDL - [expand]
1
2
3
4
5
constant all_ones : std_logic_vector(0 to M) := (others => '1');
 
...
 
done_sort <= '1' when done_arr = all_ones else '0';

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top