aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2016-10-12 18:17:52 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-10-12 18:17:52 +0000
commit1ad16c52842e0513b96a0e02d2a431dc0f338c5d (patch)
treef6eaddf65fba9d031ed9b3008a3c3ba4ff0ebd0b /libgo/runtime
parent2ec69f566076547b618447ba5531260c25abed3e (diff)
downloadgcc-1ad16c52842e0513b96a0e02d2a431dc0f338c5d.zip
gcc-1ad16c52842e0513b96a0e02d2a431dc0f338c5d.tar.gz
gcc-1ad16c52842e0513b96a0e02d2a431dc0f338c5d.tar.bz2
compiler, runtime: copy string code from Go 1.7
Add compiler support for turning concatenating strings into a call to a runtime function that takes the appropriate number of arguments. Rename some local variables in mgc0.c to avoid macros that the new rune.go causes to appear in runtime.inc. Reviewed-on: https://go-review.googlesource.com/30827 From-SVN: r241074
Diffstat (limited to 'libgo/runtime')
-rw-r--r--libgo/runtime/go-byte-array-to-string.c24
-rw-r--r--libgo/runtime/go-int-array-to-string.c89
-rw-r--r--libgo/runtime/go-int-to-string.c69
-rw-r--r--libgo/runtime/go-rune.c97
-rw-r--r--libgo/runtime/go-string-to-byte-array.c28
-rw-r--r--libgo/runtime/go-string-to-int-array.c56
-rw-r--r--libgo/runtime/go-strplus.c30
-rw-r--r--libgo/runtime/malloc.h3
-rw-r--r--libgo/runtime/mgc0.c26
-rw-r--r--libgo/runtime/runtime.h8
-rw-r--r--libgo/runtime/string.goc123
11 files changed, 19 insertions, 534 deletions
diff --git a/libgo/runtime/go-byte-array-to-string.c b/libgo/runtime/go-byte-array-to-string.c
deleted file mode 100644
index 088b786..0000000
--- a/libgo/runtime/go-byte-array-to-string.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* go-byte-array-to-string.c -- convert an array of bytes to a string in Go.
-
- Copyright 2009 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. */
-
-#include "runtime.h"
-#include "arch.h"
-#include "malloc.h"
-
-String
-__go_byte_array_to_string (const void* p, intgo len)
-{
- const unsigned char *bytes;
- unsigned char *retdata;
- String ret;
-
- bytes = (const unsigned char *) p;
- retdata = runtime_mallocgc ((uintptr) len, 0, FlagNoScan);
- __builtin_memcpy (retdata, bytes, len);
- ret.str = retdata;
- ret.len = len;
- return ret;
-}
diff --git a/libgo/runtime/go-int-array-to-string.c b/libgo/runtime/go-int-array-to-string.c
deleted file mode 100644
index f372131..0000000
--- a/libgo/runtime/go-int-array-to-string.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/* go-int-array-to-string.c -- convert an array of ints to a string in Go.
-
- Copyright 2009 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. */
-
-#include "go-assert.h"
-#include "runtime.h"
-#include "arch.h"
-#include "malloc.h"
-
-String
-__go_int_array_to_string (const void* p, intgo len)
-{
- const int32 *ints;
- intgo slen;
- intgo i;
- unsigned char *retdata;
- String ret;
- unsigned char *s;
-
- ints = (const int32 *) p;
-
- slen = 0;
- for (i = 0; i < len; ++i)
- {
- int32 v;
-
- v = ints[i];
-
- if (v < 0 || v > 0x10ffff)
- v = 0xfffd;
- else if (0xd800 <= v && v <= 0xdfff)
- v = 0xfffd;
-
- if (v <= 0x7f)
- slen += 1;
- else if (v <= 0x7ff)
- slen += 2;
- else if (v <= 0xffff)
- slen += 3;
- else
- slen += 4;
- }
-
- retdata = runtime_mallocgc ((uintptr) slen, 0, FlagNoScan);
- ret.str = retdata;
- ret.len = slen;
-
- s = retdata;
- for (i = 0; i < len; ++i)
- {
- int32 v;
-
- v = ints[i];
-
- /* If V is out of range for UTF-8, substitute the replacement
- character. */
- if (v < 0 || v > 0x10ffff)
- v = 0xfffd;
- else if (0xd800 <= v && v <= 0xdfff)
- v = 0xfffd;
-
- if (v <= 0x7f)
- *s++ = v;
- else if (v <= 0x7ff)
- {
- *s++ = 0xc0 | ((v >> 6) & 0x1f);
- *s++ = 0x80 | (v & 0x3f);
- }
- else if (v <= 0xffff)
- {
- *s++ = 0xe0 | ((v >> 12) & 0xf);
- *s++ = 0x80 | ((v >> 6) & 0x3f);
- *s++ = 0x80 | (v & 0x3f);
- }
- else
- {
- *s++ = 0xf0 | ((v >> 18) & 0x7);
- *s++ = 0x80 | ((v >> 12) & 0x3f);
- *s++ = 0x80 | ((v >> 6) & 0x3f);
- *s++ = 0x80 | (v & 0x3f);
- }
- }
-
- __go_assert (s - retdata == slen);
-
- return ret;
-}
diff --git a/libgo/runtime/go-int-to-string.c b/libgo/runtime/go-int-to-string.c
deleted file mode 100644
index d90b1dd..0000000
--- a/libgo/runtime/go-int-to-string.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* go-int-to-string.c -- convert an integer to a string in Go.
-
- Copyright 2009 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. */
-
-#include "runtime.h"
-#include "arch.h"
-#include "malloc.h"
-
-String
-__go_int_to_string (intgo v)
-{
- char buf[4];
- int len;
- unsigned char *retdata;
- String ret;
-
- /* A negative value is not valid UTF-8; turn it into the replacement
- character. */
- if (v < 0)
- v = 0xfffd;
-
- if (v <= 0x7f)
- {
- buf[0] = v;
- len = 1;
- }
- else if (v <= 0x7ff)
- {
- buf[0] = 0xc0 + (v >> 6);
- buf[1] = 0x80 + (v & 0x3f);
- len = 2;
- }
- else
- {
- /* If the value is out of range for UTF-8, turn it into the
- "replacement character". */
- if (v > 0x10ffff)
- v = 0xfffd;
- /* If the value is a surrogate pair, which is invalid in UTF-8,
- turn it into the replacement character. */
- if (v >= 0xd800 && v < 0xe000)
- v = 0xfffd;
-
- if (v <= 0xffff)
- {
- buf[0] = 0xe0 + (v >> 12);
- buf[1] = 0x80 + ((v >> 6) & 0x3f);
- buf[2] = 0x80 + (v & 0x3f);
- len = 3;
- }
- else
- {
- buf[0] = 0xf0 + (v >> 18);
- buf[1] = 0x80 + ((v >> 12) & 0x3f);
- buf[2] = 0x80 + ((v >> 6) & 0x3f);
- buf[3] = 0x80 + (v & 0x3f);
- len = 4;
- }
- }
-
- retdata = runtime_mallocgc (len, 0, FlagNoScan);
- __builtin_memcpy (retdata, buf, len);
- ret.str = retdata;
- ret.len = len;
-
- return ret;
-}
diff --git a/libgo/runtime/go-rune.c b/libgo/runtime/go-rune.c
deleted file mode 100644
index 4c65e21..0000000
--- a/libgo/runtime/go-rune.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/* go-rune.c -- rune functions for Go.
-
- Copyright 2009, 2010 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. */
-
-#include <stddef.h>
-
-#include "runtime.h"
-#include "go-string.h"
-
-/* Get a character from the UTF-8 string STR, of length LEN. Store
- the Unicode character, if any, in *RUNE. Return the number of
- characters used from STR. */
-
-int
-__go_get_rune (const unsigned char *str, size_t len, int32 *rune)
-{
- int c, c1, c2, c3, l;
-
- /* Default to the "replacement character". */
- *rune = 0xfffd;
-
- if (len <= 0)
- return 1;
-
- c = *str;
- if (c <= 0x7f)
- {
- *rune = c;
- return 1;
- }
-
- if (len <= 1)
- return 1;
-
- c1 = str[1];
- if ((c & 0xe0) == 0xc0
- && (c1 & 0xc0) == 0x80)
- {
- l = (((c & 0x1f) << 6) + (c1 & 0x3f));
- if (l <= 0x7f)
- return 1;
- *rune = l;
- return 2;
- }
-
- if (len <= 2)
- return 1;
-
- c2 = str[2];
- if ((c & 0xf0) == 0xe0
- && (c1 & 0xc0) == 0x80
- && (c2 & 0xc0) == 0x80)
- {
- l = (((c & 0xf) << 12)
- + ((c1 & 0x3f) << 6)
- + (c2 & 0x3f));
-
- if (l <= 0x7ff)
- return 1;
-
- if (l >= 0xd800 && l < 0xe000)
- {
- /* Invalid surrogate half; return replace character. */
- return 1;
- }
-
- *rune = l;
-
- return 3;
- }
-
- if (len <= 3)
- return 1;
-
- c3 = str[3];
- if ((c & 0xf8) == 0xf0
- && (c1 & 0xc0) == 0x80
- && (c2 & 0xc0) == 0x80
- && (c3 & 0xc0) == 0x80)
- {
- l = (((c & 0x7) << 18)
- + ((c1 & 0x3f) << 12)
- + ((c2 & 0x3f) << 6)
- + (c3 & 0x3f));
-
- if (l <= 0xffff || l > 0x10ffff)
- return 1;
-
- *rune = l;
- return 4;
- }
-
- /* Invalid encoding. Return 1 so that we advance. */
- return 1;
-}
diff --git a/libgo/runtime/go-string-to-byte-array.c b/libgo/runtime/go-string-to-byte-array.c
deleted file mode 100644
index 61591eb..0000000
--- a/libgo/runtime/go-string-to-byte-array.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/* go-string-to-byte-array.c -- convert a string to an array of bytes in Go.
-
- Copyright 2010 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. */
-
-#include "runtime.h"
-#include "array.h"
-#include "arch.h"
-#include "malloc.h"
-
-struct __go_open_array
-__go_string_to_byte_array (String str)
-{
- uintptr cap;
- unsigned char *data;
- struct __go_open_array ret;
-
- cap = runtime_roundupsize (str.len);
- data = (unsigned char *) runtime_mallocgc (cap, 0, FlagNoScan | FlagNoZero);
- __builtin_memcpy (data, str.str, str.len);
- if (cap != (uintptr) str.len)
- __builtin_memset (data + str.len, 0, cap - (uintptr) str.len);
- ret.__values = (void *) data;
- ret.__count = str.len;
- ret.__capacity = str.len;
- return ret;
-}
diff --git a/libgo/runtime/go-string-to-int-array.c b/libgo/runtime/go-string-to-int-array.c
deleted file mode 100644
index 5546889..0000000
--- a/libgo/runtime/go-string-to-int-array.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/* go-string-to-int-array.c -- convert a string to an array of ints in Go.
-
- Copyright 2010 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. */
-
-#include "runtime.h"
-#include "go-alloc.h"
-#include "go-string.h"
-#include "array.h"
-#include "arch.h"
-#include "malloc.h"
-
-struct __go_open_array
-__go_string_to_int_array (String str)
-{
- size_t c;
- const unsigned char *p;
- const unsigned char *pend;
- uintptr mem;
- uint32_t *data;
- uint32_t *pd;
- struct __go_open_array ret;
-
- c = 0;
- p = str.str;
- pend = p + str.len;
- while (p < pend)
- {
- int rune;
-
- ++c;
- p += __go_get_rune (p, pend - p, &rune);
- }
-
- if (c > MaxMem / sizeof (uint32_t))
- runtime_throw ("out of memory");
-
- mem = runtime_roundupsize (c * sizeof (uint32_t));
- data = (uint32_t *) runtime_mallocgc (mem, 0, FlagNoScan | FlagNoZero);
- p = str.str;
- pd = data;
- while (p < pend)
- {
- int rune;
-
- p += __go_get_rune (p, pend - p, &rune);
- *pd++ = rune;
- }
- if (mem > (uintptr) c * sizeof (uint32_t))
- __builtin_memset (data + c, 0, mem - (uintptr) c * sizeof (uint32_t));
- ret.__values = (void *) data;
- ret.__count = c;
- ret.__capacity = (intgo) (mem / sizeof (uint32_t));
- return ret;
-}
diff --git a/libgo/runtime/go-strplus.c b/libgo/runtime/go-strplus.c
deleted file mode 100644
index 13915e3..0000000
--- a/libgo/runtime/go-strplus.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* go-strplus.c -- the go string append function.
-
- Copyright 2009 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. */
-
-#include "runtime.h"
-#include "arch.h"
-#include "malloc.h"
-
-String
-__go_string_plus (String s1, String s2)
-{
- int len;
- byte *retdata;
- String ret;
-
- if (s1.len == 0)
- return s2;
- else if (s2.len == 0)
- return s1;
-
- len = s1.len + s2.len;
- retdata = runtime_mallocgc (len, 0, FlagNoScan | FlagNoZero);
- __builtin_memcpy (retdata, s1.str, s1.len);
- __builtin_memcpy (retdata + s1.len, s2.str, s2.len);
- ret.str = retdata;
- ret.len = len;
- return ret;
-}
diff --git a/libgo/runtime/malloc.h b/libgo/runtime/malloc.h
index 1efbbbe..b2dbf90 100644
--- a/libgo/runtime/malloc.h
+++ b/libgo/runtime/malloc.h
@@ -285,7 +285,8 @@ void runtime_updatememstats(GCStats *stats);
// making new objects in class i
int32 runtime_SizeToClass(int32);
-uintptr runtime_roundupsize(uintptr);
+uintptr runtime_roundupsize(uintptr)
+ __asm__(GOSYM_PREFIX "runtime.roundupsize");
extern int32 runtime_class_to_size[_NumSizeClasses];
extern int32 runtime_class_to_allocnpages[_NumSizeClasses];
extern int8 runtime_size_to_class8[1024/8 + 1];
diff --git a/libgo/runtime/mgc0.c b/libgo/runtime/mgc0.c
index ac6e396..0044821 100644
--- a/libgo/runtime/mgc0.c
+++ b/libgo/runtime/mgc0.c
@@ -2216,7 +2216,7 @@ static void
gc(struct gc_args *args)
{
M *m;
- int64 t0, t1, t2, t3, t4;
+ int64 tm0, tm1, tm2, tm3, tm4;
uint64 heap0, heap1, obj, ninstr;
GCStats stats;
uint32 i;
@@ -2228,7 +2228,7 @@ gc(struct gc_args *args)
runtime_tracegc();
m->traceback = 2;
- t0 = args->start_time;
+ tm0 = args->start_time;
work.tstart = args->start_time;
if(CollectStats)
@@ -2239,9 +2239,9 @@ gc(struct gc_args *args)
work.markfor = runtime_parforalloc(MaxGcproc);
m->locks--;
- t1 = 0;
+ tm1 = 0;
if(runtime_debug.gctrace)
- t1 = runtime_nanotime();
+ tm1 = runtime_nanotime();
// Sweep what is not sweeped by bgsweep.
while(runtime_sweepone() != (uintptr)-1)
@@ -2256,17 +2256,17 @@ gc(struct gc_args *args)
runtime_helpgc(work.nproc);
}
- t2 = 0;
+ tm2 = 0;
if(runtime_debug.gctrace)
- t2 = runtime_nanotime();
+ tm2 = runtime_nanotime();
gchelperstart();
runtime_parfordo(work.markfor);
scanblock(nil, true);
- t3 = 0;
+ tm3 = 0;
if(runtime_debug.gctrace)
- t3 = runtime_nanotime();
+ tm3 = runtime_nanotime();
bufferList[m->helpgc].busy = 0;
if(work.nproc > 1)
@@ -2280,14 +2280,14 @@ gc(struct gc_args *args)
// concurrent/lazy sweep will reduce this number while discovering new garbage
mstats.next_gc = mstats.heap_alloc+(mstats.heap_alloc-runtime_stacks_sys)*gcpercent/100;
- t4 = runtime_nanotime();
+ tm4 = runtime_nanotime();
mstats.last_gc = runtime_unixnanotime(); // must be Unix time to make sense to user
- mstats.pause_ns[mstats.numgc%nelem(mstats.pause_ns)] = t4 - t0;
+ mstats.pause_ns[mstats.numgc%nelem(mstats.pause_ns)] = tm4 - tm0;
mstats.pause_end[mstats.numgc%nelem(mstats.pause_end)] = mstats.last_gc;
- mstats.pause_total_ns += t4 - t0;
+ mstats.pause_total_ns += tm4 - tm0;
mstats.numgc++;
if(mstats.debuggc)
- runtime_printf("pause %D\n", t4-t0);
+ runtime_printf("pause %D\n", tm4-tm0);
if(runtime_debug.gctrace) {
heap1 = mstats.heap_alloc;
@@ -2305,7 +2305,7 @@ gc(struct gc_args *args)
runtime_printf("gc%d(%d): %D+%D+%D+%D us, %D -> %D MB, %D (%D-%D) objects,"
" %d/%d/%d sweeps,"
" %D(%D) handoff, %D(%D) steal, %D/%D/%D yields\n",
- mstats.numgc, work.nproc, (t1-t0)/1000, (t2-t1)/1000, (t3-t2)/1000, (t4-t3)/1000,
+ mstats.numgc, work.nproc, (tm1-tm0)/1000, (tm2-tm1)/1000, (tm3-tm2)/1000, (tm4-tm3)/1000,
heap0>>20, heap1>>20, obj,
mstats.nmalloc, mstats.nfree,
sweep.nspan, gcstats.nbgsweep, gcstats.npausesweep,
diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h
index 69d2f5a..8c12265 100644
--- a/libgo/runtime/runtime.h
+++ b/libgo/runtime/runtime.h
@@ -307,8 +307,8 @@ extern bool runtime_isarchive;
#define runtime_strcmp(s1, s2) __builtin_strcmp((s1), (s2))
#define runtime_strncmp(s1, s2, n) __builtin_strncmp((s1), (s2), (n))
#define runtime_strstr(s1, s2) __builtin_strstr((s1), (s2))
-intgo runtime_findnull(const byte*);
-intgo runtime_findnullw(const uint16*);
+intgo runtime_findnull(const byte*)
+ __asm__ (GOSYM_PREFIX "runtime.findnull");
void runtime_gogo(G*);
struct __go_func_type;
@@ -328,8 +328,8 @@ int32 runtime_snprintf(byte*, int32, const char*, ...);
#define runtime_mcmp(a, b, s) __builtin_memcmp((a), (b), (s))
#define runtime_memmove(a, b, s) __builtin_memmove((a), (b), (s))
void* runtime_mal(uintptr);
-String runtime_gostring(const byte*);
-String runtime_gostringnocopy(const byte*);
+String runtime_gostringnocopy(const byte*)
+ __asm__ (GOSYM_PREFIX "runtime.gostringnocopy");
void runtime_schedinit(void);
void runtime_initsig(bool);
void runtime_sigenable(uint32 sig);
diff --git a/libgo/runtime/string.goc b/libgo/runtime/string.goc
deleted file mode 100644
index 0ad180b..0000000
--- a/libgo/runtime/string.goc
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright 2009, 2010 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 runtime
-#include "runtime.h"
-#include "arch.h"
-#include "malloc.h"
-#include "go-string.h"
-
-#define charntorune(pv, str, len) __go_get_rune(str, len, pv)
-
-const String runtime_emptystring;
-
-intgo
-runtime_findnull(const byte *s)
-{
- if(s == nil)
- return 0;
- return __builtin_strlen((const char*) s);
-}
-
-intgo
-runtime_findnullw(const uint16 *s)
-{
- intgo l;
-
- if(s == nil)
- return 0;
- for(l=0; s[l]!=0; l++)
- ;
- return l;
-}
-
-static String
-gostringsize(intgo l, byte** pmem)
-{
- String s;
- byte *mem;
-
- if(l == 0) {
- *pmem = nil;
- return runtime_emptystring;
- }
- mem = runtime_mallocgc(l, 0, FlagNoScan|FlagNoZero);
- s.str = mem;
- s.len = l;
- *pmem = mem;
- return s;
-}
-
-String
-runtime_gostring(const byte *str)
-{
- intgo l;
- String s;
- byte *mem;
-
- l = runtime_findnull(str);
- s = gostringsize(l, &mem);
- runtime_memmove(mem, str, l);
- return s;
-}
-
-String
-runtime_gostringnocopy(const byte *str)
-{
- String s;
-
- s.str = str;
- s.len = runtime_findnull(str);
- return s;
-}
-
-func cstringToGo(str *byte) (s String) {
- s = runtime_gostringnocopy(str);
-}
-
-enum
-{
- Runeself = 0x80,
-};
-
-func stringiter(s String, k int) (retk int) {
- int32 l;
-
- if(k >= s.len) {
- // retk=0 is end of iteration
- retk = 0;
- goto out;
- }
-
- l = s.str[k];
- if(l < Runeself) {
- retk = k+1;
- goto out;
- }
-
- // multi-char rune
- retk = k + charntorune(&l, s.str+k, s.len-k);
-
-out:
-}
-
-func stringiter2(s String, k int) (retk int, retv int32) {
- if(k >= s.len) {
- // retk=0 is end of iteration
- retk = 0;
- retv = 0;
- goto out;
- }
-
- retv = s.str[k];
- if(retv < Runeself) {
- retk = k+1;
- goto out;
- }
-
- // multi-char rune
- retk = k + charntorune(&retv, s.str+k, s.len-k);
-
-out:
-}