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)
23 print("case = %.8llux\n", q->val);
24 gmove(nodconst(q->val), tn);
25 gopcode(OEQ, n, tn, Z);
36 print("case > %.8llux\n", r->val);
37 gmove(nodconst(r->val), tn);
38 gopcode(OLT, tn, n, Z);
40 gopcode(OEQ, n, tn, Z);
42 swit2(q, i, def, n, tn);
45 print("case < %.8llux\n", r->val);
47 swit2(r+1, nc-i-1, def, n, tn);
51 bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
58 * n1 gets adjusted/masked value
59 * n2 gets address of cell
60 * n3 gets contents of cell
67 gopcode(OAS, n2, Z, n3);
68 gopcode(OAS, n3, Z, n1);
73 if(b->type->shift == 0 && typeu[b->type->etype]) {
74 v = ~0 + (1L << b->type->nbits);
75 gopcode(OAND, nodconst(v), Z, n1);
77 sh = 32 - b->type->shift - b->type->nbits;
79 gopcode(OASHL, nodconst(sh), Z, n1);
82 if(typeu[b->type->etype])
83 gopcode(OLSHR, nodconst(sh), Z, n1);
85 gopcode(OASHR, nodconst(sh), Z, n1);
90 bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
97 * n1 has adjusted/masked value
98 * n2 has address of cell
99 * n3 has contents of cell
102 regalloc(&nod, l, Z);
103 v = ~0 + (1L << b->type->nbits);
104 gopcode(OAND, nodconst(v), Z, n1);
105 gopcode(OAS, n1, Z, &nod);
107 gopcode(OAS, n1, Z, nn);
110 gopcode(OASHL, nodconst(sh), Z, &nod);
112 gopcode(OAND, nodconst(~v), Z, n3);
113 gopcode(OOR, n3, Z, &nod);
114 gopcode(OAS, &nod, Z, n2);
123 outstring(char *s, long n)
131 string[mnstring] = *s++;
134 if(mnstring >= NSNAME) {
135 gpseudo(ADATA, symstring, nodconst(0L));
136 p->from.offset += nstring - NSNAME;
138 p->to.type = D_SCONST;
139 memmove(p->to.sval, string, NSNAME);
148 mulcon(Node *n, Node *nn)
150 Node *l, *r, nod1, nod2;
154 char code[sizeof(m->code)+2], *p;
156 if(typefd[n->type->etype])
160 if(l->op == OCONST) {
166 v = convvtox(r->vconst, n->type->etype);
169 print("%L multiply conv: %lld\n", n->lineno, r->vconst);
175 print("%L multiply table: %lld\n", n->lineno, r->vconst);
178 if(debug['M'] && debug['v'])
179 print("%L multiply: %ld\n", n->lineno, v);
181 memmove(code, m->code, sizeof(m->code));
182 code[sizeof(m->code)] = 0;
187 regalloc(&nod1, n, nn);
190 gopcode(OSUB, &nod1, nodconst(0), &nod1);
191 regalloc(&nod2, n, Z);
197 gopcode(OAS, &nod1, Z, nn);
205 addsub: /* number is r,n,l */
218 default: /* op is shiftcount, number is r,l */
227 if(v < 0 || v >= 32) {
228 diag(n, "mulcon unknown op: %c%c", p[0], p[1]);
231 gopcode(OASHL, nodconst(v), l, r);
239 sextern(Sym *s, Node *a, long o, long w)
243 for(e=0; e<w; e+=NSNAME) {
247 gpseudo(ADATA, s, nodconst(0));
248 p->from.offset += o+e;
250 p->to.type = D_SCONST;
251 memmove(p->to.sval, a->cstring+e, lw);
256 gextern(Sym *s, Node *a, long o, long w)
259 if(a->op == OCONST && typev[a->type->etype]) {
260 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
261 gpseudo(ADATA, s, nod32const(a->vconst>>32));
263 gpseudo(ADATA, s, nod32const(a->vconst));
266 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
267 gpseudo(ADATA, s, nod32const(a->vconst));
269 gpseudo(ADATA, s, nod32const(a->vconst>>32));
270 p->from.offset += o + 4;
274 gpseudo(ADATA, s, a);
277 if(p->to.type == D_OREG)
278 p->to.type = D_CONST;
281 void zname(Biobuf*, Sym*, int);
282 char* zaddr(char*, Adr*, int);
283 void zwrite(Biobuf*, Prog*, int, int);
284 void outhist(Biobuf*);
287 zwrite(Biobuf *b, Prog *p, int sf, int st)
294 bf[3] = p->lineno>>8;
295 bf[4] = p->lineno>>16;
296 bf[5] = p->lineno>>24;
297 bp = zaddr(bf+6, &p->from, sf);
298 bp = zaddr(bp, &p->to, st);
299 Bwrite(b, bf, bp-bf);
305 struct { Sym *sym; short type; } h[NSYM];
311 for(p = firstp; p != P; p = p->link)
312 if(p->as != ADATA && p->as != AGLOBL)
314 for(p = firstp; p != P; p = p->link) {
316 if(p->as != ADATA && p->as != AGLOBL)
321 for(sym=0; sym<NSYM; sym++) {
326 for(p = firstp; p != P; p = p->link) {
332 if(sf < 0 || sf >= NSYM)
339 zname(&outbuf, s, t);
352 if(st < 0 || st >= NSYM)
359 zname(&outbuf, s, t);
370 zwrite(&outbuf, p, sf, st);
387 for(h = hist; h != H; h = h->link) {
390 /* on windows skip drive specifier in pathname */
391 if(systemtype(Windows) && p && p[1] == ':'){
395 if(p && p[0] != c && h->offset == 0 && pathname){
396 /* on windows skip drive specifier in pathname */
397 if(systemtype(Windows) && pathname[1] == ':') {
401 } else if(pathname[0] == c){
411 n = 1; /* leading "/" */
412 *p = '/'; /* don't emit "\" on windows */
434 pg.to.type = zprog.to.type;
435 pg.to.offset = h->offset;
437 pg.to.type = D_CONST;
439 zwrite(b, &pg, 0, 0);
444 zname(Biobuf *b, Sym *s, int t)
450 if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
464 bf[1] = t; /* type */
465 bf[2] = s->sym; /* sym */
468 Bwrite(b, n, strlen(n)+1);
472 zaddr(char *bp, Adr *a, int s)
484 diag(Z, "unknown type %d in zaddr", a->type);
507 memmove(bp, a->sval, NSNAME);
512 ieeedtod(&e, a->dval);
531 align(long i, Type *t, int op)
541 diag(Z, "unknown align opcode %d", op);
544 case Asu2: /* padding at end of a struct */
550 case Ael1: /* initial allign of struct element */
551 for(v=t; v->etype==TARRAY; v=v->link)
553 w = ewidth[v->etype];
554 if(w <= 0 || w >= SZ_LONG)
560 case Ael2: /* width of a struct element */
564 case Aarg0: /* initial passbyptr argument in arg list */
565 if(typesuv[t->etype]) {
566 o = align(o, types[TIND], Aarg1);
567 o = align(o, types[TIND], Aarg2);
571 case Aarg1: /* initial allign of parameter */
572 w = ewidth[t->etype];
573 if(w <= 0 || w >= SZ_LONG) {
578 o += SZ_LONG - w; /* big endian adjustment */
582 case Aarg2: /* width of a parameter */
587 case Aaut3: /* total allign of automatic */
588 o = align(o, t, Ael1);
589 o = align(o, t, Ael2);
595 print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
600 maxround(long max, long v)
604 max = round(v, SZ_LONG);