Routines are called with calls instead of jsb. EM_BSIZE is required to

be a constant.
This commit is contained in:
em 1985-01-18 15:33:44 +00:00
parent 8d87404836
commit 10ce06ff2b

View file

@ -1,6 +1,6 @@
#ifndef NORCSID #ifndef lint
static char rcsid[] = "$Header$"; static char rcsid[] = "$Header$";
#endif #endif lint
/* /*
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
* *
@ -18,17 +18,23 @@ static char rcsid[] = "$Header$";
* *
*/ */
/* Machine dependent back end routines for the VAX using 4-byte words /*
* Machine dependent back end routines for the VAX using 4-byte words
*/ */
con_part(sz,w) register sz; word w; { /*
* Byte order: | 3 | 2 | 1 | 0 |
/* Byte order: | 3 | 2 | 1 | 0 | */ */
con_part(sz, w)
/* Align new bytes on boundary of its on size. */ register int sz;
word w;
{
/*
* Align new bytes on boundary of its on size.
*/
while (part_size % sz) part_size++; while (part_size % sz) part_size++;
if (part_size == EM_WSIZE) if (part_size == TEM_WSIZE)
part_flush(); part_flush();
if (sz == 1 || sz == 2) { if (sz == 1 || sz == 2) {
/* Smaller than a machineword. */ /* Smaller than a machineword. */
@ -40,22 +46,26 @@ con_part(sz,w) register sz; word w; {
part_word = w; part_word = w;
} }
part_size += sz; part_size += sz;
} /* con_part */ }
con_mult(sz) word sz; {
con_mult(sz)
word sz;
{
if (sz != 4) if (sz != 4)
fatal("bad icon/ucon size"); fatal("bad icon/ucon size");
fprintf(codefile,".long\t%s\n",str); fprintf(codefile,".long\t%s\n",str);
} }
mes(mesno) word mesno ; { mes(mesno)
word mesno;
{
while (getarg(any_ptyp) != sp_cend ); while (getarg(any_ptyp) != sp_cend );
} }
con_float() { con_float()
{
/* Insert a dot at the right position, if it is not present, /*
* Insert a dot at the right position, if it is not present,
* to make the floating point constant acceptable to the assembler. * to make the floating point constant acceptable to the assembler.
*/ */
register char *c; register char *c;
@ -70,7 +80,8 @@ con_float() {
if (index(str,'.') != (char *) 0) { if (index(str,'.') != (char *) 0) {
fprintf(codefile,"%s\n",str); fprintf(codefile,"%s\n",str);
/* There must be a dot after the `e' or - if the `e' is not present - /*
* There must be a dot after the `e' or - if the `e' is not present -
* at the end. * at the end.
*/ */
} else if ((c = index(str,'e')) != (char *) 0) { } else if ((c = index(str,'e')) != (char *) 0) {
@ -78,12 +89,13 @@ con_float() {
fprintf(codefile,"%s.e%s\n",str,c--); fprintf(codefile,"%s.e%s\n",str,c--);
*c = 'e'; *c = 'e';
} else fprintf(codefile,"%s.\n",str); } else fprintf(codefile,"%s.\n",str);
} /* con_float */ }
#ifndef REGVARS #ifndef REGVARS
prolog(nlocals) full nlocals; { prolog(nlocals)
full nlocals;
fprintf(codefile,"\tpushl\tfp\n\tmovl\tsp,fp\n"); {
fprintf(codefile,".word 00\n");
if (nlocals == 0) if (nlocals == 0)
return; return;
if (nlocals == 4) if (nlocals == 4)
@ -94,7 +106,7 @@ prolog(nlocals) full nlocals; {
fprintf(codefile,"\tsubl2\t$%ld,sp\n",nlocals); fprintf(codefile,"\tsubl2\t$%ld,sp\n",nlocals);
} }
#endif REGVARS #endif not REGVARS
char *segname[] = { char *segname[] = {
".text", /* SEGTXT */ ".text", /* SEGTXT */
@ -104,14 +116,17 @@ char *segname[] = {
}; };
#ifdef REGVARS #ifdef REGVARS
int EM_BSIZE; /* Difference between AB and LB. */ static full nlocals; /* Number of local variables. */
static int nlocals; /* Number of local variables. */
#define NR_REG 8 /* Number of registers. */ #define NR_REG 8 /* Number of registers. */
#define FIRST_REG 4 #define FIRST_REG 4
#define LAST_REG (FIRST_REG + NR_REG - 1) #define LAST_REG (FIRST_REG + NR_REG - 1)
prolog(n) { /* Save number of locals. */ /*
* Save number of locals.
*/
prolog(n)
{
nlocals = n; nlocals = n;
} }
@ -124,15 +139,23 @@ static struct s_reg {
int sr_size; /* Size in bytes. */ int sr_size; /* Size in bytes. */
} a_reg[NR_REG + 1], *p_reg; } a_reg[NR_REG + 1], *p_reg;
i_regsave() { /* Initialize saving of registers. */ /*
EM_BSIZE = 0; * Initialize saving of registers.
*/
i_regsave()
{
p_reg = a_reg; p_reg = a_reg;
} }
regsave(str, off, size) char * str; long off; int size; { /*
* Called for each register to be saved.
/* Called for each register to be saved. */ * Save the parameters in the struct.
*/
regsave(str, off, size)
char *str;
long off;
int size;
{
p_reg->sr_str = str; p_reg->sr_str = str;
p_reg->sr_off = off; p_reg->sr_off = off;
(p_reg++)->sr_size = size; (p_reg++)->sr_size = size;
@ -142,8 +165,11 @@ regsave(str, off, size) char * str; long off; int size; {
); );
} }
f_regsave() { /*
* Generate code to save the registers.
*/
f_regsave()
{
register struct s_reg *p; register struct s_reg *p;
register int mask; register int mask;
register int i; register int i;
@ -151,10 +177,11 @@ f_regsave() {
mask = 0; mask = 0;
count = p_reg - a_reg; count = p_reg - a_reg;
for (p = a_reg; p < p_reg; p++) { /*
/* For each register to be saved, set a bit in the * For each register to be saved, set a bit in the
* mask corresponding to its number. * mask corresponding to its number.
*/ */
for (p = a_reg; p < p_reg; p++) {
i = atoi(p->sr_str + 1); i = atoi(p->sr_str + 1);
if (p->sr_size <= 4) if (p->sr_size <= 4)
mask |= (1 << i); mask |= (1 << i);
@ -163,59 +190,25 @@ f_regsave() {
count++; count++;
} }
} }
/*
/* Generate code to save registers. */ * Now generate code to save registers.
if (count > 2)
fprintf(codefile, "pushr\t$%d\n", mask);
else
for (i = FIRST_REG; i <= LAST_REG; i++) {
/* For all registers that can be used,
* see if it must be saved, and do that as cheap
* as possible.
*/ */
if (((mask >> i) & 03) == 03) { fprintf(codefile, ".word 0%o\n", mask);
fprintf(codefile, "movq\tr%d,-(sp)\n",i); /*
break; * Emit code to initialize parameters in registers.
} else if ((1 << i) & mask) {
if (count == 1)
fprintf(codefile,"pushl\tr%d\n",i);
else
fprintf(codefile,"pushr\t$%d\n",mask);
break;
}
}
/* Save a word indicating which registers were saved.
* The count uniquely specifies which registers were saved, because
* registers are always allocated consecutively within a class,
* starting from FIRST_REG. I only have one class.
*/ */
fprintf(codefile, "pushl\t$%d\n", count); for (p = a_reg; p < p_reg; p++)
if (p->sr_off >= 0)
/* Compute AB - LB. */
EM_BSIZE = 4 * count + 12;
/* Now finish the procedure prolog. */
fprintf(codefile, "pushl\tfp\nmovl\tsp,fp\n");
/* Emit code to initialize parameters in registers. */
for (p = a_reg; p < p_reg; p++) {
if (p->sr_off >= 0) {
if (p->sr_size == 4) {
fprintf(codefile, fprintf(codefile,
"movl\t%ld(fp),%s\n", "mov%c\t%ld(ap), %s\n,
p->sr_off + EM_BSIZE, p->sr_str p->sr_size == 4 ? 'l' : 'q',
p->sr_off,
p->sr_str
); );
} else if (p->sr_size == 8) {
fprintf(codefile,
"movq\t%ld(fp),%s\n",
p->sr_off + EM_BSIZE, p->sr_str
);
}
}
}
/* Generate room for locals. */ /*
* Generate room for locals.
*/
if (nlocals == 0) if (nlocals == 0)
return; return;
if (nlocals == 4) if (nlocals == 4)
@ -225,46 +218,36 @@ f_regsave() {
else else
fprintf(codefile,"subl2\t$%ld,sp\n",nlocals); fprintf(codefile,"subl2\t$%ld,sp\n",nlocals);
} /* f_regsave */ }
regreturn() { regreturn() { }
fprintf(codefile, "jmp\t.return\n"); regscore(off, size, typ, score, totyp)
} /* regreturn */ long off;
int size, typ, totyp, score;
{
register int i = score;
regscore(off, size, typ, score, totyp) long off; { /*
* If the offset doesn't fit in a byte, word-offset is used,
register int i;
i = score; /* Local/parameter is used score times. */
/* If the offset doesn't fit in a byte, word-offset is used,
* which is one byte more expensive. * which is one byte more expensive.
*/ */
if (off > 109 || off < -128) i *= 2; /* Word offset. */ if (off > 127 || off < -128) i *= 2;
/*
/* 109: guestimate. We don't know AB -LB yet. * Compute cost of initialization for parameters.
* 109 is the number if there are two registervariables.
*/ */
if (off > 127) i -= 5;
/* Compute cost of initialization for parameters. */ else if (off >= 0) i -= 4;
if (off > 109) /*
i -= 5; * Storing a pointer in a register sometimes saves an instruction.
else if (off >= 0)
i -= 4;
if (typ == reg_pointer)
i += score; /* Sometimes saves an instruction. */
else if (typ == reg_loop)
i += 5;
i -= 2; /* Cost of save. */
/* Actually the first registers are more expensive, but then
* the following registers are cheaper.
*/ */
if (typ == reg_pointer) i += score;
return (i); else if (typ == reg_loop) i += 5;
} /* regscore */ /*
* Now adjust for the saving of the register.
* But this costs no space at all.
*/
return i - 1;
}
#endif REGVARS #endif REGVARS