1
0
mirror of https://github.com/golang/go synced 2024-11-20 01:24:43 -07:00

change alignment rules: roll receiver into

input parameters, move output parameters
into their own struct.

R=ken
OCL=30954
CL=30966
This commit is contained in:
Russ Cox 2009-06-30 20:02:07 -07:00
parent 150a64572b
commit 20cfa4a568
3 changed files with 68 additions and 49 deletions

View File

@ -194,8 +194,8 @@ dowidth(Type *t)
case TFUNC: case TFUNC:
// function is 3 cated structures; // function is 3 cated structures;
// compute their widths as side-effect. // compute their widths as side-effect.
w = widstruct(*getthis(t), 0, 1); w = widstruct(*getthis(t), 0, 0);
w = widstruct(*getinarg(t), w, 0); w = widstruct(*getinarg(t), w, 1);
w = widstruct(*getoutarg(t), w, 1); w = widstruct(*getoutarg(t), w, 1);
t->argwid = w; t->argwid = w;

View File

@ -88,6 +88,10 @@ static uint32 gcd(uint32, uint32);
static uint32 fastrand1(void); static uint32 fastrand1(void);
static uint32 fastrand2(void); static uint32 fastrand2(void);
enum {
Structrnd = sizeof(uintptr)
};
// newchan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any); // newchan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any);
void void
sys·newchan(uint32 elemsize, uint32 elemalg, uint32 hint, sys·newchan(uint32 elemsize, uint32 elemalg, uint32 hint,
@ -393,7 +397,7 @@ sys·chansend2(Hchan* c, ...)
o = rnd(sizeof(c), c->elemsize); o = rnd(sizeof(c), c->elemsize);
ae = (byte*)&c + o; ae = (byte*)&c + o;
o = rnd(o+c->elemsize, 1); o = rnd(o+c->elemsize, Structrnd);
ap = (byte*)&c + o; ap = (byte*)&c + o;
sendchan(c, ae, ap); sendchan(c, ae, ap);
@ -406,7 +410,7 @@ sys·chanrecv1(Hchan* c, ...)
int32 o; int32 o;
byte *ae; byte *ae;
o = rnd(sizeof(c), c->elemsize); o = rnd(sizeof(c), Structrnd);
ae = (byte*)&c + o; ae = (byte*)&c + o;
chanrecv(c, ae, nil); chanrecv(c, ae, nil);
@ -419,7 +423,7 @@ sys·chanrecv2(Hchan* c, ...)
int32 o; int32 o;
byte *ae, *ap; byte *ae, *ap;
o = rnd(sizeof(c), c->elemsize); o = rnd(sizeof(c), Structrnd);
ae = (byte*)&c + o; ae = (byte*)&c + o;
o = rnd(o+c->elemsize, 1); o = rnd(o+c->elemsize, 1);
ap = (byte*)&c + o; ap = (byte*)&c + o;
@ -436,10 +440,14 @@ sys·chanrecv3(Hchan* c, byte* ep, byte pres)
// newselect(size uint32) (sel *byte); // newselect(size uint32) (sel *byte);
void 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; n = 0;
if(size > 1) if(size > 1)
n = size-1; n = size-1;
@ -457,7 +465,7 @@ sys·newselect(int32 size, Select *sel)
sel->tcase = size; sel->tcase = size;
sel->ncase = 0; sel->ncase = 0;
FLUSH(&sel); *selp = sel;
if(debug) { if(debug) {
prints("newselect s="); prints("newselect s=");
sys·printpointer(sel); sys·printpointer(sel);
@ -494,7 +502,7 @@ sys·selectsend(Select *sel, Hchan *c, ...)
eo = rnd(sizeof(sel), sizeof(c)); eo = rnd(sizeof(sel), sizeof(c));
eo = rnd(eo+sizeof(c), c->elemsize); eo = rnd(eo+sizeof(c), c->elemsize);
cas->so = rnd(eo+c->elemsize, 1); cas->so = rnd(eo+c->elemsize, Structrnd);
cas->send = 1; cas->send = 1;
ae = (byte*)&sel + eo; ae = (byte*)&sel + eo;
@ -540,7 +548,7 @@ sys·selectrecv(Select *sel, Hchan *c, ...)
eo = rnd(sizeof(sel), sizeof(c)); eo = rnd(sizeof(sel), sizeof(c));
eo = rnd(eo+sizeof(c), sizeof(byte*)); 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->send = 0;
cas->u.elemp = *(byte**)((byte*)&sel + eo); cas->u.elemp = *(byte**)((byte*)&sel + eo);
@ -579,7 +587,7 @@ sys·selectdefault(Select *sel, ...)
cas->pc = sys·getcallerpc(&sel); cas->pc = sys·getcallerpc(&sel);
cas->chan = nil; cas->chan = nil;
cas->so = rnd(sizeof(sel), 1); cas->so = rnd(sizeof(sel), Structrnd);
cas->send = 2; cas->send = 2;
cas->u.elemp = nil; cas->u.elemp = nil;

View File

@ -24,9 +24,20 @@ struct hash { /* a hash table; initialize with hash_init() */
uint32 keysize; uint32 keysize;
uint32 valsize; uint32 valsize;
uint32 datavo; uint32 datavo;
uint32 ko;
uint32 vo; // three sets of offsets: the digit counts how many
uint32 po; // 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* keyalg;
Alg* valalg; Alg* valalg;
}; };
@ -654,6 +665,10 @@ donothing(uint32 s, void *a, void *b)
typedef struct hash Hmap; typedef struct hash Hmap;
static int32 debug = 0; static int32 debug = 0;
enum {
Structrnd = sizeof(uintptr)
};
// newmap(keysize uint32, valsize uint32, // newmap(keysize uint32, valsize uint32,
// keyalg uint32, valalg uint32, // keyalg uint32, valalg uint32,
// hint uint32) (hmap *map[any]any); // hint uint32) (hmap *map[any]any);
@ -675,7 +690,7 @@ sys·newmap(uint32 keysize, uint32 valsize,
} }
h = mal(sizeof(*h)); h = mal(sizeof(*h));
// align value inside data so that mark-sweep gc can find it. // align value inside data so that mark-sweep gc can find it.
// might remove in the future and just assume datavo == keysize. // might remove in the future and just assume datavo == keysize.
h->datavo = keysize; h->datavo = keysize;
@ -692,34 +707,30 @@ sys·newmap(uint32 keysize, uint32 valsize,
h->valsize = valsize; h->valsize = valsize;
h->keyalg = &algarray[keyalg]; h->keyalg = &algarray[keyalg];
h->valalg = &algarray[valalg]; h->valalg = &algarray[valalg];
// these calculations are compiler dependent. // these calculations are compiler dependent.
// figure out offsets of map call arguments. // figure out offsets of map call arguments.
h->ko = rnd(sizeof(h), keysize);
h->vo = rnd(h->ko+keysize, valsize); // func() (key, val)
h->po = rnd(h->vo+valsize, 1); 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; ret = h;
FLUSH(&ret); FLUSH(&ret);
if(debug) { if(debug) {
prints("newmap: map="); printf("newmap: map=%p; keysize=%d; valsize=%d; keyalg=%d; valalg=%d; offsets=%d,%d; %d,%d,%d; %d,%d,%d\n",
sys·printpointer(h); h, keysize, valsize, keyalg, valalg, h->ko0, h->vo0, h->ko1, h->vo1, h->po1, h->ko2, h->vo2, h->po2);
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");
} }
} }
@ -731,8 +742,8 @@ sys·mapaccess1(Hmap *h, ...)
byte *res; byte *res;
int32 hit; int32 hit;
ak = (byte*)&h + h->ko; ak = (byte*)&h + h->ko1;
av = (byte*)&h + h->vo; av = (byte*)&h + h->vo1;
res = nil; res = nil;
hit = hash_lookup(h, ak, (void**)&res); hit = hash_lookup(h, ak, (void**)&res);
@ -763,9 +774,9 @@ sys·mapaccess2(Hmap *h, ...)
byte *res; byte *res;
int32 hit; int32 hit;
ak = (byte*)&h + h->ko; ak = (byte*)&h + h->ko1;
av = (byte*)&h + h->vo; av = (byte*)&h + h->vo1;
ap = (byte*)&h + h->po; ap = (byte*)&h + h->po1;
res = nil; res = nil;
hit = hash_lookup(h, ak, (void**)&res); hit = hash_lookup(h, ak, (void**)&res);
@ -826,8 +837,8 @@ sys·mapassign1(Hmap *h, ...)
{ {
byte *ak, *av; byte *ak, *av;
ak = (byte*)&h + h->ko; ak = (byte*)&h + h->ko2;
av = (byte*)&h + h->vo; av = (byte*)&h + h->vo2;
mapassign(h, ak, av); mapassign(h, ak, av);
} }
@ -840,9 +851,9 @@ sys·mapassign2(Hmap *h, ...)
byte *res; byte *res;
int32 hit; int32 hit;
ak = (byte*)&h + h->ko; ak = (byte*)&h + h->ko2;
av = (byte*)&h + h->vo; av = (byte*)&h + h->vo2;
ap = (byte*)&h + h->po; ap = (byte*)&h + h->po2;
if(*ap == true) { if(*ap == true) {
// assign // assign
@ -909,7 +920,7 @@ sys·mapiter1(struct hash_iter *it, ...)
byte *ak, *res; byte *ak, *res;
h = it->h; h = it->h;
ak = (byte*)&it + h->ko; ak = (byte*)&it + h->ko0;
res = it->data; res = it->data;
if(res == nil) if(res == nil)
@ -934,8 +945,8 @@ sys·mapiter2(struct hash_iter *it, ...)
byte *ak, *av, *res; byte *ak, *av, *res;
h = it->h; h = it->h;
ak = (byte*)&it + h->ko; ak = (byte*)&it + h->ko0;
av = (byte*)&it + h->vo; av = (byte*)&it + h->vo0;
res = it->data; res = it->data;
if(res == nil) if(res == nil)