Skip to content

Commit

Permalink
cmd/compile,runtime: remove runtime.mulUintptr
Browse files Browse the repository at this point in the history
For #48798

Change-Id: I3e928d3921cfd5a7bf35b23d0ae6442aa6d2d482
GitHub-Last-Rev: b101a8a54f2cc9ea917f879a545f30c702508743
GitHub-Pull-Request: golang/go#63349
Reviewed-on: https://go-review.googlesource.com/c/go/+/532355
TryBot-Result: Gopher Robot <[email protected]>
Commit-Queue: Keith Randall <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Run-TryBot: Martin Möhrmann <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Auto-Submit: Keith Randall <[email protected]>
Reviewed-by: Martin Möhrmann <[email protected]>
  • Loading branch information
qiulaidongfeng authored and gopherbot committed Oct 3, 2023
1 parent 638e0d3 commit 53827ba
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 115 deletions.
1 change: 0 additions & 1 deletion src/cmd/compile/internal/ssagen/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -4117,7 +4117,6 @@ func InitTables() {
return s.newValue2(ssa.OpMul64uover, types.NewTuple(types.Types[types.TUINT], types.Types[types.TUINT]), args[0], args[1])
},
sys.AMD64, sys.I386, sys.Loong64, sys.MIPS64, sys.RISCV64, sys.ARM64)
alias("runtime", "mulUintptr", "runtime/internal/math", "MulUintptr", all...)
add("runtime", "KeepAlive",
func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
data := s.newValue1(ssa.OpIData, s.f.Config.Types.BytePtr, args[0])
Expand Down
2 changes: 0 additions & 2 deletions src/cmd/compile/internal/typecheck/_builtin/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ func unsafestringcheckptr(ptr unsafe.Pointer, len int64)
func panicunsafestringlen()
func panicunsafestringnilptr()

func mulUintptr(x, y uintptr) (uintptr, bool)

func memmove(to *any, frm *any, length uintptr)
func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
func memclrHasPointers(ptr unsafe.Pointer, n uintptr)
Expand Down
204 changes: 101 additions & 103 deletions src/cmd/compile/internal/typecheck/builtin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions src/cmd/compile/internal/walk/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,23 @@ func walkUnsafeSlice(n *ir.BinaryExpr, init *ir.Nodes) ir.Node {
return walkExpr(typecheck.Expr(h), init)
}

// mem, overflow := runtime.mulUintptr(et.size, len)
// mem, overflow := math.mulUintptr(et.size, len)
mem := typecheck.TempAt(base.Pos, ir.CurFunc, types.Types[types.TUINTPTR])
overflow := typecheck.TempAt(base.Pos, ir.CurFunc, types.Types[types.TBOOL])
fn := typecheck.LookupRuntime("mulUintptr")
call := mkcall1(fn, fn.Type().ResultsTuple(), init, ir.NewInt(base.Pos, sliceType.Elem().Size()), typecheck.Conv(typecheck.Conv(len, lenType), types.Types[types.TUINTPTR]))

decl := types.NewSignature(nil,
[]*types.Field{
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
},
[]*types.Field{
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
types.NewField(base.Pos, nil, types.Types[types.TBOOL]),
})

fn := ir.NewFunc(n.Pos(), n.Pos(), math_MulUintptr, decl)

call := mkcall1(fn.Nname, fn.Type().ResultsTuple(), init, ir.NewInt(base.Pos, sliceType.Elem().Size()), typecheck.Conv(typecheck.Conv(len, lenType), types.Types[types.TUINTPTR]))
appendWalkStmt(init, ir.NewAssignListStmt(base.Pos, ir.OAS2, []ir.Node{mem, overflow}, []ir.Node{call}))

// if overflow || mem > -uintptr(ptr) {
Expand All @@ -778,6 +790,8 @@ func walkUnsafeSlice(n *ir.BinaryExpr, init *ir.Nodes) ir.Node {
return walkExpr(typecheck.Expr(h), init)
}

var math_MulUintptr = &types.Sym{Pkg: types.NewPkg("runtime/internal/math", "math"), Name: "MulUintptr"}

func walkUnsafeString(n *ir.BinaryExpr, init *ir.Nodes) ir.Node {
ptr := safeExpr(n.X, init)
len := safeExpr(n.Y, init)
Expand Down
6 changes: 0 additions & 6 deletions src/runtime/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ func makeslice64(et *_type, len64, cap64 int64) unsafe.Pointer {
return makeslice(et, len, cap)
}

// This is a wrapper over runtime/internal/math.MulUintptr,
// so the compiler can recognize and treat it as an intrinsic.
func mulUintptr(a, b uintptr) (uintptr, bool) {
return math.MulUintptr(a, b)
}

// growslice allocates new backing store for a slice.
//
// arguments:
Expand Down

0 comments on commit 53827ba

Please sign in to comment.