aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-06-30 20:02:07 -0700
committerRuss Cox <rsc@golang.org>2009-06-30 20:02:07 -0700
commit20cfa4a568bc696ac7bccdbffc3f204d7a104010 (patch)
tree35d345d08624390ec45fb6357279df0a5abfa0d5 /src/pkg/runtime
parent150a64572b2a11c8d704ea143ec78a0c7166f8f0 (diff)
downloadgo-20cfa4a568bc696ac7bccdbffc3f204d7a104010.tar.xz
change alignment rules: roll receiver into
input parameters, move output parameters into their own struct. R=ken OCL=30954 CL=30966
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r--src/pkg/runtime/chan.c26
-rw-r--r--src/pkg/runtime/hashmap.c87
2 files changed, 66 insertions, 47 deletions
diff --git a/src/pkg/runtime/chan.c b/src/pkg/runtime/chan.c
index be65bcbc16..de58c40e49 100644
--- a/src/pkg/runtime/chan.c
+++ b/src/pkg/runtime/chan.c
@@ -88,6 +88,10 @@ static uint32 gcd(uint32, uint32);
static uint32 fastrand1(void);
static uint32 fastrand2(void);
+enum {
+ Structrnd = sizeof(uintptr)
+};
+
// newchan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any);
void
sys·newchan(uint32 elemsize, uint32 elemalg, uint32 hint,
@@ -393,7 +397,7 @@ sys·chansend2(Hchan* c, ...)
o = rnd(sizeof(c), c->elemsize);
ae = (byte*)&c + o;
- o = rnd(o+c->elemsize, 1);
+ o = rnd(o+c->elemsize, Structrnd);
ap = (byte*)&c + o;
sendchan(c, ae, ap);
@@ -406,7 +410,7 @@ sys·chanrecv1(Hchan* c, ...)
int32 o;
byte *ae;
- o = rnd(sizeof(c), c->elemsize);
+ o = rnd(sizeof(c), Structrnd);
ae = (byte*)&c + o;
chanrecv(c, ae, nil);
@@ -419,7 +423,7 @@ sys·chanrecv2(Hchan* c, ...)
int32 o;
byte *ae, *ap;
- o = rnd(sizeof(c), c->elemsize);
+ o = rnd(sizeof(c), Structrnd);
ae = (byte*)&c + o;
o = rnd(o+c->elemsize, 1);
ap = (byte*)&c + o;
@@ -436,10 +440,14 @@ sys·chanrecv3(Hchan* c, byte* ep, byte pres)
// newselect(size uint32) (sel *byte);
void
-sys·newselect(int32 size, Select *sel)
+sys·newselect(int32 size, ...)
{
- int32 n;
+ int32 n, o;
+ Select **selp;
+ Select *sel;
+ o = rnd(sizeof(size), Structrnd);
+ selp = (Select**)((byte*)&size + o);
n = 0;
if(size > 1)
n = size-1;
@@ -457,7 +465,7 @@ sys·newselect(int32 size, Select *sel)
sel->tcase = size;
sel->ncase = 0;
- FLUSH(&sel);
+ *selp = sel;
if(debug) {
prints("newselect s=");
sys·printpointer(sel);
@@ -494,7 +502,7 @@ sys·selectsend(Select *sel, Hchan *c, ...)
eo = rnd(sizeof(sel), sizeof(c));
eo = rnd(eo+sizeof(c), c->elemsize);
- cas->so = rnd(eo+c->elemsize, 1);
+ cas->so = rnd(eo+c->elemsize, Structrnd);
cas->send = 1;
ae = (byte*)&sel + eo;
@@ -540,7 +548,7 @@ sys·selectrecv(Select *sel, Hchan *c, ...)
eo = rnd(sizeof(sel), sizeof(c));
eo = rnd(eo+sizeof(c), sizeof(byte*));
- cas->so = rnd(eo+sizeof(byte*), 1);
+ cas->so = rnd(eo+sizeof(byte*), Structrnd);
cas->send = 0;
cas->u.elemp = *(byte**)((byte*)&sel + eo);
@@ -579,7 +587,7 @@ sys·selectdefault(Select *sel, ...)
cas->pc = sys·getcallerpc(&sel);
cas->chan = nil;
- cas->so = rnd(sizeof(sel), 1);
+ cas->so = rnd(sizeof(sel), Structrnd);
cas->send = 2;
cas->u.elemp = nil;
diff --git a/src/pkg/runtime/hashmap.c b/src/pkg/runtime/hashmap.c
index b3022ca149..49448ba780 100644
--- a/src/pkg/runtime/hashmap.c
+++ b/src/pkg/runtime/hashmap.c
@@ -24,9 +24,20 @@ struct hash { /* a hash table; initialize with hash_init() */
uint32 keysize;
uint32 valsize;
uint32 datavo;
- uint32 ko;
- uint32 vo;
- uint32 po;
+
+ // three sets of offsets: the digit counts how many
+ // of key, value are passed as inputs:
+ // 0 = func() (key, value)
+ // 1 = func(key) (value)
+ // 2 = func(key, value)
+ uint32 ko0;
+ uint32 vo0;
+ uint32 ko1;
+ uint32 vo1;
+ uint32 po1;
+ uint32 ko2;
+ uint32 vo2;
+ uint32 po2;
Alg* keyalg;
Alg* valalg;
};
@@ -654,6 +665,10 @@ donothing(uint32 s, void *a, void *b)
typedef struct hash Hmap;
static int32 debug = 0;
+enum {
+ Structrnd = sizeof(uintptr)
+};
+
// newmap(keysize uint32, valsize uint32,
// keyalg uint32, valalg uint32,
// hint uint32) (hmap *map[any]any);
@@ -675,7 +690,7 @@ sys·newmap(uint32 keysize, uint32 valsize,
}
h = mal(sizeof(*h));
-
+
// align value inside data so that mark-sweep gc can find it.
// might remove in the future and just assume datavo == keysize.
h->datavo = keysize;
@@ -692,34 +707,30 @@ sys·newmap(uint32 keysize, uint32 valsize,
h->valsize = valsize;
h->keyalg = &algarray[keyalg];
h->valalg = &algarray[valalg];
-
+
// these calculations are compiler dependent.
// figure out offsets of map call arguments.
- h->ko = rnd(sizeof(h), keysize);
- h->vo = rnd(h->ko+keysize, valsize);
- h->po = rnd(h->vo+valsize, 1);
+
+ // func() (key, val)
+ h->ko0 = rnd(sizeof(h), Structrnd);
+ h->vo0 = rnd(h->ko0+keysize, valsize);
+
+ // func(key) (val[, pres])
+ h->ko1 = rnd(sizeof(h), keysize);
+ h->vo1 = rnd(h->ko1+keysize, Structrnd);
+ h->po1 = rnd(h->vo1+valsize, 1);
+
+ // func(key, val[, pres])
+ h->ko2 = rnd(sizeof(h), keysize);
+ h->vo2 = rnd(h->ko2+keysize, valsize);
+ h->po2 = rnd(h->vo2+valsize, 1);
ret = h;
FLUSH(&ret);
if(debug) {
- prints("newmap: map=");
- sys·printpointer(h);
- prints("; keysize=");
- sys·printint(keysize);
- prints("; valsize=");
- sys·printint(valsize);
- prints("; keyalg=");
- sys·printint(keyalg);
- prints("; valalg=");
- sys·printint(valalg);
- prints("; ko=");
- sys·printint(h->ko);
- prints("; vo=");
- sys·printint(h->vo);
- prints("; po=");
- sys·printint(h->po);
- prints("\n");
+ printf("newmap: map=%p; keysize=%d; valsize=%d; keyalg=%d; valalg=%d; offsets=%d,%d; %d,%d,%d; %d,%d,%d\n",
+ h, keysize, valsize, keyalg, valalg, h->ko0, h->vo0, h->ko1, h->vo1, h->po1, h->ko2, h->vo2, h->po2);
}
}
@@ -731,8 +742,8 @@ sys·mapaccess1(Hmap *h, ...)
byte *res;
int32 hit;
- ak = (byte*)&h + h->ko;
- av = (byte*)&h + h->vo;
+ ak = (byte*)&h + h->ko1;
+ av = (byte*)&h + h->vo1;
res = nil;
hit = hash_lookup(h, ak, (void**)&res);
@@ -763,9 +774,9 @@ sys·mapaccess2(Hmap *h, ...)
byte *res;
int32 hit;
- ak = (byte*)&h + h->ko;
- av = (byte*)&h + h->vo;
- ap = (byte*)&h + h->po;
+ ak = (byte*)&h + h->ko1;
+ av = (byte*)&h + h->vo1;
+ ap = (byte*)&h + h->po1;
res = nil;
hit = hash_lookup(h, ak, (void**)&res);
@@ -826,8 +837,8 @@ sys·mapassign1(Hmap *h, ...)
{
byte *ak, *av;
- ak = (byte*)&h + h->ko;
- av = (byte*)&h + h->vo;
+ ak = (byte*)&h + h->ko2;
+ av = (byte*)&h + h->vo2;
mapassign(h, ak, av);
}
@@ -840,9 +851,9 @@ sys·mapassign2(Hmap *h, ...)
byte *res;
int32 hit;
- ak = (byte*)&h + h->ko;
- av = (byte*)&h + h->vo;
- ap = (byte*)&h + h->po;
+ ak = (byte*)&h + h->ko2;
+ av = (byte*)&h + h->vo2;
+ ap = (byte*)&h + h->po2;
if(*ap == true) {
// assign
@@ -909,7 +920,7 @@ sys·mapiter1(struct hash_iter *it, ...)
byte *ak, *res;
h = it->h;
- ak = (byte*)&it + h->ko;
+ ak = (byte*)&it + h->ko0;
res = it->data;
if(res == nil)
@@ -934,8 +945,8 @@ sys·mapiter2(struct hash_iter *it, ...)
byte *ak, *av, *res;
h = it->h;
- ak = (byte*)&it + h->ko;
- av = (byte*)&it + h->vo;
+ ak = (byte*)&it + h->ko0;
+ av = (byte*)&it + h->vo0;
res = it->data;
if(res == nil)