From nobody Sat Nov 8 10:05:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550068749957965.4755557450356; Wed, 13 Feb 2019 06:39:09 -0800 (PST) Received: from localhost ([127.0.0.1]:57787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtvgo-0003gR-Rd for importer@patchew.org; Wed, 13 Feb 2019 09:39:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtvbp-000055-Bi for qemu-devel@nongnu.org; Wed, 13 Feb 2019 09:34:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtvbn-0002KK-Fa for qemu-devel@nongnu.org; Wed, 13 Feb 2019 09:33:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59902) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtvbl-0002HN-Ih; Wed, 13 Feb 2019 09:33:53 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B14C8AE4A; Wed, 13 Feb 2019 14:33:51 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-173.ams2.redhat.com [10.36.116.173]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8597B5D6AA; Wed, 13 Feb 2019 14:33:48 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 13 Feb 2019 15:33:17 +0100 Message-Id: <20190213143322.31371-11-david@redhat.com> In-Reply-To: <20190213143322.31371-1-david@redhat.com> References: <20190213143322.31371-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 13 Feb 2019 14:33:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 10/15] s390x/tcg: Refactor saving/restoring the bfp rounding mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We want to reuse this in the context of vector instructions. So use better matching names and introduce s390_restore_bfp_rounding_mode(). While at it, add proper newlines. Reviewed-by: Richard Henderson Signed-off-by: David Hildenbrand --- target/s390x/fpu_helper.c | 112 +++++++++++++++++++++++--------------- target/s390x/internal.h | 2 + 2 files changed, 71 insertions(+), 43 deletions(-) diff --git a/target/s390x/fpu_helper.c b/target/s390x/fpu_helper.c index 70fa053e8d..0cd6e19ce8 100644 --- a/target/s390x/fpu_helper.c +++ b/target/s390x/fpu_helper.c @@ -372,7 +372,7 @@ uint32_t HELPER(cxb)(CPUS390XState *env, uint64_t ah, u= int64_t al, return float_comp_to_cc(env, cmp); } =20 -static int swap_round_mode(CPUS390XState *env, int m3) +int s390_swap_bfp_rounding_mode(CPUS390XState *env, int m3) { int ret =3D env->fpu_status.float_rounding_mode; switch (m3) { @@ -401,12 +401,18 @@ static int swap_round_mode(CPUS390XState *env, int m3) return ret; } =20 +void s390_restore_bfp_rounding_mode(CPUS390XState *env, int old_mode) +{ + set_float_rounding_mode(old_mode, &env->fpu_status); +} + /* convert 64-bit int to 32-bit float */ uint64_t HELPER(cegb)(CPUS390XState *env, int64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float32 ret =3D int64_to_float32(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -414,9 +420,10 @@ uint64_t HELPER(cegb)(CPUS390XState *env, int64_t v2, = uint32_t m3) /* convert 64-bit int to 64-bit float */ uint64_t HELPER(cdgb)(CPUS390XState *env, int64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float64 ret =3D int64_to_float64(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -424,9 +431,10 @@ uint64_t HELPER(cdgb)(CPUS390XState *env, int64_t v2, = uint32_t m3) /* convert 64-bit int to 128-bit float */ uint64_t HELPER(cxgb)(CPUS390XState *env, int64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float128 ret =3D int64_to_float128(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return RET128(ret); } @@ -434,9 +442,10 @@ uint64_t HELPER(cxgb)(CPUS390XState *env, int64_t v2, = uint32_t m3) /* convert 64-bit uint to 32-bit float */ uint64_t HELPER(celgb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float32 ret =3D uint64_to_float32(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -444,9 +453,10 @@ uint64_t HELPER(celgb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 64-bit uint to 64-bit float */ uint64_t HELPER(cdlgb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float64 ret =3D uint64_to_float64(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -454,9 +464,10 @@ uint64_t HELPER(cdlgb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 64-bit uint to 128-bit float */ uint64_t HELPER(cxlgb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float128 ret =3D uint64_to_float128(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return RET128(ret); } @@ -464,9 +475,10 @@ uint64_t HELPER(cxlgb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 32-bit float to 64-bit int */ uint64_t HELPER(cgeb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); int64_t ret =3D float32_to_int64(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -474,9 +486,10 @@ uint64_t HELPER(cgeb)(CPUS390XState *env, uint64_t v2,= uint32_t m3) /* convert 64-bit float to 64-bit int */ uint64_t HELPER(cgdb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); int64_t ret =3D float64_to_int64(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -484,10 +497,11 @@ uint64_t HELPER(cgdb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 128-bit float to 64-bit int */ uint64_t HELPER(cgxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t= m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float128 v2 =3D make_float128(h, l); int64_t ret =3D float128_to_int64(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -495,9 +509,10 @@ uint64_t HELPER(cgxb)(CPUS390XState *env, uint64_t h, = uint64_t l, uint32_t m3) /* convert 32-bit float to 32-bit int */ uint64_t HELPER(cfeb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); int32_t ret =3D float32_to_int32(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -505,9 +520,10 @@ uint64_t HELPER(cfeb)(CPUS390XState *env, uint64_t v2,= uint32_t m3) /* convert 64-bit float to 32-bit int */ uint64_t HELPER(cfdb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); int32_t ret =3D float64_to_int32(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -515,10 +531,11 @@ uint64_t HELPER(cfdb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 128-bit float to 32-bit int */ uint64_t HELPER(cfxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t= m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float128 v2 =3D make_float128(h, l); int32_t ret =3D float128_to_int32(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -526,11 +543,12 @@ uint64_t HELPER(cfxb)(CPUS390XState *env, uint64_t h,= uint64_t l, uint32_t m3) /* convert 32-bit float to 64-bit uint */ uint64_t HELPER(clgeb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); uint64_t ret; + v2 =3D float32_to_float64(v2, &env->fpu_status); ret =3D float64_to_uint64(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -538,9 +556,10 @@ uint64_t HELPER(clgeb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 64-bit float to 64-bit uint */ uint64_t HELPER(clgdb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); uint64_t ret =3D float64_to_uint64(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -548,9 +567,10 @@ uint64_t HELPER(clgdb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 128-bit float to 64-bit uint */ uint64_t HELPER(clgxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_= t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); uint64_t ret =3D float128_to_uint64(make_float128(h, l), &env->fpu_sta= tus); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -558,9 +578,10 @@ uint64_t HELPER(clgxb)(CPUS390XState *env, uint64_t h,= uint64_t l, uint32_t m3) /* convert 32-bit float to 32-bit uint */ uint64_t HELPER(clfeb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); uint32_t ret =3D float32_to_uint32(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -568,9 +589,10 @@ uint64_t HELPER(clfeb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 64-bit float to 32-bit uint */ uint64_t HELPER(clfdb)(CPUS390XState *env, uint64_t v2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); uint32_t ret =3D float64_to_uint32(v2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -578,9 +600,10 @@ uint64_t HELPER(clfdb)(CPUS390XState *env, uint64_t v2= , uint32_t m3) /* convert 128-bit float to 32-bit uint */ uint64_t HELPER(clfxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_= t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); uint32_t ret =3D float128_to_uint32(make_float128(h, l), &env->fpu_sta= tus); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -588,9 +611,10 @@ uint64_t HELPER(clfxb)(CPUS390XState *env, uint64_t h,= uint64_t l, uint32_t m3) /* round to integer 32-bit */ uint64_t HELPER(fieb)(CPUS390XState *env, uint64_t f2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float32 ret =3D float32_round_to_int(f2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -598,9 +622,10 @@ uint64_t HELPER(fieb)(CPUS390XState *env, uint64_t f2,= uint32_t m3) /* round to integer 64-bit */ uint64_t HELPER(fidb)(CPUS390XState *env, uint64_t f2, uint32_t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); float64 ret =3D float64_round_to_int(f2, &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return ret; } @@ -608,10 +633,11 @@ uint64_t HELPER(fidb)(CPUS390XState *env, uint64_t f2= , uint32_t m3) /* round to integer 128-bit */ uint64_t HELPER(fixb)(CPUS390XState *env, uint64_t ah, uint64_t al, uint32= _t m3) { - int hold =3D swap_round_mode(env, m3); + int old_mode =3D s390_swap_bfp_rounding_mode(env, m3); + float128 ret =3D float128_round_to_int(make_float128(ah, al), &env->fpu_status); - set_float_rounding_mode(hold, &env->fpu_status); + s390_restore_bfp_rounding_mode(env, old_mode); handle_exceptions(env, GETPC()); return RET128(ret); } diff --git a/target/s390x/internal.h b/target/s390x/internal.h index e1c0b1bd3b..122fe037bc 100644 --- a/target/s390x/internal.h +++ b/target/s390x/internal.h @@ -315,6 +315,8 @@ uint32_t set_cc_nz_f128(float128 v); #define S390_IEEE_MASK_INEXACT 0x08 #define S390_IEEE_MASK_QUANTUM 0x04 uint8_t s390_softfloat_exc_to_ieee(unsigned int exc); +int s390_swap_bfp_rounding_mode(CPUS390XState *env, int m3); +void s390_restore_bfp_rounding_mode(CPUS390XState *env, int old_mode); =20 =20 /* gdbstub.c */ --=20 2.17.2