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

Comments

Projects
None yet
2 participants
@randall77
Contributor

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

This comment has been minimized.

Member

bradfitz commented Oct 27, 2016

Typo in code snippet?

@randall77

This comment has been minimized.

Contributor

randall77 commented Oct 27, 2016

Thanks, fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment