Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
peephole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
peephole
Commits
98a981ab
Commit
98a981ab
authored
Dec 30, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed use and def of div instruction.
parent
f971a60e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
6 deletions
+8
-6
src/optimize/advanced.py
src/optimize/advanced.py
+2
-1
src/statement.py
src/statement.py
+3
-3
tests/test_statement.py
tests/test_statement.py
+3
-2
No files found.
src/optimize/advanced.py
View file @
98a981ab
...
...
@@ -141,7 +141,7 @@ def fold_constants(block):
if
s
.
name
==
'li'
:
# 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
)
else
:
register
[
s
[
0
]]
=
s
[
1
]
...
...
@@ -176,6 +176,7 @@ def fold_constants(block):
elif
s
.
name
in
[
'mult'
,
'div'
]
\
and
s
[
0
]
in
register
and
s
[
1
]
in
register
:
# Multiplication/division with constants
print
s
rs
,
rt
=
s
a
,
b
=
register
[
rs
],
register
[
rt
]
...
...
src/statement.py
View file @
98a981ab
...
...
@@ -154,7 +154,7 @@ class Statement:
def get_def(self):
"""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
'):
return [self[1]]
...
...
@@ -178,7 +178,7 @@ class Statement:
if (self.is_branch()
\
and not self.is_command(*['
bc1f
', '
bc1t
', '
bct
', '
bcf
']))
\
or self.is_store() or self.is_compare()
\
or self.is_command(*['
mult
', '
d
iv
', '
d
sz
', '
mtc1
']):
or self.is_command(*['
mult
', '
dsz
', '
mtc1
']):
if self.name == '
dsz
':
m = re.match('
^
[
^
(]
+
\
(([
^
)]
+
)
\
)
$
', self[0])
...
...
@@ -206,7 +206,7 @@ class Statement:
# Case arg2
if self.is_double_arithmetic() or self.is_set_if_less()
\
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):
use.append(self[2])
...
...
tests/test_statement.py
View file @
98a981ab
...
...
@@ -99,8 +99,9 @@ class TestStatement(unittest.TestCase):
a
=
[
'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'
,
'div'
,
'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'
,
'la'
,
'a'
,
'16($fp)'
).
get_def
(),
a
)
...
...
@@ -130,7 +131,7 @@ class TestStatement(unittest.TestCase):
self
.
assertEqual
(
S
(
'command'
,
'subu'
,
'$3'
,
'$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'
,
'beq'
,
'$1'
,
'$2'
,
'$L1'
).
get_use
(),
\
arg2
)
...
...
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