Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Platform-independent core collection
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
18
Issues
18
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Platform-independent core collection
Commits
ddf1319c
Commit
ddf1319c
authored
Dec 21, 2023
by
Tristan Gingold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gencores_pkg: add f_log2 and f_max
parent
4273aed0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
gencores_pkg.vhd
modules/common/gencores_pkg.vhd
+27
-0
No files found.
modules/common/gencores_pkg.vhd
View file @
ddf1319c
...
...
@@ -45,6 +45,11 @@ package gencores_pkg is
function
f_gray_encode
(
x
:
std_logic_vector
)
return
std_logic_vector
;
function
f_gray_decode
(
x
:
std_logic_vector
;
step
:
natural
)
return
std_logic_vector
;
-- Returns the log2 of N such that 2**f_log2(N) >= N.
-- The result is the minimum value. Can return 0.
function
f_log2
(
N
:
positive
)
return
natural
;
-- Slightly incorrect version of log2: the result is at least 1.
function
f_log2_ceil
(
N
:
natural
)
return
positive
;
-- kept for backwards compatibility, same as f_log2_ceil()
function
log2_ceil
(
N
:
natural
)
return
positive
;
...
...
@@ -72,6 +77,9 @@ package gencores_pkg is
function
f_pick
(
cond
:
std_logic
;
if_1
:
std_logic_vector
;
if_0
:
std_logic_vector
)
return
std_logic_vector
;
-- Return the maximum of L and R.
function
f_max
(
l
,
r
:
natural
)
return
natural
;
-- Functions to convert characters and strings to upper/lower case
function
to_upper
(
c
:
character
)
return
character
;
function
to_lower
(
c
:
character
)
return
character
;
...
...
@@ -885,6 +893,16 @@ package body gencores_pkg is
end
if
;
end
f_gray_decode
;
function
f_log2
(
N
:
positive
)
return
natural
is
begin
for
i
in
0
to
30
loop
if
N
<=
2
**
i
then
return
i
;
end
if
;
end
loop
;
report
"N is too large"
severity
error
;
end
f_log2
;
------------------------------------------------------------------------------
-- Returns log of 2 of a natural number
------------------------------------------------------------------------------
...
...
@@ -1020,6 +1038,15 @@ package body gencores_pkg is
return
f_pick
(
f_to_std_logic
(
cond
),
if_1
,
if_0
);
end
function
f_pick
;
function
f_max
(
l
,
r
:
natural
)
return
natural
is
begin
if
l
>=
r
then
return
l
;
else
return
r
;
end
if
;
end
f_max
;
------------------------------------------------------------------------------
-- Functions to convert characters and strings to upper/lower case
------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment