Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: use better code for slicing #17638

Open
randall77 opened this issue Oct 27, 2016 · 2 comments
Open

cmd/compile: use better code for slicing #17638

randall77 opened this issue Oct 27, 2016 · 2 comments
Milestone

Comments

@randall77
Copy link
Contributor

@randall77 randall77 commented Oct 27, 2016

func f(s []int, i int) []int {
    return s[i:]
}

The assembly starts out with

MOVQ    "".i+32(FP), AX
MOVQ    "".s+16(FP), CX
CMPQ    AX, CX
JHI $0, 60
SUBQ    AX, CX

The CMP and SUB are almost redundant. Instead, we could do

MOVQ    "".i+32(FP), AX
MOVQ    "".s+16(FP), CX
SUBQ    AX, CX
JHI $0, 60

We just need a subtract that also generates flags. (We have a 32-bit one for synthesizing 64-bit ops. We need a 64-bit one also.)

@randall77 randall77 added this to the Go1.9 milestone Oct 27, 2016
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Oct 27, 2016

Typo in code snippet?

Loading

@randall77
Copy link
Contributor Author

@randall77 randall77 commented Oct 27, 2016

Thanks, fixed.

Loading

@randall77 randall77 added this to the Go1.10 milestone May 31, 2017
@randall77 randall77 removed this from the Go1.9 milestone May 31, 2017
@bradfitz bradfitz removed this from the Go1.10 milestone Nov 28, 2017
@bradfitz bradfitz added this to the Go1.11 milestone Nov 28, 2017
@bradfitz bradfitz removed this from the Go1.11 milestone May 18, 2018
@bradfitz bradfitz added this to the Unplanned milestone May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants