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
aab5818c
Commit
aab5818c
authored
3 years ago
by
Eric Kooistra
Browse files
Options
Downloads
Patches
Plain Diff
Added comments to RESIZE_NUM(), no functional change.
parent
95b730bc
No related branches found
No related tags found
1 merge request
!165
Resolve L2SDP-303
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/base/common/src/vhdl/common_pkg.vhd
+12
-4
12 additions, 4 deletions
libraries/base/common/src/vhdl/common_pkg.vhd
with
12 additions
and
4 deletions
libraries/base/common/src/vhdl/common_pkg.vhd
+
12
−
4
View file @
aab5818c
...
...
@@ -388,7 +388,10 @@ PACKAGE common_pkg IS
-- appropriate approach is to ignore the MSbit sign and just keep the LS part. For too large values this
-- means that the result gets wrapped, but that is fine for default behaviour, because that is also what
-- happens for RESIZE of UNSIGNED. Therefor this is what the RESIZE_NUM for SIGNED and the RESIZE_SVEC do
-- and better not use RESIZE for SIGNED anymore.
-- and better not use RESIZE for SIGNED anymore. When w keeps or increases the data width then the values
-- do not change (of course). When w reduces the data width then:
-- * RESIZE() wraps between -, 0 for negative and 0, + for positive, so it keeps the sign and w-1 LSbits
-- * RESIZE_NUM() removes MSbits, so it wraps from + to - and from - to +, and it keeps the w LSbits
FUNCTION
RESIZE_NUM
(
u
:
UNSIGNED
;
w
:
NATURAL
)
RETURN
UNSIGNED
;
-- left extend with '0' or keep LS part (same as RESIZE for UNSIGNED)
FUNCTION
RESIZE_NUM
(
s
:
SIGNED
;
w
:
NATURAL
)
RETURN
SIGNED
;
-- extend sign bit or keep LS part
FUNCTION
RESIZE_UVEC
(
sl
:
STD_LOGIC
;
w
:
NATURAL
)
RETURN
STD_LOGIC_VECTOR
;
-- left extend with '0' into slv
...
...
@@ -1975,8 +1978,8 @@ PACKAGE BODY common_pkg IS
FUNCTION
RESIZE_NUM
(
u
:
UNSIGNED
;
w
:
NATURAL
)
RETURN
UNSIGNED
IS
BEGIN
-- left extend with '0' or
keep LS part (same as RESIZE for UNSIGNED
)
RETURN
RESIZE
(
u
,
w
);
-- left extend with '0' or
remove MSbits and keep LS part (= u[w-1:0]
)
RETURN
RESIZE
(
u
,
w
);
-- same as RESIZE for UNSIGNED
END
;
FUNCTION
RESIZE_NUM
(
s
:
SIGNED
;
w
:
NATURAL
)
RETURN
SIGNED
IS
...
...
@@ -1985,7 +1988,12 @@ PACKAGE BODY common_pkg IS
IF
w
>
s
'LENGTH
THEN
RETURN
RESIZE
(
s
,
w
);
-- extend sign bit
ELSE
RETURN
SIGNED
(
RESIZE
(
UNSIGNED
(
s
),
w
));
-- keep LSbits (= vec[w-1:0])
-- RESIZE() wraps between -, 0 for negative and 0, + for positive, so it keeps the sign and w-1 LSbits
-- RESIZE_NUM() removes MSbits, so it wraps from + to - and from - to +, and it keeps the w LSbits
-- remove MSbits and keep LS part (= s[w-1:0])
-- use RESIZE(UNSIGNED()) rather than s[w-1:0] to be independent of RANGE of s
RETURN
SIGNED
(
RESIZE
(
UNSIGNED
(
s
),
w
));
END
IF
;
END
;
...
...
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