Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HDL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RTSD
HDL
Commits
320d6c1b
Commit
320d6c1b
authored
4 years ago
by
Eric Kooistra
Browse files
Options
Downloads
Patches
Plain Diff
Added NEGATE_SVEC().
parent
da09aee9
No related branches found
Branches containing commit
No related tags found
1 merge request
!28
Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/base/common/src/vhdl/common_pkg.vhd
+19
-0
19 additions, 0 deletions
libraries/base/common/src/vhdl/common_pkg.vhd
with
19 additions
and
0 deletions
libraries/base/common/src/vhdl/common_pkg.vhd
+
19
−
0
View file @
320d6c1b
...
...
@@ -372,6 +372,9 @@ PACKAGE common_pkg IS
FUNCTION
RESIZE_UVEC_32
(
vec
:
STD_LOGIC_VECTOR
)
RETURN
STD_LOGIC_VECTOR
;
-- = RESIZE_UVEC() with w=32 for t_slv_32_arr slv elements
FUNCTION
RESIZE_SVEC_32
(
vec
:
STD_LOGIC_VECTOR
)
RETURN
STD_LOGIC_VECTOR
;
-- = RESIZE_SVEC() with w=32 for t_slv_32_arr slv elements
-- Negate vec, but avoid overflow by forcing -min to +max. Use w <= vec'LENGTH.
FUNCTION
NEGATE_SVEC
(
vec
:
STD_LOGIC_VECTOR
;
w
:
INTEGER
)
RETURN
STD_LOGIC_VECTOR
;
FUNCTION
INCR_UVEC
(
vec
:
STD_LOGIC_VECTOR
;
dec
:
INTEGER
)
RETURN
STD_LOGIC_VECTOR
;
FUNCTION
INCR_UVEC
(
vec
:
STD_LOGIC_VECTOR
;
dec
:
UNSIGNED
)
RETURN
STD_LOGIC_VECTOR
;
...
...
@@ -1754,6 +1757,22 @@ PACKAGE BODY common_pkg IS
RETURN
RESIZE_SVEC
(
vec
,
32
);
END
;
-- Negate vec, but avoid overflow by forcing -min to +max. Use w <= vec'LENGTH.
FUNCTION
NEGATE_SVEC
(
vec
:
STD_LOGIC_VECTOR
;
w
:
INTEGER
)
RETURN
STD_LOGIC_VECTOR
IS
CONSTANT
c_max
:
INTEGER
:
=
2
**
(
w
-1
)
-1
;
CONSTANT
c_min
:
INTEGER
:
=
-2
**
(
w
-1
);
CONSTANT
c_vec_w
:
NATURAL
:
=
vec
'LENGTH
;
VARIABLE
v_vec
:
STD_LOGIC_VECTOR
(
c_vec_w
-1
DOWNTO
0
)
:
=
vec
;
-- independent of vec'RANGE
VARIABLE
v_val
:
STD_LOGIC_VECTOR
(
w
-1
DOWNTO
0
);
BEGIN
v_val
:
=
v_vec
(
w
-1
DOWNTO
0
);
-- operate on width w and resize to c_vec_w for return
IF
SIGNED
(
v_val
)
=
c_min
THEN
RETURN
STD_LOGIC_VECTOR
(
TO_SIGNED
(
c_max
,
c_vec_w
));
-- most negative becomes most positive
ELSE
RETURN
STD_LOGIC_VECTOR
(
RESIZE_NUM
(
-
SIGNED
(
v_val
),
c_vec_w
));
-- negate by multiplying by -1
END
IF
;
END
;
FUNCTION
INCR_UVEC
(
vec
:
STD_LOGIC_VECTOR
;
dec
:
INTEGER
)
RETURN
STD_LOGIC_VECTOR
IS
VARIABLE
v_dec
:
INTEGER
;
BEGIN
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment