aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/arena.go2
-rw-r--r--src/runtime/chan.go2
-rw-r--r--src/runtime/hash64.go2
-rw-r--r--src/runtime/internal/math/math.go55
-rw-r--r--src/runtime/internal/math/math_test.go79
-rw-r--r--src/runtime/malloc.go2
-rw-r--r--src/runtime/map.go2
-rw-r--r--src/runtime/rand.go2
-rw-r--r--src/runtime/slice.go2
-rw-r--r--src/runtime/unsafe.go2
10 files changed, 8 insertions, 142 deletions
diff --git a/src/runtime/arena.go b/src/runtime/arena.go
index cd9a9dfae1..96197099ca 100644
--- a/src/runtime/arena.go
+++ b/src/runtime/arena.go
@@ -86,7 +86,7 @@ import (
"internal/abi"
"internal/goarch"
"internal/runtime/atomic"
- "runtime/internal/math"
+ "internal/runtime/math"
"runtime/internal/sys"
"unsafe"
)
diff --git a/src/runtime/chan.go b/src/runtime/chan.go
index f1cd74a3fd..4c854c72bc 100644
--- a/src/runtime/chan.go
+++ b/src/runtime/chan.go
@@ -20,7 +20,7 @@ package runtime
import (
"internal/abi"
"internal/runtime/atomic"
- "runtime/internal/math"
+ "internal/runtime/math"
"unsafe"
)
diff --git a/src/runtime/hash64.go b/src/runtime/hash64.go
index 05cdb81113..124bb7d77a 100644
--- a/src/runtime/hash64.go
+++ b/src/runtime/hash64.go
@@ -10,7 +10,7 @@
package runtime
import (
- "runtime/internal/math"
+ "internal/runtime/math"
"unsafe"
)
diff --git a/src/runtime/internal/math/math.go b/src/runtime/internal/math/math.go
deleted file mode 100644
index b2e5508651..0000000000
--- a/src/runtime/internal/math/math.go
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package math
-
-import "internal/goarch"
-
-const MaxUintptr = ^uintptr(0)
-
-// MulUintptr returns a * b and whether the multiplication overflowed.
-// On supported platforms this is an intrinsic lowered by the compiler.
-func MulUintptr(a, b uintptr) (uintptr, bool) {
- if a|b < 1<<(4*goarch.PtrSize) || a == 0 {
- return a * b, false
- }
- overflow := b > MaxUintptr/a
- return a * b, overflow
-}
-
-// Mul64 returns the 128-bit product of x and y: (hi, lo) = x * y
-// with the product bits' upper half returned in hi and the lower
-// half returned in lo.
-// This is a copy from math/bits.Mul64
-// On supported platforms this is an intrinsic lowered by the compiler.
-func Mul64(x, y uint64) (hi, lo uint64) {
- const mask32 = 1<<32 - 1
- x0 := x & mask32
- x1 := x >> 32
- y0 := y & mask32
- y1 := y >> 32
- w0 := x0 * y0
- t := x1*y0 + w0>>32
- w1 := t & mask32
- w2 := t >> 32
- w1 += x0 * y1
- hi = x1*y1 + w2 + w1>>32
- lo = x * y
- return
-}
-
-// Add64 returns the sum with carry of x, y and carry: sum = x + y + carry.
-// The carry input must be 0 or 1; otherwise the behavior is undefined.
-// The carryOut output is guaranteed to be 0 or 1.
-//
-// This function's execution time does not depend on the inputs.
-// On supported platforms this is an intrinsic lowered by the compiler.
-func Add64(x, y, carry uint64) (sum, carryOut uint64) {
- sum = x + y + carry
- // The sum will overflow if both top bits are set (x & y) or if one of them
- // is (x | y), and a carry from the lower place happened. If such a carry
- // happens, the top bit will be 1 + 0 + 1 = 0 (&^ sum).
- carryOut = ((x & y) | ((x | y) &^ sum)) >> 63
- return
-}
diff --git a/src/runtime/internal/math/math_test.go b/src/runtime/internal/math/math_test.go
deleted file mode 100644
index 303eb63405..0000000000
--- a/src/runtime/internal/math/math_test.go
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package math_test
-
-import (
- . "runtime/internal/math"
- "testing"
-)
-
-const (
- UintptrSize = 32 << (^uintptr(0) >> 63)
-)
-
-type mulUintptrTest struct {
- a uintptr
- b uintptr
- overflow bool
-}
-
-var mulUintptrTests = []mulUintptrTest{
- {0, 0, false},
- {1000, 1000, false},
- {MaxUintptr, 0, false},
- {MaxUintptr, 1, false},
- {MaxUintptr / 2, 2, false},
- {MaxUintptr / 2, 3, true},
- {MaxUintptr, 10, true},
- {MaxUintptr, 100, true},
- {MaxUintptr / 100, 100, false},
- {MaxUintptr / 1000, 1001, true},
- {1<<(UintptrSize/2) - 1, 1<<(UintptrSize/2) - 1, false},
- {1 << (UintptrSize / 2), 1 << (UintptrSize / 2), true},
- {MaxUintptr >> 32, MaxUintptr >> 32, false},
- {MaxUintptr, MaxUintptr, true},
-}
-
-func TestMulUintptr(t *testing.T) {
- for _, test := range mulUintptrTests {
- a, b := test.a, test.b
- for i := 0; i < 2; i++ {
- mul, overflow := MulUintptr(a, b)
- if mul != a*b || overflow != test.overflow {
- t.Errorf("MulUintptr(%v, %v) = %v, %v want %v, %v",
- a, b, mul, overflow, a*b, test.overflow)
- }
- a, b = b, a
- }
- }
-}
-
-var SinkUintptr uintptr
-var SinkBool bool
-
-var x, y uintptr
-
-func BenchmarkMulUintptr(b *testing.B) {
- x, y = 1, 2
- b.Run("small", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- var overflow bool
- SinkUintptr, overflow = MulUintptr(x, y)
- if overflow {
- SinkUintptr = 0
- }
- }
- })
- x, y = MaxUintptr, MaxUintptr-1
- b.Run("large", func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- var overflow bool
- SinkUintptr, overflow = MulUintptr(x, y)
- if overflow {
- SinkUintptr = 0
- }
- }
- })
-}
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index b92a213245..cbb4f67ee8 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -104,7 +104,7 @@ import (
"internal/goarch"
"internal/goos"
"internal/runtime/atomic"
- "runtime/internal/math"
+ "internal/runtime/math"
"runtime/internal/sys"
"unsafe"
)
diff --git a/src/runtime/map.go b/src/runtime/map.go
index 112084f5a7..9169d5733e 100644
--- a/src/runtime/map.go
+++ b/src/runtime/map.go
@@ -57,7 +57,7 @@ import (
"internal/abi"
"internal/goarch"
"internal/runtime/atomic"
- "runtime/internal/math"
+ "internal/runtime/math"
"unsafe"
)
diff --git a/src/runtime/rand.go b/src/runtime/rand.go
index a66553feeb..11be6552aa 100644
--- a/src/runtime/rand.go
+++ b/src/runtime/rand.go
@@ -9,7 +9,7 @@ package runtime
import (
"internal/chacha8rand"
"internal/goarch"
- "runtime/internal/math"
+ "internal/runtime/math"
"unsafe"
_ "unsafe" // for go:linkname
)
diff --git a/src/runtime/slice.go b/src/runtime/slice.go
index 78475735af..65883ea2f3 100644
--- a/src/runtime/slice.go
+++ b/src/runtime/slice.go
@@ -7,7 +7,7 @@ package runtime
import (
"internal/abi"
"internal/goarch"
- "runtime/internal/math"
+ "internal/runtime/math"
"runtime/internal/sys"
"unsafe"
)
diff --git a/src/runtime/unsafe.go b/src/runtime/unsafe.go
index ca428b56e0..85fc8b61eb 100644
--- a/src/runtime/unsafe.go
+++ b/src/runtime/unsafe.go
@@ -5,7 +5,7 @@
package runtime
import (
- "runtime/internal/math"
+ "internal/runtime/math"
"unsafe"
)