Skip to content

Commit

Permalink
Optimize pointer movements with set-zero loops
Browse files Browse the repository at this point in the history
  • Loading branch information
terminationshock committed Feb 18, 2023
1 parent 3882f89 commit 24844dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/assembly.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func Assembly(code []*Command, file string, stackSize int) (string, error) {
program += fmt.Sprintf("subq %%rax, %d(%%r12)", -8 * m.Offset) + br
}
}
program += "movq $0, (%r12)" + br
if c.Offset != 0 {
program += fmt.Sprintf("movq $0, %d(%%r12)", -8 * c.Offset) + br
} else {
program += "movq $0, (%r12)" + br
}
}
break
}
Expand Down
3 changes: 2 additions & 1 deletion src/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func optimizePointerMovement(commands []*Command, verbose bool) []*Command {
i := 0
block := []*Command{}
for i < len(commands) {
if strings.Contains("><+-,.", commands[i].String) && i < len(commands) - 1 {
if (strings.Contains("><+-,.", commands[i].String) || commands[i].String == "[-]") && i < len(commands) - 1 {
block = append(block, commands[i])
} else {
if len(block) > 0 {
Expand Down Expand Up @@ -216,6 +216,7 @@ func getRemoteCommands(commands []*Command) []*Command {
Offset: pointer,
Row: c.Row,
Col: c.Col,
MultiplyLoop: c.MultiplyLoop,
})
}
}
Expand Down

0 comments on commit 24844dc

Please sign in to comment.