diff options
| author | Martin Möhrmann <moehrmann@google.com> | 2018-11-07 09:33:12 +0100 |
|---|---|---|
| committer | Martin Möhrmann <moehrmann@google.com> | 2019-03-18 14:05:54 +0000 |
| commit | 6ca51f78978de7e6206d38b99eef8172fc8540d0 (patch) | |
| tree | 1d612af0e3c1fa3d55e9777c55975a3bbff49d27 /src/runtime/mksizeclasses.go | |
| parent | e5f6e2d1c8ae540504e1728a5449af3715bf27eb (diff) | |
| download | go-6ca51f78978de7e6206d38b99eef8172fc8540d0.tar.xz | |
runtime: replace division by span element size by multiply and shifts
Divisions are generally slow. The compiler can optimize a division
to use a sequence of faster multiplies and shifts (magic constants)
if the divisor is not know at compile time.
The value of the span element size in mcentral.grow is not known at
compile time but magic constants to compute n / span.elementsize
are already stored in class_to_divmagic and mspan.
They however need to be adjusted to work for
(0 <= n <= span.npages * pagesize) instead of
(0 <= n < span.npages * pagesize).
Change-Id: Ieea59f1c94525a88d012f2557d43691967900deb
Reviewed-on: https://go-review.googlesource.com/c/go/+/148057
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/mksizeclasses.go')
| -rw-r--r-- | src/runtime/mksizeclasses.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/runtime/mksizeclasses.go b/src/runtime/mksizeclasses.go index b146dbcd6c..cacbb64207 100644 --- a/src/runtime/mksizeclasses.go +++ b/src/runtime/mksizeclasses.go @@ -171,7 +171,7 @@ func makeClasses() []class { // computeDivMagic computes some magic constants to implement // the division required to compute object number from span offset. // n / c.size is implemented as n >> c.shift * c.mul >> c.shift2 -// for all 0 <= n < c.npages * pageSize +// for all 0 <= n <= c.npages * pageSize func computeDivMagic(c *class) { // divisor d := c.size @@ -180,7 +180,7 @@ func computeDivMagic(c *class) { } // maximum input value for which the formula needs to work. - max := c.npages*pageSize - 1 + max := c.npages * pageSize if powerOfTwo(d) { // If the size is a power of two, heapBitsForObject can divide even faster by masking. |
