Commit 6482fe6c authored by Russ Cox's avatar Russ Cox

runtime: delete dead code called from C.

printf, vprintf, snprintf, gc_m_ptr, gc_g_ptr, gc_itab_ptr, gc_unixnanotime.

These were called from C.
There is no more C.

Now that vprintf is gone, delete roundup, which is unsafe (see CL 2814).

Change-Id: If8a7b727d497ffa13165c0d3a1ed62abc18f008c
Reviewed-on: https://go-review.googlesource.com/2824Reviewed-by: default avatarAustin Clements <austin@google.com>
parent f6d0054e
......@@ -2551,7 +2551,6 @@ func getgcmask(p unsafe.Pointer, t *_type, mask **byte, len *uintptr) {
}
func unixnanotime() int64 {
var now int64
gc_unixnanotime(&now)
return now
sec, nsec := time_now()
return sec*1e9 + int64(nsec)
}
......@@ -6,26 +6,6 @@ package runtime
import "unsafe"
// Called from C. Returns the Go type *m.
func gc_m_ptr(ret *interface{}) {
*ret = (*m)(nil)
}
// Called from C. Returns the Go type *g.
func gc_g_ptr(ret *interface{}) {
*ret = (*g)(nil)
}
// Called from C. Returns the Go type *itab.
func gc_itab_ptr(ret *interface{}) {
*ret = (*itab)(nil)
}
func gc_unixnanotime(now *int64) {
sec, nsec := time_now()
*now = sec*1e9 + int64(nsec)
}
//go:linkname runtime_debug_freeOSMemory runtime/debug.freeOSMemory
func runtime_debug_freeOSMemory() {
gogc(2) // force GC and do eager sweep
......
......@@ -19,28 +19,6 @@ func bytes(s string) (ret []byte) {
return
}
// printf is only called from C code. It has no type information for the args,
// but C stacks are ignored by the garbage collector anyway, so having
// type information would not add anything.
//go:nosplit
func printf(s *byte) {
vprintf(gostringnocopy(s), add(unsafe.Pointer(&s), unsafe.Sizeof(s)))
}
// sprintf is only called from C code. It has no type information for the args,
// but C stacks are ignored by the garbage collector anyway, so having
// type information would not add anything.
//go:nosplit
func snprintf(dst *byte, n int32, s *byte) {
buf := (*[1 << 30]byte)(unsafe.Pointer(dst))[0:n:n]
gp := getg()
gp.writebuf = buf[0:0 : n-1] // leave room for NUL, this is called from C
vprintf(gostringnocopy(s), add(unsafe.Pointer(&s), unsafe.Sizeof(s)))
buf[len(gp.writebuf)] = '\x00'
gp.writebuf = nil
}
var debuglock mutex
// The compiler emits calls to printlock and printunlock around
......@@ -85,16 +63,6 @@ func gwrite(b []byte) {
gp.writebuf = gp.writebuf[:len(gp.writebuf)+n]
}
func prints(s *byte) {
b := (*[1 << 30]byte)(unsafe.Pointer(s))
for i := 0; ; i++ {
if b[i] == 0 {
gwrite(b[:i])
return
}
}
}
func printsp() {
print(" ")
}
......@@ -103,92 +71,6 @@ func printnl() {
print("\n")
}
// Very simple printf. Only for debugging prints.
// Do not add to this without checking with Rob.
func vprintf(str string, arg unsafe.Pointer) {
printlock()
s := bytes(str)
start := 0
i := 0
for ; i < len(s); i++ {
if s[i] != '%' {
continue
}
if i > start {
gwrite(s[start:i])
}
if i++; i >= len(s) {
break
}
var siz uintptr
switch s[i] {
case 't', 'c':
siz = 1
case 'd', 'x': // 32-bit
arg = roundup(arg, 4)
siz = 4
case 'D', 'U', 'X', 'f': // 64-bit
arg = roundup(arg, unsafe.Sizeof(uintreg(0)))
siz = 8
case 'C':
arg = roundup(arg, unsafe.Sizeof(uintreg(0)))
siz = 16
case 'p', 's': // pointer-sized
arg = roundup(arg, unsafe.Sizeof(uintptr(0)))
siz = unsafe.Sizeof(uintptr(0))
case 'S': // pointer-aligned but bigger
arg = roundup(arg, unsafe.Sizeof(uintptr(0)))
siz = unsafe.Sizeof(string(""))
case 'a': // pointer-aligned but bigger
arg = roundup(arg, unsafe.Sizeof(uintptr(0)))
siz = unsafe.Sizeof([]byte{})
case 'i', 'e': // pointer-aligned but bigger
arg = roundup(arg, unsafe.Sizeof(uintptr(0)))
siz = unsafe.Sizeof(interface{}(nil))
}
switch s[i] {
case 'a':
printslice(*(*[]byte)(arg))
case 'c':
printbyte(*(*byte)(arg))
case 'd':
printint(int64(*(*int32)(arg)))
case 'D':
printint(int64(*(*int64)(arg)))
case 'e':
printeface(*(*interface{})(arg))
case 'f':
printfloat(*(*float64)(arg))
case 'C':
printcomplex(*(*complex128)(arg))
case 'i':
printiface(*(*fInterface)(arg))
case 'p':
printpointer(*(*unsafe.Pointer)(arg))
case 's':
prints(*(**byte)(arg))
case 'S':
printstring(*(*string)(arg))
case 't':
printbool(*(*bool)(arg))
case 'U':
printuint(*(*uint64)(arg))
case 'x':
printhex(uint64(*(*uint32)(arg)))
case 'X':
printhex(*(*uint64)(arg))
}
arg = add(arg, siz)
start = i + 1
}
if start < i {
gwrite(s[start:i])
}
printunlock()
}
func printpc(p unsafe.Pointer) {
print("PC=", hex(uintptr(p)))
}
......
......@@ -17,12 +17,6 @@ func add(p unsafe.Pointer, x uintptr) unsafe.Pointer {
return unsafe.Pointer(uintptr(p) + x)
}
// n must be a power of 2
func roundup(p unsafe.Pointer, n uintptr) unsafe.Pointer {
delta := -uintptr(p) & (n - 1)
return unsafe.Pointer(uintptr(p) + delta)
}
func getg() *g
// mcall switches from the g to the g0 stack and invokes fn(g),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment