mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: clean up power-of-two rounding code with align functions
This change renames the "round" function to the more appropriately named "alignUp" which rounds an integer up to the next multiple of a power of two. This change also adds the alignDown function, which is almost like alignUp but rounds down to the previous multiple of a power of two. With these two functions, we also go and replace manual rounding code with it where we can. Change-Id: Ie1487366280484dcb2662972b01b4f7135f72fec Reviewed-on: https://go-review.googlesource.com/c/go/+/190618 Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
2566e21f24
commit
383b447e0d
10 changed files with 40 additions and 34 deletions
|
|
@ -337,7 +337,7 @@ func stackalloc(n uint32) stack {
|
|||
}
|
||||
|
||||
if debug.efence != 0 || stackFromSystem != 0 {
|
||||
n = uint32(round(uintptr(n), physPageSize))
|
||||
n = uint32(alignUp(uintptr(n), physPageSize))
|
||||
v := sysAlloc(uintptr(n), &memstats.stacks_sys)
|
||||
if v == nil {
|
||||
throw("out of memory (stackalloc)")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue