Skip to content

Commit 0637c56

Browse files
rth7680aurel32
authored andcommittedApr 27, 2013
tcg-arm: Implement division instructions
An armv7 extension implements division, present on Cortex A15. Reviewed-by: Aurelien Jarno <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent b6b24cb commit 0637c56

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
 

‎disas/arm.c

+4
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,10 @@ static const struct opcode32 arm_opcodes[] =
819819
{ARM_EXT_V3M, 0x00800090, 0x0fa000f0, "%22?sumull%20's%c\t%12-15r, %16-19r, %0-3r, %8-11r"},
820820
{ARM_EXT_V3M, 0x00a00090, 0x0fa000f0, "%22?sumlal%20's%c\t%12-15r, %16-19r, %0-3r, %8-11r"},
821821

822+
/* IDIV instructions. */
823+
{ARM_EXT_DIV, 0x0710f010, 0x0ff0f0f0, "sdiv%c\t%16-19r, %0-3r, %8-11r"},
824+
{ARM_EXT_DIV, 0x0730f010, 0x0ff0f0f0, "udiv%c\t%16-19r, %0-3r, %8-11r"},
825+
822826
/* V7 instructions. */
823827
{ARM_EXT_V7, 0xf450f000, 0xfd70f000, "pli\t%P"},
824828
{ARM_EXT_V7, 0x0320f0f0, 0x0ffffff0, "dbg%c\t#%0-3d"},

‎tcg/arm/tcg-target.c

+36
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,16 @@ static inline void tcg_out_smull32(TCGContext *s,
597597
}
598598
}
599599

600+
static inline void tcg_out_sdiv(TCGContext *s, int cond, int rd, int rn, int rm)
601+
{
602+
tcg_out32(s, 0x0710f010 | (cond << 28) | (rd << 16) | rn | (rm << 8));
603+
}
604+
605+
static inline void tcg_out_udiv(TCGContext *s, int cond, int rd, int rn, int rm)
606+
{
607+
tcg_out32(s, 0x0730f010 | (cond << 28) | (rd << 16) | rn | (rm << 8));
608+
}
609+
600610
static inline void tcg_out_ext8s(TCGContext *s, int cond,
601611
int rd, int rn)
602612
{
@@ -1868,6 +1878,25 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
18681878
args[3], args[4], const_args[2]);
18691879
break;
18701880

1881+
case INDEX_op_div_i32:
1882+
tcg_out_sdiv(s, COND_AL, args[0], args[1], args[2]);
1883+
break;
1884+
case INDEX_op_divu_i32:
1885+
tcg_out_udiv(s, COND_AL, args[0], args[1], args[2]);
1886+
break;
1887+
case INDEX_op_rem_i32:
1888+
tcg_out_sdiv(s, COND_AL, TCG_REG_R8, args[1], args[2]);
1889+
tcg_out_mul32(s, COND_AL, TCG_REG_R8, TCG_REG_R8, args[2]);
1890+
tcg_out_dat_reg(s, COND_AL, ARITH_SUB, args[0], args[1], TCG_REG_R8,
1891+
SHIFT_IMM_LSL(0));
1892+
break;
1893+
case INDEX_op_remu_i32:
1894+
tcg_out_udiv(s, COND_AL, TCG_REG_R8, args[1], args[2]);
1895+
tcg_out_mul32(s, COND_AL, TCG_REG_R8, TCG_REG_R8, args[2]);
1896+
tcg_out_dat_reg(s, COND_AL, ARITH_SUB, args[0], args[1], TCG_REG_R8,
1897+
SHIFT_IMM_LSL(0));
1898+
break;
1899+
18711900
default:
18721901
tcg_abort();
18731902
}
@@ -1954,6 +1983,13 @@ static const TCGTargetOpDef arm_op_defs[] = {
19541983

19551984
{ INDEX_op_deposit_i32, { "r", "0", "rZ" } },
19561985

1986+
#if TCG_TARGET_HAS_div_i32
1987+
{ INDEX_op_div_i32, { "r", "r", "r" } },
1988+
{ INDEX_op_rem_i32, { "r", "r", "r" } },
1989+
{ INDEX_op_divu_i32, { "r", "r", "r" } },
1990+
{ INDEX_op_remu_i32, { "r", "r", "r" } },
1991+
#endif
1992+
19571993
{ -1 },
19581994
};
19591995

‎tcg/arm/tcg-target.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ typedef enum {
5656
#define TCG_TARGET_CALL_STACK_OFFSET 0
5757

5858
/* optional instructions */
59-
#define TCG_TARGET_HAS_div_i32 0
6059
#define TCG_TARGET_HAS_ext8s_i32 1
6160
#define TCG_TARGET_HAS_ext16s_i32 1
6261
#define TCG_TARGET_HAS_ext8u_i32 0 /* and r0, r1, #0xff */
@@ -75,6 +74,12 @@ typedef enum {
7574
#define TCG_TARGET_HAS_movcond_i32 1
7675
#define TCG_TARGET_HAS_muls2_i32 1
7776

77+
#ifdef __ARM_ARCH_EXT_IDIV__
78+
#define TCG_TARGET_HAS_div_i32 1
79+
#else
80+
#define TCG_TARGET_HAS_div_i32 0
81+
#endif
82+
7883
extern bool tcg_target_deposit_valid(int ofs, int len);
7984
#define TCG_TARGET_deposit_i32_valid tcg_target_deposit_valid
8085

0 commit comments

Comments
 (0)
Please sign in to comment.