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 gopcode(OEQ, n, Z, nodconst(q->val));
25 gopcode(OSUB, nodconst(q->val), n, tn);
26 gopcode(OEQ, tn, Z, nodconst(0));
38 gopcode(OGT, n, Z, nodconst(r->val));
41 gopcode(OSUB, nodconst(r->val), n, tn);
42 gopcode(OGT, tn, Z, nodconst(0));
48 swit2(q, i, def, n, tn);
51 swit2(r+1, nc-i-1, def, n, tn);
55 bitload(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
62 * n1 gets adjusted/masked value
63 * n2 gets address of cell
64 * n3 gets contents of cell
71 gopcode(OAS, n2, Z, n3);
72 gopcode(OAS, n3, Z, n1);
77 if(b->type->shift == 0 && typeu[b->type->etype]) {
78 v = ~0 + (1L << b->type->nbits);
79 gopcode(OAND, nodconst(v), Z, n1);
81 sh = 32 - b->type->shift - b->type->nbits;
83 gopcode(OASHL, nodconst(sh), Z, n1);
86 if(typeu[b->type->etype])
87 gopcode(OLSHR, nodconst(sh), Z, n1);
89 gopcode(OASHR, nodconst(sh), Z, n1);
94 bitstore(Node *b, Node *n1, Node *n2, Node *n3, Node *nn)
101 * n1 has adjusted/masked value
102 * n2 has address of cell
103 * n3 has contents of cell
106 regalloc(&nod, l, Z);
107 v = ~0 + (1L << b->type->nbits);
108 gopcode(OAND, nodconst(v), Z, n1);
109 gopcode(OAS, n1, Z, &nod);
111 gopcode(OAS, n1, Z, nn);
114 gopcode(OASHL, nodconst(sh), Z, &nod);
116 gopcode(OAND, nodconst(~v), Z, n3);
117 gopcode(OOR, n3, Z, &nod);
118 gopcode(OAS, &nod, Z, n2);
127 outstring(char *s, long n)
133 string[mnstring] = *s++;
136 if(mnstring >= NSNAME) {
137 gpseudo(ADATA, symstring, nodconst(0L));
138 p->from.offset += nstring - NSNAME;
140 p->to.type = D_SCONST;
141 memmove(p->to.sval, string, NSNAME);
150 mulcon(Node *n, Node *nn)
152 Node *l, *r, nod1, nod2;
156 char code[sizeof(m->code)+2], *p;
158 if(typefd[n->type->etype])
162 if(l->op == OCONST) {
168 v = convvtox(r->vconst, n->type->etype);
171 print("%L multiply conv: %lld\n", n->lineno, r->vconst);
177 print("%L multiply table: %lld\n", n->lineno, r->vconst);
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)
258 if(a->op == OCONST && typev[a->type->etype]) {
259 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
260 gpseudo(ADATA, s, nod32const(a->vconst>>32));
262 gpseudo(ADATA, s, nod32const(a->vconst));
265 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
266 gpseudo(ADATA, s, nod32const(a->vconst));
268 gpseudo(ADATA, s, nod32const(a->vconst>>32));
269 p->from.offset += o + 4;
273 gpseudo(ADATA, s, a);
276 if(p->to.type == D_OREG)
277 p->to.type = D_CONST;
280 void zname(Biobuf*, Sym*, int);
281 void zaddr(Biobuf*, Adr*, int);
282 void zwrite(Biobuf*, Prog*, int, int);
283 void outhist(Biobuf*);
288 struct { Sym *sym; short type; } h[NSYM];
294 for(p = firstp; p != P; p = p->link)
295 if(p->as != ADATA && p->as != AGLOBL)
297 for(p = firstp; p != P; p = p->link) {
299 if(p->as != ADATA && p->as != AGLOBL)
304 for(sym=0; sym<NSYM; sym++) {
309 for(p = firstp; p != P; p = p->link) {
315 if(sf < 0 || sf >= NSYM)
322 zname(&outbuf, s, t);
335 if(st < 0 || st >= NSYM)
342 zname(&outbuf, s, t);
353 zwrite(&outbuf, p, sf, st);
360 zwrite(Biobuf *b, Prog *p, int sf, int st)
371 zaddr(b, &p->from, sf);
372 zaddr(b, &p->to, st);
386 for(h = hist; h != H; h = h->link) {
389 /* on windows skip drive specifier in pathname */
390 if(systemtype(Windows) && p && p[1] == ':'){
394 if(p && p[0] != c && h->offset == 0 && pathname){
395 /* on windows skip drive specifier in pathname */
396 if(systemtype(Windows) && pathname[1] == ':') {
400 } else if(pathname[0] == c){
410 n = 1; /* leading "/" */
411 *p = '/'; /* don't emit "\" on windows */
433 pg.to.type = zprog.to.type;
434 pg.to.offset = h->offset;
436 pg.to.type = D_CONST;
438 zwrite(b, &pg, 0, 0);
443 zname(Biobuf *b, Sym *s, int t)
448 if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
458 Bputc(b, ANAME); /* as */
459 Bputc(b, t); /* type */
460 Bputc(b, s->sym); /* sym */
470 zaddr(Biobuf *b, Adr *a, int s)
483 diag(Z, "unknown type %d in zaddr", a->type);
503 for(i=0; i<NSNAME; i++) {
510 ieeedtod(&e, a->dval);
526 align(long i, Type *t, int op)
536 diag(Z, "unknown align opcode %d", op);
539 case Asu2: /* padding at end of a struct */
545 case Ael1: /* initial allign of struct element */
546 for(v=t; v->etype==TARRAY; v=v->link)
548 w = ewidth[v->etype];
549 if(w <= 0 || w >= SZ_LONG)
555 case Ael2: /* width of a struct element */
559 case Aarg0: /* initial passbyptr argument in arg list */
560 if(typesuv[t->etype]) {
561 o = align(o, types[TIND], Aarg1);
562 o = align(o, types[TIND], Aarg2);
566 case Aarg1: /* initial allign of parameter */
567 w = ewidth[t->etype];
568 if(w <= 0 || w >= SZ_LONG) {
572 o += SZ_LONG - w; /* big endian adjustment */
576 case Aarg2: /* width of a parameter */
581 case Aaut3: /* total allign of automatic */
582 o = align(o, t, Ael1);
583 o = align(o, t, Ael2);
588 print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
593 maxround(long max, long v)
597 max = round(v, SZ_LONG);