]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use divRoundUp
authorAustin Clements <austin@google.com>
Fri, 20 Mar 2020 15:37:54 +0000 (11:37 -0400)
committerAustin Clements <austin@google.com>
Fri, 20 Mar 2020 16:05:35 +0000 (16:05 +0000)
There are a handful of places where the runtime wants to round up the
result of a division. We just introduced a helper to do this. This CL
replaces all of the hand-coded round-ups (that I could find) with this
helper.

Change-Id: I465d152157ff0f3cad40c0aa57491e4f2de510ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/224385
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/runtime/malloc.go
src/runtime/mgcmark.go
src/runtime/mgcsweepbuf.go
src/runtime/msize.go

index 483ea0aee5a503c5516dcf34273f32e5506c2fed..346d7f4742890613c60b18082ccab73e2c058270 100644 (file)
@@ -1035,9 +1035,9 @@ func mallocgc(size uintptr, typ *_type, needzero bool) unsafe.Pointer {
                } else {
                        var sizeclass uint8
                        if size <= smallSizeMax-8 {
-                               sizeclass = size_to_class8[(size+smallSizeDiv-1)/smallSizeDiv]
+                               sizeclass = size_to_class8[divRoundUp(size, smallSizeDiv)]
                        } else {
-                               sizeclass = size_to_class128[(size-smallSizeMax+largeSizeDiv-1)/largeSizeDiv]
+                               sizeclass = size_to_class128[divRoundUp(size-smallSizeMax, largeSizeDiv)]
                        }
                        size = uintptr(class_to_size[sizeclass])
                        spc := makeSpanClass(sizeclass, noscan)
index 2c17d8befa18fe1a69f08ebc6f3272626fdd7a30..301d8020f1c4f43743ffb2ec37208077b1a72705 100644 (file)
@@ -54,7 +54,7 @@ func gcMarkRootPrepare() {
 
        // Compute how many data and BSS root blocks there are.
        nBlocks := func(bytes uintptr) int {
-               return int((bytes + rootBlockBytes - 1) / rootBlockBytes)
+               return int(divRoundUp(bytes, rootBlockBytes))
        }
 
        work.nDataRoots = 0
index 78288229c839e4705817010d43cad415263816b6..1f722c3d585080b930da7eb586f6e2443f302c6e 100644 (file)
@@ -144,7 +144,7 @@ func (b *gcSweepBuf) pop() *mspan {
 // intervening pops. Spans that are pushed after the call may also
 // appear in these blocks.
 func (b *gcSweepBuf) numBlocks() int {
-       return int((atomic.Load(&b.index) + gcSweepBlockEntries - 1) / gcSweepBlockEntries)
+       return int(divRoundUp(uintptr(atomic.Load(&b.index)), gcSweepBlockEntries))
 }
 
 // block returns the spans in the i'th block of buffer b. block is
index 11d06ce0251c1f9543398e52bf9ac13199473866..c56aa5a7b2c59abfa8f9028ba23e9cd65fb758c3 100644 (file)
@@ -13,9 +13,9 @@ package runtime
 func roundupsize(size uintptr) uintptr {
        if size < _MaxSmallSize {
                if size <= smallSizeMax-8 {
-                       return uintptr(class_to_size[size_to_class8[(size+smallSizeDiv-1)/smallSizeDiv]])
+                       return uintptr(class_to_size[size_to_class8[divRoundUp(size, smallSizeDiv)]])
                } else {
-                       return uintptr(class_to_size[size_to_class128[(size-smallSizeMax+largeSizeDiv-1)/largeSizeDiv]])
+                       return uintptr(class_to_size[size_to_class128[divRoundUp(size-smallSizeMax, largeSizeDiv)]])
                }
        }
        if size+_PageSize < size {