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
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Milestone

Comments

@randall77
Copy link
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
Copy link
Contributor

Typo in code snippet?

@randall77
Copy link
Contributor Author

Thanks, fixed.

@randall77 randall77 modified the milestones: Go1.10, Go1.9 May 31, 2017
@bradfitz bradfitz modified the milestones: Go1.10, Go1.11 Nov 28, 2017
@bradfitz bradfitz modified the milestones: Go1.11, Unplanned May 18, 2018
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Performance
Projects
None yet
Development

No branches or pull requests

3 participants