Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sv2v
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
sv2v
Commits
03a913ad
Commit
03a913ad
authored
Nov 15, 2021
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix illegal removal of width-extending `+ 0` and `* 1`
parent
5105ccbb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
22 deletions
+78
-22
CHANGELOG.md
+5
-0
src/Convert/ExprUtils.hs
+0
-4
src/Convert/MultiplePacked.hs
+39
-18
test/basic/clip_add.sv
+17
-0
test/basic/clip_mul.sv
+17
-0
No files found.
CHANGELOG.md
View file @
03a913ad
...
@@ -10,6 +10,11 @@
...
@@ -10,6 +10,11 @@
*
Certain errors raised during conversion now also provide hierarchical and
*
Certain errors raised during conversion now also provide hierarchical and
approximate source location information to help locate the error
approximate source location information to help locate the error
### Bug Fixes
*
Fixed inadvertent design behavior changes caused by constant folding removing
intentional width-extending operations such as
`+ 0`
and
`* 1`
## v0.0.9
## v0.0.9
### Breaking Changes
### Breaking Changes
...
...
src/Convert/ExprUtils.hs
View file @
03a913ad
...
@@ -76,14 +76,10 @@ simplifyStep other = other
...
@@ -76,14 +76,10 @@ simplifyStep other = other
simplifyBinOp
::
BinOp
->
Expr
->
Expr
->
Expr
simplifyBinOp
::
BinOp
->
Expr
->
Expr
->
Expr
simplifyBinOp
Add
(
Dec
0
)
e
=
e
simplifyBinOp
Add
e
(
Dec
0
)
=
e
simplifyBinOp
Sub
e
(
Dec
0
)
=
e
simplifyBinOp
Sub
e
(
Dec
0
)
=
e
simplifyBinOp
Sub
(
Dec
0
)
e
=
UniOp
UniSub
e
simplifyBinOp
Sub
(
Dec
0
)
e
=
UniOp
UniSub
e
simplifyBinOp
Mul
(
Dec
0
)
_
=
toDec
0
simplifyBinOp
Mul
(
Dec
0
)
_
=
toDec
0
simplifyBinOp
Mul
(
Dec
1
)
e
=
e
simplifyBinOp
Mul
_
(
Dec
0
)
=
toDec
0
simplifyBinOp
Mul
_
(
Dec
0
)
=
toDec
0
simplifyBinOp
Mul
e
(
Dec
1
)
=
e
simplifyBinOp
Mod
_
(
Dec
1
)
=
toDec
0
simplifyBinOp
Mod
_
(
Dec
1
)
=
toDec
0
simplifyBinOp
Add
e1
(
UniOp
UniSub
e2
)
=
BinOp
Sub
e1
e2
simplifyBinOp
Add
e1
(
UniOp
UniSub
e2
)
=
BinOp
Sub
e1
e2
...
...
src/Convert/MultiplePacked.hs
View file @
03a913ad
...
@@ -118,9 +118,9 @@ combineRanges r1 r2 = r
...
@@ -118,9 +118,9 @@ combineRanges r1 r2 = r
where
where
size1
=
rangeSizeHiLo
(
s1
,
e1
)
size1
=
rangeSizeHiLo
(
s1
,
e1
)
size2
=
rangeSizeHiLo
(
s2
,
e2
)
size2
=
rangeSizeHiLo
(
s2
,
e2
)
lower
=
BinOp
Add
e2
(
B
inOp
Mul
e1
size2
)
lower
=
binOp
Add
e2
(
b
inOp
Mul
e1
size2
)
upper
=
BinOp
Add
(
B
inOp
Mul
size1
size2
)
upper
=
binOp
Add
(
b
inOp
Mul
size1
size2
)
(
B
inOp
Sub
lower
(
RawNum
1
))
(
b
inOp
Sub
lower
(
RawNum
1
))
traverseStmtM
::
Stmt
->
Scoper
TypeInfo
Stmt
traverseStmtM
::
Stmt
->
Scoper
TypeInfo
Stmt
traverseStmtM
=
traverseStmtM
=
...
@@ -217,7 +217,7 @@ convertExpr scopes =
...
@@ -217,7 +217,7 @@ convertExpr scopes =
orientIdx
r
e
=
orientIdx
r
e
=
endianCondExpr
r
e
eSwapped
endianCondExpr
r
e
eSwapped
where
where
eSwapped
=
BinOp
Sub
(
snd
r
)
(
B
inOp
Sub
e
(
fst
r
))
eSwapped
=
binOp
Sub
(
snd
r
)
(
b
inOp
Sub
e
(
fst
r
))
-- Converted idents are prefixed with an invalid character to ensure
-- Converted idents are prefixed with an invalid character to ensure
-- that are not converted twice when the traversal steps downward. When
-- that are not converted twice when the traversal steps downward. When
...
@@ -240,8 +240,8 @@ convertExpr scopes =
...
@@ -240,8 +240,8 @@ convertExpr scopes =
Just
(
dimInner
,
dimOuter
,
expr'
)
=
maybeDims
Just
(
dimInner
,
dimOuter
,
expr'
)
=
maybeDims
idxInner'
=
orientIdx
dimInner
idxInner
idxInner'
=
orientIdx
dimInner
idxInner
idxOuter'
=
orientIdx
dimOuter
idxOuter
idxOuter'
=
orientIdx
dimOuter
idxOuter
base
=
B
inOp
Mul
idxInner'
(
rangeSize
dimOuter
)
base
=
b
inOp
Mul
idxInner'
(
rangeSize
dimOuter
)
idx'
=
simplify
$
B
inOp
Add
base
idxOuter'
idx'
=
simplify
$
b
inOp
Add
base
idxOuter'
rewriteExpr
orig
@
(
Range
(
Bit
expr
idxInner
)
NonIndexed
rangeOuter
)
=
rewriteExpr
orig
@
(
Range
(
Bit
expr
idxInner
)
NonIndexed
rangeOuter
)
=
if
isJust
maybeDims
&&
expr
==
rewriteExpr
expr
if
isJust
maybeDims
&&
expr
==
rewriteExpr
expr
then
rewriteExpr
$
Range
exprOuter
IndexedMinus
range
then
rewriteExpr
$
Range
exprOuter
IndexedMinus
range
...
@@ -250,7 +250,7 @@ convertExpr scopes =
...
@@ -250,7 +250,7 @@ convertExpr scopes =
maybeDims
=
dims
expr
maybeDims
=
dims
expr
exprOuter
=
Bit
expr
idxInner
exprOuter
=
Bit
expr
idxInner
baseDec
=
fst
rangeOuter
baseDec
=
fst
rangeOuter
baseInc
=
BinOp
Sub
(
B
inOp
Add
baseDec
len
)
(
RawNum
1
)
baseInc
=
binOp
Sub
(
b
inOp
Add
baseDec
len
)
(
RawNum
1
)
base
=
endianCondExpr
rangeOuter
baseDec
baseInc
base
=
endianCondExpr
rangeOuter
baseDec
baseInc
len
=
rangeSize
rangeOuter
len
=
rangeSize
rangeOuter
range
=
(
base
,
len
)
range
=
(
base
,
len
)
...
@@ -264,11 +264,11 @@ convertExpr scopes =
...
@@ -264,11 +264,11 @@ convertExpr scopes =
idxInner'
=
orientIdx
dimInner
idxInner
idxInner'
=
orientIdx
dimInner
idxInner
(
baseOuter
,
lenOuter
)
=
rangeOuter
(
baseOuter
,
lenOuter
)
=
rangeOuter
baseOuter'
=
orientIdx
dimOuter
baseOuter
baseOuter'
=
orientIdx
dimOuter
baseOuter
start
=
B
inOp
Mul
idxInner'
(
rangeSize
dimOuter
)
start
=
b
inOp
Mul
idxInner'
(
rangeSize
dimOuter
)
baseDec
=
B
inOp
Add
start
baseOuter'
baseDec
=
b
inOp
Add
start
baseOuter'
baseInc
=
if
modeOuter
==
IndexedPlus
baseInc
=
if
modeOuter
==
IndexedPlus
then
BinOp
Add
(
B
inOp
Sub
baseDec
len
)
one
then
binOp
Add
(
b
inOp
Sub
baseDec
len
)
one
else
BinOp
Sub
(
B
inOp
Add
baseDec
len
)
one
else
binOp
Sub
(
b
inOp
Add
baseDec
len
)
one
base
=
endianCondExpr
dimOuter
baseDec
baseInc
base
=
endianCondExpr
dimOuter
baseDec
baseInc
len
=
lenOuter
len
=
lenOuter
range'
=
(
base
,
len
)
range'
=
(
base
,
len
)
...
@@ -287,7 +287,7 @@ convertExpr scopes =
...
@@ -287,7 +287,7 @@ convertExpr scopes =
mode'
=
IndexedPlus
mode'
=
IndexedPlus
idx'
=
orientIdx
dimInner
idx
idx'
=
orientIdx
dimInner
idx
len
=
rangeSize
dimOuter
len
=
rangeSize
dimOuter
base
=
BinOp
Add
(
endianCondExpr
dimOuter
(
snd
dimOuter
)
(
fst
dimOuter
))
(
B
inOp
Mul
idx'
len
)
base
=
binOp
Add
(
endianCondExpr
dimOuter
(
snd
dimOuter
)
(
fst
dimOuter
))
(
b
inOp
Mul
idx'
len
)
range'
=
(
simplify
base
,
simplify
len
)
range'
=
(
simplify
base
,
simplify
len
)
rewriteExprLowPrec
orig
@
(
Range
expr
NonIndexed
range
)
=
rewriteExprLowPrec
orig
@
(
Range
expr
NonIndexed
range
)
=
if
isJust
maybeDims
&&
expr
==
rewriteExpr
expr
if
isJust
maybeDims
&&
expr
==
rewriteExpr
expr
...
@@ -296,7 +296,7 @@ convertExpr scopes =
...
@@ -296,7 +296,7 @@ convertExpr scopes =
where
where
maybeDims
=
dims
expr
maybeDims
=
dims
expr
baseDec
=
fst
range
baseDec
=
fst
range
baseInc
=
BinOp
Sub
(
B
inOp
Add
baseDec
len
)
(
RawNum
1
)
baseInc
=
binOp
Sub
(
b
inOp
Add
baseDec
len
)
(
RawNum
1
)
base
=
endianCondExpr
range
baseDec
baseInc
base
=
endianCondExpr
range
baseDec
baseInc
len
=
rangeSize
range
len
=
rangeSize
range
range'
=
(
base
,
len
)
range'
=
(
base
,
len
)
...
@@ -310,20 +310,41 @@ convertExpr scopes =
...
@@ -310,20 +310,41 @@ convertExpr scopes =
sizeOuter
=
rangeSize
dimOuter
sizeOuter
=
rangeSize
dimOuter
offsetOuter
=
uncurry
(
endianCondExpr
dimOuter
)
$
swap
dimOuter
offsetOuter
=
uncurry
(
endianCondExpr
dimOuter
)
$
swap
dimOuter
(
baseOrig
,
lenOrig
)
=
range
(
baseOrig
,
lenOrig
)
=
range
lenOrigMinusOne
=
B
inOp
Sub
lenOrig
(
RawNum
1
)
lenOrigMinusOne
=
b
inOp
Sub
lenOrig
(
RawNum
1
)
baseSwapped
=
baseSwapped
=
orientIdx
dimInner
$
orientIdx
dimInner
$
if
mode
==
IndexedPlus
if
mode
==
IndexedPlus
then
then
endianCondExpr
dimInner
endianCondExpr
dimInner
baseOrig
baseOrig
(
B
inOp
Add
baseOrig
lenOrigMinusOne
)
(
b
inOp
Add
baseOrig
lenOrigMinusOne
)
else
else
endianCondExpr
dimInner
endianCondExpr
dimInner
(
B
inOp
Sub
baseOrig
lenOrigMinusOne
)
(
b
inOp
Sub
baseOrig
lenOrigMinusOne
)
baseOrig
baseOrig
base
=
BinOp
Add
offsetOuter
(
B
inOp
Mul
sizeOuter
baseSwapped
)
base
=
binOp
Add
offsetOuter
(
b
inOp
Mul
sizeOuter
baseSwapped
)
mode'
=
IndexedPlus
mode'
=
IndexedPlus
len
=
B
inOp
Mul
sizeOuter
lenOrig
len
=
b
inOp
Mul
sizeOuter
lenOrig
range'
=
(
base
,
len
)
range'
=
(
base
,
len
)
rewriteExprLowPrec
other
=
other
rewriteExprLowPrec
other
=
other
-- Traditional identity operations like `+ 0` and `* 1` are not no-ops in
-- SystemVerilog because they may implicitly extend the width of the other
-- operand. Encouraged by the official language specifications (e.g., Section
-- 11.6.2 of IEEE 1800-2017), these operations are used in real designs as
-- workarounds for the standard expression evaluation semantics.
--
-- The process of flattening arrays in this conversion can naturally lead to
-- unnecessary identity operations. Previously, `simplifyStep` was responsible
-- for cleaning up the below unnecessary operations produced by this conversion,
-- but it inadvertently changed the behavior of legitimate input designs.
--
-- Rather than applying these specific simplifications to all expressions, they
-- are now only considered when constructing a new binary operation expression
-- as part of array flattening.
binOp
::
BinOp
->
Expr
->
Expr
->
Expr
binOp
Add
(
RawNum
0
)
e
=
e
binOp
Add
e
(
RawNum
0
)
=
e
binOp
Mul
(
RawNum
1
)
e
=
e
binOp
Mul
e
(
RawNum
1
)
=
e
binOp
op
a
b
=
BinOp
op
a
b
test/basic/clip_add.sv
0 → 100644
View file @
03a913ad
module
top
;
wire
[
3
:
0
]
a
,
b
,
w
,
x
,
y
,
z
;
assign
a
=
4'b1111
;
assign
b
=
4'b0001
;
// loses upper bit
assign
w
=
(
a
+
b
)
>>
1
;
// preserves upper bit via implicit extension
assign
y
=
(
0
+
a
+
b
)
>>
1
;
assign
y
=
(
a
+
b
+
0
)
>>
1
;
// preserves upper bit via "casting"
wire
[
4
:
0
]
tmp
;
assign
tmp
=
x
+
b
;
assign
z
=
tmp
>>
1
;
endmodule
test/basic/clip_mul.sv
0 → 100644
View file @
03a913ad
module
top
;
wire
[
3
:
0
]
a
,
b
,
w
,
x
,
y
,
z
;
assign
a
=
4'b1011
;
assign
b
=
4'b0101
;
// loses upper bits
assign
w
=
(
a
*
b
)
>>
4
;
// preserves upper bits via implicit extension
assign
x
=
(
1
*
a
*
b
)
>>
4
;
assign
y
=
(
a
*
b
*
1
)
>>
4
;
// preserves upper bits via "casting"
wire
[
7
:
0
]
tmp
;
assign
tmp
=
a
*
b
;
assign
z
=
tmp
>>
4
;
endmodule
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