From patchwork Sun Aug 30 02:32:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 248723 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp2299670ilg; Sat, 29 Aug 2020 19:35:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJfLfCkXDpDhgHzWjG70DbDhp5q2nVRf9F6oLgVmHhH174UifQSniIDmaUMDtoiH1bu9p1 X-Received: by 2002:a25:af05:: with SMTP id a5mr11133884ybh.411.1598754914470; Sat, 29 Aug 2020 19:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598754914; cv=none; d=google.com; s=arc-20160816; b=tUue2uwKWKth9AMdSal6PH7zzNFO9HjSfFhU+HC/lFuJj9K2FtNn7v/RjH5DiSY3k4 mkkNuIrSvZg25al5aGigNkdNTa2H80wGDS0XuVWBOkVbHRlY+AW9CeEvXxvTkzZoD0Q8 3O6a+n2foyP+lh4VKRChG57d/xZtELwxMR7KEGTMbJqnmvJ9XnprCwfL+IGXKSSxcmuB gAq4QwpGTj2fk8w2cvcY8Zhc74ShObdLXBqaSqOvAY4gJvn9TpArfwSCx7GkWkcsF6UF N6FYJpx5PC8CxZ6QQzAOkDLQRhoFP38WOREopYm4qDUB3xsCnvoRAk5Cdsq7fnR9coJw +4cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=3gEElP2a5vebEo0iaIMnucOEoCEL2rO6ZaUClQLywK4=; b=U0+e/BYFQnvTSjbWKTMj8z/TGa3SaR32TwjwCV+B1HurltgW5/2S81whc0k8hB+ulc nK7/7BvP/wva0/gcTo4MkbDCboSQ3CksDh7OeHT73/t2Otj8X8TrUTe/Nb416iGz1ALI D7XBgqhSSG2r8miZdQmUXxkxq4uJuWfMmKy5CKuBfzdvzSHZklo6Kxa0BbrYPqla1Hpp C6bf+4wzkTaP3tnZi15cWEduwH1xGOZ76ozOxgAlhPlqX4MLeR3Nw7aGeC6Dpy8fX9iT IobpEi2XCzxkiilgttIayxzO4LhadavB51cBhngI4pj/a0+MhVgTV+Rtl0wU/YsdNrU6 m/Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KehiPrlt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f16si3709288yba.391.2020.08.29.19.35.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 29 Aug 2020 19:35:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KehiPrlt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kCDBZ-0008Rb-WC for patch@linaro.org; Sat, 29 Aug 2020 22:35:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kCD8j-0002mx-G2 for qemu-devel@nongnu.org; Sat, 29 Aug 2020 22:32:17 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:44177) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kCD8h-0002Yw-HR for qemu-devel@nongnu.org; Sat, 29 Aug 2020 22:32:17 -0400 Received: by mail-pf1-x430.google.com with SMTP id p11so2657809pfn.11 for ; Sat, 29 Aug 2020 19:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3gEElP2a5vebEo0iaIMnucOEoCEL2rO6ZaUClQLywK4=; b=KehiPrltMJt52trF3WbZQSxKjq72WC4JVASEj+d/4nyxgqlp9/efQQzZfLKfE4+ttV p2IkOjGuSogn6IdwONn4GcYfNeHGFTxBMF5FXN8xdgxVvOM3apyf7Rq4EPMbMkARBynD UROD7lqXNyvV8J6ZWtkNb8DiSb8qkpnDlv/7wNBbsMXqbXVUqeA2EIgI0Nfxo5pAySzK 2lZeauFlZKTGPOFwmM+B/n33vT2rinzVeWxPlQuZxk1xCeENjHO/deus9n2JCqggXuok i7uc7EwvlI09N8Q+FM34kBOh8LCLTsKLAvNRftsb5BzflDSPPgZTIXrC558UUy70DJhg JBcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3gEElP2a5vebEo0iaIMnucOEoCEL2rO6ZaUClQLywK4=; b=cNOsP0qZthetvh1KLfXSXDk35e1Eve3KWQKkSA2uzO+CH6jaV3qYRzBU+GNu3UAs6b VL8HyyRuvFKSNmNB/QsxvkWCfG8tEE49kR1F6snkno6J1QU+mubc42akjSppfiitpr9F 0VWiq9600o23551cnBvQi4y/Su+ew6ibej+gxPdtzGm4f2DDwcJRKcVk49lJqhUmZDsx j1fL+mVKp0V+f+ymXs16piSHB5REEIGj19crB+GjNx9k5iL19zROcCagBLAjqTO5Ts8E 8kzu8j5p34F9qAeoBezJJ5UXIuw+uikD6U5vK+fbyQE/oCk1nnUErIFXXHDN8ewWu685 Bh+Q== X-Gm-Message-State: AOAM530MZ9/HWPHAcz9dfFLq9/6Jy4Q77+Zl2kNPAkNgFtXicxsSoHeg hi1bVagQmBaE/cQ5srGV8hRhe5BOhl3Y9g== X-Received: by 2002:a63:60e:: with SMTP id 14mr3964956pgg.343.1598754733833; Sat, 29 Aug 2020 19:32:13 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id l23sm3546269pgt.16.2020.08.29.19.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Aug 2020 19:32:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 6/7] softfloat: Define misc operations for bfloat16 Date: Sat, 29 Aug 2020 19:32:02 -0700 Message-Id: <20200830023203.612312-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200830023203.612312-1-richard.henderson@linaro.org> References: <20200830023203.612312-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, LIU Zhiwei Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: LIU Zhiwei Signed-off-by: LIU Zhiwei Reviewed-by: Richard Henderson Message-Id: <20200813071421.2509-4-zhiwei_liu@c-sky.com> [rth: Fix merge conflict with NO_SIGNALING_NANS; use bool for predicates.] Signed-off-by: Richard Henderson --- include/fpu/softfloat.h | 48 ++++++++++++++++++++++++++++++++++ fpu/softfloat-specialize.c.inc | 38 +++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) -- 2.25.1 diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 95f0789a92..1233f98014 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -423,9 +423,57 @@ bfloat16 bfloat16_sqrt(bfloat16, float_status *status); FloatRelation bfloat16_compare(bfloat16, bfloat16, float_status *status); FloatRelation bfloat16_compare_quiet(bfloat16, bfloat16, float_status *status); +bool bfloat16_is_quiet_nan(bfloat16, float_status *status); +bool bfloat16_is_signaling_nan(bfloat16, float_status *status); bfloat16 bfloat16_silence_nan(bfloat16, float_status *status); bfloat16 bfloat16_default_nan(float_status *status); +static inline bool bfloat16_is_any_nan(bfloat16 a) +{ + return ((a & ~0x8000) > 0x7F80); +} + +static inline bool bfloat16_is_neg(bfloat16 a) +{ + return a >> 15; +} + +static inline bool bfloat16_is_infinity(bfloat16 a) +{ + return (a & 0x7fff) == 0x7F80; +} + +static inline bool bfloat16_is_zero(bfloat16 a) +{ + return (a & 0x7fff) == 0; +} + +static inline bool bfloat16_is_zero_or_denormal(bfloat16 a) +{ + return (a & 0x7F80) == 0; +} + +static inline bool bfloat16_is_normal(bfloat16 a) +{ + return (((a >> 7) + 1) & 0xff) >= 2; +} + +static inline bfloat16 bfloat16_abs(bfloat16 a) +{ + /* Note that abs does *not* handle NaN specially, nor does + * it flush denormal inputs to zero. + */ + return a & 0x7fff; +} + +static inline bfloat16 bfloat16_chs(bfloat16 a) +{ + /* Note that chs does *not* handle NaN specially, nor does + * it flush denormal inputs to zero. + */ + return a ^ 0x8000; +} + static inline bfloat16 bfloat16_set_sign(bfloat16 a, int sign) { return (a & 0x7fff) | (sign << 15); diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc index dc4ea33c09..c2f87addb2 100644 --- a/fpu/softfloat-specialize.c.inc +++ b/fpu/softfloat-specialize.c.inc @@ -265,6 +265,25 @@ bool float16_is_quiet_nan(float16 a_, float_status *status) } } +/*---------------------------------------------------------------------------- +| Returns 1 if the bfloat16 value `a' is a quiet +| NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +bool bfloat16_is_quiet_nan(bfloat16 a_, float_status *status) +{ + if (no_signaling_nans(status)) { + return bfloat16_is_any_nan(a_); + } else { + uint16_t a = a_; + if (snan_bit_is_one(status)) { + return (((a >> 6) & 0x1FF) == 0x1FE) && (a & 0x3F); + } else { + return ((a >> 6) & 0x1FF) == 0x1FF; + } + } +} + /*---------------------------------------------------------------------------- | Returns 1 if the half-precision floating-point value `a' is a signaling | NaN; otherwise returns 0. @@ -284,6 +303,25 @@ bool float16_is_signaling_nan(float16 a_, float_status *status) } } +/*---------------------------------------------------------------------------- +| Returns 1 if the bfloat16 value `a' is a signaling +| NaN; otherwise returns 0. +*----------------------------------------------------------------------------*/ + +bool bfloat16_is_signaling_nan(bfloat16 a_, float_status *status) +{ + if (no_signaling_nans(status)) { + return 0; + } else { + uint16_t a = a_; + if (snan_bit_is_one(status)) { + return ((a >> 6) & 0x1FF) == 0x1FF; + } else { + return (((a >> 6) & 0x1FF) == 0x1FE) && (a & 0x3F); + } + } +} + /*---------------------------------------------------------------------------- | Returns 1 if the single-precision floating-point value `a' is a quiet | NaN; otherwise returns 0.