Commit 8682223f by Kazu Hirata Committed by Kazu Hirata

h8300.c: Fix a comment typo.

2000-10-18  Kazu Hirata  <kazu@hxi.com>

	* h8300.c: Fix a comment typo.
	(round_frame_size): New.
	(compute_saved_regs): Likewise.
	(push): Likewise.
	(pop): Likewise.
	(push_order): Remove.
	(pop_order): Likewise.
	(function_prologue): Rearrange code for readability.
	(function_epilogue): Likewise.

From-SVN: r36930
parent c5251260
...@@ -28,6 +28,16 @@ ...@@ -28,6 +28,16 @@
2000-10-18 Kazu Hirata <kazu@hxi.com> 2000-10-18 Kazu Hirata <kazu@hxi.com>
* h8300.c: Fix a comment typo.
(round_frame_size): New.
(compute_saved_regs): Likewise.
(push): Likewise.
(pop): Likewise.
(push_order): Remove.
(pop_order): Likewise.
(function_prologue): Rearrange code for readability.
(function_epilogue): Likewise.
* config/h8300/h8300.md: Remove an unnecessary sign_extend * config/h8300/h8300.md: Remove an unnecessary sign_extend
expander that is used when not optimizing. Output a tab after expander that is used when not optimizing. Output a tab after
each assembly insns. each assembly insns.
......
...@@ -47,6 +47,10 @@ static int h8300_interrupt_function_p PARAMS ((tree)); ...@@ -47,6 +47,10 @@ static int h8300_interrupt_function_p PARAMS ((tree));
static int h8300_monitor_function_p PARAMS ((tree)); static int h8300_monitor_function_p PARAMS ((tree));
static int h8300_os_task_function_p PARAMS ((tree)); static int h8300_os_task_function_p PARAMS ((tree));
static void dosize PARAMS ((FILE *, const char *, unsigned int)); static void dosize PARAMS ((FILE *, const char *, unsigned int));
static int round_frame_size PARAMS ((int));
static unsigned int compute_saved_regs PARAMS ((void));
static void push PARAMS ((FILE *, int));
static void pop PARAMS ((FILE *, int));
static const char *cond_string PARAMS ((enum rtx_code)); static const char *cond_string PARAMS ((enum rtx_code));
/* CPU_TYPE, says what cpu we're compiling for. */ /* CPU_TYPE, says what cpu we're compiling for. */
...@@ -100,7 +104,7 @@ h8300_init_once () ...@@ -100,7 +104,7 @@ h8300_init_once ()
} }
else else
{ {
/* For this we treat the H8/300 and H8/S the same. */ /* For this we treat the H8/300H and H8/S the same. */
cpu_type = (int) CPU_H8300H; cpu_type = (int) CPU_H8300H;
h8_reg_names = names_extended; h8_reg_names = names_extended;
} }
...@@ -184,11 +188,57 @@ dosize (file, op, size) ...@@ -184,11 +188,57 @@ dosize (file, op, size)
} }
} }
/* Output assembly language code for the function prologue. */ /* Round up frame size SIZE. */
static int push_order[FIRST_PSEUDO_REGISTER] =
{ 0, 1, 2, 3, 4, 5, 6, -1, -1, -1 }; static int
static int pop_order[FIRST_PSEUDO_REGISTER] = round_frame_size (size)
{ 6, 5, 4, 3, 2, 1, 0, -1, -1, -1 }; int size;
{
return (size + STACK_BOUNDARY / 8 - 1) & -STACK_BOUNDARY / 8;
}
/* Compute which registers to push/pop.
Return a bit vector of registers. */
static unsigned int
compute_saved_regs ()
{
unsigned int saved_regs = 0;
int regno;
/* Construct a bit vector of registers to be pushed/popped. */
for (regno = 0; regno <= 6; regno++)
{
if (WORD_REG_USED (regno))
saved_regs |= 1 << regno;
}
/* Don't push/pop the frame pointer as it is treated separately. */
if (frame_pointer_needed)
saved_regs &= ~(1 << FRAME_POINTER_REGNUM);
return saved_regs;
}
/* Output assembly language code to push register RN. */
static void
push (file, rn)
FILE *file;
int rn;
{
fprintf (file, "\t%s\t%s\n", h8_push_op, h8_reg_names[rn]);
}
/* Output assembly language code to pop register RN. */
static void
pop (file, rn)
FILE *file;
int rn;
{
fprintf (file, "\t%s\t%s\n", h8_pop_op, h8_reg_names[rn]);
}
/* This is what the stack looks like after the prolog of /* This is what the stack looks like after the prolog of
a function with a frame has been set up: a function with a frame has been set up:
...@@ -208,14 +258,16 @@ static int pop_order[FIRST_PSEUDO_REGISTER] = ...@@ -208,14 +258,16 @@ static int pop_order[FIRST_PSEUDO_REGISTER] =
<saved registers> <- sp <saved registers> <- sp
*/ */
/* Output assembly language code for the function prologue. */
void void
function_prologue (file, size) function_prologue (file, size)
FILE *file; FILE *file;
int size; int size;
{ {
int fsize = (size + STACK_BOUNDARY / 8 - 1) & -STACK_BOUNDARY / 8; int fsize = round_frame_size (size);
int idx; int idx;
int push_regs[FIRST_PSEUDO_REGISTER]; int saved_regs;
int n_regs; int n_regs;
/* Note a function with the interrupt attribute and set interrupt_handler /* Note a function with the interrupt attribute and set interrupt_handler
...@@ -243,14 +295,14 @@ function_prologue (file, size) ...@@ -243,14 +295,14 @@ function_prologue (file, size)
if (TARGET_H8300) if (TARGET_H8300)
{ {
fprintf (file, "\tsubs\t#2,sp\n"); fprintf (file, "\tsubs\t#2,sp\n");
fprintf (file, "\tpush\tr0\n"); push (file, 0);
fprintf (file, "\tstc\tccr,r0l\n"); fprintf (file, "\tstc\tccr,r0l\n");
fprintf (file, "\torc\t#128,ccr\n"); fprintf (file, "\torc\t#128,ccr\n");
fprintf (file, "\tmov.b\tr0l,@(4,sp)\n"); fprintf (file, "\tmov.b\tr0l,@(4,sp)\n");
} }
else else
{ {
fprintf (file, "\tpush\ter0\n"); push (file, 0);
fprintf (file, "\tstc\tccr,r0l\n"); fprintf (file, "\tstc\tccr,r0l\n");
fprintf (file, "\torc\t#128,ccr\n"); fprintf (file, "\torc\t#128,ccr\n");
fprintf (file, "\tmov.b\tr0l,@(4,sp)\n"); fprintf (file, "\tmov.b\tr0l,@(4,sp)\n");
...@@ -260,8 +312,7 @@ function_prologue (file, size) ...@@ -260,8 +312,7 @@ function_prologue (file, size)
if (frame_pointer_needed) if (frame_pointer_needed)
{ {
/* Push fp. */ /* Push fp. */
fprintf (file, "\t%s\t%s\n", h8_push_op, push (file, FRAME_POINTER_REGNUM);
h8_reg_names[FRAME_POINTER_REGNUM]);
fprintf (file, "\t%s\t%s,%s\n", h8_mov_op, fprintf (file, "\t%s\t%s,%s\n", h8_mov_op,
h8_reg_names[STACK_POINTER_REGNUM], h8_reg_names[STACK_POINTER_REGNUM],
h8_reg_names[FRAME_POINTER_REGNUM]); h8_reg_names[FRAME_POINTER_REGNUM]);
...@@ -270,48 +321,33 @@ function_prologue (file, size) ...@@ -270,48 +321,33 @@ function_prologue (file, size)
/* Leave room for locals. */ /* Leave room for locals. */
dosize (file, "sub", fsize); dosize (file, "sub", fsize);
/* Compute which registers to push. */ /* Push the rest of the registers in ascending order. */
for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++) saved_regs = compute_saved_regs ();
{
int regno = push_order[idx];
if (regno >= 0
&& WORD_REG_USED (regno)
&& (!frame_pointer_needed || regno != FRAME_POINTER_REGNUM))
push_regs[idx] = regno;
else
push_regs[idx] = -1;
}
/* Push the rest of the registers. */
for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx += n_regs) for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx += n_regs)
{ {
int regno = push_regs[idx]; int regno = idx;
n_regs = 1; n_regs = 1;
if (regno >= 0) if (saved_regs & (1 << regno))
{ {
if (TARGET_H8300S) if (TARGET_H8300S)
{ {
/* See how many registers we can push at the same time. */ /* See how many registers we can push at the same time. */
if ((regno == 0 || regno == 4) if ((regno == 0 || regno == 4)
&& push_regs[idx + 1] >= 0 && ((saved_regs >> regno) & 0x0f) == 0x0f)
&& push_regs[idx + 2] >= 0
&& push_regs[idx + 3] >= 0)
n_regs = 4; n_regs = 4;
else if ((regno == 0 || regno == 4) else if ((regno == 0 || regno == 4)
&& push_regs[idx + 1] >= 0 && ((saved_regs >> regno) & 0x07) == 0x07)
&& push_regs[idx + 2] >= 0)
n_regs = 3; n_regs = 3;
else if ((regno == 0 || regno == 2 || regno == 4 || regno == 6) else if ((regno == 0 || regno == 2 || regno == 4 || regno == 6)
&& push_regs[idx + 1] >= 0) && ((saved_regs >> regno) & 0x03) == 0x03)
n_regs = 2; n_regs = 2;
} }
if (n_regs == 1) if (n_regs == 1)
fprintf (file, "\t%s\t%s\n", h8_push_op, h8_reg_names[regno]); push (file, regno);
else else
fprintf (file, "\tstm.l\t%s-%s,@-sp\n", fprintf (file, "\tstm.l\t%s-%s,@-sp\n",
h8_reg_names[regno], h8_reg_names[regno],
...@@ -327,10 +363,10 @@ function_epilogue (file, size) ...@@ -327,10 +363,10 @@ function_epilogue (file, size)
FILE *file; FILE *file;
int size; int size;
{ {
int fsize = (size + STACK_BOUNDARY / 8 - 1) & -STACK_BOUNDARY / 8; int fsize = round_frame_size (size);
int idx; int idx;
rtx insn = get_last_insn (); rtx insn = get_last_insn ();
int pop_regs[FIRST_PSEUDO_REGISTER]; int saved_regs;
int n_regs; int n_regs;
if (os_task) if (os_task)
...@@ -353,48 +389,33 @@ function_epilogue (file, size) ...@@ -353,48 +389,33 @@ function_epilogue (file, size)
if (insn && GET_CODE (insn) == BARRIER) if (insn && GET_CODE (insn) == BARRIER)
goto out; goto out;
/* Compute which registers to pop. */ /* Pop the saved registers in descending order. */
for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++) saved_regs = compute_saved_regs ();
{
int regno = pop_order[idx];
if (regno >= 0
&& WORD_REG_USED (regno)
&& (!frame_pointer_needed || regno != FRAME_POINTER_REGNUM))
pop_regs[idx] = regno;
else
pop_regs[idx] = -1;
}
/* Pop the saved registers. */
for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx += n_regs) for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx += n_regs)
{ {
int regno = pop_regs[idx]; int regno = (FIRST_PSEUDO_REGISTER - 1) - idx;
n_regs = 1; n_regs = 1;
if (regno >= 0) if (saved_regs & (1 << regno))
{ {
if (TARGET_H8300S) if (TARGET_H8300S)
{ {
/* See how many registers we can pop at the same time. */ /* See how many registers we can pop at the same time. */
if ((regno == 7 || regno == 3) if ((regno == 7 || regno == 3)
&& pop_regs[idx + 1] >= 0 && ((saved_regs >> (regno - 3)) & 0x0f) == 0x0f)
&& pop_regs[idx + 2] >= 0
&& pop_regs[idx + 3] >= 0)
n_regs = 4; n_regs = 4;
else if ((regno == 6 || regno == 2) else if ((regno == 6 || regno == 2)
&& pop_regs[idx + 1] >= 0 && ((saved_regs >> (regno - 2)) & 0x07) == 0x07)
&& pop_regs[idx + 2] >= 0)
n_regs = 3; n_regs = 3;
else if ((regno == 7 || regno == 5 || regno == 3 || regno == 1) else if ((regno == 7 || regno == 5 || regno == 3 || regno == 1)
&& pop_regs[idx + 1] >= 0) && ((saved_regs >> (regno - 1)) & 0x03) == 0x03)
n_regs = 2; n_regs = 2;
} }
if (n_regs == 1) if (n_regs == 1)
fprintf (file, "\t%s\t%s\n", h8_pop_op, h8_reg_names[regno]); pop (file, regno);
else else
fprintf (file, "\tldm.l\t@sp+,%s-%s\n", fprintf (file, "\tldm.l\t@sp+,%s-%s\n",
h8_reg_names[regno - (n_regs - 1)], h8_reg_names[regno - (n_regs - 1)],
...@@ -407,13 +428,12 @@ function_epilogue (file, size) ...@@ -407,13 +428,12 @@ function_epilogue (file, size)
/* Pop frame pointer if we had one. */ /* Pop frame pointer if we had one. */
if (frame_pointer_needed) if (frame_pointer_needed)
fprintf (file, "\t%s\t%s\n", pop (file, FRAME_POINTER_REGNUM);
h8_pop_op, h8_reg_names[FRAME_POINTER_REGNUM]);
/* If this is a monitor function, there is one register still left on /* If this is a monitor function, there is one register still left on
the stack. */ the stack. */
if (monitor) if (monitor)
fprintf (file, "\t%s\t%s\n", h8_pop_op, h8_reg_names[0]); pop (file, 0);
if (interrupt_handler) if (interrupt_handler)
fprintf (file, "\trte\n"); fprintf (file, "\trte\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment