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: don't copy static array in range statement #15812

Open
randall77 opened this Issue May 24, 2016 · 0 comments

Comments

Projects
None yet
4 participants
@randall77
Contributor

randall77 commented May 24, 2016

func f() {
    for _, b := range [...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {
        println(b)
    }
}

The compiled code starts off with copying the static array to the stack, then using the stack copy to do the iteration. The static data is read-only, we could use the static data directly.

    0x0013 00019 (tmp1.go:4)    MOVQ    "".statictmp_1(SB), AX
    0x001a 00026 (tmp1.go:4)    MOVQ    "".statictmp_1+2(SB), CX
    0x0021 00033 (tmp1.go:4)    MOVQ    AX, "".autotmp_3+30(SP)
    0x0026 00038 (tmp1.go:4)    MOVQ    CX, "".autotmp_3+32(SP)
    0x002b 00043 (tmp1.go:4)    MOVQ    $0, AX
    0x002d 00045 (tmp1.go:4)    LEAQ    "".autotmp_3+30(SP), CX
    ...use CX to load the bytes...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment