4 swcmp(const void *a1, const void *a2)
12 return p1->val > p2->val;
19 C1 *q, *iq, *iqh, *iql;
20 long def, nc, i, j, isv, nh;
28 for(c = cases; c->link != C; c = c->link) {
31 diag(n, "more than one default in switch");
38 if(typev[n->type->etype])
41 warn(n, "32-bit switch expression with 64-bit case constant");
45 iq = alloc(nc*sizeof(C1));
47 for(c = cases; c->link != C; c = c->link) {
51 continue; /* can never match */
56 q->val = (long)c->val; /* cast ensures correct value for 32-bit switch on 64-bit architecture */
59 qsort(iq, nc, sizeof(C1), swcmp);
62 print("case %2ld: = %.8llux\n", i, (vlong)iq[i].val);
65 if(iq[i].val == iq[i+1].val) {
66 diag(n, "duplicate cases in switch %lld", (vlong)iq[i].val);
75 if(!isv || ewidth[TIND] > ewidth[TLONG] || n->op == OREGISTER) {
76 swit1(iq, nc, def, n);
81 * 64-bit case on 32-bit machine:
82 * switch on high-order words, and
83 * in each of those, switch on low-order words
86 fatal(n, "internal: expected register pair");
87 if(thechar == '8'){ /* TO DO: need an enquiry function */
88 vr[0] = n->left; /* low */
89 vr[1] = n->right; /* high */
94 vr[0]->type = types[TLONG];
95 vr[1]->type = types[TLONG];
98 iqh = alloc(nc*sizeof(C1));
99 iql = alloc(nc*sizeof(C1));
102 iqh[nh].val = iq[i].val >> 32;
104 /* iq is sorted, so equal top halves are adjacent */
105 for(j = i; j < nc; j++){
106 if((iq[j].val>>32) != iqh[nh].val)
108 q->val = (long)iq[j].val;
109 q->label = iq[j].label;
112 qsort(iql, q-iql, sizeof(C1), swcmp);
113 if(0){for(int k=0; k<(q-iql); k++)print("nh=%ld k=%d h=%#llux l=%#llux lab=%ld\n", nh, k, (vlong)iqh[nh].val, (vlong)iql[k].val, iql[k].label);}
116 swit1(iql, q-iql, def, vr[0]);
120 if(0){for(int k=0; k<nh; k++)print("k*=%d h=%#llux lab=%ld\n", k, (vlong)iqh[k].val, iqh[k].label);}
121 swit1(iqh, nh, def, vr[1]);
129 c = alloc(sizeof(*c));
135 outlstring(Rune *s, long n)
137 char buf[sizeof(Rune)];
143 while(nstring % sizeof buf)
148 if(align(0, types[TCHAR], Aarg1)) {
149 for(i = sizeof buf; i > 0; c >>= 8)
152 for(i = 0; i < sizeof buf; c >>= 8)
155 outstring(buf, sizeof buf);
162 nullwarn(Node *l, Node *r)
164 warn(Z, "result of operation not used");
172 ieeedtod(Ieee *ieee, double native)
178 ieeedtod(ieee, -native);
179 ieee->h |= 0x80000000L;
187 fr = frexp(native, &exp);
188 f = 2097152L; /* shouldnt use fp constants here */
189 fr = modf(fr*f, &ho);
192 ieee->h |= (exp+1022L) << 20;
194 fr = modf(fr*f, &ho);
197 ieee->l |= (long)(fr*f);