Skip to content

Commit caf1cef

Browse files
rth7680pm215
authored andcommitted
target/arm: Implement SVE Integer Compare - Scalars Group
Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20180613015641.5667-16-richard.henderson@linaro.org Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
1 parent 9ee3a61 commit caf1cef

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

target/arm/helper-sve.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,3 +678,5 @@ DEF_HELPER_FLAGS_4(sve_brkn, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
678678
DEF_HELPER_FLAGS_4(sve_brkns, TCG_CALL_NO_RWG, i32, ptr, ptr, ptr, i32)
679679

680680
DEF_HELPER_FLAGS_3(sve_cntp, TCG_CALL_NO_RWG, i64, ptr, ptr, i32)
681+
682+
DEF_HELPER_FLAGS_3(sve_while, TCG_CALL_NO_RWG, i32, ptr, i32, i32)

target/arm/sve.decode

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,14 @@ SINCDECP_r_64 00100101 .. 1010 d:1 u:1 10001 10 .... ..... @incdec_pred
606606
# SVE saturating inc/dec vector by predicate count
607607
SINCDECP_z 00100101 .. 1010 d:1 u:1 10000 00 .... ..... @incdec2_pred
608608

609+
### SVE Integer Compare - Scalars Group
610+
611+
# SVE conditionally terminate scalars
612+
CTERM 00100101 1 sf:1 1 rm:5 001000 rn:5 ne:1 0000
613+
614+
# SVE integer compare scalar count and limit
615+
WHILE 00100101 esz:2 1 rm:5 000 sf:1 u:1 1 rn:5 eq:1 rd:4
616+
609617
### SVE Memory - 32-bit Gather and Unsized Contiguous Group
610618

611619
# SVE load predicate register

target/arm/sve_helper.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,3 +2738,34 @@ uint64_t HELPER(sve_cntp)(void *vn, void *vg, uint32_t pred_desc)
27382738
}
27392739
return sum;
27402740
}
2741+
2742+
uint32_t HELPER(sve_while)(void *vd, uint32_t count, uint32_t pred_desc)
2743+
{
2744+
uintptr_t oprsz = extract32(pred_desc, 0, SIMD_OPRSZ_BITS) + 2;
2745+
intptr_t esz = extract32(pred_desc, SIMD_DATA_SHIFT, 2);
2746+
uint64_t esz_mask = pred_esz_masks[esz];
2747+
ARMPredicateReg *d = vd;
2748+
uint32_t flags;
2749+
intptr_t i;
2750+
2751+
/* Begin with a zero predicate register. */
2752+
flags = do_zero(d, oprsz);
2753+
if (count == 0) {
2754+
return flags;
2755+
}
2756+
2757+
/* Scale from predicate element count to bits. */
2758+
count <<= esz;
2759+
/* Bound to the bits in the predicate. */
2760+
count = MIN(count, oprsz * 8);
2761+
2762+
/* Set all of the requested bits. */
2763+
for (i = 0; i < count / 64; ++i) {
2764+
d->p[i] = esz_mask;
2765+
}
2766+
if (count & 63) {
2767+
d->p[i] = MAKE_64BIT_MASK(0, count & 63) & esz_mask;
2768+
}
2769+
2770+
return predtest_ones(d, oprsz, esz_mask);
2771+
}

target/arm/translate-sve.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,6 +3092,105 @@ static bool trans_SINCDECP_z(DisasContext *s, arg_incdec2_pred *a,
30923092
return true;
30933093
}
30943094

3095+
/*
3096+
*** SVE Integer Compare Scalars Group
3097+
*/
3098+
3099+
static bool trans_CTERM(DisasContext *s, arg_CTERM *a, uint32_t insn)
3100+
{
3101+
if (!sve_access_check(s)) {
3102+
return true;
3103+
}
3104+
3105+
TCGCond cond = (a->ne ? TCG_COND_NE : TCG_COND_EQ);
3106+
TCGv_i64 rn = read_cpu_reg(s, a->rn, a->sf);
3107+
TCGv_i64 rm = read_cpu_reg(s, a->rm, a->sf);
3108+
TCGv_i64 cmp = tcg_temp_new_i64();
3109+
3110+
tcg_gen_setcond_i64(cond, cmp, rn, rm);
3111+
tcg_gen_extrl_i64_i32(cpu_NF, cmp);
3112+
tcg_temp_free_i64(cmp);
3113+
3114+
/* VF = !NF & !CF. */
3115+
tcg_gen_xori_i32(cpu_VF, cpu_NF, 1);
3116+
tcg_gen_andc_i32(cpu_VF, cpu_VF, cpu_CF);
3117+
3118+
/* Both NF and VF actually look at bit 31. */
3119+
tcg_gen_neg_i32(cpu_NF, cpu_NF);
3120+
tcg_gen_neg_i32(cpu_VF, cpu_VF);
3121+
return true;
3122+
}
3123+
3124+
static bool trans_WHILE(DisasContext *s, arg_WHILE *a, uint32_t insn)
3125+
{
3126+
if (!sve_access_check(s)) {
3127+
return true;
3128+
}
3129+
3130+
TCGv_i64 op0 = read_cpu_reg(s, a->rn, 1);
3131+
TCGv_i64 op1 = read_cpu_reg(s, a->rm, 1);
3132+
TCGv_i64 t0 = tcg_temp_new_i64();
3133+
TCGv_i64 t1 = tcg_temp_new_i64();
3134+
TCGv_i32 t2, t3;
3135+
TCGv_ptr ptr;
3136+
unsigned desc, vsz = vec_full_reg_size(s);
3137+
TCGCond cond;
3138+
3139+
if (!a->sf) {
3140+
if (a->u) {
3141+
tcg_gen_ext32u_i64(op0, op0);
3142+
tcg_gen_ext32u_i64(op1, op1);
3143+
} else {
3144+
tcg_gen_ext32s_i64(op0, op0);
3145+
tcg_gen_ext32s_i64(op1, op1);
3146+
}
3147+
}
3148+
3149+
/* For the helper, compress the different conditions into a computation
3150+
* of how many iterations for which the condition is true.
3151+
*
3152+
* This is slightly complicated by 0 <= UINT64_MAX, which is nominally
3153+
* 2**64 iterations, overflowing to 0. Of course, predicate registers
3154+
* aren't that large, so any value >= predicate size is sufficient.
3155+
*/
3156+
tcg_gen_sub_i64(t0, op1, op0);
3157+
3158+
/* t0 = MIN(op1 - op0, vsz). */
3159+
tcg_gen_movi_i64(t1, vsz);
3160+
tcg_gen_umin_i64(t0, t0, t1);
3161+
if (a->eq) {
3162+
/* Equality means one more iteration. */
3163+
tcg_gen_addi_i64(t0, t0, 1);
3164+
}
3165+
3166+
/* t0 = (condition true ? t0 : 0). */
3167+
cond = (a->u
3168+
? (a->eq ? TCG_COND_LEU : TCG_COND_LTU)
3169+
: (a->eq ? TCG_COND_LE : TCG_COND_LT));
3170+
tcg_gen_movi_i64(t1, 0);
3171+
tcg_gen_movcond_i64(cond, t0, op0, op1, t0, t1);
3172+
3173+
t2 = tcg_temp_new_i32();
3174+
tcg_gen_extrl_i64_i32(t2, t0);
3175+
tcg_temp_free_i64(t0);
3176+
tcg_temp_free_i64(t1);
3177+
3178+
desc = (vsz / 8) - 2;
3179+
desc = deposit32(desc, SIMD_DATA_SHIFT, 2, a->esz);
3180+
t3 = tcg_const_i32(desc);
3181+
3182+
ptr = tcg_temp_new_ptr();
3183+
tcg_gen_addi_ptr(ptr, cpu_env, pred_full_reg_offset(s, a->rd));
3184+
3185+
gen_helper_sve_while(t2, ptr, t2, t3);
3186+
do_pred_flags(t2);
3187+
3188+
tcg_temp_free_ptr(ptr);
3189+
tcg_temp_free_i32(t2);
3190+
tcg_temp_free_i32(t3);
3191+
return true;
3192+
}
3193+
30953194
/*
30963195
*** SVE Memory - 32-bit Gather and Unsized Contiguous Group
30973196
*/

0 commit comments

Comments
 (0)