summaryrefslogtreecommitdiffhomepage
path: root/pkg/bits
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-04-27 23:25:13 +0000
committergVisor bot <gvisor-bot@google.com>2021-04-27 23:25:13 +0000
commit466d7d5a515e25cda5af0dd3a2651b4019dd3284 (patch)
treebb2c3a6d2621e06e3de575c4bbfd1f16ea40666d /pkg/bits
parenta1a77e4f6f39eee5f675de39c3734c322d07711f (diff)
parentf54d87b9eceee7f6069a4faf2628f19b8752ad06 (diff)
Merge release-20210419.0-35-gf54d87b9e (automated)
Diffstat (limited to 'pkg/bits')
-rw-r--r--pkg/bits/bits.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/pkg/bits/bits.go b/pkg/bits/bits.go
index a26433ad6..d16448c3d 100644
--- a/pkg/bits/bits.go
+++ b/pkg/bits/bits.go
@@ -14,3 +14,13 @@
// Package bits includes all bit related types and operations.
package bits
+
+// AlignUp rounds a length up to an alignment. align must be a power of 2.
+func AlignUp(length int, align uint) int {
+ return (length + int(align) - 1) & ^(int(align) - 1)
+}
+
+// AlignDown rounds a length down to an alignment. align must be a power of 2.
+func AlignDown(length int, align uint) int {
+ return length & ^(int(align) - 1)
+}