Gentoo Archives: gentoo-commits

From: Doug Goldstein <cardoe@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/qemu-kvm:qemu-kvm-0.13.0-gentoo commit in: target-sparc/
Date: Tue, 26 Jul 2011 17:16:21
Message-Id: 1b8b13f183e146667a5bbae86c04788897b2aaed.cardoe@gentoo
1 commit: 1b8b13f183e146667a5bbae86c04788897b2aaed
2 Author: Aurelien Jarno <aurelien <AT> aurel32 <DOT> net>
3 AuthorDate: Sat Dec 25 22:25:47 2010 +0000
4 Commit: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
5 CommitDate: Fri May 27 18:02:16 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/qemu-kvm.git;a=commit;h=1b8b13f1
7
8 target-sparc: fix udiv(cc) and sdiv(cc)
9
10 Since commit 5a4bb580cdb10b066f9fd67658b31cac4a4ea5e5, Xorg crashes on
11 a Debian Etch image. The commit itself is fine, but it triggers a bug
12 due to wrong computation of flags for udiv(cc) and sdiv(cc).
13
14 This patch only compute cc_src2 for the cc version of udiv/sdiv. It
15 also moves the update of cc_dst and cc_op to the helper, as it is
16 faster doing it here when there is already an helper.
17
18 Signed-off-by: Aurelien Jarno <aurelien <AT> aurel32.net>
19 Signed-off-by: Blue Swirl <blauwirbel <AT> gmail.com>
20 (cherry picked from commit 0fcec41eec0432c77645b4a407d3a3e030c4abc4)
21
22 Signed-off-by: Aurelien Jarno <aurelien <AT> aurel32.net>
23
24 ---
25 target-sparc/helper.h | 2 +
26 target-sparc/op_helper.c | 54 +++++++++++++++++++++++++++++++++++----------
27 target-sparc/translate.c | 12 +++++-----
28 3 files changed, 50 insertions(+), 18 deletions(-)
29
30 diff --git a/target-sparc/helper.h b/target-sparc/helper.h
31 index 6f103e7..e6d82f9 100644
32 --- a/target-sparc/helper.h
33 +++ b/target-sparc/helper.h
34 @@ -37,7 +37,9 @@ DEF_HELPER_0(save, void)
35 DEF_HELPER_0(restore, void)
36 DEF_HELPER_1(flush, void, tl)
37 DEF_HELPER_2(udiv, tl, tl, tl)
38 +DEF_HELPER_2(udiv_cc, tl, tl, tl)
39 DEF_HELPER_2(sdiv, tl, tl, tl)
40 +DEF_HELPER_2(sdiv_cc, tl, tl, tl)
41 DEF_HELPER_2(stdf, void, tl, int)
42 DEF_HELPER_2(lddf, void, tl, int)
43 DEF_HELPER_2(ldqf, void, tl, int)
44
45 diff --git a/target-sparc/op_helper.c b/target-sparc/op_helper.c
46 index be3c1e0..77411b8 100644
47 --- a/target-sparc/op_helper.c
48 +++ b/target-sparc/op_helper.c
49 @@ -3300,8 +3300,9 @@ void helper_rett(void)
50 }
51 #endif
52
53 -target_ulong helper_udiv(target_ulong a, target_ulong b)
54 +static target_ulong helper_udiv_common(target_ulong a, target_ulong b, int cc)
55 {
56 + int overflow = 0;
57 uint64_t x0;
58 uint32_t x1;
59
60 @@ -3314,16 +3315,31 @@ target_ulong helper_udiv(target_ulong a, target_ulong b)
61
62 x0 = x0 / x1;
63 if (x0 > 0xffffffff) {
64 - env->cc_src2 = 1;
65 - return 0xffffffff;
66 - } else {
67 - env->cc_src2 = 0;
68 - return x0;
69 + x0 = 0xffffffff;
70 + overflow = 1;
71 + }
72 +
73 + if (cc) {
74 + env->cc_dst = x0;
75 + env->cc_src2 = overflow;
76 + env->cc_op = CC_OP_DIV;
77 }
78 + return x0;
79 }
80
81 -target_ulong helper_sdiv(target_ulong a, target_ulong b)
82 +target_ulong helper_udiv(target_ulong a, target_ulong b)
83 +{
84 + return helper_udiv_common(a, b, 0);
85 +}
86 +
87 +target_ulong helper_udiv_cc(target_ulong a, target_ulong b)
88 +{
89 + return helper_udiv_common(a, b, 1);
90 +}
91 +
92 +static target_ulong helper_sdiv_common(target_ulong a, target_ulong b, int cc)
93 {
94 + int overflow = 0;
95 int64_t x0;
96 int32_t x1;
97
98 @@ -3336,12 +3352,26 @@ target_ulong helper_sdiv(target_ulong a, target_ulong b)
99
100 x0 = x0 / x1;
101 if ((int32_t) x0 != x0) {
102 - env->cc_src2 = 1;
103 - return x0 < 0? 0x80000000: 0x7fffffff;
104 - } else {
105 - env->cc_src2 = 0;
106 - return x0;
107 + x0 = x0 < 0 ? 0x80000000: 0x7fffffff;
108 + overflow = 1;
109 + }
110 +
111 + if (cc) {
112 + env->cc_dst = x0;
113 + env->cc_src2 = overflow;
114 + env->cc_op = CC_OP_DIV;
115 }
116 + return x0;
117 +}
118 +
119 +target_ulong helper_sdiv(target_ulong a, target_ulong b)
120 +{
121 + return helper_sdiv_common(a, b, 0);
122 +}
123 +
124 +target_ulong helper_sdiv_cc(target_ulong a, target_ulong b)
125 +{
126 + return helper_sdiv_common(a, b, 1);
127 }
128
129 void helper_stdf(target_ulong addr, int mem_idx)
130
131 diff --git a/target-sparc/translate.c b/target-sparc/translate.c
132 index 23f9519..21c5675 100644
133 --- a/target-sparc/translate.c
134 +++ b/target-sparc/translate.c
135 @@ -3162,20 +3162,20 @@ static void disas_sparc_insn(DisasContext * dc)
136 #endif
137 case 0xe: /* udiv */
138 CHECK_IU_FEATURE(dc, DIV);
139 - gen_helper_udiv(cpu_dst, cpu_src1, cpu_src2);
140 if (xop & 0x10) {
141 - tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
142 - tcg_gen_movi_i32(cpu_cc_op, CC_OP_DIV);
143 + gen_helper_udiv_cc(cpu_dst, cpu_src1, cpu_src2);
144 dc->cc_op = CC_OP_DIV;
145 + } else {
146 + gen_helper_udiv(cpu_dst, cpu_src1, cpu_src2);
147 }
148 break;
149 case 0xf: /* sdiv */
150 CHECK_IU_FEATURE(dc, DIV);
151 - gen_helper_sdiv(cpu_dst, cpu_src1, cpu_src2);
152 if (xop & 0x10) {
153 - tcg_gen_mov_tl(cpu_cc_dst, cpu_dst);
154 - tcg_gen_movi_i32(cpu_cc_op, CC_OP_DIV);
155 + gen_helper_sdiv_cc(cpu_dst, cpu_src1, cpu_src2);
156 dc->cc_op = CC_OP_DIV;
157 + } else {
158 + gen_helper_sdiv(cpu_dst, cpu_src1, cpu_src2);
159 }
160 break;
161 default: