static void
mphextofix(Mpint *a, char *s, int n)
{
- char *hexdigitp, *end, c;
+ char c;
long d;
- int bit;
+ int bit, hexdigitp, end;
while(*s == '0') {
s++;
return;
}
- end = s+n-1;
- for(hexdigitp=end; hexdigitp>=s; hexdigitp--) {
- c = *hexdigitp;
+ end = n-1;
+ for(hexdigitp=end; hexdigitp>=0; hexdigitp--) {
+ c = s[hexdigitp];
if(c >= '0' && c <= '9')
d = c-'0';
else if(c >= 'A' && c <= 'F')
mpnorm(a);
}
for(;;) {
- switch(c = *s++) {
+ c = *s++;
+ switch(c) {
default:
yyerror("malformed constant: %s (at %c)", as, c);
goto bad;
int
Bconv(Fmt *fp)
{
- char buf[500], *p;
+ char buf[500];
+ int p;
Mpint *xval, q, r, ten, sixteen;
int f, digit;
mpnegfix(&q);
}
- p = &buf[sizeof(buf)];
- *--p = 0;
+ p = sizeof(buf);
+ buf[--p] = 0;
if(fp->flags & FmtSharp) {
// Hexadecimal
mpmovecfix(&sixteen, 16);
mpdivmodfixfix(&q, &r, &q, &sixteen);
digit = mpgetfix(&r);
if(digit < 10)
- *--p = digit + '0';
+ buf[--p] = digit + '0';
else
- *--p = digit - 10 + 'A';
+ buf[--p] = digit - 10 + 'A';
if(mptestfix(&q) <= 0)
break;
}
- *--p = 'x';
- *--p = '0';
+ buf[--p] = 'x';
+ buf[--p] = '0';
} else {
// Decimal
mpmovecfix(&ten, 10);
for(;;) {
mpdivmodfixfix(&q, &r, &q, &ten);
- *--p = mpgetfix(&r) + '0';
+ buf[--p] = mpgetfix(&r) + '0';
if(mptestfix(&q) <= 0)
break;
}
}
if(f)
- *--p = '-';
- return fmtstrcpy(fp, p);
+ buf[--p] = '-';
+ return fmtstrcpy(fp, &buf[p]);
}
int
mplen(Mpint *a)
{
int i, n;
- long *a1;
n = -1;
- a1 = &a->a[0];
for(i=0; i<Mpprec; i++) {
- if(*a1++ != 0)
+ if(a->a[i] != 0)
n = i;
}
return n+1;
static void
mplsh(Mpint *a, int quiet)
{
- long *a1, x;
+ long x;
int i, c;
c = 0;
- a1 = &a->a[0];
for(i=0; i<Mpprec; i++) {
- x = (*a1 << 1) + c;
+ x = (a->a[i] << 1) + c;
c = 0;
if(x >= Mpbase) {
x -= Mpbase;
c = 1;
}
- *a1++ = x;
+ a->a[i] = x;
}
a->ovf = c;
if(a->ovf && !quiet)
static void
mplshw(Mpint *a, int quiet)
{
- long *a1;
int i;
- a1 = &a->a[Mpprec-1];
- if(*a1) {
+ i = Mpprec-1;
+ if(a->a[i]) {
a->ovf = 1;
if(!quiet)
yyerror("constant shift overflow");
}
- for(i=1; i<Mpprec; i++) {
- a1[0] = a1[-1];
- a1--;
- }
- a1[0] = 0;
+ for(; i > 0; i--)
+ a->a[i] = a->a[i-1];
+ a->a[i] = 0;
}
//
static void
mprsh(Mpint *a)
{
- long *a1, x, lo;
+ long x, lo;
int i, c;
c = 0;
lo = a->a[0] & 1;
- a1 = &a->a[Mpprec];
- for(i=0; i<Mpprec; i++) {
- x = *--a1;
- *a1 = (x + c) >> 1;
+ for(i=Mpprec-1; i>=0; i--) {
+ x = a->a[i];
+ a->a[i] = (x + c) >> 1;
c = 0;
if(x & 1)
c = Mpbase;
static void
mprshw(Mpint *a)
{
- long *a1, lo;
+ long lo;
int i;
lo = a->a[0];
- a1 = &a->a[0];
- for(i=1; i<Mpprec; i++) {
- a1[0] = a1[1];
- a1++;
+ for(i=0; i<Mpprec-1; i++) {
+ a->a[i] = a->a[i+1];
}
- a1[0] = 0;
+ a->a[i] = 0;
if(a->neg && lo != 0)
mpaddcfix(a, -1);
}
static int
mpcmp(Mpint *a, Mpint *b)
{
- long x, *a1, *b1;
+ long x;
int i;
if(a->ovf || b->ovf) {
return 0;
}
- a1 = &a->a[0] + Mpprec;
- b1 = &b->a[0] + Mpprec;
-
- for(i=0; i<Mpprec; i++) {
- x = *--a1 - *--b1;
+ for(i=Mpprec-1; i>=0; i--) {
+ x = a->a[i] - b->a[i];
if(x > 0)
return +1;
if(x < 0)
static void
mpneg(Mpint *a)
{
- long x, *a1;
+ long x;
int i, c;
- a1 = &a->a[0];
c = 0;
for(i=0; i<Mpprec; i++) {
- x = -*a1 -c;
+ x = -a->a[i] -c;
c = 0;
if(x < 0) {
x += Mpbase;
c = 1;
}
- *a1++ = x;
+ a->a[i] = x;
}
}
mpaddfixfix(Mpint *a, Mpint *b, int quiet)
{
int i, c;
- long x, *a1, *b1;
+ long x;
if(a->ovf || b->ovf) {
if(nsavederrors+nerrors == 0)
}
c = 0;
- a1 = &a->a[0];
- b1 = &b->a[0];
if(a->neg != b->neg)
goto sub;
// perform a+b
for(i=0; i<Mpprec; i++) {
- x = *a1 + *b1++ + c;
+ x = a->a[i] + b->a[i] + c;
c = 0;
if(x >= Mpbase) {
x -= Mpbase;
c = 1;
}
- *a1++ = x;
+ a->a[i] = x;
}
a->ovf = c;
if(a->ovf && !quiet)
case 1:
for(i=0; i<Mpprec; i++) {
- x = *a1 - *b1++ - c;
+ x = a->a[i] - b->a[i] - c;
c = 0;
if(x < 0) {
x += Mpbase;
c = 1;
}
- *a1++ = x;
+ a->a[i] = x;
}
break;
case -1:
a->neg ^= 1;
for(i=0; i<Mpprec; i++) {
- x = *b1++ - *a1 - c;
+ x = b->a[i] - a->a[i] - c;
c = 0;
if(x < 0) {
x += Mpbase;
c = 1;
}
- *a1++ = x;
+ a->a[i] = x;
}
break;
}
{
int i, j, na, nb;
- long *a1, x;
+ long x;
Mpint s, q;
+ Mpint *c;
if(a->ovf || b->ovf) {
if(nsavederrors+nerrors == 0)
nb = mplen(b);
if(na > nb) {
mpmovefixfix(&s, a);
- a1 = &b->a[0];
+ c = b;
na = nb;
} else {
mpmovefixfix(&s, b);
- a1 = &a->a[0];
+ c = a;
}
s.neg = 0;
mpmovecfix(&q, 0);
for(i=0; i<na; i++) {
- x = *a1++;
+ x = c->a[i];
for(j=0; j<Mpscale; j++) {
if(x & 1) {
if(s.ovf) {
{
int i, j;
- long *a1, x;
+ long x;
Mpint s, q;
if(a->ovf || b->ovf) {
}
mpmovefixfix(&s, b);
- a1 = &a->a[Mpprec];
s.neg = 0;
mpmovecfix(&q, 0);
- x = *--a1;
+ i = Mpprec-1;
+ x = a->a[i];
if(x != 0)
yyerror("mpmulfract not normal");
- for(i=0; i<Mpprec-1; i++) {
- x = *--a1;
+ for(i--; i >= 0; i--) {
+ x = a->a[i];
if(x == 0) {
mprshw(&s);
continue;
mporfixfix(Mpint *a, Mpint *b)
{
int i;
- long x, *a1, *b1;
+ long x;
x = 0;
if(a->ovf || b->ovf) {
if(b->neg)
mpneg(b);
- a1 = &a->a[0];
- b1 = &b->a[0];
for(i=0; i<Mpprec; i++) {
- x = *a1 | *b1++;
- *a1++ = x;
+ x = a->a[i] | b->a[i];
+ a->a[i] = x;
}
if(b->neg)
mpandfixfix(Mpint *a, Mpint *b)
{
int i;
- long x, *a1, *b1;
+ long x;
x = 0;
if(a->ovf || b->ovf) {
if(b->neg)
mpneg(b);
- a1 = &a->a[0];
- b1 = &b->a[0];
for(i=0; i<Mpprec; i++) {
- x = *a1 & *b1++;
- *a1++ = x;
+ x = a->a[i] & b->a[i];
+ a->a[i] = x;
}
if(b->neg)
mpandnotfixfix(Mpint *a, Mpint *b)
{
int i;
- long x, *a1, *b1;
+ long x;
x = 0;
if(a->ovf || b->ovf) {
if(b->neg)
mpneg(b);
- a1 = &a->a[0];
- b1 = &b->a[0];
for(i=0; i<Mpprec; i++) {
- x = *a1 & ~*b1++;
- *a1++ = x;
+ x = a->a[i] & ~b->a[i];
+ a->a[i] = x;
}
if(b->neg)
mpxorfixfix(Mpint *a, Mpint *b)
{
int i;
- long x, *a1, *b1;
+ long x;
x = 0;
if(a->ovf || b->ovf) {
if(b->neg)
mpneg(b);
- a1 = &a->a[0];
- b1 = &b->a[0];
for(i=0; i<Mpprec; i++) {
- x = *a1 ^ *b1++;
- *a1++ = x;
+ x = a->a[i] ^ b->a[i];
+ a->a[i] = x;
}
if(b->neg)
mpmovecfix(Mpint *a, vlong c)
{
int i;
- long *a1;
vlong x;
a->neg = 0;
x = -(uvlong)x;
}
- a1 = &a->a[0];
for(i=0; i<Mpprec; i++) {
- *a1++ = x&Mpmask;
+ a->a[i] = x&Mpmask;
x >>= Mpscale;
}
}
static int
mpiszero(Mpint *a)
{
- long *a1;
int i;
- a1 = &a->a[0] + Mpprec;
- for(i=0; i<Mpprec; i++) {
- if(*--a1 != 0)
+
+ for(i=Mpprec-1; i>=0; i--)
+ if(a->a[i] != 0)
return 0;
- }
return 1;
}
{
Mpint n, d;
int i, j, neg;
- long *a1, x;
+ long x;
mpmovefixfix(&n, a); // numerator
mpmovefixfix(&d, b); // denominator
- a1 = &a->a[Mpprec]; // quotient
neg = n.neg ^ d.neg;
n.neg = 0;
d.neg = 0;
- for(i=0; i<Mpprec; i++) {
+ for(i=Mpprec-1; i >= 0; i--) {
x = 0;
for(j=0; j<Mpscale; j++) {
x <<= 1;
}
mprsh(&d);
}
- *--a1 = x;
+ a->a[i] = x;
}
a->neg = neg;
}
nkill = 0;
// Special case.
- for(v = var; v < var+nvar; v++) {
+ for(i = 0; i < nvar; i++) {
+ v = &var[i];
if(v->addr)
continue;
// Used in only one instruction, which had better be a write.
// Each flood uses a new value of gen so that we don't have
// to clear all the r->active words after each variable.
gen = 0;
- for(v = var; v < var+nvar; v++) {
+ for(i = 0; i < nvar; i++) {
+ v = &var[i];
gen++;
for(f = v->use; f != nil; f = (Flow*)f->data)
mergewalk(v, f, gen);
if(debugmerge > 0 && debug['v']) {
print("%S [%d - %d]\n", curfn->nname->sym, nvar, nkill);
- for(v=var; v<var+nvar; v++) {
+ for(i = 0; i < nvar; i++) {
+ v = &var[i];
print("var %#N %T %lld-%lld", v->node, v->node->type, v->start, v->end);
if(v->addr)
print(" addr=1");
}
// Clear aux structures.
- for(v=var; v<var+nvar; v++)
+ for(i = 0; i < nvar; i++) {
+ v = &var[i];
v->node->opt = nil;
+ }
free(var);
free(bystart);
free(inuse);
int nreg;
char **regnames;
Bits bit;
+ Rgn *rgp;
if(first) {
fmtinstall('Q', Qconv);
}
for(i=0; i<nvar; i++) {
- Var *v = var+i;
+ Var *v;
+ v = var+i;
if(v->addr) {
bit = blsh(i);
for(z=0; z<BITS; z++)
}
if(debug['R'] && debug['v'])
- print("bit=%2d addr=%d et=%-6E w=%-2d s=%N + %lld\n",
+ print("bit=%2d addr=%d et=%E w=%-2d s=%N + %lld\n",
i, v->addr, v->etype, v->width, v->node, v->offset);
}
}
for(f = firstf; f != nil; f = f->link)
((Reg*)f->data)->act = zbits;
- rgp = region;
nregion = 0;
for(f = firstf; f != nil; f = f->link) {
r = (Reg*)f->data;
print("too many regions\n");
goto brk;
}
+ rgp = ®ion[nregion];
rgp->enter = f;
rgp->varno = i;
rgp->cost = change;
- rgp++;
nregion++;
}
}
* determine used registers (paint2)
* replace code (paint3)
*/
- rgp = region;
if(debug['R'] && debug['v'])
print("\nregisterizing\n");
for(i=0; i<nregion; i++) {
+ rgp = ®ion[i];
if(debug['R'] && debug['v'])
print("region %d: cost %d varno %d enter %lld\n", i, rgp->cost, rgp->varno, rgp->enter->prog->pc);
bit = blsh(rgp->varno);
Var *v;
v = var + rgp->varno;
- print("registerize %N+%lld (bit=%2d et=%2E) in %R usedreg=%#llx vreg=%#llx\n",
+ print("registerize %N+%lld (bit=%2d et=%E) in %R usedreg=%#llx vreg=%#llx\n",
v->node, v->offset, rgp->varno, v->etype, rgp->regno, usedreg, vreg);
}
paint3(rgp->enter, rgp->varno, vreg, rgp->regno);
}
- rgp++;
}
/*
if(f1->prog->as == AVARKILL && f1->prog->to.node == n)
break;
for(v=n->opt; v!=nil; v=v->nextinnode) {
- bn = v - var;
+ bn = v->id;
biset(&((Reg*)f1->data)->act, bn);
}
if(f1->prog->as == ACALL)
i = nvar;
nvar++;
v = var+i;
+ v->id = i;
v->offset = o;
v->name = n;
v->etype = et;
v->addr = 1;
if(debug['R'])
- print("bit=%2d et=%2E w=%lld+%lld %#N %D flag=%d\n", i, et, o, w, node, a, v->addr);
+ print("bit=%2d et=%E w=%lld+%lld %#N %D flag=%d\n", i, et, o, w, node, a, v->addr);
ostats.nvar++;
return bit;
{
Flow *f1, *f2;
Reg *r, *r1;
- int z, i, j;
+ int z, i;
Var *v, *v1;
for(f1 = f; f1 != nil; f1 = f1->p1) {
// v is the head of the list or if the head's bit is not yet turned on.
// This will set the bits at most twice, keeping the overall loop linear.
v1 = v->node->opt;
- j = v1 - var;
- if(v == v1 || !btest(&cal, j)) {
+ if(v == v1 || !btest(&cal, v1->id)) {
for(; v1 != nil; v1 = v1->nextinnode) {
- j = v1 - var;
- biset(&cal, j);
+ biset(&cal, v1->id);
}
}
}