Skip to content

cmd/compile: lower performance in tip and AMD64=v3 #59225

@rip-create-your-account

Description

What version of Go are you using (go version)?

$ gotip version
go version devel go1.21-a6c382eaa8 Fri Mar 24 14:23:19 2023 +0000 linux/amd64

$ go1.20.2 version
go version go1.20.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

import (
        "encoding/binary"
        "math/bits"
        "math/rand"
        "testing"
)

func BenchmarkChecksum(b *testing.B) {
        bb := make([]byte, 1024)
        r := rand.New(rand.NewSource(1))

        initial := uint16(r.Uint32())
        r.Read(bb)

        b.ResetTimer()

        var out uint16
        for i := 0; i < b.N; i++ {
                out = Checksum(bb, initial)
        }
        _ = out

        b.SetBytes(int64(len(bb)))
}

func Checksum(buf []byte, _ uint16) uint16 {
        var off int
        var sum, carry uint64
        for ; off <= len(buf)-64; off += 64 {
                chunk := (*[64]byte)(buf[off : off+64 : off+64])

                {
                        n1 := binary.BigEndian.Uint64(chunk[8*0:])
                        sum, carry = bits.Add64(sum, n1, carry)
                        n2 := binary.BigEndian.Uint64(chunk[8*1:])
                        sum, carry = bits.Add64(sum, n2, carry)
                        n3 := binary.BigEndian.Uint64(chunk[8*2:])
                        sum, carry = bits.Add64(sum, n3, carry)
                        n4 := binary.BigEndian.Uint64(chunk[8*3:])
                        sum, carry = bits.Add64(sum, n4, carry)
                }

                {
                        n1 := binary.BigEndian.Uint64(chunk[8*4:])
                        sum, carry = bits.Add64(sum, n1, carry)
                        n2 := binary.BigEndian.Uint64(chunk[8*5:])
                        sum, carry = bits.Add64(sum, n2, carry)
                        n3 := binary.BigEndian.Uint64(chunk[8*6:])
                        sum, carry = bits.Add64(sum, n3, carry)
                        n4 := binary.BigEndian.Uint64(chunk[8*7:])
                        sum, carry = bits.Add64(sum, n4, carry)
                }
        }
        return uint16(sum)
}

What did you expect to see?

gotip and GOAMD64=v3 go1.20.2 to maintain the performance of go1.20.2

What did you see instead?

go1.20.2 test --bench Checksum checksum_test.go
goos: linux
goarch: amd64
cpu: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
BenchmarkChecksum-8     15659816                72.35 ns/op     14154.40 MB/s
gotip test --bench Checksum checksum_test.go
goos: linux
goarch: amd64
cpu: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
BenchmarkChecksum-8     12009291                94.35 ns/op     10852.66 MB/s

For go1.20.2 GOAMD64=v3 I get similar performance as for gotip

GOAMD64=v3 go1.20.2 test --bench Checksum checksum_test.go
goos: linux
goarch: amd64
cpu: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
BenchmarkChecksum-8     12212551                97.91 ns/op     10458.96 MB/s

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions