]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: delete dead code called from C.
authorRuss Cox <rsc@golang.org>
Wed, 14 Jan 2015 21:41:39 +0000 (16:41 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 14 Jan 2015 22:20:44 +0000 (22:20 +0000)
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/2824
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/mgc.go
src/runtime/mgc0.go
src/runtime/print1.go
src/runtime/stubs.go

index 3b086db9b43a395a7f523dd61c06b70372b821ab..9f2eb0570a74d7d4784feadb1efe60690cbdf50f 100644 (file)
@@ -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)
 }
index 614055c941ea4ed28bb591c1830fa892f28b8281..d2b51cad943432094df1246234f4bf3f94bea6a6 100644 (file)
@@ -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
index e717c9879949a43a8fa53bbfa8be5779c8ed971d..ba5799182a114635ea1c77586f2b334524a1ef9e 100644 (file)
@@ -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)))
 }
index 1114a09c28f2254732e9a623edf47434592c9fcc..d198f02e600edec80e12335cfa9d1e7ae933d879 100644 (file)
@@ -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),