Skip to content

cmd/compile: special case slice consuming sliding window pattern #77090

@Jorropo

Description

@Jorropo
go version go1.26-devel_e7c0b74a97 Tue Jan 6 20:29:01 2026 +0100 linux/amd64

I don't know what the name is for this pattern so I've made one up, but basically the assembly for this function looks awful:

func ConstantTimeCompare(x, y []byte) int {
	if len(x) != len(y) { panic("...") }

	var v byte

	for ; len(x) > 0; x, y = x[1:], y[1:] {
		a := y[0]
		b := x[0]

		v |= a ^ b
	}

	return constanttime.Eq(v, 0)
}
  • after early loop rotation cmd/compile: early loop rotation #77089 we could move s[1:] operations into if len(x) > 0 { /* here */; goto loop } second loop check, this would allow us to remove the slice mask
  • we keep track of the length of both slices, even tho it is identical

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions