Standard log2 function for integers

Status
Not open for further replies.

shaiko

Advanced Member level 5
Joined
Aug 20, 2011
Messages
2,644
Helped
303
Reputation
608
Reaction score
297
Trophy points
1,363
Visit site
Activity points
18,302
Hello,

I know that the log2 function of the math_real package works on type "real".
Is there a standard VHDL function that calculates log2 for integers?
 

No. But I think its one of the first functions most engineers add to their toolbox.
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
I know. I have one myself...just a general question.

1. Can I cast a "positive" type into a real type in order to apply the log2 ?
2. If #1 is possible, can I recast the result back to a "positive" after applying the log2 function?
 

1. Yes, but I dont know what it would do if you tried to synthesise it into a non constant location (like assigning a signal), or slicing a signal.
2. Yes, but remember that casting a real to an integer will round the result.
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
1. Yes, but I dont know what it would do if you tried to synthesise it into a non constant location (like assigning a signal), or slicing a signal.

You mean during runtime operation as part of my RTL (not compile time) ?
 

Yes, runtime operations using real types are not allowed for synthesis.
 
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…