Skip to content

Commit fdd2028

Browse files
gaosong-loongsonMichael Tokarev
authored andcommitted
target/loongarch: add check for fcond
fcond only has 22 types, add a check for fcond. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2972 Signed-off-by: Song Gao <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-Id: <[email protected]> (cherry picked from commit e7788da9860c97920c19fa1150806186513ef256) Signed-off-by: Michael Tokarev <[email protected]>
1 parent 3cf25f4 commit fdd2028

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

target/loongarch/tcg/insn_trans/trans_fcmp.c.inc

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
*/
55

66
/* bit0(signaling/quiet) bit1(lt) bit2(eq) bit3(un) bit4(neq) */
7-
static uint32_t get_fcmp_flags(int cond)
7+
static uint32_t get_fcmp_flags(DisasContext *ctx, int cond)
88
{
99
uint32_t flags = 0;
1010

11+
/*check cond , cond =[0-8,10,12] */
12+
if ((cond > 8) &&(cond != 10) && (cond != 12)) {
13+
return -1;
14+
}
15+
1116
if (cond & 0x1) {
1217
flags |= FCMP_LT;
1318
}
@@ -26,9 +31,14 @@ static uint32_t get_fcmp_flags(int cond)
2631
static bool trans_fcmp_cond_s(DisasContext *ctx, arg_fcmp_cond_s *a)
2732
{
2833
TCGv var, src1, src2;
29-
uint32_t flags;
34+
uint32_t flags = get_fcmp_flags(ctx, a->fcond >>1);
3035
void (*fn)(TCGv, TCGv_env, TCGv, TCGv, TCGv_i32);
3136

37+
if (flags == -1) {
38+
generate_exception(ctx, EXCCODE_INE);
39+
return true;
40+
}
41+
3242
if (!avail_FP_SP(ctx)) {
3343
return false;
3444
}
@@ -39,8 +49,6 @@ static bool trans_fcmp_cond_s(DisasContext *ctx, arg_fcmp_cond_s *a)
3949
src1 = get_fpr(ctx, a->fj);
4050
src2 = get_fpr(ctx, a->fk);
4151
fn = (a->fcond & 1 ? gen_helper_fcmp_s_s : gen_helper_fcmp_c_s);
42-
flags = get_fcmp_flags(a->fcond >> 1);
43-
4452
fn(var, tcg_env, src1, src2, tcg_constant_i32(flags));
4553

4654
tcg_gen_st8_tl(var, tcg_env, offsetof(CPULoongArchState, cf[a->cd]));
@@ -50,9 +58,14 @@ static bool trans_fcmp_cond_s(DisasContext *ctx, arg_fcmp_cond_s *a)
5058
static bool trans_fcmp_cond_d(DisasContext *ctx, arg_fcmp_cond_d *a)
5159
{
5260
TCGv var, src1, src2;
53-
uint32_t flags;
61+
uint32_t flags = get_fcmp_flags(ctx, a->fcond >> 1);
5462
void (*fn)(TCGv, TCGv_env, TCGv, TCGv, TCGv_i32);
5563

64+
if (flags == -1) {
65+
generate_exception(ctx, EXCCODE_INE);
66+
return true;
67+
}
68+
5669
if (!avail_FP_DP(ctx)) {
5770
return false;
5871
}
@@ -63,8 +76,6 @@ static bool trans_fcmp_cond_d(DisasContext *ctx, arg_fcmp_cond_d *a)
6376
src1 = get_fpr(ctx, a->fj);
6477
src2 = get_fpr(ctx, a->fk);
6578
fn = (a->fcond & 1 ? gen_helper_fcmp_s_d : gen_helper_fcmp_c_d);
66-
flags = get_fcmp_flags(a->fcond >> 1);
67-
6879
fn(var, tcg_env, src1, src2, tcg_constant_i32(flags));
6980

7081
tcg_gen_st8_tl(var, tcg_env, offsetof(CPULoongArchState, cf[a->cd]));

target/loongarch/tcg/insn_trans/trans_vec.c.inc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4655,39 +4655,47 @@ TRANS(xvslti_du, LASX, do_xcmpi, MO_64, TCG_COND_LTU)
46554655

46564656
static bool do_vfcmp_cond_s(DisasContext *ctx, arg_vvv_fcond *a, uint32_t sz)
46574657
{
4658-
uint32_t flags;
4658+
uint32_t flags = get_fcmp_flags(ctx, a->fcond >> 1);
46594659
void (*fn)(TCGv_env, TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32);
46604660
TCGv_i32 vd = tcg_constant_i32(a->vd);
46614661
TCGv_i32 vj = tcg_constant_i32(a->vj);
46624662
TCGv_i32 vk = tcg_constant_i32(a->vk);
46634663
TCGv_i32 oprsz = tcg_constant_i32(sz);
46644664

4665+
if(flags == -1){
4666+
generate_exception(ctx, EXCCODE_INE);
4667+
return true;
4668+
}
4669+
46654670
if (!check_vec(ctx, sz)) {
46664671
return true;
46674672
}
46684673

46694674
fn = (a->fcond & 1 ? gen_helper_vfcmp_s_s : gen_helper_vfcmp_c_s);
4670-
flags = get_fcmp_flags(a->fcond >> 1);
46714675
fn(tcg_env, oprsz, vd, vj, vk, tcg_constant_i32(flags));
46724676

46734677
return true;
46744678
}
46754679

46764680
static bool do_vfcmp_cond_d(DisasContext *ctx, arg_vvv_fcond *a, uint32_t sz)
46774681
{
4678-
uint32_t flags;
4682+
uint32_t flags = get_fcmp_flags(ctx, a->fcond >> 1);
46794683
void (*fn)(TCGv_env, TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32);
46804684
TCGv_i32 vd = tcg_constant_i32(a->vd);
46814685
TCGv_i32 vj = tcg_constant_i32(a->vj);
46824686
TCGv_i32 vk = tcg_constant_i32(a->vk);
46834687
TCGv_i32 oprsz = tcg_constant_i32(sz);
46844688

4689+
if (flags == -1) {
4690+
generate_exception(ctx, EXCCODE_INE);
4691+
return true;
4692+
}
4693+
46854694
if (!check_vec(ctx, sz)) {
46864695
return true;
46874696
}
46884697

46894698
fn = (a->fcond & 1 ? gen_helper_vfcmp_s_d : gen_helper_vfcmp_c_d);
4690-
flags = get_fcmp_flags(a->fcond >> 1);
46914699
fn(tcg_env, oprsz, vd, vj, vk, tcg_constant_i32(flags));
46924700

46934701
return true;

0 commit comments

Comments
 (0)