Skip to content

Commit

Permalink
rename local variable
Browse files Browse the repository at this point in the history
  • Loading branch information
DrXiao committed Nov 24, 2024
1 parent 8ebcac9 commit 902e0fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/arm-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
* 1. division and modulo.
* 2. load and store operations.
*/
arm_reg helper_reg;
arm_reg interm;

switch (ph2_ir->op) {
case OP_define:
Expand Down Expand Up @@ -239,25 +239,25 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
return;
case OP_load:
case OP_global_load:
helper_reg = ph2_ir->op == OP_load ? __sp : __r12;
interm = ph2_ir->op == OP_load ? __sp : __r12;
if (ph2_ir->src0 > 4095) {
emit(__movw(__AL, __r8, ph2_ir->src0));
emit(__movt(__AL, __r8, ph2_ir->src0));
emit(__add_r(__AL, __r8, helper_reg, __r8));
emit(__add_r(__AL, __r8, interm, __r8));
emit(__lw(__AL, rd, __r8, 0));
} else
emit(__lw(__AL, rd, helper_reg, ph2_ir->src0));
emit(__lw(__AL, rd, interm, ph2_ir->src0));
return;
case OP_store:
case OP_global_store:
helper_reg = ph2_ir->op == OP_store ? __sp : __r12;
interm = ph2_ir->op == OP_store ? __sp : __r12;
if (ph2_ir->src1 > 4095) {
emit(__movw(__AL, __r8, ph2_ir->src1));
emit(__movt(__AL, __r8, ph2_ir->src1));
emit(__add_r(__AL, __r8, helper_reg, __r8));
emit(__add_r(__AL, __r8, interm, __r8));
emit(__sw(__AL, rn, __r8, 0));
} else
emit(__sw(__AL, rn, helper_reg, ph2_ir->src1));
emit(__sw(__AL, rn, interm, ph2_ir->src1));
return;
case OP_read:
if (ph2_ir->src1 == 1)
Expand Down Expand Up @@ -339,7 +339,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
}
return;
}
helper_reg = __r8;
interm = __r8;
/* div/mod emulation */
/* Preserve the values of the dividend and divisor */
emit(__stmdb(__AL, 1, __sp, (1 << rn) | (1 << rm)));
Expand All @@ -357,7 +357,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
* in __r9. The sign of the divisor is irrelevant for determining
* the result's sign.
*/
helper_reg = __r9;
interm = __r9;
emit(__mov_r(__AL, __r10, __r8));
}
/* Unsigned integer division */
Expand Down Expand Up @@ -388,7 +388,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
*/
emit(__mov_r(__AL, __r9, rn));
emit(__ldm(__AL, 1, __sp, (1 << rn) | (1 << rm)));
emit(__mov_r(__AL, rd, helper_reg));
emit(__mov_r(__AL, rd, interm));
/* Handle the correct sign for the quotient or remainder */
emit(__cmp_i(__AL, __r10, 0));
emit(__rsb_i(__NE, rd, 0, rd));
Expand Down
20 changes: 10 additions & 10 deletions src/riscv-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
* 1. division and modulo.
* 2. load and store operations.
*/
rv_reg helper_reg, divisor_mask = __t1;
rv_reg interm, divisor_mask = __t1;

switch (ph2_ir->op) {
case OP_define:
Expand Down Expand Up @@ -200,25 +200,25 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
return;
case OP_load:
case OP_global_load:
helper_reg = ph2_ir->op == OP_load ? __sp : __gp;
interm = ph2_ir->op == OP_load ? __sp : __gp;
if (ph2_ir->src0 < -2048 || ph2_ir->src0 > 2047) {
emit(__lui(__t0, rv_hi(ph2_ir->src0)));
emit(__addi(__t0, __t0, rv_lo(ph2_ir->src0)));
emit(__add(__t0, helper_reg, __t0));
emit(__add(__t0, interm, __t0));
emit(__lw(rd, __t0, 0));
} else
emit(__lw(rd, helper_reg, ph2_ir->src0));
emit(__lw(rd, interm, ph2_ir->src0));
return;
case OP_store:
case OP_global_store:
helper_reg = ph2_ir->op == OP_store ? __sp : __gp;
interm = ph2_ir->op == OP_store ? __sp : __gp;
if (ph2_ir->src1 < -2048 || ph2_ir->src1 > 2047) {
emit(__lui(__t0, rv_hi(ph2_ir->src1)));
emit(__addi(__t0, __t0, rv_lo(ph2_ir->src1)));
emit(__add(__t0, helper_reg, __t0));
emit(__add(__t0, interm, __t0));
emit(__sw(rs1, __t0, 0));
} else
emit(__sw(rs1, helper_reg, ph2_ir->src1));
emit(__sw(rs1, interm, ph2_ir->src1));
return;
case OP_read:
if (ph2_ir->src1 == 1)
Expand Down Expand Up @@ -313,14 +313,14 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
emit(__mod(rd, rs1, rs2));
return;
}
helper_reg = __t0;
interm = __t0;
/* div/mod emulation */
if (ph2_ir->op == OP_mod) {
/* If the requested operation is modulo, the result will be stored
* in __t2. The sign of the divisor is irrelevant for determining
* the result's sign.
*/
helper_reg = __t2;
interm = __t2;
divisor_mask = __zero;
}
/* Obtain absolute values of the dividend and divisor */
Expand Down Expand Up @@ -348,7 +348,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
emit(__srli(__t1, __t1, 1));
emit(__srli(__t3, __t3, 1));
emit(__bne(__t1, __zero, -20));
emit(__addi(rd, helper_reg, 0));
emit(__addi(rd, interm, 0));
/* Handle the correct sign for the quotient or remainder */
emit(__beq(__t5, __zero, 8));
emit(__sub(rd, __zero, rd));
Expand Down

0 comments on commit 902e0fb

Please sign in to comment.