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)
135 string[mnstring] = *s++;
138 if(mnstring >= NSNAME) {
139 gpseudo(ADATA, symstring, nodconst(0L));
140 p->from.offset += nstring - NSNAME;
142 p->to.type = D_SCONST;
143 memmove(p->to.sval, string, NSNAME);
152 mulcon(Node *n, Node *nn)
154 Node *l, *r, nod1, nod2;
158 char code[sizeof(m->code)+2], *p;
160 if(typefd[n->type->etype])
164 if(l->op == OCONST) {
170 v = convvtox(r->vconst, n->type->etype);
173 print("%L multiply conv: %lld\n", n->lineno, r->vconst);
179 print("%L multiply table: %lld\n", n->lineno, r->vconst);
183 memmove(code, m->code, sizeof(m->code));
184 code[sizeof(m->code)] = 0;
189 regalloc(&nod1, n, nn);
192 gopcode(OSUB, &nod1, nodconst(0), &nod1);
193 regalloc(&nod2, n, Z);
199 gopcode(OAS, &nod1, Z, nn);
207 addsub: /* number is r,n,l */
220 default: /* op is shiftcount, number is r,l */
229 if(v < 0 || v >= 32) {
230 diag(n, "mulcon unknown op: %c%c", p[0], p[1]);
233 gopcode(OASHL, nodconst(v), l, r);
241 sextern(Sym *s, Node *a, long o, long w)
245 for(e=0; e<w; e+=NSNAME) {
249 gpseudo(ADATA, s, nodconst(0));
250 p->from.offset += o+e;
252 p->to.type = D_SCONST;
253 memmove(p->to.sval, a->cstring+e, lw);
258 gextern(Sym *s, Node *a, long o, long w)
260 if(a->op == OCONST && typev[a->type->etype]) {
261 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
262 gpseudo(ADATA, s, nod32const(a->vconst>>32));
264 gpseudo(ADATA, s, nod32const(a->vconst));
267 if(align(0, types[TCHAR], Aarg1)) /* isbigendian */
268 gpseudo(ADATA, s, nod32const(a->vconst));
270 gpseudo(ADATA, s, nod32const(a->vconst>>32));
271 p->from.offset += o + 4;
275 gpseudo(ADATA, s, a);
278 if(p->to.type == D_OREG)
279 p->to.type = D_CONST;
282 void zname(Biobuf*, Sym*, int);
283 void zaddr(Biobuf*, Adr*, int);
284 void zwrite(Biobuf*, Prog*, int, int);
285 void outhist(Biobuf*);
290 struct { Sym *sym; short type; } h[NSYM];
296 for(p = firstp; p != P; p = p->link)
297 if(p->as != ADATA && p->as != AGLOBL)
299 for(p = firstp; p != P; p = p->link) {
301 if(p->as != ADATA && p->as != AGLOBL)
306 for(sym=0; sym<NSYM; sym++) {
311 for(p = firstp; p != P; p = p->link) {
317 if(sf < 0 || sf >= NSYM)
324 zname(&outbuf, s, t);
337 if(st < 0 || st >= NSYM)
344 zname(&outbuf, s, t);
355 zwrite(&outbuf, p, sf, st);
362 zwrite(Biobuf *b, Prog *p, int sf, int st)
373 zaddr(b, &p->from, sf);
374 zaddr(b, &p->to, st);
388 for(h = hist; h != H; h = h->link) {
391 /* on windows skip drive specifier in pathname */
392 if(systemtype(Windows) && p && p[1] == ':'){
396 if(p && p[0] != c && h->offset == 0 && pathname){
397 /* on windows skip drive specifier in pathname */
398 if(systemtype(Windows) && pathname[1] == ':') {
402 } else if(pathname[0] == c){
412 n = 1; /* leading "/" */
413 *p = '/'; /* don't emit "\" on windows */
435 pg.to.type = zprog.to.type;
436 pg.to.offset = h->offset;
438 pg.to.type = D_CONST;
440 zwrite(b, &pg, 0, 0);
445 zname(Biobuf *b, Sym *s, int t)
450 if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){
460 Bputc(b, ANAME); /* as */
461 Bputc(b, t); /* type */
462 Bputc(b, s->sym); /* sym */
472 zaddr(Biobuf *b, Adr *a, int s)
485 diag(Z, "unknown type %d in zaddr", a->type);
505 for(i=0; i<NSNAME; i++) {
512 ieeedtod(&e, a->dval);
528 align(long i, Type *t, int op)
538 diag(Z, "unknown align opcode %d", op);
541 case Asu2: /* padding at end of a struct */
547 case Ael1: /* initial allign of struct element */
548 for(v=t; v->etype==TARRAY; v=v->link)
550 w = ewidth[v->etype];
551 if(w <= 0 || w >= SZ_LONG)
557 case Ael2: /* width of a struct element */
561 case Aarg0: /* initial passbyptr argument in arg list */
562 if(typesuv[t->etype]) {
563 o = align(o, types[TIND], Aarg1);
564 o = align(o, types[TIND], Aarg2);
568 case Aarg1: /* initial allign of parameter */
569 w = ewidth[t->etype];
570 if(w <= 0 || w >= SZ_LONG) {
574 o += SZ_LONG - w; /* big endian adjustment */
578 case Aarg2: /* width of a parameter */
583 case Aaut3: /* total allign of automatic */
584 o = align(o, t, Ael1);
585 o = align(o, t, Ael2);
590 print("align %s %ld %T = %ld\n", bnames[op], i, t, o);
595 maxround(long max, long v)
599 max = round(v, SZ_LONG);