6 swit1(C1 *q, int nc, long def, Node *n)
10 regalloc(&tn, ®node, Z);
11 swit2(q, nc, def, n, &tn);
16 swit2(C1 *q, int nc, long def, Node *n, Node *tn)
25 gopcode(OEQ, n, Z, nodconst(q->val));
27 gopcode(OSUB, nodconst(q->val), n, tn);
28 gopcode(OEQ, tn, Z, nodconst(0));
40 gopcode(OGT, n, Z, nodconst(r->val));
43 gopcode(OSUB, nodconst(r->val), n, tn);
44 gopcode(OGT, tn, Z, nodconst(0));
50 swit2(q, i, def, n, tn);
53 swit2(r+1, nc-i-1, def, n, tn);
57 bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
64 * n1 gets adjusted/masked value
65 * n2 gets address of cell
66 * n3 gets contents of cell
73 gopcode(OAS, n2, Z, n3);
74 gopcode(OAS, n3, Z, n1);
79 if(b->type->shift == 0 && typeu[b->type->etype]) {
80 v = ~0 + (1L << b->type->nbits);
81 gopcode(OAND, nodconst(v), Z, n1);
83 sh = 32 - b->type->shift - b->type->nbits;
85 gopcode(OASHL, nodconst(sh), Z, n1);
88 if(typeu[b->type->etype])
89 gopcode(OLSHR, nodconst(sh), Z, n1);
91 gopcode(OASHR, nodconst(sh), Z, n1);
96 bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
103 * n1 has adjusted/masked value
104 * n2 has address of cell
105 * n3 has contents of cell
108 regalloc(&nod, l, Z);
109 v = ~0 + (1L << b->type->nbits);
110 gopcode(OAND, nodconst(v), Z, n1);
111 gopcode(OAS, n1, Z, &nod);
113 gopcode(OAS, n1, Z, nn);
116 gopcode(OASHL, nodconst(sh), Z, &nod);
118 gopcode(OAND, nodconst(~v), Z, n3);
119 gopcode(OOR, n3, Z, &nod);
120 gopcode(OAS, &nod, Z, n2);
129 outstring(char *s, long n)
137 string[mnstring] = *s++;
140 if(mnstring >= NSNAME) {
141 gpseudo(ADATA, symstring, nodconst(0L));
142 p->from.offset += nstring - NSNAME;
144 p->to.type = D_SCONST;
145 memmove(p->to.sval, string, NSNAME);
154 mulcon(Node *n, Node *nn)
156 Node *l, *r, nod1, nod2;
160 char code[sizeof(m->code)+2], *p;
162 if(typefd[n->type->etype])
166 if(l->op == OCONST) {
172 v = convvtox(r->vconst, n->type->etype);
175 print("%L multiply conv: %lld\n", n->lineno, r->vconst);
181 print("%L multiply table: %lld\n", n->lineno, r->vconst);
185 memmove(code, m->code, sizeof(m->code));
186 code[sizeof(m->code)] = 0;
191 regalloc(&nod1, n, nn);
194 gopcode(ONEG, &nod1, Z, &nod1);
195 regalloc(&nod2, n, Z);
201 gopcode(OAS, &nod1, Z, nn);
209 addsub: /* number is r,n,l */
222 default: /* op is shiftcount, number is r,l */
231 if(v < 0 || v >= 32) {
232 diag(n, "mulcon unknown op: %c%c", p[0], p[1]);
235 gopcode(OASHL, nodconst(v), l, r);
243 sextern(Sym *s, Node *a, long o, long w)
247 for(e=0; e<w; e+=NSNAME) {
251 gpseudo(ADATA, s, nodconst(0));
252 p->from.offset += o+e;
254 p->to.type = D_SCONST;
255 memmove(p->to.sval, a->cstring+e, lw);
260 gextern(Sym *s, Node *a, long o, long w)
262 if(a->op == OCONST && typev[a->type->etype]) {
263 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
264 gpseudo(ADATA, s, nod32const(a->vconst>>32));
266 gpseudo(ADATA, s, nod32const(a->vconst));
269 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
270 gpseudo(ADATA, s, nod32const(a->vconst));
272 gpseudo(ADATA, s, nod32const(a->vconst>>32));
273 p->from.offset += o + 4;
277 gpseudo(ADATA, s, a);
280 if(p->to.type == D_OREG)
281 p->to.type = D_CONST;
284 void zname(Biobuf*, Sym*, int);
285 char* zaddr(char*, Adr*, int);
286 void zwrite(Biobuf*, Prog*, int, int);
287 void outhist(Biobuf*);
292 struct { Sym *sym; short type; } h[NSYM];
298 for(p = firstp; p != P; p = p->link)
299 if(p->as != ADATA && p->as != AGLOBL)
301 for(p = firstp; p != P; p = p->link) {
303 if(p->as != ADATA && p->as != AGLOBL)
308 for(sym=0; sym<NSYM; sym++) {
313 for(p = firstp; p != P; p = p->link) {
319 if(sf < 0 || sf >= NSYM)
326 zname(&outbuf, s, t);
339 if(st < 0 || st >= NSYM)
346 zname(&outbuf, s, t);
357 zwrite(&outbuf, p, sf, st);
364 zwrite(Biobuf *b, Prog *p, int sf, int st)
372 if(p->from3.type != D_NONE)
379 bp = zaddr(bf+7, &p->from, sf);
381 bp = zaddr(bp, &p->from3, 0);
382 bp = zaddr(bp, &p->to, st);
383 Bwrite(b, bf, bp-bf);
397 for(h = hist; h != H; h = h->link) {
400 /* on windows skip drive specifier in pathname */
401 if(systemtype(Windows) && p && p[1] == ':'){
405 if(p && p[0] != c && h->offset == 0 && pathname){
406 /* on windows skip drive specifier in pathname */
407 if(systemtype(Windows) && pathname[1] == ':') {
411 } else if(pathname[0] == c){
421 n = 1; /* leading "/" */
422 *p = '/'; /* don't emit "\" on windows */
445 pg.to.type = zprog.to.type;
446 pg.to.offset = h->offset;
448 pg.to.type = D_CONST;
450 zwrite(b, &pg, 0, 0);
455 zname(Biobuf *b, Sym *s, int t)
461 if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
477 bf[2] = t; /* type */
478 bf[3] = s->sym; /* sym */
481 Bwrite(b, n, strlen(n)+1);
485 zaddr(char *bp, Adr *a, int s)
497 diag(Z, "unknown type %d in zaddr", a->type);
517 memmove(bp, a->sval, NSNAME);
522 ieeedtod(&e, a->dval);
554 for(v=t; v->etype==TARRAY; v=v->link)
556 return v->etype == TDOUBLE;
560 for(v = t->link; v != T; v = v->down)
569 align(long i, Type *t, int op)
580 diag(Z, "unknown align opcode %d", op);
583 case Asu2: /* padding at end of a struct */
584 w = doubled(t)? SZ_DOUBLE: SZ_LONG;
589 case Ael1: /* initial align of struct element (also automatic) */
590 for(v=t; v->etype==TARRAY; v=v->link)
592 w = ewidth[v->etype];
593 if(w <= 0 || w >= SZ_LONG){
604 case Ael2: /* width of a struct element */
608 case Aarg0: /* initial passbyptr argument in arg list */
609 if(typesuv[t->etype]) {
610 o = align(o, types[TIND], Aarg1);
611 o = align(o, types[TIND], Aarg2);
615 case Aarg1: /* initial align of parameter */
616 w = ewidth[t->etype];
617 if(w <= 0 || w >= SZ_LONG) {
620 pc = SZ_LONG; /* alignment must account for pc */
626 o += SZ_LONG - w; /* big endian adjustment */
630 case Aarg2: /* width of a parameter */
639 case Aaut3: /* total align of automatic */
641 o = align(o, t, Ael1);
642 o = align(o, t, Ael2);
643 hasdoubled |= doubleflag;
646 o = round(o+pc, w)-pc;
648 print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
653 maxround(long max, long v)
658 if((debug['8'] || hasdoubled) && !debug['4'])