Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
peephole
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Taddeüs Kroes
peephole
Commits
98a981ab
Commit
98a981ab
authored
13 years ago
by
Jayke Meijer
Browse files
Options
Downloads
Patches
Plain Diff
Fixed use and def of div instruction.
parent
f971a60e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/optimize/advanced.py
+2
-1
2 additions, 1 deletion
src/optimize/advanced.py
src/statement.py
+3
-3
3 additions, 3 deletions
src/statement.py
tests/test_statement.py
+3
-2
3 additions, 2 deletions
tests/test_statement.py
with
8 additions
and
6 deletions
src/optimize/advanced.py
+
2
−
1
View file @
98a981ab
...
@@ -141,7 +141,7 @@ def fold_constants(block):
...
@@ -141,7 +141,7 @@ def fold_constants(block):
if
s
.
name
==
'
li
'
:
if
s
.
name
==
'
li
'
:
# Save value in register
# Save value in register
if
not
isinstance
(
s
[
1
],
int
):
if
not
isinstance
(
s
[
1
],
int
):
# Negative numbers are stored as int
register
[
s
[
0
]]
=
int
(
s
[
1
],
16
)
register
[
s
[
0
]]
=
int
(
s
[
1
],
16
)
else
:
else
:
register
[
s
[
0
]]
=
s
[
1
]
register
[
s
[
0
]]
=
s
[
1
]
...
@@ -176,6 +176,7 @@ def fold_constants(block):
...
@@ -176,6 +176,7 @@ def fold_constants(block):
elif
s
.
name
in
[
'
mult
'
,
'
div
'
]
\
elif
s
.
name
in
[
'
mult
'
,
'
div
'
]
\
and
s
[
0
]
in
register
and
s
[
1
]
in
register
:
and
s
[
0
]
in
register
and
s
[
1
]
in
register
:
# Multiplication/division with constants
# Multiplication/division with constants
print
s
rs
,
rt
=
s
rs
,
rt
=
s
a
,
b
=
register
[
rs
],
register
[
rt
]
a
,
b
=
register
[
rs
],
register
[
rt
]
...
...
This diff is collapsed.
Click to expand it.
src/statement.py
+
3
−
3
View file @
98a981ab
...
@@ -154,7 +154,7 @@ class Statement:
...
@@ -154,7 +154,7 @@ class Statement:
def
get_def
(
self
):
def
get_def
(
self
):
"""
Get the variable that this statement defines, if any.
"""
"""
Get the variable that this statement defines, if any.
"""
instr
=
[
'
move
'
,
'
addu
'
,
'
subu
'
,
'
li
'
,
'
dmfc1
'
,
'
mov.d
'
]
instr
=
[
'
div
'
,
'
move
'
,
'
addu
'
,
'
subu
'
,
'
li
'
,
'
dmfc1
'
,
'
mov.d
'
]
if
self
.
is_command
(
'
mtc1
'
):
if
self
.
is_command
(
'
mtc1
'
):
return
[
self
[
1
]]
return
[
self
[
1
]]
...
@@ -178,7 +178,7 @@ class Statement:
...
@@ -178,7 +178,7 @@ class Statement:
if
(
self
.
is_branch
()
\
if
(
self
.
is_branch
()
\
and
not
self
.
is_command
(
*
[
'
bc1f
'
,
'
bc1t
'
,
'
bct
'
,
'
bcf
'
]))
\
and
not
self
.
is_command
(
*
[
'
bc1f
'
,
'
bc1t
'
,
'
bct
'
,
'
bcf
'
]))
\
or
self
.
is_store
()
or
self
.
is_compare
()
\
or
self
.
is_store
()
or
self
.
is_compare
()
\
or
self
.
is_command
(
*
[
'
mult
'
,
'
div
'
,
'
dsz
'
,
'
mtc1
'
]):
or
self
.
is_command
(
*
[
'
mult
'
,
'
dsz
'
,
'
mtc1
'
]):
if
self
.
name
==
'
dsz
'
:
if
self
.
name
==
'
dsz
'
:
m
=
re
.
match
(
'
^[^(]+\(([^)]+)\)$
'
,
self
[
0
])
m
=
re
.
match
(
'
^[^(]+\(([^)]+)\)$
'
,
self
[
0
])
...
@@ -206,7 +206,7 @@ class Statement:
...
@@ -206,7 +206,7 @@ class Statement:
# Case arg2
# Case arg2
if
self
.
is_double_arithmetic
()
or
self
.
is_set_if_less
()
\
if
self
.
is_double_arithmetic
()
or
self
.
is_set_if_less
()
\
or
self
.
is_logical
()
or
self
.
is_truncate
()
\
or
self
.
is_logical
()
or
self
.
is_truncate
()
\
or
self
.
is_command
(
*
[
'
addu
'
,
'
subu
'
]):
or
self
.
is_command
(
*
[
'
addu
'
,
'
subu
'
,
'
div
'
]):
if
not
isinstance
(
self
[
2
],
int
):
if
not
isinstance
(
self
[
2
],
int
):
use
.
append
(
self
[
2
])
use
.
append
(
self
[
2
])
...
...
This diff is collapsed.
Click to expand it.
tests/test_statement.py
+
3
−
2
View file @
98a981ab
...
@@ -99,8 +99,9 @@ class TestStatement(unittest.TestCase):
...
@@ -99,8 +99,9 @@ class TestStatement(unittest.TestCase):
a
=
[
'
a
'
]
a
=
[
'
a
'
]
self
.
assertEqual
(
S
(
'
command
'
,
'
move
'
,
'
a
'
,
'
b
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
move
'
,
'
a
'
,
'
b
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
subu
'
,
'
a
'
,
'
b
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
subu
'
,
'
a
'
,
'
b
'
,
'
c
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
addu
'
,
'
a
'
,
'
b
'
,
'
c
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
addu
'
,
'
a
'
,
'
b
'
,
'
c
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
div
'
,
'
a
'
,
'
b
'
,
'
c
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
sll
'
,
'
a
'
,
'
b
'
,
'
c
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
sll
'
,
'
a
'
,
'
b
'
,
'
c
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
srl
'
,
'
a
'
,
'
b
'
,
'
c
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
srl
'
,
'
a
'
,
'
b
'
,
'
c
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
la
'
,
'
a
'
,
'
16($fp)
'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'
command
'
,
'
la
'
,
'
a
'
,
'
16($fp)
'
).
get_def
(),
a
)
...
@@ -130,7 +131,7 @@ class TestStatement(unittest.TestCase):
...
@@ -130,7 +131,7 @@ class TestStatement(unittest.TestCase):
self
.
assertEqual
(
S
(
'
command
'
,
'
subu
'
,
'
$3
'
,
'
$1
'
,
'
$2
'
).
get_use
(),
\
self
.
assertEqual
(
S
(
'
command
'
,
'
subu
'
,
'
$3
'
,
'
$1
'
,
'
$2
'
).
get_use
(),
\
arg2
)
arg2
)
self
.
assertEqual
(
S
(
'
command
'
,
'
mult
'
,
'
$1
'
,
'
$2
'
).
get_use
(),
arg2
)
self
.
assertEqual
(
S
(
'
command
'
,
'
mult
'
,
'
$1
'
,
'
$2
'
).
get_use
(),
arg2
)
self
.
assertEqual
(
S
(
'
command
'
,
'
div
'
,
'
$1
'
,
'
$2
'
).
get_use
(),
arg2
)
self
.
assertEqual
(
S
(
'
command
'
,
'
div
'
,
'
$3
'
,
'
$1
'
,
'
$2
'
).
get_use
(),
arg2
)
self
.
assertEqual
(
S
(
'
command
'
,
'
move
'
,
'
$2
'
,
'
$1
'
).
get_use
(),
arg1
)
self
.
assertEqual
(
S
(
'
command
'
,
'
move
'
,
'
$2
'
,
'
$1
'
).
get_use
(),
arg1
)
self
.
assertEqual
(
S
(
'
command
'
,
'
beq
'
,
'
$1
'
,
'
$2
'
,
'
$L1
'
).
get_use
(),
\
self
.
assertEqual
(
S
(
'
command
'
,
'
beq
'
,
'
$1
'
,
'
$2
'
,
'
$L1
'
).
get_use
(),
\
arg2
)
arg2
)
...
...
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