]> Cypherpunks repositories - gostls13.git/commit
cmd/compile,runtime: remember idx+len for bounds check failure with less code
authorKeith Randall <khr@golang.org>
Wed, 18 Jun 2025 21:50:23 +0000 (14:50 -0700)
committerKeith Randall <khr@golang.org>
Thu, 24 Jul 2025 23:05:59 +0000 (16:05 -0700)
commit3024785b929cd8a740da87e1c24aef2c9b30e019
tree4268d684d7707ce8b17a5781b8e8c82d1812c714
parent741a19ab4197fb528f8d7f7d8a73d3db3ef99355
cmd/compile,runtime: remember idx+len for bounds check failure with less code

Currently we must put the index and length into specific registers so
we can call into the runtime to report a bounds check failure.

So a typical bounds check call is something like:

MOVD  R3, R0
MOVD  R7, R1
CALL  runtime.panicIndex

or, if for instance the index is constant,

MOVD  $7, R0
MOVD  R9, R1
CALL  runtime.panicIndex

Sometimes the MOVD can be avoided, if the value happens to be in the
right register already. But that's not terribly common, and doesn't
work at all for constants.

Let's get rid of those MOVD instructions. They pollute the instruction
cache and are almost never executed.

Instead, we'll encode in a PCDATA table where the runtime should find
the index and length. The table encodes, for each index and length,
whether it is a constant or in a register, and which register or
constant it is.

That way, we can avoid all those useless MOVDs. Instead, we can figure
out the index and length at runtime. This makes the bounds panic path
slower, but that's a good tradeoff.

We can encode registers 0-15 and constants 0-31. Anything outside that
range still needs to use an explicit instruction.

This CL is the foundation, followon CLs will move each architecture
to the new strategy.

Change-Id: I705c511e546e6aac59fed922a8eaed4585e96820
Reviewed-on: https://go-review.googlesource.com/c/go/+/682396
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/cmd/compile/internal/ir/symtab.go
src/cmd/compile/internal/ssa/_gen/rulegen.go
src/cmd/compile/internal/ssa/check.go
src/cmd/compile/internal/ssa/op.go
src/cmd/compile/internal/ssa/rewrite.go
src/cmd/compile/internal/ssagen/ssa.go
src/internal/abi/bounds.go
src/internal/abi/symtab.go
src/runtime/panic.go