3 typedef struct Malg Malg;
4 typedef struct Mparam Mparam;
21 static Mparam multab[32];
28 {-9, -5, -3, 3, 5, 9, 100},
29 {6, 10, 12, 18, 20, 24, 36, 40, 72, 100},
30 {-8, -4, -2, 2, 4, 8, 100},
34 * return position of lowest 1
44 for(i = 16; i > 0; i >>= 1) {
55 genmuladd(Node *d, Node *s, int m, Node *a)
63 nod.type = types[TIND];
66 gopcode(OADDR, d->type, &nod, d);
70 mulparam(ulong m, Mparam *mp)
72 int c, i, j, n, o, q, s;
73 int bc, bi, bn, bo, bq, bs, bt;
79 bi = bn = bo = bs = bt = 0;
80 for(i = 0; i < nelem(malgs); i++) {
81 for(p = malgs[i].vals, j = 0; (o = p[j]) < 100; j++)
82 for(s = 0; s < 2; s++) {
167 if(c < bc || (c == bc && q > bq)) {
292 shiftit(Type *t, Node *s, Node *d)
296 c = (long)s->vconst & 31;
301 gopcode(OADD, t, d, d);
304 gopcode(OASHL, t, s, d);
309 mulgen1(ulong v, Node *n)
320 for(i = 0; i < nelem(multab); i++) {
327 if(++mulptr == nelem(multab))
333 // print("v=%.lx a=%d n=%d s=%d g=%d o=%d \n", p->value, p->alg, p->neg, p->shift, p->arg, p->off);
337 nods = *nodconst(p->shift);
341 regalloc(&nod, n, Z);
350 shiftit(n->type, &nods, n);
357 genmuladd(n, n, m1(p->arg), n);
362 genmuladd(n, n, m0(p->arg), n);
363 shiftit(n->type, &nods, n);
375 shiftit(n->type, &nods, &nod);
380 genmuladd(&nod, n, m0(p->arg), n);
381 shiftit(n->type, &nods, &nod);
387 gopcode(o, n->type, &nod, n);
389 gopcode(o, n->type, n, &nod);
394 genmuladd(&nod, n, m0(p->off), n);
395 shiftit(n->type, &nods, n);
398 genmuladd(&nod, n, m0(p->off), n);
399 shiftit(n->type, &nods, n);
400 genmuladd(n, &nod, m2(p->off), n);
403 genmuladd(&nod, n, m0(p->off), nodconst(0));
404 shiftit(n->type, &nods, n);
407 diag(Z, "bad mul alg");
411 gopcode(o, n->type, n, &nod);
415 gopcode(o, n->type, &nod, n);
424 diag(Z, "mulgen botch");
429 mulgen(Type *t, Node *r, Node *n)
431 if(!mulgen1(r->vconst, n))
432 gopcode(OMUL, t, r, n);