summaryrefslogtreecommitdiff
path: root/src/cmd/gc/reflect.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-09-22 05:53:37 +1000
committerRuss Cox <rsc@golang.org>2012-09-22 05:53:37 +1000
commit678ca8377c884ef24358f09ffc2f4b1f1a368322 (patch)
treea05ec61da85fd6cd5eb73748b65e6ad6b5cd2013 /src/cmd/gc/reflect.c
parent878813f2aab5e8aeae64d8b9f1d0ad6bf31fb701 (diff)
downloadgo-678ca8377c884ef24358f09ffc2f4b1f1a368322.tar.gz
[release-branch.go1] runtime: replace runtime?rnd function with ROUND macro
??? backport 722bb90ae3ee runtime: replace runtime?rnd function with ROUND macro It's sad to introduce a new macro, but rnd shows up consistently in profiles, and the function call overwhelms the two arithmetic instructions it performs. R=r CC=golang-dev http://codereview.appspot.com/6260051 ???
Diffstat (limited to 'src/cmd/gc/reflect.c')
-rw-r--r--src/cmd/gc/reflect.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/cmd/gc/reflect.c b/src/cmd/gc/reflect.c
index 62759bcba..f77697a6b 100644
--- a/src/cmd/gc/reflect.c
+++ b/src/cmd/gc/reflect.c
@@ -19,7 +19,7 @@ static int
sigcmp(Sig *a, Sig *b)
{
int i;
-
+
i = strcmp(a->name, b->name);
if(i != 0)
return i;
@@ -262,12 +262,12 @@ imethods(Type *t)
else
last->link = a;
last = a;
-
+
// Compiler can only refer to wrappers for
// named interface types.
if(t->sym == S)
continue;
-
+
// NOTE(rsc): Perhaps an oversight that
// IfaceType.Method is not in the reflect data.
// Generate the method body, so that compiled
@@ -287,7 +287,7 @@ dimportpath(Pkg *p)
static Pkg *gopkg;
char *nam;
Node *n;
-
+
if(p->pathsym != S)
return;
@@ -303,7 +303,7 @@ dimportpath(Pkg *p)
n->class = PEXTERN;
n->xoffset = 0;
p->pathsym = n->sym;
-
+
gdatastring(n, p->path);
ggloblsym(n->sym, types[TSTRING]->width, 1);
}
@@ -319,7 +319,7 @@ dgopkgpath(Sym *s, int ot, Pkg *pkg)
// that imports this one directly defines the symbol.
if(pkg == localpkg) {
static Sym *ns;
-
+
if(ns == nil)
ns = pkglookup("importpath.\"\".", mkpkg(strlit("go")));
return dsymptr(s, ot, ns, 0);
@@ -343,7 +343,7 @@ dextratype(Sym *sym, int off, Type *t, int ptroff)
m = methods(t);
if(t->sym == nil && m == nil)
return off;
-
+
// fill in *extraType pointer in header
dsymptr(sym, ptroff, sym, off);
@@ -419,7 +419,7 @@ enum {
KindString,
KindStruct,
KindUnsafePointer,
-
+
KindNoPointers = 1<<7,
};
@@ -559,8 +559,16 @@ dcommontype(Sym *s, int ot, Type *t)
ot = duintptr(s, ot, t->width);
ot = duint32(s, ot, typehash(t));
ot = duint8(s, ot, 0); // unused
+
+ // runtime (and common sense) expects alignment to be a power of two.
+ i = t->align;
+ if(i == 0)
+ i = 1;
+ if((i&(i-1)) != 0)
+ fatal("invalid alignment %d for %T", t->align, t);
ot = duint8(s, ot, t->align); // align
ot = duint8(s, ot, t->align); // fieldAlign
+
i = kinds[t->etype];
if(t->etype == TARRAY && t->bound < 0)
i = KindSlice;
@@ -575,7 +583,7 @@ dcommontype(Sym *s, int ot, Type *t)
//print("dcommontype: %s\n", p);
ot = dgostringptr(s, ot, p); // string
free(p);
-
+
// skip pointer to extraType,
// which follows the rest of this type structure.
// caller will fill in if needed.
@@ -680,7 +688,7 @@ dtypesym(Type *t)
tbase = t->type;
dupok = tbase->sym == S;
- if(compiling_runtime &&
+ if(compiling_runtime &&
(tbase == types[tbase->etype] ||
tbase == bytetype ||
tbase == runetype ||
@@ -899,10 +907,10 @@ dumptypestructs(void)
// emit type structs for error and func(error) string.
// The latter is the type of an auto-generated wrapper.
dtypesym(ptrto(errortype));
- dtypesym(functype(nil,
+ dtypesym(functype(nil,
list1(nod(ODCLFIELD, N, typenod(errortype))),
list1(nod(ODCLFIELD, N, typenod(types[TSTRING])))));
-
+
// add paths for runtime and main, which 6l imports implicitly.
dimportpath(runtimepkg);
dimportpath(mkpkg(strlit("main")));