target/arm: Convert CLZ

Document our choice about the T32 CONSTRAINED UNPREDICTABLE behaviour.
This matches the undocumented choice made by the legacy decoder.

Backports commit 4c97f5b2f0fa9b37f9ff497f15411d809e6fd098 from qemu
This commit is contained in:
Richard Henderson 2019-11-19 20:14:35 -05:00 committed by Lioncash
parent 94968602b8
commit 74040da34c
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
3 changed files with 26 additions and 17 deletions

View file

@ -29,6 +29,7 @@
&s_rrrr s rd rn rm ra
&rrrr rd rn rm ra
&rrr rd rn rm
&rr rd rm
&r rm
&msr_reg rn r mask
&mrs_reg rd r
@ -197,6 +198,7 @@ CRC32CW .... 0001 0100 .... .... 0010 0100 .... @rndm
%sysm 8:1 16:4
@rm ---- .... .... .... .... .... .... rm:4 &r
@rdm ---- .... .... .... rd:4 .... .... rm:4 &rr
MRS_bank ---- 0001 0 r:1 00 .... rd:4 001. 0000 0000 &mrs_bank %sysm
MSR_bank ---- 0001 0 r:1 10 .... 1111 001. 0000 rn:4 &msr_bank %sysm
@ -207,3 +209,5 @@ MSR_reg ---- 0001 0 r:1 10 mask:4 1111 0000 0000 rn:4 &msr_reg
BX .... 0001 0010 1111 1111 1111 0001 .... @rm
BXJ .... 0001 0010 1111 1111 1111 0010 .... @rm
BLX_r .... 0001 0010 1111 1111 1111 0011 .... @rm
CLZ .... 0001 0110 1111 .... 1111 0001 .... @rdm

View file

@ -26,6 +26,7 @@
&s_rrrr !extern s rd rn rm ra
&rrrr !extern rd rn rm ra
&rrr !extern rd rn rm
&rr !extern rd rm
&r !extern rm
&msr_reg !extern rn r mask
&mrs_reg !extern rd r
@ -124,8 +125,9 @@ RSB_rri 1111 0.0 1110 . .... 0 ... .... ........ @s_rri_rot
@s0_rnadm .... .... .... rn:4 ra:4 rd:4 .... rm:4 &s_rrrr s=0
@s0_rn0dm .... .... .... rn:4 .... rd:4 .... rm:4 &s_rrrr ra=0 s=0
@rnadm .... .... .... rn:4 ra:4 rd:4 .... rm:4 &rrrr
@rndm .... .... .... rn:4 .... rd:4 .... rm:4 &rrr
@rn0dm .... .... .... rn:4 .... rd:4 .... rm:4 &rrrr ra=0
@rndm .... .... .... rn:4 .... rd:4 .... rm:4 &rrr
@rdm .... .... .... .... .... rd:4 .... rm:4 &rr
{
MUL 1111 1011 0000 .... 1111 .... 0000 .... @s0_rn0dm
@ -180,6 +182,9 @@ CRC32CB 1111 1010 1101 .... 1111 .... 1000 .... @rndm
CRC32CH 1111 1010 1101 .... 1111 .... 1001 .... @rndm
CRC32CW 1111 1010 1101 .... 1111 .... 1010 .... @rndm
# Note rn != rm is CONSTRAINED UNPREDICTABLE; we choose to ignore rn.
CLZ 1111 1010 1011 ---- 1111 .... 1000 .... @rdm
# Branches and miscellaneous control
%msr_sysm 4:1 8:4

View file

@ -8717,6 +8717,20 @@ static bool trans_BLX_r(DisasContext *s, arg_BLX_r *a)
return true;
}
static bool trans_CLZ(DisasContext *s, arg_CLZ *a)
{
TCGContext *tcg_ctx = s->uc->tcg_ctx;
TCGv_i32 tmp;
if (!ENABLE_ARCH_5) {
return false;
}
tmp = load_reg(s, a->rm);
tcg_gen_clzi_i32(tcg_ctx, tmp, tmp, 32);
store_reg(s, a->rd, tmp);
return true;
}
/*
* Legacy decoder.
*/
@ -9014,18 +9028,7 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
/* MSR/MRS (banked/register) */
/* All done in decodetree. Illegal ops already signalled. */
g_assert_not_reached();
case 0x1:
if (op1 == 3) {
/* clz */
ARCH(5);
rd = (insn >> 12) & 0xf;
tmp = load_reg(s, rm);
tcg_gen_clzi_i32(tcg_ctx, tmp, tmp, 32);
store_reg(s, rd, tmp);
} else {
goto illegal_op;
}
break;
case 0x1: /* bx, clz */
case 0x2: /* bxj */
case 0x3: /* blx */
case 0x4: /* crc32 */
@ -10470,13 +10473,13 @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
case 0x08: /* rev */
case 0x09: /* rev16 */
case 0x0b: /* revsh */
case 0x18: /* clz */
break;
case 0x10: /* sel */
if (!arm_dc_feature(s, ARM_FEATURE_THUMB_DSP)) {
goto illegal_op;
}
break;
case 0x18: /* clz, in decodetree */
case 0x20: /* crc32/crc32c, in decodetree */
case 0x21:
case 0x22:
@ -10509,9 +10512,6 @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
tcg_temp_free_i32(tcg_ctx, tmp3);
tcg_temp_free_i32(tcg_ctx, tmp2);
break;
case 0x18: /* clz */
tcg_gen_clzi_i32(tcg_ctx, tmp, tmp, 32);
break;
default:
g_assert_not_reached();
}