Received: from [140.186.70.92] (port=54847 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q2p2G-0004jZ-CS for qemu-devel@nongnu.org; Thu, 24 Mar 2011 14:13:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q2p2F-0001DS-0A for qemu-devel@nongnu.org; Thu, 24 Mar 2011 14:13:28 -0400 Received: from cantor2.suse.de ([195.135.220.15]:38007 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q2p2E-0001DI-HR for qemu-devel@nongnu.org; Thu, 24 Mar 2011 14:13:26 -0400 References: <1300982333-12802-1-git-send-email-agraf@suse.de> <1300982333-12802-15-git-send-email-agraf@suse.de> In-Reply-To: Mime-Version: 1.0 (iPhone Mail 8C148) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Message-Id: From: Alexander Graf Subject: Re: [Qemu-devel] [PATCH 14/17] s390x: Implement opcode helpers Date: Thu, 24 Mar 2011 19:13:03 +0100 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU-devel Developers , Aurelien Jarno , Richard Henderson Am 24.03.2011 um 18:29 schrieb Peter Maydell : > On 24 March 2011 15:58, Alexander Graf wrote: >=20 > This is more random comments in passing than a thorough review; sorry. >=20 >> +#if HOST_LONG_BITS =3D=3D 64 && defined(__GNUC__) >> + /* assuming 64-bit hosts have __uint128_t */ >> + __uint128_t dividend =3D (((__uint128_t)env->regs[r1]) << 64) | >> + (env->regs[r1+1]); >> + __uint128_t quotient =3D dividend / divisor; >> + env->regs[r1+1] =3D quotient; >> + __uint128_t remainder =3D dividend % divisor; >> + env->regs[r1] =3D remainder; >> +#else >> + /* 32-bit hosts would need special wrapper functionality - just a= bort if >> + we encounter such a case; it's very unlikely anyways. */ >> + cpu_abort(env, "128 -> 64/64 division not implemented\n"); >> +#endif >=20 > ...I'm still using a 32 bit system :-) >=20 >> +/* condition codes for binary FP ops */ >> +static uint32_t set_cc_f32(float32 v1, float32 v2) >> +{ >> + if (float32_is_any_nan(v1) || float32_is_any_nan(v2)) { >> + return 3; >> + } else if (float32_eq(v1, v2, &env->fpu_status)) { >> + return 0; >> + } else if (float32_lt(v1, v2, &env->fpu_status)) { >> + return 1; >> + } else { >> + return 2; >> + } >> +} >=20 > Can you not use float32_compare_quiet() (returns a value > telling you if it's less/equal/greater/unordered)? > If not, needs a comment saying why you need to do it the hard way. Phew - I really have (almost) no clue about fp. Those parts come from Uli. S= o I guess it's the easiest to just ask him :) >=20 >> +/* negative absolute of 32-bit float */ >> +uint32_t HELPER(lcebr)(uint32_t f1, uint32_t f2) >> +{ >> + env->fregs[f1].l.upper =3D float32_sub(float32_zero, env->fregs[f2].= l.upper, >> + &env->fpu_status); >> + return set_cc_nz_f32(env->fregs[f1].l.upper); >> +} >=20 > Google suggests this is wrong: > http://publib.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/DZ9AR006/19.4.10?SHELF=3D= &DT=3D19990630131355&CASE=3D > says for lcebr that: > "The sign is inverted for any operand, including a QNaN or SNaN, > without causing an arithmetic exception." >=20 > but float32_sub will raise exceptions for NaNs. You want > float32_chs() (and similarly for the other types). >=20 >> +/* convert 64-bit float to 128-bit float */ >> +uint32_t HELPER(lcxbr)(uint32_t f1, uint32_t f2) >=20 > Wrong comment? Looks like another invert-sign op from > the online POO. >=20 >> +/* 128-bit FP compare RR */ >> +uint32_t HELPER(cxbr)(uint32_t f1, uint32_t f2) >> +{ >> + CPU_QuadU v1; >> + v1.ll.upper =3D env->fregs[f1].ll; >> + v1.ll.lower =3D env->fregs[f1 + 2].ll; >> + CPU_QuadU v2; >> + v2.ll.upper =3D env->fregs[f2].ll; >> + v2.ll.lower =3D env->fregs[f2 + 2].ll; >> + if (float128_is_any_nan(v1.q) || float128_is_any_nan(v2.q)) { >> + return 3; >> + } else if (float128_eq(v1.q, v2.q, &env->fpu_status)) { >> + return 0; >> + } else if (float128_lt(v1.q, v2.q, &env->fpu_status)) { >> + return 1; >> + } else { >> + return 2; >> + } >> +} >=20 > float128_compare_quiet() again? >=20 >> +/* convert 32-bit float to 64-bit int */ >> +uint32_t HELPER(cgebr)(uint32_t r1, uint32_t f2, uint32_t m3) >> +{ >> + float32 v2 =3D env->fregs[f2].l.upper; >> + set_round_mode(m3); >> + env->regs[r1] =3D float32_to_int64(v2, &env->fpu_status); >> + return set_cc_nz_f32(v2); >> +} >=20 > Should this really be permanently setting the rounding mode > for future instructions as well as for the op it does itself? >=20 >> +/* load 32-bit FP zero */ >> +void HELPER(lzer)(uint32_t f1) >> +{ >> + env->fregs[f1].l.upper =3D float32_zero; >> +} >=20 > Surely this is trivial enough to inline rather than > calling a helper function... >=20 >> +/* load 128-bit FP zero */ >> +void HELPER(lzxr)(uint32_t f1) >> +{ >> + CPU_QuadU x; >> + x.q =3D float64_to_float128(float64_zero, &env->fpu_status); >=20 > Yuck. Just define a float128_zero if we need one. >=20 >> +uint32_t HELPER(tceb)(uint32_t f1, uint64_t m2) >> +{ >> + float32 v1 =3D env->fregs[f1].l.upper; >> + int neg =3D float32_is_neg(v1); >> + uint32_t cc =3D 0; >> + >> + HELPER_LOG("%s: v1 0x%lx m2 0x%lx neg %d\n", __FUNCTION__, (long)v1,= m2, neg); >> + if ((float32_is_zero(v1) && (m2 & (1 << (11-neg)))) || >> + (float32_is_infinity(v1) && (m2 & (1 << (5-neg)))) || >> + (float32_is_any_nan(v1) && (m2 & (1 << (3-neg)))) || >> + (float32_is_signaling_nan(v1) && (m2 & (1 << (1-neg))))) { >> + cc =3D 1; >> + } else if (m2 & (1 << (9-neg))) { >> + /* assume normalized number */ >> + cc =3D 1; >> + } >> + >> + /* FIXME: denormalized? */ >> + return cc; >> +} >=20 > There's a float32_is_zero_or_denormal(); if you need a > float32_is_denormal() which is false for real zero we > could add it, I guess. >=20 >> +static inline uint32_t cc_calc_nabs_32(CPUState *env, int32_t dst) >> +{ >> + return !!dst; >> +} >=20 > Another candidate for inlining. >=20 > -- PMM