]> Cypherpunks repositories - gostls13.git/commit
runtime: replace division by span element size by multiply and shifts
authorMartin Möhrmann <moehrmann@google.com>
Wed, 7 Nov 2018 08:33:12 +0000 (09:33 +0100)
committerMartin Möhrmann <moehrmann@google.com>
Mon, 18 Mar 2019 14:05:54 +0000 (14:05 +0000)
commit6ca51f78978de7e6206d38b99eef8172fc8540d0
tree1d612af0e3c1fa3d55e9777c55975a3bbff49d27
parente5f6e2d1c8ae540504e1728a5449af3715bf27eb
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>
src/runtime/mcentral.go
src/runtime/mksizeclasses.go
src/runtime/sizeclasses.go