summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkugwa <kugwa2000@gmail.com>2016-01-19 12:09:57 +0800
committerkugwa <kugwa2000@gmail.com>2016-01-20 09:37:32 +0800
commitd78cec38b6850a5a59bd50da318f201528fdcb02 (patch)
tree01568bb6f86a56eff9d7ce94a24f864cadad892d
parent46b7c22b5f3fcb33c753ec7ddceba530999283f0 (diff)
downloadcompiler2015-d78cec38b6850a5a59bd50da318f201528fdcb02.tar
compiler2015-d78cec38b6850a5a59bd50da318f201528fdcb02.tar.gz
compiler2015-d78cec38b6850a5a59bd50da318f201528fdcb02.tar.bz2
compiler2015-d78cec38b6850a5a59bd50da318f201528fdcb02.tar.lz
compiler2015-d78cec38b6850a5a59bd50da318f201528fdcb02.tar.xz
compiler2015-d78cec38b6850a5a59bd50da318f201528fdcb02.tar.zst
compiler2015-d78cec38b6850a5a59bd50da318f201528fdcb02.zip
Fix the problem of immediates in register.c
-rw-r--r--src/register.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/register.c b/src/register.c
index e7759fd..af34c90 100644
--- a/src/register.c
+++ b/src/register.c
@@ -7,14 +7,15 @@
#include <stdlib.h>
#include <string.h>
-#define REG_NUM 6
-#define REG_RESERVED "w9"
+#define REG_NUM 5
+#define REG_ADDR "x9"
+#define REG_SWAP "w10"
#define REG_LOCK_MAX 3
#define REG_SIZE 4
#define SPILL_MAX 64
static const char *reg_name[REG_NUM] = {
- "w10", "w11", "w12", "w13", "w14", "w15"};
+ "w11", "w12", "w13", "w14", "w15"};
CcmmcRegPool *ccmmc_register_init(FILE *asm_output)
{
@@ -96,12 +97,15 @@ const char *ccmmc_register_lock(CcmmcRegPool *pool, CcmmcTmp *tmp)
"\t\t/* ccmmc_register_lock(): swap %s, [fp, #-%" PRIu64 "] */\n",
pool->list[i]->name,
tmp->addr);
- fprintf(pool->asm_output, "\t\tmov\t%s, %s\n", REG_RESERVED,
+ fprintf(pool->asm_output, // REG_ADDR holds the address on the stack
+ "\t\tldr\t" REG_ADDR ", =%" PRIu64 "\n"
+ "\t\tsub\t" REG_ADDR ", fp, " REG_ADDR "\n"
+ "\t\tmov\t" REG_SWAP ", %s\n"
+ "\t\tldr\t%s, [" REG_ADDR "]\n"
+ "\t\tstr\t" REG_SWAP ", [" REG_ADDR "]\n",
+ tmp->addr,
+ pool->list[i]->name,
pool->list[i]->name);
- fprintf(pool->asm_output, "\t\tldr\t%s, [fp, #-%" PRIu64 "]\n",
- pool->list[i]->name, tmp->addr);
- fprintf(pool->asm_output, "\t\tstr\t%s, [fp, #-%" PRIu64 "]\n",
- REG_RESERVED, tmp->addr);
// find the index of tmp in pool->spill
for (j = 0; j < pool->top - pool->num && pool->spill[j] != tmp; j++);
@@ -167,9 +171,14 @@ void ccmmc_register_free(CcmmcRegPool *pool, CcmmcTmp *tmp, uint64_t *offset)
// gen code to move the last tmp to this register
fprintf(pool->asm_output, "\t\t/* ccmmc_register_free(): */\n");
- fprintf(pool->asm_output, "\t\tldr\t%s, [fp, #-%" PRIu64 "]\n",
- tmp->reg->name, pool->spill[pool->top - pool->num]->addr);
- fprintf(pool->asm_output, "\t\tadd\tsp, sp, #%d\n", REG_SIZE);
+ fprintf(pool->asm_output, // REG_ADDR holds the address on the stack
+ "\t\tldr\t" REG_ADDR ", =%" PRIu64 "\n"
+ "\t\tsub\t" REG_ADDR ", fp, " REG_ADDR "\n"
+ "\t\tldr\t%s, [" REG_ADDR "]\n"
+ "\t\tadd\tsp, sp, #%d\n",
+ pool->spill[pool->top - pool->num]->addr,
+ tmp->reg->name,
+ REG_SIZE);
// offset
*offset -= REG_SIZE;