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
e098d91c
Commit
e098d91c
authored
Dec 29, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed algebraic optimizations to proper mult structure.
parent
72807a00
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
16 deletions
+25
-16
src/optimize/advanced.py
src/optimize/advanced.py
+17
-12
tests/test_optimize_advanced.py
tests/test_optimize_advanced.py
+8
-4
No files found.
src/optimize/advanced.py
View file @
e098d91c
...
@@ -137,7 +137,7 @@ def fold_constants(block):
...
@@ -137,7 +137,7 @@ def fold_constants(block):
register
[
s
[
0
]]
=
constants
[
s
[
1
]]
register
[
s
[
0
]]
=
constants
[
s
[
1
]]
elif
s
.
name
in
[
'addu'
,
'subu'
,
'mult'
,
'div'
]:
elif
s
.
name
in
[
'addu'
,
'subu'
,
'mult'
,
'div'
]:
# Calculation with constants
# Calculation with constants
rd
,
rs
,
rt
=
s
rd
,
rs
,
rt
=
s
[
0
],
s
[
1
],
s
[
2
]
rs_known
=
rs
in
register
rs_known
=
rs
in
register
rt_known
=
rt
in
register
rt_known
=
rt
in
register
...
@@ -255,17 +255,22 @@ def algebraic_transformations(block):
...
@@ -255,17 +255,22 @@ def algebraic_transformations(block):
if
(
s
.
is_command
(
'addu'
)
or
s
.
is_command
(
'subu'
))
and
s
[
2
]
==
0
:
if
(
s
.
is_command
(
'addu'
)
or
s
.
is_command
(
'subu'
))
and
s
[
2
]
==
0
:
block
.
replace
(
1
,
[
S
(
'command'
,
'move'
,
s
[
0
],
s
[
1
])])
block
.
replace
(
1
,
[
S
(
'command'
,
'move'
,
s
[
0
],
s
[
1
])])
changed
=
True
changed
=
True
elif
s
.
is_command
(
'mult'
)
and
s
[
2
]
==
1
:
elif
s
.
is_command
(
'mult'
):
block
.
replace
(
1
,
[
S
(
'command'
,
'move'
,
s
[
0
],
s
[
1
])])
next
=
block
.
peek
()
if
next
.
is_command
(
'mflo'
):
if
s
[
1
]
==
1
:
block
.
replace
(
2
,
[
S
(
'command'
,
'move'
,
next
[
0
],
s
[
0
])])
changed
=
True
changed
=
True
elif
s
.
is_command
(
'mult'
)
and
s
[
2
]
==
0
:
break
block
.
replace
(
1
,
[
S
(
'command'
,
'li'
,
'$1'
,
to_hex
(
0
))])
elif
s
[
1
]
==
0
:
block
.
replace
(
2
,
[
S
(
'command'
,
'li'
,
'$1'
,
to_hex
(
0
))])
changed
=
True
changed
=
True
elif
s
.
is_command
(
'mult'
):
break
shift_amount
=
log
(
s
[
2
],
2
)
shift_amount
=
log
(
s
[
1
],
2
)
if
shift_amount
.
is_integer
():
if
shift_amount
.
is_integer
():
new_command
=
S
(
'command'
,
'sll'
,
s
[
0
],
s
[
1
],
shift_amount
)
new_command
=
S
(
'command'
,
'sll'
,
next
[
0
],
s
[
0
],
int
(
shift_amount
)
)
block
.
replace
(
1
,
[
new_command
])
block
.
replace
(
2
,
[
new_command
])
changed
=
True
changed
=
True
return
changed
return
changed
tests/test_optimize_advanced.py
View file @
e098d91c
...
@@ -125,7 +125,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
...
@@ -125,7 +125,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
def
test_algebraic_transforms_mult0
(
self
):
def
test_algebraic_transforms_mult0
(
self
):
block
=
B
([
self
.
foo
,
block
=
B
([
self
.
foo
,
S
(
'command'
,
'mult'
,
'$1'
,
'$2'
,
0
),
S
(
'command'
,
'mult'
,
'$2'
,
0
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
])
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertTrue
(
algebraic_transformations
(
block
))
...
@@ -135,7 +136,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
...
@@ -135,7 +136,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
def
test_algebraic_transforms_mult1
(
self
):
def
test_algebraic_transforms_mult1
(
self
):
block
=
B
([
self
.
foo
,
block
=
B
([
self
.
foo
,
S
(
'command'
,
'mult'
,
'$1'
,
'$2'
,
1
),
S
(
'command'
,
'mult'
,
'$2'
,
1
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
])
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertTrue
(
algebraic_transformations
(
block
))
...
@@ -145,7 +147,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
...
@@ -145,7 +147,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
def
test_algebraic_transforms_mult2
(
self
):
def
test_algebraic_transforms_mult2
(
self
):
block
=
B
([
self
.
foo
,
block
=
B
([
self
.
foo
,
S
(
'command'
,
'mult'
,
'$1'
,
'$2'
,
2
),
S
(
'command'
,
'mult'
,
'$2'
,
2
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
])
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertTrue
(
algebraic_transformations
(
block
))
...
@@ -155,7 +158,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
...
@@ -155,7 +158,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
def
test_algebraic_transforms_mult16
(
self
):
def
test_algebraic_transforms_mult16
(
self
):
block
=
B
([
self
.
foo
,
block
=
B
([
self
.
foo
,
S
(
'command'
,
'mult'
,
'$1'
,
'$2'
,
16
),
S
(
'command'
,
'mult'
,
'$2'
,
16
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
])
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertTrue
(
algebraic_transformations
(
block
))
...
...
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