4 swit1(C1 *q, int nc, long def, Node *n)
8 regalloc(&tn, ®node, Z);
9 swit2(q, nc, def, n, &tn);
14 swit2(C1 *q, int nc, long def, Node *n, Node *tn)
22 i = (q+nc-1)->val - (q+0)->val;
29 print("case = %.8lux\n", q->val);
30 gopcode(OEQ, nodconst(q->val), n, Z);
42 print("case > %.8lux\n", r->val);
43 gopcode(OGT, nodconst(r->val), n, Z);
45 gopcode(OEQ, nodconst(r->val), n, Z); /* just gen the B.EQ */
47 swit2(q, i, def, n, tn);
50 print("case < %.8lux\n", r->val);
52 swit2(r+1, nc-i-1, def, n, tn);
58 gopcode(OSUB, nodconst(v), Z, n);
59 gopcode(OCASE, nodconst((q+nc-1)->val - v), n, Z);
63 print("case = %.8lux\n", q->val);
76 gbranch(OGOTO); /* so that regopt() won't be confused */
81 bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
88 * n1 gets adjusted/masked value
89 * n2 gets address of cell
90 * n3 gets contents of cell
97 gopcode(OAS, n2, Z, n3);
98 gopcode(OAS, n3, Z, n1);
103 if(b->type->shift == 0 && typeu[b->type->etype]) {
104 v = ~0 + (1L << b->type->nbits);
105 gopcode(OAND, nodconst(v), Z, n1);
107 sh = 32 - b->type->shift - b->type->nbits;
109 gopcode(OASHL, nodconst(sh), Z, n1);
110 sh += b->type->shift;
112 if(typeu[b->type->etype])
113 gopcode(OLSHR, nodconst(sh), Z, n1);
115 gopcode(OASHR, nodconst(sh), Z, n1);
120 bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
127 * n1 has adjusted/masked value
128 * n2 has address of cell
129 * n3 has contents of cell
132 regalloc(&nod, l, Z);
133 v = ~0 + (1L << b->type->nbits);
134 gopcode(OAND, nodconst(v), Z, n1);
135 gopcode(OAS, n1, Z, &nod);
137 gopcode(OAS, n1, Z, nn);
140 gopcode(OASHL, nodconst(sh), Z, &nod);
142 gopcode(OAND, nodconst(~v), Z, n3);
143 gopcode(OOR, n3, Z, &nod);
144 gopcode(OAS, &nod, Z, n2);
153 outstring(char *s, long n)
161 string[mnstring] = *s++;
164 if(mnstring >= NSNAME) {
165 gpseudo(ADATA, symstring, nodconst(0L));
166 p->from.offset += nstring - NSNAME;
168 p->to.type = D_SCONST;
169 memmove(p->to.sval, string, NSNAME);
178 mulcon(Node *n, Node *nn)
180 Node *l, *r, nod1, nod2;
184 char code[sizeof(m->code)+2], *p;
186 if(typefd[n->type->etype])
190 if(l->op == OCONST) {
196 v = convvtox(r->vconst, n->type->etype);
199 print("%L multiply conv: %lld\n", n->lineno, r->vconst);
205 print("%L multiply table: %lld\n", n->lineno, r->vconst);
208 if(debug['M'] && debug['v'])
209 print("%L multiply: %ld\n", n->lineno, v);
211 memmove(code, m->code, sizeof(m->code));
212 code[sizeof(m->code)] = 0;
217 regalloc(&nod1, n, nn);
220 regalloc(&nod2, n, Z);
227 gopcode(OAS, &nod1, Z, &nod1);
228 gopcode(OSUB, &nod1, nodconst(0), nn);
230 gopcode(OAS, &nod1, Z, nn);
238 addsub: /* number is r,n,l */
251 default: /* op is shiftcount, number is r,l */
260 if(v < 0 || v >= 32) {
261 diag(n, "mulcon unknown op: %c%c", p[0], p[1]);
264 gopcode(OASHL, nodconst(v), l, r);
272 sextern(Sym *s, Node *a, long o, long w)
276 for(e=0; e<w; e+=NSNAME) {
280 gpseudo(ADATA, s, nodconst(0));
281 p->from.offset += o+e;
283 p->to.type = D_SCONST;
284 memmove(p->to.sval, a->cstring+e, lw);
289 gextern(Sym *s, Node *a, long o, long w)
292 if(a->op == OCONST && typev[a->type->etype]) {
293 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
294 gpseudo(ADATA, s, nod32const(a->vconst>>32));
296 gpseudo(ADATA, s, nod32const(a->vconst));
299 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
300 gpseudo(ADATA, s, nod32const(a->vconst));
302 gpseudo(ADATA, s, nod32const(a->vconst>>32));
303 p->from.offset += o + 4;
307 gpseudo(ADATA, s, a);
310 if(p->to.type == D_OREG)
311 p->to.type = D_CONST;
314 void zname(Biobuf*, Sym*, int);
315 char* zaddr(char*, Adr*, int);
316 void zwrite(Biobuf*, Prog*, int, int);
317 void outhist(Biobuf*);
320 zwrite(Biobuf *b, Prog *p, int sf, int st)
328 bf[4] = p->lineno>>8;
329 bf[5] = p->lineno>>16;
330 bf[6] = p->lineno>>24;
331 bp = zaddr(bf+7, &p->from, sf);
332 bp = zaddr(bp, &p->to, st);
333 Bwrite(b, bf, bp-bf);
339 struct { Sym *sym; short type; } h[NSYM];
345 for(p = firstp; p != P; p = p->link)
346 if(p->as != ADATA && p->as != AGLOBL)
348 for(p = firstp; p != P; p = p->link) {
350 if(p->as != ADATA && p->as != AGLOBL)
355 for(sym=0; sym<NSYM; sym++) {
360 for(p = firstp; p != P; p = p->link) {
366 if(sf < 0 || sf >= NSYM)
373 zname(&outbuf, s, t);
386 if(st < 0 || st >= NSYM)
393 zname(&outbuf, s, t);
404 zwrite(&outbuf, p, sf, st);
421 for(h = hist; h != H; h = h->link) {
424 /* on windows skip drive specifier in pathname */
425 if(systemtype(Windows) && p && p[1] == ':'){
429 if(p && p[0] != c && h->offset == 0 && pathname){
430 /* on windows skip drive specifier in pathname */
431 if(systemtype(Windows) && pathname[1] == ':') {
435 } else if(pathname[0] == c){
445 n = 1; /* leading "/" */
446 *p = '/'; /* don't emit "\" on windows */
468 pg.to.type = zprog.to.type;
469 pg.to.offset = h->offset;
471 pg.to.type = D_CONST;
473 zwrite(b, &pg, 0, 0);
478 zname(Biobuf *b, Sym *s, int t)
484 if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
498 bf[1] = t; /* type */
499 bf[2] = s->sym; /* sym */
502 Bwrite(b, n, strlen(n)+1);
506 zaddr(char *bp, Adr *a, int s)
518 diag(Z, "unknown type %d in zaddr", a->type);
539 memmove(bp, a->sval, NSNAME);
544 ieeedtod(&e, a->dval);
563 align(long i, Type *t, int op)
573 diag(Z, "unknown align opcode %d", op);
576 case Asu2: /* padding at end of a struct */
582 case Ael1: /* initial allign of struct element */
583 for(v=t; v->etype==TARRAY; v=v->link)
585 w = ewidth[v->etype];
586 if(w <= 0 || w >= SZ_LONG)
592 case Ael2: /* width of a struct element */
596 case Aarg0: /* initial passbyptr argument in arg list */
597 if(typesuv[t->etype]) {
598 o = align(o, types[TIND], Aarg1);
599 o = align(o, types[TIND], Aarg2);
603 case Aarg1: /* initial allign of parameter */
604 w = ewidth[t->etype];
605 if(w <= 0 || w >= SZ_LONG) {
609 w = 1; /* little endian no adjustment */
612 case Aarg2: /* width of a parameter */
617 case Aaut3: /* total allign of automatic */
618 o = align(o, t, Ael2);
619 o = align(o, t, Ael1);
620 w = SZ_LONG; /* because of a pun in cc/dcl.c:contig() */
625 print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
630 maxround(long max, long v)
632 v = round(v, SZ_LONG);