From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756647; cv=none; d=zohomail.com; s=zohoarc; b=CcxKFREqAxD1GN9K86LMGzdkNGh/fW9pflsEs8QPSIuTbtSosVB8Z17MYcdW4j3Mmx/LX4M/t0/LpiZIaLbDm3ocWpX0KzRxoCYRfaSe2QR6PgnJvkxDAZ0tUPHm1hqHV/wVF3awi0dn5yKaevWVBPfGmCpjYrR/Gj69zzGsk4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756647; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/8zGSmRtRNib0B0xN2lfOZiuTchPOPYviatx/oRU9nA=; b=miWKFTCbxHoo9RfqPLzh8zK7osHGZF/J+dG5jcvEbaWa8G4rQ3mPNWzKrqbpCKDdC5qlfURqN4oIaSDQDa1TCoUiw9Xow+WlBarhhxGMLYPvZX+iB/gZydpwlgEju3UkiQYrqCNysPRQVoWVVyCImwjeeOX7Aku7JuMvw8JtDV8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756647248174.62309156499123; Thu, 3 Jun 2021 14:44:07 -0700 (PDT) Received: from localhost ([::1]:55328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lov8I-0000PU-2q for importer@patchew.org; Thu, 03 Jun 2021 17:44:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5t-0001xu-Ou for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:37 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:35475) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5r-0000zZ-34 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:37 -0400 Received: by mail-pf1-x42c.google.com with SMTP id h12so3084100pfe.2 for ; Thu, 03 Jun 2021 14:41:34 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:33 -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=/8zGSmRtRNib0B0xN2lfOZiuTchPOPYviatx/oRU9nA=; b=yxXjNhZZtX3x5ymMeDRdM7+QaPl24bagMpqxQ4MX0Fq7Zjk+4vnwo1g06T8wfJx+ZD mFeo3Q/rOhGEa8Z9iwkbJYFGYWujpOWZmr4H0zcGoGdn/cgzyuyZIk7VQSNWEyfEnHB6 YrlyA2hNIA3o8dskwSiuYheWpkAuXT+vmLbW/zUBPx7LsAtwN1vhhHL6IOLnMwRAE/Ig 67fOdmerHU494KvBmvuDD62X6op77cXs4b6iuiWGGSGZl3M7U/NwB7B48ZrbOc0VAoCl 4ctZT9Zt4XrjW41T+2KwA1M4GbFb9zgaObo9sAh9StGKeaNLPUpOIIcVFNVaqTzm96d3 05Gg== 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=/8zGSmRtRNib0B0xN2lfOZiuTchPOPYviatx/oRU9nA=; b=cTdD7d1IYHaA1GECXP+CqnrUOvntqAZum64GjlpwmnbkD944c/0h1KmupfEMvNu25U iiKHsHFz6cm5eamwfx5ANneFwJdq+VqZ2Dw442Vk7/Bf5EoErM65qgoc1LXPZOzrN5iQ 51g0xzdaNA+q3NhQoVMlwRlaiVOc5zw9my47QKP4a18JSMHYswLoxzoThdb+RjrxyjU0 nFd0MU0YOG2bQ+oo8X5rug+v0zdDb3AfN3PS8/lYJcm2dSqzLgFPONxHLpCOVvHdjKpX faETTA0alvjTwl9otmXNn63fnCVjii5xwq8AuznyXfUV0x1Pzs3bvOeEHr8cK4fEOlkG WVOw== X-Gm-Message-State: AOAM530Lgjv3VkTh7ItGQrj2KdA2F1ynWgPW0rssMoV8n4DpZVSQd/gO BlWs+0Ba4di8ENlSWNsoTJNjN7tMjraUqg== X-Google-Smtp-Source: ABdhPJwqCjfvCC9PkkUGseG3v/VOYZK5CAFTdt1oiL8zsqX0geuiTG/kHUCdeCpMfHlz0v/LnQbmMg== X-Received: by 2002:a63:521a:: with SMTP id g26mr1469611pgb.279.1622756493522; Thu, 03 Jun 2021 14:41:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 01/29] softfloat: Move round_to_uint_and_pack to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:03 -0700 Message-Id: <20210603214131.629841-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Rename to parts$N_float_to_uint. Reimplement float128_to_uint{32,64}{_round_to_zero} with FloatParts128. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 357 +++++++++----------------------------- fpu/softfloat-parts.c.inc | 68 +++++++- 2 files changed, 147 insertions(+), 278 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 0dc2203477..3181678ea9 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -839,6 +839,16 @@ static int64_t parts128_float_to_sint(FloatParts128 *p= , FloatRoundMode rmode, #define parts_float_to_sint(P, R, Z, MN, MX, S) \ PARTS_GENERIC_64_128(float_to_sint, P)(P, R, Z, MN, MX, S) =20 +static uint64_t parts64_float_to_uint(FloatParts64 *p, FloatRoundMode rmod= e, + int scale, uint64_t max, + float_status *s); +static uint64_t parts128_float_to_uint(FloatParts128 *p, FloatRoundMode rm= ode, + int scale, uint64_t max, + float_status *s); + +#define parts_float_to_uint(P, R, Z, M, S) \ + PARTS_GENERIC_64_128(float_to_uint, P)(P, R, Z, M, S) + /* * Helper functions for softfloat-parts.c.inc, per-size operations. */ @@ -2646,80 +2656,16 @@ int64_t bfloat16_to_int64_round_to_zero(bfloat16 a,= float_status *s) } =20 /* - * Returns the result of converting the floating-point value `a' to - * the unsigned integer format. The conversion is performed according - * to the IEC/IEEE Standard for Binary Floating-Point - * Arithmetic---which means in particular that the conversion is - * rounded according to the current rounding mode. If `a' is a NaN, - * the largest unsigned integer is returned. Otherwise, if the - * conversion overflows, the largest unsigned integer is returned. If - * the 'a' is negative, the result is rounded and zero is returned; - * values that do not round to zero will raise the inexact exception - * flag. + * Floating-point to unsigned integer conversions */ =20 -static uint64_t round_to_uint_and_pack(FloatParts64 p, FloatRoundMode rmod= e, - int scale, uint64_t max, - float_status *s) -{ - int flags =3D 0; - uint64_t r; - - switch (p.cls) { - case float_class_snan: - case float_class_qnan: - flags =3D float_flag_invalid; - r =3D max; - break; - - case float_class_inf: - flags =3D float_flag_invalid; - r =3D p.sign ? 0 : max; - break; - - case float_class_zero: - return 0; - - case float_class_normal: - /* TODO: 62 =3D N - 2, frac_size for rounding */ - if (parts_round_to_int_normal(&p, rmode, scale, 62)) { - flags =3D float_flag_inexact; - if (p.cls =3D=3D float_class_zero) { - r =3D 0; - break; - } - } - - if (p.sign) { - flags =3D float_flag_invalid; - r =3D 0; - } else if (p.exp > DECOMPOSED_BINARY_POINT) { - flags =3D float_flag_invalid; - r =3D max; - } else { - r =3D p.frac >> (DECOMPOSED_BINARY_POINT - p.exp); - if (r > max) { - flags =3D float_flag_invalid; - r =3D max; - } - } - break; - - default: - g_assert_not_reached(); - } - - float_raise(flags, s); - return r; -} - uint8_t float16_to_uint8_scalbn(float16 a, FloatRoundMode rmode, int scale, float_status *s) { FloatParts64 p; =20 float16_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT8_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT8_MAX, s); } =20 uint16_t float16_to_uint16_scalbn(float16 a, FloatRoundMode rmode, int sca= le, @@ -2728,7 +2674,7 @@ uint16_t float16_to_uint16_scalbn(float16 a, FloatRou= ndMode rmode, int scale, FloatParts64 p; =20 float16_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT16_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT16_MAX, s); } =20 uint32_t float16_to_uint32_scalbn(float16 a, FloatRoundMode rmode, int sca= le, @@ -2737,7 +2683,7 @@ uint32_t float16_to_uint32_scalbn(float16 a, FloatRou= ndMode rmode, int scale, FloatParts64 p; =20 float16_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT32_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT32_MAX, s); } =20 uint64_t float16_to_uint64_scalbn(float16 a, FloatRoundMode rmode, int sca= le, @@ -2746,7 +2692,7 @@ uint64_t float16_to_uint64_scalbn(float16 a, FloatRou= ndMode rmode, int scale, FloatParts64 p; =20 float16_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT64_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT64_MAX, s); } =20 uint16_t float32_to_uint16_scalbn(float32 a, FloatRoundMode rmode, int sca= le, @@ -2755,7 +2701,7 @@ uint16_t float32_to_uint16_scalbn(float32 a, FloatRou= ndMode rmode, int scale, FloatParts64 p; =20 float32_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT16_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT16_MAX, s); } =20 uint32_t float32_to_uint32_scalbn(float32 a, FloatRoundMode rmode, int sca= le, @@ -2764,7 +2710,7 @@ uint32_t float32_to_uint32_scalbn(float32 a, FloatRou= ndMode rmode, int scale, FloatParts64 p; =20 float32_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT32_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT32_MAX, s); } =20 uint64_t float32_to_uint64_scalbn(float32 a, FloatRoundMode rmode, int sca= le, @@ -2773,7 +2719,7 @@ uint64_t float32_to_uint64_scalbn(float32 a, FloatRou= ndMode rmode, int scale, FloatParts64 p; =20 float32_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT64_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT64_MAX, s); } =20 uint16_t float64_to_uint16_scalbn(float64 a, FloatRoundMode rmode, int sca= le, @@ -2782,7 +2728,7 @@ uint16_t float64_to_uint16_scalbn(float64 a, FloatRou= ndMode rmode, int scale, FloatParts64 p; =20 float64_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT16_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT16_MAX, s); } =20 uint32_t float64_to_uint32_scalbn(float64 a, FloatRoundMode rmode, int sca= le, @@ -2791,7 +2737,7 @@ uint32_t float64_to_uint32_scalbn(float64 a, FloatRou= ndMode rmode, int scale, FloatParts64 p; =20 float64_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT32_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT32_MAX, s); } =20 uint64_t float64_to_uint64_scalbn(float64 a, FloatRoundMode rmode, int sca= le, @@ -2800,7 +2746,52 @@ uint64_t float64_to_uint64_scalbn(float64 a, FloatRo= undMode rmode, int scale, FloatParts64 p; =20 float64_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT64_MAX, s); + return parts_float_to_uint(&p, rmode, scale, UINT64_MAX, s); +} + +uint16_t bfloat16_to_uint16_scalbn(bfloat16 a, FloatRoundMode rmode, + int scale, float_status *s) +{ + FloatParts64 p; + + bfloat16_unpack_canonical(&p, a, s); + return parts_float_to_uint(&p, rmode, scale, UINT16_MAX, s); +} + +uint32_t bfloat16_to_uint32_scalbn(bfloat16 a, FloatRoundMode rmode, + int scale, float_status *s) +{ + FloatParts64 p; + + bfloat16_unpack_canonical(&p, a, s); + return parts_float_to_uint(&p, rmode, scale, UINT32_MAX, s); +} + +uint64_t bfloat16_to_uint64_scalbn(bfloat16 a, FloatRoundMode rmode, + int scale, float_status *s) +{ + FloatParts64 p; + + bfloat16_unpack_canonical(&p, a, s); + return parts_float_to_uint(&p, rmode, scale, UINT64_MAX, s); +} + +static uint32_t float128_to_uint32_scalbn(float128 a, FloatRoundMode rmode, + int scale, float_status *s) +{ + FloatParts128 p; + + float128_unpack_canonical(&p, a, s); + return parts_float_to_uint(&p, rmode, scale, UINT32_MAX, s); +} + +static uint64_t float128_to_uint64_scalbn(float128 a, FloatRoundMode rmode, + int scale, float_status *s) +{ + FloatParts128 p; + + float128_unpack_canonical(&p, a, s); + return parts_float_to_uint(&p, rmode, scale, UINT64_MAX, s); } =20 uint8_t float16_to_uint8(float16 a, float_status *s) @@ -2853,6 +2844,16 @@ uint64_t float64_to_uint64(float64 a, float_status *= s) return float64_to_uint64_scalbn(a, s->float_rounding_mode, 0, s); } =20 +uint32_t float128_to_uint32(float128 a, float_status *s) +{ + return float128_to_uint32_scalbn(a, s->float_rounding_mode, 0, s); +} + +uint64_t float128_to_uint64(float128 a, float_status *s) +{ + return float128_to_uint64_scalbn(a, s->float_rounding_mode, 0, s); +} + uint16_t float16_to_uint16_round_to_zero(float16 a, float_status *s) { return float16_to_uint16_scalbn(a, float_round_to_zero, 0, s); @@ -2898,36 +2899,14 @@ uint64_t float64_to_uint64_round_to_zero(float64 a,= float_status *s) return float64_to_uint64_scalbn(a, float_round_to_zero, 0, s); } =20 -/* - * Returns the result of converting the bfloat16 value `a' to - * the unsigned integer format. - */ - -uint16_t bfloat16_to_uint16_scalbn(bfloat16 a, FloatRoundMode rmode, - int scale, float_status *s) +uint32_t float128_to_uint32_round_to_zero(float128 a, float_status *s) { - FloatParts64 p; - - bfloat16_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT16_MAX, s); + return float128_to_uint32_scalbn(a, float_round_to_zero, 0, s); } =20 -uint32_t bfloat16_to_uint32_scalbn(bfloat16 a, FloatRoundMode rmode, - int scale, float_status *s) +uint64_t float128_to_uint64_round_to_zero(float128 a, float_status *s) { - FloatParts64 p; - - bfloat16_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT32_MAX, s); -} - -uint64_t bfloat16_to_uint64_scalbn(bfloat16 a, FloatRoundMode rmode, - int scale, float_status *s) -{ - FloatParts64 p; - - bfloat16_unpack_canonical(&p, a, s); - return round_to_uint_and_pack(p, rmode, scale, UINT64_MAX, s); + return float128_to_uint64_scalbn(a, float_round_to_zero, 0, s); } =20 uint16_t bfloat16_to_uint16(bfloat16 a, float_status *s) @@ -4123,66 +4102,6 @@ static int64_t roundAndPackInt64(bool zSign, uint64_= t absZ0, uint64_t absZ1, =20 } =20 -/*------------------------------------------------------------------------= ---- -| Takes the 128-bit fixed-point value formed by concatenating `absZ0' and -| `absZ1', with binary point between bits 63 and 64 (between the input wor= ds), -| and returns the properly rounded 64-bit unsigned integer corresponding t= o the -| input. Ordinarily, the fixed-point input is simply rounded to an intege= r, -| with the inexact exception raised if the input cannot be represented exa= ctly -| as an integer. However, if the fixed-point input is too large, the inva= lid -| exception is raised and the largest unsigned integer is returned. -*-------------------------------------------------------------------------= ---*/ - -static int64_t roundAndPackUint64(bool zSign, uint64_t absZ0, - uint64_t absZ1, float_status *status) -{ - int8_t roundingMode; - bool roundNearestEven, increment; - - roundingMode =3D status->float_rounding_mode; - roundNearestEven =3D (roundingMode =3D=3D float_round_nearest_even); - switch (roundingMode) { - case float_round_nearest_even: - case float_round_ties_away: - increment =3D ((int64_t)absZ1 < 0); - break; - case float_round_to_zero: - increment =3D 0; - break; - case float_round_up: - increment =3D !zSign && absZ1; - break; - case float_round_down: - increment =3D zSign && absZ1; - break; - case float_round_to_odd: - increment =3D !(absZ0 & 1) && absZ1; - break; - default: - abort(); - } - if (increment) { - ++absZ0; - if (absZ0 =3D=3D 0) { - float_raise(float_flag_invalid, status); - return UINT64_MAX; - } - if (!(absZ1 << 1) && roundNearestEven) { - absZ0 &=3D ~1; - } - } - - if (zSign && absZ0) { - float_raise(float_flag_invalid, status); - return 0; - } - - if (absZ1) { - float_raise(float_flag_inexact, status); - } - return absZ0; -} - /*------------------------------------------------------------------------= ---- | Normalizes the subnormal single-precision floating-point value represent= ed | by the denormalized significand `aSig'. The normalized exponent and @@ -6536,122 +6455,6 @@ floatx80 floatx80_sqrt(floatx80 a, float_status *st= atus) 0, zExp, zSig0, zSig1, status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the quadruple-precision floating-point = value -| `a' to the 64-bit unsigned integer format. The conversion is -| performed according to the IEC/IEEE Standard for Binary Floating-Point -| Arithmetic---which means in particular that the conversion is rounded -| according to the current rounding mode. If `a' is a NaN, the largest -| positive integer is returned. If the conversion overflows, the -| largest unsigned integer is returned. If 'a' is negative, the value is -| rounded and zero is returned; negative values that do not round to zero -| will raise the inexact exception. -*-------------------------------------------------------------------------= ---*/ - -uint64_t float128_to_uint64(float128 a, float_status *status) -{ - bool aSign; - int aExp; - int shiftCount; - uint64_t aSig0, aSig1; - - aSig0 =3D extractFloat128Frac0(a); - aSig1 =3D extractFloat128Frac1(a); - aExp =3D extractFloat128Exp(a); - aSign =3D extractFloat128Sign(a); - if (aSign && (aExp > 0x3FFE)) { - float_raise(float_flag_invalid, status); - if (float128_is_any_nan(a)) { - return UINT64_MAX; - } else { - return 0; - } - } - if (aExp) { - aSig0 |=3D UINT64_C(0x0001000000000000); - } - shiftCount =3D 0x402F - aExp; - if (shiftCount <=3D 0) { - if (0x403E < aExp) { - float_raise(float_flag_invalid, status); - return UINT64_MAX; - } - shortShift128Left(aSig0, aSig1, -shiftCount, &aSig0, &aSig1); - } else { - shift64ExtraRightJamming(aSig0, aSig1, shiftCount, &aSig0, &aSig1); - } - return roundAndPackUint64(aSign, aSig0, aSig1, status); -} - -uint64_t float128_to_uint64_round_to_zero(float128 a, float_status *status) -{ - uint64_t v; - signed char current_rounding_mode =3D status->float_rounding_mode; - - set_float_rounding_mode(float_round_to_zero, status); - v =3D float128_to_uint64(a, status); - set_float_rounding_mode(current_rounding_mode, status); - - return v; -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the quadruple-precision floating-point -| value `a' to the 32-bit unsigned integer format. The conversion -| is performed according to the IEC/IEEE Standard for Binary Floating-Point -| Arithmetic except that the conversion is always rounded toward zero. -| If `a' is a NaN, the largest positive integer is returned. Otherwise, -| if the conversion overflows, the largest unsigned integer is returned. -| If 'a' is negative, the value is rounded and zero is returned; negative -| values that do not round to zero will raise the inexact exception. -*-------------------------------------------------------------------------= ---*/ - -uint32_t float128_to_uint32_round_to_zero(float128 a, float_status *status) -{ - uint64_t v; - uint32_t res; - int old_exc_flags =3D get_float_exception_flags(status); - - v =3D float128_to_uint64_round_to_zero(a, status); - if (v > 0xffffffff) { - res =3D 0xffffffff; - } else { - return v; - } - set_float_exception_flags(old_exc_flags, status); - float_raise(float_flag_invalid, status); - return res; -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the quadruple-precision floating-point = value -| `a' to the 32-bit unsigned integer format. The conversion is -| performed according to the IEC/IEEE Standard for Binary Floating-Point -| Arithmetic---which means in particular that the conversion is rounded -| according to the current rounding mode. If `a' is a NaN, the largest -| positive integer is returned. If the conversion overflows, the -| largest unsigned integer is returned. If 'a' is negative, the value is -| rounded and zero is returned; negative values that do not round to zero -| will raise the inexact exception. -*-------------------------------------------------------------------------= ---*/ - -uint32_t float128_to_uint32(float128 a, float_status *status) -{ - uint64_t v; - uint32_t res; - int old_exc_flags =3D get_float_exception_flags(status); - - v =3D float128_to_uint64(a, status); - if (v > 0xffffffff) { - res =3D 0xffffffff; - } else { - return v; - } - set_float_exception_flags(old_exc_flags, status); - float_raise(float_flag_invalid, status); - return res; -} - /*------------------------------------------------------------------------= ---- | Returns the result of converting the quadruple-precision floating-point | value `a' to the extended double-precision floating-point format. The diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 7f69da1d8f..483bdc0e21 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -763,7 +763,7 @@ static void partsN(round_to_int)(FloatPartsN *a, FloatR= oundMode rmode, * the largest positive integer is returned. Otherwise, if the * conversion overflows, the largest integer with the same sign as `a' * is returned. -*/ + */ static int64_t partsN(float_to_sint)(FloatPartsN *p, FloatRoundMode rmode, int scale, int64_t min, int64_t max, float_status *s) @@ -817,3 +817,69 @@ static int64_t partsN(float_to_sint)(FloatPartsN *p, F= loatRoundMode rmode, float_raise(flags, s); return r; } + +/* + * Returns the result of converting the floating-point value `a' to + * the unsigned integer format. The conversion is performed according + * to the IEC/IEEE Standard for Binary Floating-Point + * Arithmetic---which means in particular that the conversion is + * rounded according to the current rounding mode. If `a' is a NaN, + * the largest unsigned integer is returned. Otherwise, if the + * conversion overflows, the largest unsigned integer is returned. If + * the 'a' is negative, the result is rounded and zero is returned; + * values that do not round to zero will raise the inexact exception + * flag. + */ +static uint64_t partsN(float_to_uint)(FloatPartsN *p, FloatRoundMode rmode, + int scale, uint64_t max, float_statu= s *s) +{ + int flags =3D 0; + uint64_t r; + + switch (p->cls) { + case float_class_snan: + case float_class_qnan: + flags =3D float_flag_invalid; + r =3D max; + break; + + case float_class_inf: + flags =3D float_flag_invalid; + r =3D p->sign ? 0 : max; + break; + + case float_class_zero: + return 0; + + case float_class_normal: + /* TODO: N - 2 is frac_size for rounding; could use input fmt. */ + if (parts_round_to_int_normal(p, rmode, scale, N - 2)) { + flags =3D float_flag_inexact; + if (p->cls =3D=3D float_class_zero) { + r =3D 0; + break; + } + } + + if (p->sign) { + flags =3D float_flag_invalid; + r =3D 0; + } else if (p->exp > DECOMPOSED_BINARY_POINT) { + flags =3D float_flag_invalid; + r =3D max; + } else { + r =3D p->frac_hi >> (DECOMPOSED_BINARY_POINT - p->exp); + if (r > max) { + flags =3D float_flag_invalid; + r =3D max; + } + } + break; + + default: + g_assert_not_reached(); + } + + float_raise(flags, s); + return r; +} --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756579; cv=none; d=zohomail.com; s=zohoarc; b=ASAlSEBlnATxQGWh69OkXKBj6HKE9iYJ1wkGXhKhL8Uki2OhnPfPTALZfdvUpm+FeR6vF5oCAuxmZWmSC1hKKttzIf97cF0Pfrvh7dIiASBvXXd0Zy0/+H3CkalGdwTNzVk8hoERMKZJ3Bi0XM4o/xMJMIbRz+hpGN8AseKJRCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756579; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jExZoW94fQf1KTDSzPZo60kTKr+L9V1ApVnhdi+DwN4=; b=O8tCBCrJ6wpNMMLNebefzB6ASsjQWYYR3d/RPVV5TqEzG1FX2sIjCSqxxkEWI2c5noH9Ty1VBpB7hGDTgGjHTqM4z5K10KbwvjM+vIYH3DwL8jZ52Qj1i7MI440d2rXxHHcTYKhUGwaw7RZhswZKx8ZYNRKCq+0LrJ8DLg7llaU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756579945904.7683492742239; Thu, 3 Jun 2021 14:42:59 -0700 (PDT) Received: from localhost ([::1]:49268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lov7C-0004q0-N8 for importer@patchew.org; Thu, 03 Jun 2021 17:42:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5u-0001zP-GU for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:38 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:42605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5r-0000zu-BK for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:38 -0400 Received: by mail-pg1-x535.google.com with SMTP id t8so6149200pgb.9 for ; Thu, 03 Jun 2021 14:41:34 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:33 -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=jExZoW94fQf1KTDSzPZo60kTKr+L9V1ApVnhdi+DwN4=; b=omRWt91qfFzA3nkkwRbpAZIY+cSyYlCri9Bj5NJ4zOYe2ZfSLMB+r+wtG5kI2wNG+Y r8XWdO6XgS+8pxSJpYT/qrv+C+d30RFlHrurwvwbdjXq7Kdd4uV+YDa1hKyql1vDs5XX IIODnjr9NzdkV7TaG/XLrR+YwLakawYTnY8LM/A70OokKXkAC7lLVYobUEDJYIj3QVG2 J+lOzXQ0dlT5ZVNFAci5r5oJfLCrjipO9fooRlddtp4FRmmnMVKbe9K63n1pAdJiTOUR raSxAmGqjgGqCYTYgpgL0pqJC6XuL+Qss/CGLcDaoHOlsxGfvboSkfxELULBT6G/k57X rkTw== 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=jExZoW94fQf1KTDSzPZo60kTKr+L9V1ApVnhdi+DwN4=; b=EjTLwQKNvYVM7NyshoicmvN//KfMEPEPtQOmH/2tT8yTdRESt+Dlabouh+ubKfQdJ3 Zu5r/NNmInMQfUiKu303RJB/gX5OfAnZcDlHFtsX+9cB28wzmWNSvwj8XUn0T5sr6326 zC7tn157A00nL4ZbJHjkKWvyGec0eJphY9DQR6YFBiHb35b7lzutXpEKDn8CWr9lEN3o y0fKa5LzEbuAaWugpJ8k0t9Cdp52I6k5NH8Sx+OE43sjM3pwg3V6mNgIDWVOyH9OqYaa HtEqWNr8nSEyKWL1eYf93n2NnDDWSoziLNL4ZjX/etIU5Yw879Wp8jZalNcv7B3XLsPc WLLw== X-Gm-Message-State: AOAM530/vroE5hyDJtzXxGck1YS8eVmBAw596iavrLvpgc3lFf4wjpX9 nOSuS99ZPr9ci79h9OxSrWaJOxLuxDpc/Q== X-Google-Smtp-Source: ABdhPJzpdE+pzVSyyjTIysF9sRjfPSZ6u6++fWd7ZXhehDhio03UoRw1cgdnGCKGOT8b20kHILoOdA== X-Received: by 2002:a62:3344:0:b029:24c:735c:4546 with SMTP id z65-20020a6233440000b029024c735c4546mr1409766pfz.1.1622756494055; Thu, 03 Jun 2021 14:41:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 02/29] softfloat: Move int_to_float to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:04 -0700 Message-Id: <20210603214131.629841-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Rename to parts$N_sint_to_float. Reimplement int{32,64}_to_float128 with FloatParts128. Reviewed-by: Alex Benn=C3=A9e Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson --- fpu/softfloat.c | 136 +++++++++++--------------------------- fpu/softfloat-parts.c.inc | 32 +++++++++ 2 files changed, 70 insertions(+), 98 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 3181678ea9..6404a2997f 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -849,6 +849,14 @@ static uint64_t parts128_float_to_uint(FloatParts128 *= p, FloatRoundMode rmode, #define parts_float_to_uint(P, R, Z, M, S) \ PARTS_GENERIC_64_128(float_to_uint, P)(P, R, Z, M, S) =20 +static void parts64_sint_to_float(FloatParts64 *p, int64_t a, + int scale, float_status *s); +static void parts128_sint_to_float(FloatParts128 *p, int64_t a, + int scale, float_status *s); + +#define parts_sint_to_float(P, I, Z, S) \ + PARTS_GENERIC_64_128(sint_to_float, P)(P, I, Z, S) + /* * Helper functions for softfloat-parts.c.inc, per-size operations. */ @@ -2940,42 +2948,15 @@ uint64_t bfloat16_to_uint64_round_to_zero(bfloat16 = a, float_status *s) } =20 /* - * Integer to float conversions - * - * Returns the result of converting the two's complement integer `a' - * to the floating-point format. The conversion is performed according - * to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. + * Signed integer to floating-point conversions */ =20 -static FloatParts64 int_to_float(int64_t a, int scale, float_status *statu= s) -{ - FloatParts64 r =3D { .sign =3D false }; - - if (a =3D=3D 0) { - r.cls =3D float_class_zero; - } else { - uint64_t f =3D a; - int shift; - - r.cls =3D float_class_normal; - if (a < 0) { - f =3D -f; - r.sign =3D true; - } - shift =3D clz64(f); - scale =3D MIN(MAX(scale, -0x10000), 0x10000); - - r.exp =3D DECOMPOSED_BINARY_POINT - shift + scale; - r.frac =3D f << shift; - } - - return r; -} - float16 int64_to_float16_scalbn(int64_t a, int scale, float_status *status) { - FloatParts64 pa =3D int_to_float(a, scale, status); - return float16_round_pack_canonical(&pa, status); + FloatParts64 p; + + parts_sint_to_float(&p, a, scale, status); + return float16_round_pack_canonical(&p, status); } =20 float16 int32_to_float16_scalbn(int32_t a, int scale, float_status *status) @@ -3010,8 +2991,10 @@ float16 int8_to_float16(int8_t a, float_status *stat= us) =20 float32 int64_to_float32_scalbn(int64_t a, int scale, float_status *status) { - FloatParts64 pa =3D int_to_float(a, scale, status); - return float32_round_pack_canonical(&pa, status); + FloatParts64 p; + + parts64_sint_to_float(&p, a, scale, status); + return float32_round_pack_canonical(&p, status); } =20 float32 int32_to_float32_scalbn(int32_t a, int scale, float_status *status) @@ -3041,8 +3024,10 @@ float32 int16_to_float32(int16_t a, float_status *st= atus) =20 float64 int64_to_float64_scalbn(int64_t a, int scale, float_status *status) { - FloatParts64 pa =3D int_to_float(a, scale, status); - return float64_round_pack_canonical(&pa, status); + FloatParts64 p; + + parts_sint_to_float(&p, a, scale, status); + return float64_round_pack_canonical(&p, status); } =20 float64 int32_to_float64_scalbn(int32_t a, int scale, float_status *status) @@ -3070,15 +3055,12 @@ float64 int16_to_float64(int16_t a, float_status *s= tatus) return int64_to_float64_scalbn(a, 0, status); } =20 -/* - * Returns the result of converting the two's complement integer `a' - * to the bfloat16 format. - */ - bfloat16 int64_to_bfloat16_scalbn(int64_t a, int scale, float_status *stat= us) { - FloatParts64 pa =3D int_to_float(a, scale, status); - return bfloat16_round_pack_canonical(&pa, status); + FloatParts64 p; + + parts_sint_to_float(&p, a, scale, status); + return bfloat16_round_pack_canonical(&p, status); } =20 bfloat16 int32_to_bfloat16_scalbn(int32_t a, int scale, float_status *stat= us) @@ -3106,6 +3088,19 @@ bfloat16 int16_to_bfloat16(int16_t a, float_status *= status) return int64_to_bfloat16_scalbn(a, 0, status); } =20 +float128 int64_to_float128(int64_t a, float_status *status) +{ + FloatParts128 p; + + parts_sint_to_float(&p, a, 0, status); + return float128_round_pack_canonical(&p, status); +} + +float128 int32_to_float128(int32_t a, float_status *status) +{ + return int64_to_float128(a, status); +} + /* * Unsigned Integer to float conversions * @@ -4956,28 +4951,6 @@ floatx80 int32_to_floatx80(int32_t a, float_status *= status) =20 } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the 32-bit two's complement integer `a'= to -| the quadruple-precision floating-point format. The conversion is perfor= med -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float128 int32_to_float128(int32_t a, float_status *status) -{ - bool zSign; - uint32_t absA; - int8_t shiftCount; - uint64_t zSig0; - - if ( a =3D=3D 0 ) return packFloat128( 0, 0, 0, 0 ); - zSign =3D ( a < 0 ); - absA =3D zSign ? - a : a; - shiftCount =3D clz32(absA) + 17; - zSig0 =3D absA; - return packFloat128( zSign, 0x402E - shiftCount, zSig0<cls =3D float_class_zero; + return; + } + + p->cls =3D float_class_normal; + if (a < 0) { + f =3D -f; + p->sign =3D true; + } + shift =3D clz64(f); + scale =3D MIN(MAX(scale, -0x10000), 0x10000); + + p->exp =3D DECOMPOSED_BINARY_POINT - shift + scale; + p->frac_hi =3D f << shift; +} --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756763; cv=none; d=zohomail.com; s=zohoarc; b=P0QkMxrL6FmI9hOokHGWD2UcdgPuJeNbSK2SRthm79Huk6J763BGkN7zALLdJAs4nZIBFHD/xbPeQLgQPx57zClUv4y3/7DZy+8L+M059k8qnF3INDFM9gSHjdmiXqw4JuvAHwYAjfpM5ajkWa6dkcevj2Dz8fH8va8mxUgc16A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756763; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/O3G+s5zkrQ27z7duiC08BP2nW9q9ClatbZtV+eVQt0=; b=JvDe3+lz/UMqpWvz2kgvmDTgyV7m3xWTmjfV46CKw9om/4EGi3kR0SW6zM+z8pIuj9Q1MGdQyqBFsXCS9JAFZ1BZiCrYCsUrs5+jNIpyOtjbXQh86oWGjX6jyiltBGmOGsOPrJnJHLwlzy0UZqaHPUGaPXfteAIWN0xYCeHvdao= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756763464953.5129669874335; Thu, 3 Jun 2021 14:46:03 -0700 (PDT) Received: from localhost ([::1]:35690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovAA-000663-Cy for importer@patchew.org; Thu, 03 Jun 2021 17:46:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5w-00025j-Sl for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:40 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:47023) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5s-000117-1f for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:40 -0400 Received: by mail-pf1-x42a.google.com with SMTP id u126so1935757pfu.13 for ; Thu, 03 Jun 2021 14:41:35 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:34 -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=/O3G+s5zkrQ27z7duiC08BP2nW9q9ClatbZtV+eVQt0=; b=AdXiEiXz11/DSAfCNJlFbgdN1GA1QAjYQX+j1qseJZEdu0oxXrsxodCmygAuVA5JRU jDX4bpxKJFI2qVyRwwJi6Lu4LIr+xtVYgPV0e8fBdedH1babfzDGHY5OKjOJ8QIQo0ou YdyI0jQK+/+Uf4hMDT2WMdFgNBwOXbpaFiOUObtlpjKByUAHWLDJdtbnULk8mdT/FShP mK6pEVZUl7zvhJQSMLOU77AYLc3pTJA/hxSYiEe9LYh3JAtZCUMEaWDsHKs+jxjqyqK5 tg7v+aDO/2pWFxY2YNvuwWbjl5u0RavUp2R3NT62pZ6GVvTvafOfMeLf5zszK6CnpHRJ iz2Q== 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=/O3G+s5zkrQ27z7duiC08BP2nW9q9ClatbZtV+eVQt0=; b=NvAk19pSV/hdHK49RrCBfOPSWaDsqKVnJvgpfbx/eSoHrgwlgNOiEfuO+k0fByoYGr RC8zWPs7JsE3rlqbXWeEKPQiIx7vM/G6RnqpAhSy8Fsi1+WsMMdZ6Yfmpp5YSdWIjbSE zt6QYIawQj11vjBajpp9/6gZoakMRbBgTg1IPqL5TNrjqAB9rtOCQk/sgL+wV3w1rXyH gJQNDmAjf3W+Ybv3413dbopASz1uvouDmXt5KqZ7UyK8wOLtGLyyJ9ET2j6zCxpLd3kM NN3tZ/hVJUqngC31CF3YCcUgVdknLMaKOzUAMXBi+UZ9OZKHRj9CHGtONA8PJdstAEuN BGMQ== X-Gm-Message-State: AOAM5327eMUkf6UXH2oz7tHBax9wUIwwtBuy4xKh42ld1xOL641PnAlt yNvDewDDD5755nbSLdwez/8oFvq2Q7Iq4g== X-Google-Smtp-Source: ABdhPJw6C1uqfHrCsBLhS/ERYIRyrVUG79bLDe2I6pCfqNi2YtXXCmDj/dRSlmQ4gpTdWusyU6pA4g== X-Received: by 2002:a63:4b42:: with SMTP id k2mr1481437pgl.33.1622756494694; Thu, 03 Jun 2021 14:41:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 03/29] softfloat: Move uint_to_float to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:05 -0700 Message-Id: <20210603214131.629841-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Rename to parts$N_uint_to_float. Reimplement uint64_to_float128 with FloatParts128. Reviewed-by: Alex Benn=C3=A9e Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson --- fpu/softfloat.c | 83 ++++++++++++++++----------------------- fpu/softfloat-parts.c.inc | 23 +++++++++++ 2 files changed, 56 insertions(+), 50 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6404a2997f..db14bd09aa 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -857,6 +857,14 @@ static void parts128_sint_to_float(FloatParts128 *p, i= nt64_t a, #define parts_sint_to_float(P, I, Z, S) \ PARTS_GENERIC_64_128(sint_to_float, P)(P, I, Z, S) =20 +static void parts64_uint_to_float(FloatParts64 *p, uint64_t a, + int scale, float_status *s); +static void parts128_uint_to_float(FloatParts128 *p, uint64_t a, + int scale, float_status *s); + +#define parts_uint_to_float(P, I, Z, S) \ + PARTS_GENERIC_64_128(uint_to_float, P)(P, I, Z, S) + /* * Helper functions for softfloat-parts.c.inc, per-size operations. */ @@ -3102,35 +3110,15 @@ float128 int32_to_float128(int32_t a, float_status = *status) } =20 /* - * Unsigned Integer to float conversions - * - * Returns the result of converting the unsigned integer `a' to the - * floating-point format. The conversion is performed according to the - * IEC/IEEE Standard for Binary Floating-Point Arithmetic. + * Unsigned Integer to floating-point conversions */ =20 -static FloatParts64 uint_to_float(uint64_t a, int scale, float_status *sta= tus) -{ - FloatParts64 r =3D { .sign =3D false }; - int shift; - - if (a =3D=3D 0) { - r.cls =3D float_class_zero; - } else { - scale =3D MIN(MAX(scale, -0x10000), 0x10000); - shift =3D clz64(a); - r.cls =3D float_class_normal; - r.exp =3D DECOMPOSED_BINARY_POINT - shift + scale; - r.frac =3D a << shift; - } - - return r; -} - float16 uint64_to_float16_scalbn(uint64_t a, int scale, float_status *stat= us) { - FloatParts64 pa =3D uint_to_float(a, scale, status); - return float16_round_pack_canonical(&pa, status); + FloatParts64 p; + + parts_uint_to_float(&p, a, scale, status); + return float16_round_pack_canonical(&p, status); } =20 float16 uint32_to_float16_scalbn(uint32_t a, int scale, float_status *stat= us) @@ -3165,8 +3153,10 @@ float16 uint8_to_float16(uint8_t a, float_status *st= atus) =20 float32 uint64_to_float32_scalbn(uint64_t a, int scale, float_status *stat= us) { - FloatParts64 pa =3D uint_to_float(a, scale, status); - return float32_round_pack_canonical(&pa, status); + FloatParts64 p; + + parts_uint_to_float(&p, a, scale, status); + return float32_round_pack_canonical(&p, status); } =20 float32 uint32_to_float32_scalbn(uint32_t a, int scale, float_status *stat= us) @@ -3196,8 +3186,10 @@ float32 uint16_to_float32(uint16_t a, float_status *= status) =20 float64 uint64_to_float64_scalbn(uint64_t a, int scale, float_status *stat= us) { - FloatParts64 pa =3D uint_to_float(a, scale, status); - return float64_round_pack_canonical(&pa, status); + FloatParts64 p; + + parts_uint_to_float(&p, a, scale, status); + return float64_round_pack_canonical(&p, status); } =20 float64 uint32_to_float64_scalbn(uint32_t a, int scale, float_status *stat= us) @@ -3225,15 +3217,12 @@ float64 uint16_to_float64(uint16_t a, float_status = *status) return uint64_to_float64_scalbn(a, 0, status); } =20 -/* - * Returns the result of converting the unsigned integer `a' to the - * bfloat16 format. - */ - bfloat16 uint64_to_bfloat16_scalbn(uint64_t a, int scale, float_status *st= atus) { - FloatParts64 pa =3D uint_to_float(a, scale, status); - return bfloat16_round_pack_canonical(&pa, status); + FloatParts64 p; + + parts_uint_to_float(&p, a, scale, status); + return bfloat16_round_pack_canonical(&p, status); } =20 bfloat16 uint32_to_bfloat16_scalbn(uint32_t a, int scale, float_status *st= atus) @@ -3261,6 +3250,14 @@ bfloat16 uint16_to_bfloat16(uint16_t a, float_status= *status) return uint64_to_bfloat16_scalbn(a, 0, status); } =20 +float128 uint64_to_float128(uint64_t a, float_status *status) +{ + FloatParts128 p; + + parts_uint_to_float(&p, a, 0, status); + return float128_round_pack_canonical(&p, status); +} + /* Float Min/Max */ /* min() and max() functions. These can't be implemented as * 'compare and pick one input' because that would mishandle @@ -4972,20 +4969,6 @@ floatx80 int64_to_floatx80(int64_t a, float_status *= status) =20 } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the 64-bit unsigned integer `a' -| to the quadruple-precision floating-point format. The conversion is per= formed -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float128 uint64_to_float128(uint64_t a, float_status *status) -{ - if (a =3D=3D 0) { - return float128_zero; - } - return normalizeRoundAndPackFloat128(0, 0x406E, 0, a, status); -} - /*------------------------------------------------------------------------= ---- | Returns the result of converting the single-precision floating-point val= ue | `a' to the extended double-precision floating-point format. The convers= ion diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index b7486f02db..2eb7bb96b3 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -915,3 +915,26 @@ static void partsN(sint_to_float)(FloatPartsN *p, int6= 4_t a, p->exp =3D DECOMPOSED_BINARY_POINT - shift + scale; p->frac_hi =3D f << shift; } + +/* + * Unsigned Integer to float conversions + * + * Returns the result of converting the unsigned integer `a' to the + * floating-point format. The conversion is performed according to the + * IEC/IEEE Standard for Binary Floating-Point Arithmetic. + */ +static void partsN(uint_to_float)(FloatPartsN *p, uint64_t a, + int scale, float_status *status) +{ + memset(p, 0, sizeof(*p)); + + if (a =3D=3D 0) { + p->cls =3D float_class_zero; + } else { + int shift =3D clz64(a); + scale =3D MIN(MAX(scale, -0x10000), 0x10000); + p->cls =3D float_class_normal; + p->exp =3D DECOMPOSED_BINARY_POINT - shift + scale; + p->frac_hi =3D a << shift; + } +} --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756669; cv=none; d=zohomail.com; s=zohoarc; b=HQCpMhrmBJe7Gj3/MoZ/ohPBIaR//sS007srPnWzJUTiN5MJRr/xKdfSBiJ8UY2IvlYlnx7xXfYPzoblDmnbfoNufWoOgmS5WhTq2/Ffd6RoTqvw+tgna6c+0zw849TNlhzNNmIgWHgfLqAEF7eCp3sitjBf7atd8ZnUiUXGxjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756669; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZyqAk3JV1lMheoleEpLdtdhruI6JP69rj7H32n7LYXs=; b=TYVyASMjkA417teeJiiZKBjvRlce2zd4Qvrp4dVQ2QLc16ywXtmIDoMXd264IBpUn/DB4tNhR47lWlP7BGYYq0Ps3V5n1mSGT9j2YKKgHfdNXjXF1tX3nDigYL9PXw99kd14z88hOZPxndjbb7Jo3MIowmZwmEMziD5NjggmoC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756669633191.73151905292616; Thu, 3 Jun 2021 14:44:29 -0700 (PDT) Received: from localhost ([::1]:57542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lov8e-0001sx-JC for importer@patchew.org; Thu, 03 Jun 2021 17:44:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5v-00020o-2q for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:39 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:50901) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5s-00011T-O3 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:38 -0400 Received: by mail-pj1-x102b.google.com with SMTP id i22so4470922pju.0 for ; Thu, 03 Jun 2021 14:41:36 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:35 -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=ZyqAk3JV1lMheoleEpLdtdhruI6JP69rj7H32n7LYXs=; b=RSVhTeGQm/Y7zgKdYqb0hfCRi7df6m1rpJB9L5tyag2dP+VEPzb8nUAfw8o+mBdklf l3Rzwk5pIcusQf0Gfmc7M2LRDYD9m3Y6ajgsBmBC+bCOvWIq4tbmakoIATPFI8aIKUtN rdgY4gVLJBFtN+gbApAAnRRAMyqWOCgzRdNmyAaxj5S5xI+gm7eLR9EbpcIA7kbgIjZC Z/Axjr7nzyA5G18Zzhnxa7vfXvlhOX99OnA/xS4Uw/7AzDbr7giE4wRfMA1adP2k1BTu rpzIvh6hWkdh09XBmbq7IgJ1Nfno7s/s/dccNRBhWxqG8ia+mbIIjwgkALZbcAGzQXJh 2vew== 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=ZyqAk3JV1lMheoleEpLdtdhruI6JP69rj7H32n7LYXs=; b=LzAlBmSik1crI2bkgrhPIRFS+BoKCCoYnrsh7OQUvnFmuqd8AiRj7M21thh0uJeQBF h4VOaZ4P+Le2ReSzyXhz/6jNQTcpxU04oJ/4n7ERDORbQ08Eqq1jjGSQSpV77GchdIfN pxiHSn9RKVXAQ58mtmnIf0z4ACoYztoRyDchq7xEASXZar9dR4EoP3AuIReN52TMvTXO J+sxvu2UNogi3T5Im3wAU7/OtE06XnMhBnBFkzB57nYcloNdCYOaSOdRHI/pWpdEFv1m LP7bWgz6EtMTm6IE1vZzh0JiOB6uIZYcuioOVScUgUJGF6sHpuzsyXWgPhHU2N0j/ncU makQ== X-Gm-Message-State: AOAM530UUfTETpBbyHLfvFT3FxR7AIdHSuLvkO8jU9JZm9FtuitRF7Ag Z6M/PEEkz4dQU7z3Y8DJUf4LH4hQ9e+Eew== X-Google-Smtp-Source: ABdhPJzHsRHSVHsTLbg+/IZUDLxUpA5ivvPW+gm1hP55PkVrXNHA0HTiVXLY+2YmB7v01qQxl1q8NQ== X-Received: by 2002:a17:902:728c:b029:f6:6aff:4d66 with SMTP id d12-20020a170902728cb02900f66aff4d66mr1114100pll.20.1622756495406; Thu, 03 Jun 2021 14:41:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 04/29] softfloat: Move minmax_flags to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:06 -0700 Message-Id: <20210603214131.629841-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com 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: David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" Rename to parts$N_minmax. Combine 3 bool arguments to a bitmask. Introduce ftype_minmax functions as a common optimization point. Fold bfloat16 expansions into the same macro as the other types. Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson --- fpu/softfloat.c | 198 ++++++++++++++------------------------ fpu/softfloat-parts.c.inc | 80 +++++++++++++++ 2 files changed, 152 insertions(+), 126 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index db14bd09aa..ef750e1e95 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -482,6 +482,15 @@ enum { float_cmask_anynan =3D float_cmask_qnan | float_cmask_snan, }; =20 +/* Flags for parts_minmax. */ +enum { + /* Set for minimum; clear for maximum. */ + minmax_ismin =3D 1, + /* Set for the IEEE 754-2008 minNum() and maxNum() operations. */ + minmax_isnum =3D 2, + /* Set for the IEEE 754-2008 minNumMag() and minNumMag() operations. */ + minmax_ismag =3D 4, +}; =20 /* Simple helpers for checking if, or what kind of, NaN we have */ static inline __attribute__((unused)) bool is_nan(FloatClass c) @@ -865,6 +874,14 @@ static void parts128_uint_to_float(FloatParts128 *p, u= int64_t a, #define parts_uint_to_float(P, I, Z, S) \ PARTS_GENERIC_64_128(uint_to_float, P)(P, I, Z, S) =20 +static FloatParts64 *parts64_minmax(FloatParts64 *a, FloatParts64 *b, + float_status *s, int flags); +static FloatParts128 *parts128_minmax(FloatParts128 *a, FloatParts128 *b, + float_status *s, int flags); + +#define parts_minmax(A, B, S, F) \ + PARTS_GENERIC_64_128(minmax, A)(A, B, S, F) + /* * Helper functions for softfloat-parts.c.inc, per-size operations. */ @@ -3258,145 +3275,74 @@ float128 uint64_to_float128(uint64_t a, float_stat= us *status) return float128_round_pack_canonical(&p, status); } =20 -/* Float Min/Max */ -/* min() and max() functions. These can't be implemented as - * 'compare and pick one input' because that would mishandle - * NaNs and +0 vs -0. - * - * minnum() and maxnum() functions. These are similar to the min() - * and max() functions but if one of the arguments is a QNaN and - * the other is numerical then the numerical argument is returned. - * SNaNs will get quietened before being returned. - * minnum() and maxnum correspond to the IEEE 754-2008 minNum() - * and maxNum() operations. min() and max() are the typical min/max - * semantics provided by many CPUs which predate that specification. - * - * minnummag() and maxnummag() functions correspond to minNumMag() - * and minNumMag() from the IEEE-754 2008. +/* + * Minimum and maximum */ -static FloatParts64 minmax_floats(FloatParts64 a, FloatParts64 b, bool ism= in, - bool ieee, bool ismag, float_status *s) + +static float16 float16_minmax(float16 a, float16 b, float_status *s, int f= lags) { - if (unlikely(is_nan(a.cls) || is_nan(b.cls))) { - if (ieee) { - /* Takes two floating-point values `a' and `b', one of - * which is a NaN, and returns the appropriate NaN - * result. If either `a' or `b' is a signaling NaN, - * the invalid exception is raised. - */ - if (is_snan(a.cls) || is_snan(b.cls)) { - return *parts_pick_nan(&a, &b, s); - } else if (is_nan(a.cls) && !is_nan(b.cls)) { - return b; - } else if (is_nan(b.cls) && !is_nan(a.cls)) { - return a; - } - } - return *parts_pick_nan(&a, &b, s); - } else { - int a_exp, b_exp; + FloatParts64 pa, pb, *pr; =20 - switch (a.cls) { - case float_class_normal: - a_exp =3D a.exp; - break; - case float_class_inf: - a_exp =3D INT_MAX; - break; - case float_class_zero: - a_exp =3D INT_MIN; - break; - default: - g_assert_not_reached(); - break; - } - switch (b.cls) { - case float_class_normal: - b_exp =3D b.exp; - break; - case float_class_inf: - b_exp =3D INT_MAX; - break; - case float_class_zero: - b_exp =3D INT_MIN; - break; - default: - g_assert_not_reached(); - break; - } + float16_unpack_canonical(&pa, a, s); + float16_unpack_canonical(&pb, b, s); + pr =3D parts_minmax(&pa, &pb, s, flags); =20 - if (ismag && (a_exp !=3D b_exp || a.frac !=3D b.frac)) { - bool a_less =3D a_exp < b_exp; - if (a_exp =3D=3D b_exp) { - a_less =3D a.frac < b.frac; - } - return a_less ^ ismin ? b : a; - } - - if (a.sign =3D=3D b.sign) { - bool a_less =3D a_exp < b_exp; - if (a_exp =3D=3D b_exp) { - a_less =3D a.frac < b.frac; - } - return a.sign ^ a_less ^ ismin ? b : a; - } else { - return a.sign ^ ismin ? b : a; - } - } + return float16_round_pack_canonical(pr, s); } =20 -#define MINMAX(sz, name, ismin, isiee, ismag) \ -float ## sz float ## sz ## _ ## name(float ## sz a, float ## sz b, \ - float_status *s) \ -{ \ - FloatParts64 pa, pb, pr; \ - float ## sz ## _unpack_canonical(&pa, a, s); \ - float ## sz ## _unpack_canonical(&pb, b, s); \ - pr =3D minmax_floats(pa, pb, ismin, isiee, ismag, s); \ - return float ## sz ## _round_pack_canonical(&pr, s); \ +static bfloat16 bfloat16_minmax(bfloat16 a, bfloat16 b, + float_status *s, int flags) +{ + FloatParts64 pa, pb, *pr; + + bfloat16_unpack_canonical(&pa, a, s); + bfloat16_unpack_canonical(&pb, b, s); + pr =3D parts_minmax(&pa, &pb, s, flags); + + return bfloat16_round_pack_canonical(pr, s); } =20 -MINMAX(16, min, true, false, false) -MINMAX(16, minnum, true, true, false) -MINMAX(16, minnummag, true, true, true) -MINMAX(16, max, false, false, false) -MINMAX(16, maxnum, false, true, false) -MINMAX(16, maxnummag, false, true, true) +static float32 float32_minmax(float32 a, float32 b, float_status *s, int f= lags) +{ + FloatParts64 pa, pb, *pr; =20 -MINMAX(32, min, true, false, false) -MINMAX(32, minnum, true, true, false) -MINMAX(32, minnummag, true, true, true) -MINMAX(32, max, false, false, false) -MINMAX(32, maxnum, false, true, false) -MINMAX(32, maxnummag, false, true, true) + float32_unpack_canonical(&pa, a, s); + float32_unpack_canonical(&pb, b, s); + pr =3D parts_minmax(&pa, &pb, s, flags); =20 -MINMAX(64, min, true, false, false) -MINMAX(64, minnum, true, true, false) -MINMAX(64, minnummag, true, true, true) -MINMAX(64, max, false, false, false) -MINMAX(64, maxnum, false, true, false) -MINMAX(64, maxnummag, false, true, true) - -#undef MINMAX - -#define BF16_MINMAX(name, ismin, isiee, ismag) \ -bfloat16 bfloat16_ ## name(bfloat16 a, bfloat16 b, float_status *s) \ -{ \ - FloatParts64 pa, pb, pr; \ - bfloat16_unpack_canonical(&pa, a, s); \ - bfloat16_unpack_canonical(&pb, b, s); \ - pr =3D minmax_floats(pa, pb, ismin, isiee, ismag, s); \ - return bfloat16_round_pack_canonical(&pr, s); \ + return float32_round_pack_canonical(pr, s); } =20 -BF16_MINMAX(min, true, false, false) -BF16_MINMAX(minnum, true, true, false) -BF16_MINMAX(minnummag, true, true, true) -BF16_MINMAX(max, false, false, false) -BF16_MINMAX(maxnum, false, true, false) -BF16_MINMAX(maxnummag, false, true, true) +static float64 float64_minmax(float64 a, float64 b, float_status *s, int f= lags) +{ + FloatParts64 pa, pb, *pr; =20 -#undef BF16_MINMAX + float64_unpack_canonical(&pa, a, s); + float64_unpack_canonical(&pb, b, s); + pr =3D parts_minmax(&pa, &pb, s, flags); + + return float64_round_pack_canonical(pr, s); +} + +#define MINMAX_1(type, name, flags) \ + type type##_##name(type a, type b, float_status *s) \ + { return type##_minmax(a, b, s, flags); } + +#define MINMAX_2(type) \ + MINMAX_1(type, max, 0) \ + MINMAX_1(type, maxnum, minmax_isnum) \ + MINMAX_1(type, maxnummag, minmax_isnum | minmax_ismag) \ + MINMAX_1(type, min, minmax_ismin) \ + MINMAX_1(type, minnum, minmax_ismin | minmax_isnum) \ + MINMAX_1(type, minnummag, minmax_ismin | minmax_isnum | minmax_ismag) + +MINMAX_2(float16) +MINMAX_2(bfloat16) +MINMAX_2(float32) +MINMAX_2(float64) + +#undef MINMAX_1 +#undef MINMAX_2 =20 /* Floating point compare */ static FloatRelation compare_floats(FloatParts64 a, FloatParts64 b, bool i= s_quiet, diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 2eb7bb96b3..b9094768db 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -938,3 +938,83 @@ static void partsN(uint_to_float)(FloatPartsN *p, uint= 64_t a, p->frac_hi =3D a << shift; } } + +/* + * Float min/max. + */ +static FloatPartsN *partsN(minmax)(FloatPartsN *a, FloatPartsN *b, + float_status *s, int flags) +{ + int ab_mask =3D float_cmask(a->cls) | float_cmask(b->cls); + int a_exp, b_exp, cmp; + + if (unlikely(ab_mask & float_cmask_anynan)) { + /* + * For minnum/maxnum, if one operand is a QNaN, and the other + * operand is numerical, then return numerical argument. + */ + if ((flags & minmax_isnum) + && !(ab_mask & float_cmask_snan) + && (ab_mask & ~float_cmask_qnan)) { + return is_nan(a->cls) ? b : a; + } + return parts_pick_nan(a, b, s); + } + + a_exp =3D a->exp; + b_exp =3D b->exp; + + if (unlikely(ab_mask !=3D float_cmask_normal)) { + switch (a->cls) { + case float_class_normal: + break; + case float_class_inf: + a_exp =3D INT16_MAX; + break; + case float_class_zero: + a_exp =3D INT16_MIN; + break; + default: + g_assert_not_reached(); + break; + } + switch (b->cls) { + case float_class_normal: + break; + case float_class_inf: + b_exp =3D INT16_MAX; + break; + case float_class_zero: + b_exp =3D INT16_MIN; + break; + default: + g_assert_not_reached(); + break; + } + } + + /* Compare magnitudes. */ + cmp =3D a_exp - b_exp; + if (cmp =3D=3D 0) { + cmp =3D frac_cmp(a, b); + } + + /* + * Take the sign into account. + * For ismag, only do this if the magnitudes are equal. + */ + if (!(flags & minmax_ismag) || cmp =3D=3D 0) { + if (a->sign !=3D b->sign) { + /* For differing signs, the negative operand is less. */ + cmp =3D a->sign ? -1 : 1; + } else if (a->sign) { + /* For two negative operands, invert the magnitude comparison.= */ + cmp =3D -cmp; + } + } + + if (flags & minmax_ismin) { + cmp =3D -cmp; + } + return cmp < 0 ? b : a; +} --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756813; cv=none; d=zohomail.com; s=zohoarc; b=YV0jEQQresBS5DxQWkx69Y2RPo0rHb8Htry6vENv2t/lxQbUFL0EqhpSQBcETAJBnZsiXivLgyEvjKdlQubmASB4siUjhnPWKF6l/McuNkKeA2EN3BBVGqRJkGQ8pNTkkiFKTUXPbRSmP7WjTfXqFQwr68L5BrwlGDblv7uYVgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756813; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=keKjVz3imnmcUE3wTIllL+iQylaB2Eebnx0eXWC+uoM=; b=I00m2+wkPZ7VPnxKWU5EuWwQOJTufRRp5Wv6Vu3KkimXjD+wJbRojd87qEjZ3tJ5fvFEFMCN4uuFbxT1DBjtr6Py6VxgfW7loZCxZyEIX22a1IX7ob1oOXYePBMbBq90k3FbQk1YBY9r1dJX7vRutiDHSJu8xUUJT3T6R6DxPLY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756813693620.7483260173633; Thu, 3 Jun 2021 14:46:53 -0700 (PDT) Received: from localhost ([::1]:38034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovAy-0007m7-2E for importer@patchew.org; Thu, 03 Jun 2021 17:46:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5v-00021f-GS for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:39 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:53094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5t-00011b-NH for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:39 -0400 Received: by mail-pj1-x1030.google.com with SMTP id h16so4445410pjv.2 for ; Thu, 03 Jun 2021 14:41:36 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:35 -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=keKjVz3imnmcUE3wTIllL+iQylaB2Eebnx0eXWC+uoM=; b=Jg6erSt06mrzVQ8iwCmUTSU+JmpntcyfKNOvUAEPdki+s6Of3krtkKHY12lyzaL0vE L5e40lnB7C6j/uHh7YQk7pfkQAaUCNIh3r05qFZRGUXbmR2FAUsNNhAPkRqDI1Bkn5XI 0thG+6ob0GwXYgeug/99gQm1pdey7Z/4cutfhFvdoSImSk7nfwTESNdG7/rakXEHC04h TRHGUvRuVkkO/lM7maNK7Ym7hVYiMK7CeAWZcz0VzpFcyLIahYA0H0qqk2s3+luFxqsW L7wpLubvhxzniHBzrqlnRSzgEpXIGAHjBFFETimxg7N65zIbZBDEkLITaSngAtG0xWuI xiTg== 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=keKjVz3imnmcUE3wTIllL+iQylaB2Eebnx0eXWC+uoM=; b=HBfZotLArGYevFsgkn8GxbfDVFOqdpzrNhtpHPlJEbxqSYjVxB+NNGhMx14SuTlk3r CKcUEgliiBlf0Lib15YVyq5PBsjeKQjMyB6ZQ9X/7xUp6qBtWhcmGCYHjRF6ktREDUYt YXfClmb1CnSvDFBeComGJIZ8xjx9pIlG4S5R/zlafV4hNulC4uImAJnOKPwwyacrAk4N BlSs9QnGT22JjhKmY9pFHLCf4FFnZTAKY6hJnzrh7M2+k9MH9dALG3xxMt7O0Emu2CEr SZYLhWdacooIik8maH11b5pyd9CgZR++k/ByGLIRCjqMHs1P2Z45Ybj1VSAFi0uJMu6i FHMQ== X-Gm-Message-State: AOAM5327B1DjiL5SthUaJChyt9X7YZ2gxGsfKs2pGE4HUp36z4qdRTVY uBpsMak8/xV+gRf++0LRI91GuBFFBFx5Ng== X-Google-Smtp-Source: ABdhPJyK9QslLughvJNZpeVtMN9niT2fKnLR4DAlRkn7b/nAd7TL3X2eD47qZxqOLMSHXYjKTVdgrw== X-Received: by 2002:a17:902:ea92:b029:103:a022:c545 with SMTP id x18-20020a170902ea92b0290103a022c545mr1192574plb.43.1622756496107; Thu, 03 Jun 2021 14:41:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 05/29] softfloat: Implement float128_(min|minnum|minnummag|max|maxnum|maxnummag) Date: Thu, 3 Jun 2021 14:41:07 -0700 Message-Id: <20210603214131.629841-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.google.com 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: David Hildenbrand Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand The float128 implementation is straight-forward. Unfortuantely, we don't have any tests we can simply adjust/unlock. Signed-off-by: David Hildenbrand Message-Id: <20210517142739.38597-24-david@redhat.com> [rth: Update for changed parts_minmax return value] Signed-off-by: Richard Henderson --- include/fpu/softfloat.h | 6 ++++++ fpu/softfloat.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 53f2c2ea3c..ed32040aa9 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -1204,6 +1204,12 @@ float128 float128_rem(float128, float128, float_stat= us *status); float128 float128_sqrt(float128, float_status *status); FloatRelation float128_compare(float128, float128, float_status *status); FloatRelation float128_compare_quiet(float128, float128, float_status *sta= tus); +float128 float128_min(float128, float128, float_status *status); +float128 float128_max(float128, float128, float_status *status); +float128 float128_minnum(float128, float128, float_status *status); +float128 float128_maxnum(float128, float128, float_status *status); +float128 float128_minnummag(float128, float128, float_status *status); +float128 float128_maxnummag(float128, float128, float_status *status); bool float128_is_quiet_nan(float128, float_status *status); bool float128_is_signaling_nan(float128, float_status *status); float128 float128_silence_nan(float128, float_status *status); diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ef750e1e95..4fee5a6cb7 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3324,6 +3324,18 @@ static float64 float64_minmax(float64 a, float64 b, = float_status *s, int flags) return float64_round_pack_canonical(pr, s); } =20 +static float128 float128_minmax(float128 a, float128 b, + float_status *s, int flags) +{ + FloatParts128 pa, pb, *pr; + + float128_unpack_canonical(&pa, a, s); + float128_unpack_canonical(&pb, b, s); + pr =3D parts_minmax(&pa, &pb, s, flags); + + return float128_round_pack_canonical(pr, s); +} + #define MINMAX_1(type, name, flags) \ type type##_##name(type a, type b, float_status *s) \ { return type##_minmax(a, b, s, flags); } @@ -3340,6 +3352,7 @@ MINMAX_2(float16) MINMAX_2(bfloat16) MINMAX_2(float32) MINMAX_2(float64) +MINMAX_2(float128) =20 #undef MINMAX_1 #undef MINMAX_2 --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756942; cv=none; d=zohomail.com; s=zohoarc; b=fXy4uGGIcZz1w4A1iY1WrUoR4OherJAwSsl4ASt2rbmXORaQJmf2sGnzFsCmKTp6Rt1VQvCk0xocm65t9Aqp99IGDjmRSEbpHxFX/rNL6qbc6mnCvBWZH0K1Eh/wFfpZFPpB5skSoyoIOlBaepLar1DdzMuiI92SaMzqppu5yIc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756942; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mH+tBMzgWSEdrBM44cETXcgu3S/9bsd4y7eciPgdKaQ=; b=VXcTzY1r16MQpX5Y39KMifzKHJE+DiEC3kzX9oyk8h8ZLhWOUBNNIpqQI3i4JMJiacFLD7OM0l9Slbsa5S0cRh0TpzSW4pWBCOom8ltpr+KiRiTYbREOF+xE/pXME9vDHIej1aPTjEjOxCFOkjubQuDG8KfhGraeyuyR2w0j4/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162275694268346.26042964892963; Thu, 3 Jun 2021 14:49:02 -0700 (PDT) Received: from localhost ([::1]:46652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovD3-00057N-LC for importer@patchew.org; Thu, 03 Jun 2021 17:49:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5x-00028u-Oi for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:41 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:46710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5u-00011r-6X for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:41 -0400 Received: by mail-pg1-x52b.google.com with SMTP id n12so6135079pgs.13 for ; Thu, 03 Jun 2021 14:41:37 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:36 -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=mH+tBMzgWSEdrBM44cETXcgu3S/9bsd4y7eciPgdKaQ=; b=GEBYsj+xwXsyz5iTrIAIm4WNtRTzfubAC5blxqb4mKwHOiPcLEIIPKNlLJeFQNNPR6 w2JerqyCqwaQgVMMdYTjR6IN4JlLFFapLalfbpKg/TidN5Wb/05R5StlvTUV+B5n1PTi RC1DZOCXJ2jxbid+7YfYmDgkWJATqHMgw1rVAr0ByyHv5h6r2emxZemN0moLafWGRnAI IxI+8h6HA4eA+3LNADyEqDe0YFOR+iuB27JKnXcSiZboby4nbrkOaofNgb/a4jgpKuos jszG+e+3iQtVx96lME2+XbgxWdZivbSDykKdcF9PT3JchQi1VjFm2Z9busdSxDQqkuYW 5LFw== 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=mH+tBMzgWSEdrBM44cETXcgu3S/9bsd4y7eciPgdKaQ=; b=rUUwnXVzlUs83BY6AKcCy5XE4iJ5g1QW0UjO+S3v43MOesa99MuuHZyqEnldIVgJhe s/erVd5XTQbwPMdUeDsg8ymuYN+jhrq60Di5yU9oAjDfydp3GTmZZGDWoKkJ4yPbQnNZ 9grWnm5koPGYzV/BTJ71Cf9GRrRzfDD8I+G10wgRSHyEU3A2bBVlAebvQFeDVBL1c8+O v5n9knmBFjaoInXkSthRPsn0ZQBSzk5AXrQmYpbdJVB/6bt01vZxVbyN456Z0BQu6Lbl SximNNO8YCh+WbYidkI9Ia7xh/PoSNmDdVTP+ZDRd7AtwDK3ADFBASlA+71Du2Av/IpQ erSw== X-Gm-Message-State: AOAM532wuGGF9db5LVRPIu3SPR5Pvwbtt2vF0599XFus1qXSQ/Ld05ol nYF6UeHpngXJBB7VD3mFGAlOXAOb35dQXQ== X-Google-Smtp-Source: ABdhPJwUhbTfWpBoF/8VJcztnr/XnAd7ZBY/Cdso83nZbD9AzM6SR+zrLke/thf1Q5lCQJLCG8aTzQ== X-Received: by 2002:a63:fc20:: with SMTP id j32mr1515221pgi.8.1622756496756; Thu, 03 Jun 2021 14:41:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 06/29] softfloat: Move compare_floats to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:08 -0700 Message-Id: <20210603214131.629841-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Rename to parts$N_compare. Rename all of the intermediate functions to ftype_do_compare. Rename the hard-float functions to ftype_hs_compare. Convert float128 to FloatParts128. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 208 ++++++++++++++------------------------ fpu/softfloat-parts.c.inc | 57 +++++++++++ 2 files changed, 133 insertions(+), 132 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 4fee5a6cb7..6f1bbbe6cf 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -882,6 +882,14 @@ static FloatParts128 *parts128_minmax(FloatParts128 *a= , FloatParts128 *b, #define parts_minmax(A, B, S, F) \ PARTS_GENERIC_64_128(minmax, A)(A, B, S, F) =20 +static int parts64_compare(FloatParts64 *a, FloatParts64 *b, + float_status *s, bool q); +static int parts128_compare(FloatParts128 *a, FloatParts128 *b, + float_status *s, bool q); + +#define parts_compare(A, B, S, Q) \ + PARTS_GENERIC_64_128(compare, A)(A, B, S, Q) + /* * Helper functions for softfloat-parts.c.inc, per-size operations. */ @@ -3357,92 +3365,42 @@ MINMAX_2(float128) #undef MINMAX_1 #undef MINMAX_2 =20 -/* Floating point compare */ -static FloatRelation compare_floats(FloatParts64 a, FloatParts64 b, bool i= s_quiet, - float_status *s) +/* + * Floating point compare + */ + +static FloatRelation QEMU_FLATTEN +float16_do_compare(float16 a, float16 b, float_status *s, bool is_quiet) { - if (is_nan(a.cls) || is_nan(b.cls)) { - if (!is_quiet || - a.cls =3D=3D float_class_snan || - b.cls =3D=3D float_class_snan) { - float_raise(float_flag_invalid, s); - } - return float_relation_unordered; - } + FloatParts64 pa, pb; =20 - if (a.cls =3D=3D float_class_zero) { - if (b.cls =3D=3D float_class_zero) { - return float_relation_equal; - } - return b.sign ? float_relation_greater : float_relation_less; - } else if (b.cls =3D=3D float_class_zero) { - return a.sign ? float_relation_less : float_relation_greater; - } - - /* The only really important thing about infinity is its sign. If - * both are infinities the sign marks the smallest of the two. - */ - if (a.cls =3D=3D float_class_inf) { - if ((b.cls =3D=3D float_class_inf) && (a.sign =3D=3D b.sign)) { - return float_relation_equal; - } - return a.sign ? float_relation_less : float_relation_greater; - } else if (b.cls =3D=3D float_class_inf) { - return b.sign ? float_relation_greater : float_relation_less; - } - - if (a.sign !=3D b.sign) { - return a.sign ? float_relation_less : float_relation_greater; - } - - if (a.exp =3D=3D b.exp) { - if (a.frac =3D=3D b.frac) { - return float_relation_equal; - } - if (a.sign) { - return a.frac > b.frac ? - float_relation_less : float_relation_greater; - } else { - return a.frac > b.frac ? - float_relation_greater : float_relation_less; - } - } else { - if (a.sign) { - return a.exp > b.exp ? float_relation_less : float_relation_gr= eater; - } else { - return a.exp > b.exp ? float_relation_greater : float_relation= _less; - } - } + float16_unpack_canonical(&pa, a, s); + float16_unpack_canonical(&pb, b, s); + return parts_compare(&pa, &pb, s, is_quiet); } =20 -#define COMPARE(name, attr, sz) \ -static int attr \ -name(float ## sz a, float ## sz b, bool is_quiet, float_status *s) \ -{ \ - FloatParts64 pa, pb; \ - float ## sz ## _unpack_canonical(&pa, a, s); \ - float ## sz ## _unpack_canonical(&pb, b, s); \ - return compare_floats(pa, pb, is_quiet, s); \ -} - -COMPARE(soft_f16_compare, QEMU_FLATTEN, 16) -COMPARE(soft_f32_compare, QEMU_SOFTFLOAT_ATTR, 32) -COMPARE(soft_f64_compare, QEMU_SOFTFLOAT_ATTR, 64) - -#undef COMPARE - FloatRelation float16_compare(float16 a, float16 b, float_status *s) { - return soft_f16_compare(a, b, false, s); + return float16_do_compare(a, b, s, false); } =20 FloatRelation float16_compare_quiet(float16 a, float16 b, float_status *s) { - return soft_f16_compare(a, b, true, s); + return float16_do_compare(a, b, s, true); +} + +static FloatRelation QEMU_SOFTFLOAT_ATTR +float32_do_compare(float32 a, float32 b, float_status *s, bool is_quiet) +{ + FloatParts64 pa, pb; + + float32_unpack_canonical(&pa, a, s); + float32_unpack_canonical(&pb, b, s); + return parts_compare(&pa, &pb, s, is_quiet); } =20 static FloatRelation QEMU_FLATTEN -f32_compare(float32 xa, float32 xb, bool is_quiet, float_status *s) +float32_hs_compare(float32 xa, float32 xb, float_status *s, bool is_quiet) { union_float32 ua, ub; =20 @@ -3463,25 +3421,36 @@ f32_compare(float32 xa, float32 xb, bool is_quiet, = float_status *s) if (likely(isless(ua.h, ub.h))) { return float_relation_less; } - /* The only condition remaining is unordered. + /* + * The only condition remaining is unordered. * Fall through to set flags. */ soft: - return soft_f32_compare(ua.s, ub.s, is_quiet, s); + return float32_do_compare(ua.s, ub.s, s, is_quiet); } =20 FloatRelation float32_compare(float32 a, float32 b, float_status *s) { - return f32_compare(a, b, false, s); + return float32_hs_compare(a, b, s, false); } =20 FloatRelation float32_compare_quiet(float32 a, float32 b, float_status *s) { - return f32_compare(a, b, true, s); + return float32_hs_compare(a, b, s, true); +} + +static FloatRelation QEMU_SOFTFLOAT_ATTR +float64_do_compare(float64 a, float64 b, float_status *s, bool is_quiet) +{ + FloatParts64 pa, pb; + + float64_unpack_canonical(&pa, a, s); + float64_unpack_canonical(&pb, b, s); + return parts_compare(&pa, &pb, s, is_quiet); } =20 static FloatRelation QEMU_FLATTEN -f64_compare(float64 xa, float64 xb, bool is_quiet, float_status *s) +float64_hs_compare(float64 xa, float64 xb, float_status *s, bool is_quiet) { union_float64 ua, ub; =20 @@ -3502,41 +3471,62 @@ f64_compare(float64 xa, float64 xb, bool is_quiet, = float_status *s) if (likely(isless(ua.h, ub.h))) { return float_relation_less; } - /* The only condition remaining is unordered. + /* + * The only condition remaining is unordered. * Fall through to set flags. */ soft: - return soft_f64_compare(ua.s, ub.s, is_quiet, s); + return float64_do_compare(ua.s, ub.s, s, is_quiet); } =20 FloatRelation float64_compare(float64 a, float64 b, float_status *s) { - return f64_compare(a, b, false, s); + return float64_hs_compare(a, b, s, false); } =20 FloatRelation float64_compare_quiet(float64 a, float64 b, float_status *s) { - return f64_compare(a, b, true, s); + return float64_hs_compare(a, b, s, true); } =20 static FloatRelation QEMU_FLATTEN -soft_bf16_compare(bfloat16 a, bfloat16 b, bool is_quiet, float_status *s) +bfloat16_do_compare(bfloat16 a, bfloat16 b, float_status *s, bool is_quiet) { FloatParts64 pa, pb; =20 bfloat16_unpack_canonical(&pa, a, s); bfloat16_unpack_canonical(&pb, b, s); - return compare_floats(pa, pb, is_quiet, s); + return parts_compare(&pa, &pb, s, is_quiet); } =20 FloatRelation bfloat16_compare(bfloat16 a, bfloat16 b, float_status *s) { - return soft_bf16_compare(a, b, false, s); + return bfloat16_do_compare(a, b, s, false); } =20 FloatRelation bfloat16_compare_quiet(bfloat16 a, bfloat16 b, float_status = *s) { - return soft_bf16_compare(a, b, true, s); + return bfloat16_do_compare(a, b, s, true); +} + +static FloatRelation QEMU_FLATTEN +float128_do_compare(float128 a, float128 b, float_status *s, bool is_quiet) +{ + FloatParts128 pa, pb; + + float128_unpack_canonical(&pa, a, s); + float128_unpack_canonical(&pb, b, s); + return parts_compare(&pa, &pb, s, is_quiet); +} + +FloatRelation float128_compare(float128 a, float128 b, float_status *s) +{ + return float128_do_compare(a, b, s, false); +} + +FloatRelation float128_compare_quiet(float128 a, float128 b, float_status = *s) +{ + return float128_do_compare(a, b, s, true); } =20 /* Multiply A by 2 raised to the power N. */ @@ -6609,52 +6599,6 @@ FloatRelation floatx80_compare_quiet(floatx80 a, flo= atx80 b, return floatx80_compare_internal(a, b, 1, status); } =20 -static inline FloatRelation -float128_compare_internal(float128 a, float128 b, bool is_quiet, - float_status *status) -{ - bool aSign, bSign; - - if (( ( extractFloat128Exp( a ) =3D=3D 0x7fff ) && - ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) ) ) || - ( ( extractFloat128Exp( b ) =3D=3D 0x7fff ) && - ( extractFloat128Frac0( b ) | extractFloat128Frac1( b ) ) )) { - if (!is_quiet || - float128_is_signaling_nan(a, status) || - float128_is_signaling_nan(b, status)) { - float_raise(float_flag_invalid, status); - } - return float_relation_unordered; - } - aSign =3D extractFloat128Sign( a ); - bSign =3D extractFloat128Sign( b ); - if ( aSign !=3D bSign ) { - if ( ( ( ( a.high | b.high )<<1 ) | a.low | b.low ) =3D=3D 0 ) { - /* zero case */ - return float_relation_equal; - } else { - return 1 - (2 * aSign); - } - } else { - if (a.low =3D=3D b.low && a.high =3D=3D b.high) { - return float_relation_equal; - } else { - return 1 - 2 * (aSign ^ ( lt128( a.high, a.low, b.high, b.low = ) )); - } - } -} - -FloatRelation float128_compare(float128 a, float128 b, float_status *statu= s) -{ - return float128_compare_internal(a, b, 0, status); -} - -FloatRelation float128_compare_quiet(float128 a, float128 b, - float_status *status) -{ - return float128_compare_internal(a, b, 1, status); -} - floatx80 floatx80_scalbn(floatx80 a, int n, float_status *status) { bool aSign; diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index b9094768db..3dacb5b4f0 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -1018,3 +1018,60 @@ static FloatPartsN *partsN(minmax)(FloatPartsN *a, F= loatPartsN *b, } return cmp < 0 ? b : a; } + +/* + * Floating point compare + */ +static FloatRelation partsN(compare)(FloatPartsN *a, FloatPartsN *b, + float_status *s, bool is_quiet) +{ + int ab_mask =3D float_cmask(a->cls) | float_cmask(b->cls); + int cmp; + + if (likely(ab_mask =3D=3D float_cmask_normal)) { + if (a->sign !=3D b->sign) { + goto a_sign; + } + if (a->exp !=3D b->exp) { + cmp =3D a->exp < b->exp ? -1 : 1; + } else { + cmp =3D frac_cmp(a, b); + } + if (a->sign) { + cmp =3D -cmp; + } + return cmp; + } + + if (unlikely(ab_mask & float_cmask_anynan)) { + if (!is_quiet || (ab_mask & float_cmask_snan)) { + float_raise(float_flag_invalid, s); + } + return float_relation_unordered; + } + + if (ab_mask & float_cmask_zero) { + if (ab_mask =3D=3D float_cmask_zero) { + return float_relation_equal; + } else if (a->cls =3D=3D float_class_zero) { + goto b_sign; + } else { + goto a_sign; + } + } + + if (ab_mask =3D=3D float_cmask_inf) { + if (a->sign =3D=3D b->sign) { + return float_relation_equal; + } + } else if (b->cls =3D=3D float_class_inf) { + goto b_sign; + } else { + g_assert(a->cls =3D=3D float_class_inf); + } + + a_sign: + return a->sign ? float_relation_less : float_relation_greater; + b_sign: + return b->sign ? float_relation_greater : float_relation_less; +} --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756704; cv=none; d=zohomail.com; s=zohoarc; b=VFMqgcaPnspHw1+Ao0pHHRr6Y5Vm3KzOT3HP5KqMfR4inzjnVbGtlAYu5rJAhQPrVErjEuLKIPEmGQ5kSeW3aq/pt+S10t2zFyvpgFlfxtavUpYIpmTAQXs09ei+8QAtt0wP8ULWWZIIf1AZTrOqB7XQlFFVG7GQnbLjD7vFK/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756704; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WsA5H1SuomDIfHMs/+kNzjnQxEcCGSovs51rLnUzoiU=; b=bYpyXmxO7bDa0XRkYkTvDql9nOwQORPLdwRrb1reIfWjnekV9JWXIjz9POgvohSNwwgmiR6M7jVibSOemvQ5SiNBMAvwBgmm19ojZmZWLajl6rb4LmrKfv7uZ01AiSwoFeqGPhcUizQW9n428gzDFj/qyd9dMZVLvoTvtqlwJ9I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756704572251.0771908280767; Thu, 3 Jun 2021 14:45:04 -0700 (PDT) Received: from localhost ([::1]:32788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lov9D-0004CG-Ie for importer@patchew.org; Thu, 03 Jun 2021 17:45:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5y-0002Ah-99 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:42 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:42771) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5u-00012e-Oh for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:42 -0400 Received: by mail-pl1-x632.google.com with SMTP id v13so3582253ple.9 for ; Thu, 03 Jun 2021 14:41:38 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:37 -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=WsA5H1SuomDIfHMs/+kNzjnQxEcCGSovs51rLnUzoiU=; b=dP7hLQuVnKWMn920KUn1YXKSwBLOwSDF9yjYp9atbS4QrOYTthuPJlpEAh4oqu1w0T +30ja24isQQiEEIAlzixdbtTtkaAhb7ygX8kRP3sL1/KQmn0+l4xA66XQTtUSpMXNOaz sbpmVYxh/sG3euRekcSKfMeyyTkG4DGOR9mJpbobGs20fdUPPyX4XmHO9P9LruSbVyHp pEPEWZnlLRVyiuhJ7bwwI9ZIM0JLwsKs6cDAcTY5HoJleTM3afR4wpgYwofVlA1FdJkN P8lIHFEpGd+KGCVQ34ixxRNQCy+gxBLaW7QuegI4DkoyoDgB9cne1+ByfhIdzqB/o/1J wGQw== 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=WsA5H1SuomDIfHMs/+kNzjnQxEcCGSovs51rLnUzoiU=; b=b+E+4rN5rAEbuBIKnN94h/g9Md9YyctexWntp1AMnclb/KjOebQdPOsD981FAtsP8J FNqAEx9OU0UjnZSjajiOrRAc/n90DGGoIlUf/BsYPDSEtBi1xj6b+8aTeEmGvWW+ahw+ X0MYwvwgSsNFZYVO7x4wtBTRhRJUXnDp0KlZWE3jMcYDjy2iCdann+f2+k2Ds1KX1xg1 zNlyK9fDr2vaz19MT1fiqeJRqGieYo+vXA0eDXTHcd77WIDiqXrY+q39EZqzB6ZzOYEj ueaHf0YF76X9L1H422anBNguLFZovynNyn+8UjISqWu50cNqatOKPF+dgK0RA9s69SQC NIoA== X-Gm-Message-State: AOAM530t3CkqhUJoEb7OtbeYO8bD0WT7CYCjA+ZW8oCKrUezn+KH+ShF XGg69C2RIvQNNG3IMBI0j1eIz84p5nuuuQ== X-Google-Smtp-Source: ABdhPJyFjaTI8J3KGHs66RqnyOERwuG68f+KOQO427FOx0YiFyRYQscTUR8hPxDcH2qlIj+ZbLqzBQ== X-Received: by 2002:a17:902:9f91:b029:107:5976:f9de with SMTP id g17-20020a1709029f91b02901075976f9demr1163505plq.38.1622756497301; Thu, 03 Jun 2021 14:41:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 07/29] softfloat: Move scalbn_decomposed to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:09 -0700 Message-Id: <20210603214131.629841-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Rename to parts$N_scalbn. Reimplement float128_scalbn with FloatParts128. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 103 +++++++++++++------------------------- fpu/softfloat-parts.c.inc | 21 ++++++++ 2 files changed, 55 insertions(+), 69 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6f1bbbe6cf..666b5a25d6 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -890,6 +890,12 @@ static int parts128_compare(FloatParts128 *a, FloatPar= ts128 *b, #define parts_compare(A, B, S, Q) \ PARTS_GENERIC_64_128(compare, A)(A, B, S, Q) =20 +static void parts64_scalbn(FloatParts64 *a, int n, float_status *s); +static void parts128_scalbn(FloatParts128 *a, int n, float_status *s); + +#define parts_scalbn(A, N, S) \ + PARTS_GENERIC_64_128(scalbn, A)(A, N, S) + /* * Helper functions for softfloat-parts.c.inc, per-size operations. */ @@ -3529,58 +3535,53 @@ FloatRelation float128_compare_quiet(float128 a, fl= oat128 b, float_status *s) return float128_do_compare(a, b, s, true); } =20 -/* Multiply A by 2 raised to the power N. */ -static FloatParts64 scalbn_decomposed(FloatParts64 a, int n, float_status = *s) -{ - if (unlikely(is_nan(a.cls))) { - parts_return_nan(&a, s); - } - if (a.cls =3D=3D float_class_normal) { - /* The largest float type (even though not supported by FloatParts= 64) - * is float128, which has a 15 bit exponent. Bounding N to 16 bits - * still allows rounding to infinity, without allowing overflow - * within the int32_t that backs FloatParts64.exp. - */ - n =3D MIN(MAX(n, -0x10000), 0x10000); - a.exp +=3D n; - } - return a; -} +/* + * Scale by 2**N + */ =20 float16 float16_scalbn(float16 a, int n, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; =20 - float16_unpack_canonical(&pa, a, status); - pr =3D scalbn_decomposed(pa, n, status); - return float16_round_pack_canonical(&pr, status); + float16_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return float16_round_pack_canonical(&p, status); } =20 float32 float32_scalbn(float32 a, int n, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; =20 - float32_unpack_canonical(&pa, a, status); - pr =3D scalbn_decomposed(pa, n, status); - return float32_round_pack_canonical(&pr, status); + float32_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return float32_round_pack_canonical(&p, status); } =20 float64 float64_scalbn(float64 a, int n, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; =20 - float64_unpack_canonical(&pa, a, status); - pr =3D scalbn_decomposed(pa, n, status); - return float64_round_pack_canonical(&pr, status); + float64_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return float64_round_pack_canonical(&p, status); } =20 bfloat16 bfloat16_scalbn(bfloat16 a, int n, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; =20 - bfloat16_unpack_canonical(&pa, a, status); - pr =3D scalbn_decomposed(pa, n, status); - return bfloat16_round_pack_canonical(&pr, status); + bfloat16_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return bfloat16_round_pack_canonical(&p, status); +} + +float128 float128_scalbn(float128 a, int n, float_status *status) +{ + FloatParts128 p; + + float128_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return float128_round_pack_canonical(&p, status); } =20 /* @@ -6638,42 +6639,6 @@ floatx80 floatx80_scalbn(floatx80 a, int n, float_st= atus *status) aSign, aExp, aSig, 0, status); } =20 -float128 float128_scalbn(float128 a, int n, float_status *status) -{ - bool aSign; - int32_t aExp; - uint64_t aSig0, aSig1; - - aSig1 =3D extractFloat128Frac1( a ); - aSig0 =3D extractFloat128Frac0( a ); - aExp =3D extractFloat128Exp( a ); - aSign =3D extractFloat128Sign( a ); - if ( aExp =3D=3D 0x7FFF ) { - if ( aSig0 | aSig1 ) { - return propagateFloat128NaN(a, a, status); - } - return a; - } - if (aExp !=3D 0) { - aSig0 |=3D UINT64_C(0x0001000000000000); - } else if (aSig0 =3D=3D 0 && aSig1 =3D=3D 0) { - return a; - } else { - aExp++; - } - - if (n > 0x10000) { - n =3D 0x10000; - } else if (n < -0x10000) { - n =3D -0x10000; - } - - aExp +=3D n - 1; - return normalizeRoundAndPackFloat128( aSign, aExp, aSig0, aSig1 - , status); - -} - static void __attribute__((constructor)) softfloat_init(void) { union_float64 ua, ub, uc, ur; diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 3dacb5b4f0..bf935c4fc2 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -1075,3 +1075,24 @@ static FloatRelation partsN(compare)(FloatPartsN *a,= FloatPartsN *b, b_sign: return b->sign ? float_relation_greater : float_relation_less; } + +/* + * Multiply A by 2 raised to the power N. + */ +static void partsN(scalbn)(FloatPartsN *a, int n, float_status *s) +{ + switch (a->cls) { + case float_class_snan: + case float_class_qnan: + parts_return_nan(a, s); + break; + case float_class_zero: + case float_class_inf: + break; + case float_class_normal: + a->exp +=3D MIN(MAX(n, -0x10000), 0x10000); + break; + default: + g_assert_not_reached(); + } +} --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756673; cv=none; d=zohomail.com; s=zohoarc; b=C8O476YHen5y1hdQiJLvEARXAxr93Zu0znVKW9/wIf/TcGhuWGlCcnyALV1U6gnbb+gZ8FsyMvAjM0+aaQeNTN+fkz27d77mlPIYU5Ju1BTkbSwysicJt/X3Gv2THXciGtM8wdjUMu+Fnuy60U7XMCCZ2W2ceG4u+Fq0wIoeXeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756673; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=daxdDiwfd3WqyKzbUdPQYbEO4yA2SpqfeiJ6sgOBQMg=; b=Z2gcWwcbNZVwcCz6BlPj7bMESpTKVoyrsImUW7nK6OyiAuuORhdug52S14P4BODDGTBrq7ILgtxzotMTSrJM73U5frcqYZN8MdqqpwJ+jHRLd8XdAobk8bXan7w5RGBf3HNHPGgg4VYl9ABXPcS6Yr8INVkh0+DQypqIVMihDH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756673318685.5271698415645; Thu, 3 Jun 2021 14:44:33 -0700 (PDT) Received: from localhost ([::1]:57908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lov8i-00027Z-7T for importer@patchew.org; Thu, 03 Jun 2021 17:44:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5y-0002CJ-QE for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:42 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:46067) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5v-00014G-He for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:42 -0400 Received: by mail-pj1-x1031.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso1272994pjb.4 for ; Thu, 03 Jun 2021 14:41:39 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:37 -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=daxdDiwfd3WqyKzbUdPQYbEO4yA2SpqfeiJ6sgOBQMg=; b=fbNFpLS8iB0+BpgaAa3xSu/YDsI5SqSL1+abePnjyI6JpUXNuThMLdKYlnjK9QJIbE zgKlqW7oO9a8u0BBW0AEBfgMM3izEh95VEqjnGSsB518+MR1ec7BGvqEH1/fuw9NGW9A TzblLTUbgJW2SmGKMdZ0UwAvM6JlaoateR0pxxVJmsP4IpNTC7JejUExz8PPEKwvqpij NmIKPgGbhkfvWDKf3rKttQUlNz+4NyBySavT7Ebuz0POob8czuQrXeWoQe1GAAu294xK o4bQMATZTjRV7F+hdn9mx7u+enLghY2t7JVkJEBnlZmVH2CKcwzGLoC0pBRDegK5hmxF GTnA== 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=daxdDiwfd3WqyKzbUdPQYbEO4yA2SpqfeiJ6sgOBQMg=; b=eiFxP6PNFlxgm/kRRoESSCsj/dt5WBSsWGA0v+LtuECzzTQ+ZVZuM7gT93Ck7m5F6q qo6AtIUtHYfu5pbcGv4Iy8NOfKQhhf7W0/bS9sP74hXX0dP8YxuyA5Y5ZxinOS485ftr 6dKOgcQ+QXs4NkV5xbnHm1GVNpRI4H+k4LOcP+cP4cKsm9HOz2EpJauE21yyCb0fl84F KUO1/lbjrmead1w/nqtrnAw6GrMnib48pr6IK27Yiosi7gZ3LvZwTU69cCv1MDqprxwS VUtrDFnJo0YTZrLFj3P65g+iCjGCZuruaN/iW8Ubdf9esDyY/IDTzUq/D9R4tzg52zdK LSmw== X-Gm-Message-State: AOAM531nO3izDYVQW/RKZR6HA7U0tuE7OwwS/06RS6i1eMymcj6pxhbj /FzCSPl9w42czXYZji9lEvI+GTuCSjLnTA== X-Google-Smtp-Source: ABdhPJzVjeY+A9/7Tfsn2EQ23+lPvkrjz3oG7V8OGneBFdSoABPxJ9lfQYHUYTfHqJ/PYl6FKauYnA== X-Received: by 2002:a17:90a:e98f:: with SMTP id v15mr13320945pjy.235.1622756498028; Thu, 03 Jun 2021 14:41:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 08/29] softfloat: Move sqrt_float to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:10 -0700 Message-Id: <20210603214131.629841-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Rename to parts$N_sqrt. Reimplement float128_sqrt with FloatParts128. Reimplement with the inverse sqrt newton-raphson algorithm from musl. This is significantly faster than even the berkeley sqrt n-r algorithm, because it does not use division instructions, only multiplication. Ordinarily, changing algorithms at the same time as migrating code is a bad idea, but this is the only way I found that didn't break one of the routines at the same time. Tested-by: Alex Benn=C3=A9e Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 207 ++++++++++---------------------------- fpu/softfloat-parts.c.inc | 206 +++++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+), 152 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 666b5a25d6..0f2eed8d29 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -820,6 +820,12 @@ static FloatParts128 *parts128_div(FloatParts128 *a, F= loatParts128 *b, #define parts_div(A, B, S) \ PARTS_GENERIC_64_128(div, A)(A, B, S) =20 +static void parts64_sqrt(FloatParts64 *a, float_status *s, const FloatFmt = *f); +static void parts128_sqrt(FloatParts128 *a, float_status *s, const FloatFm= t *f); + +#define parts_sqrt(A, S, F) \ + PARTS_GENERIC_64_128(sqrt, A)(A, S, F) + static bool parts64_round_to_int_normal(FloatParts64 *a, FloatRoundMode rm, int scale, int frac_size); static bool parts128_round_to_int_normal(FloatParts128 *a, FloatRoundMode = r, @@ -1386,6 +1392,30 @@ static void frac128_widen(FloatParts256 *r, FloatPar= ts128 *a) =20 #define frac_widen(A, B) FRAC_GENERIC_64_128(widen, B)(A, B) =20 +/* + * Reciprocal sqrt table. 1 bit of exponent, 6-bits of mantessa. + * From https://git.musl-libc.org/cgit/musl/tree/src/math/sqrt_data.c + * and thus MIT licenced. + */ +static const uint16_t rsqrt_tab[128] =3D { + 0xb451, 0xb2f0, 0xb196, 0xb044, 0xaef9, 0xadb6, 0xac79, 0xab43, + 0xaa14, 0xa8eb, 0xa7c8, 0xa6aa, 0xa592, 0xa480, 0xa373, 0xa26b, + 0xa168, 0xa06a, 0x9f70, 0x9e7b, 0x9d8a, 0x9c9d, 0x9bb5, 0x9ad1, + 0x99f0, 0x9913, 0x983a, 0x9765, 0x9693, 0x95c4, 0x94f8, 0x9430, + 0x936b, 0x92a9, 0x91ea, 0x912e, 0x9075, 0x8fbe, 0x8f0a, 0x8e59, + 0x8daa, 0x8cfe, 0x8c54, 0x8bac, 0x8b07, 0x8a64, 0x89c4, 0x8925, + 0x8889, 0x87ee, 0x8756, 0x86c0, 0x862b, 0x8599, 0x8508, 0x8479, + 0x83ec, 0x8361, 0x82d8, 0x8250, 0x81c9, 0x8145, 0x80c2, 0x8040, + 0xff02, 0xfd0e, 0xfb25, 0xf947, 0xf773, 0xf5aa, 0xf3ea, 0xf234, + 0xf087, 0xeee3, 0xed47, 0xebb3, 0xea27, 0xe8a3, 0xe727, 0xe5b2, + 0xe443, 0xe2dc, 0xe17a, 0xe020, 0xdecb, 0xdd7d, 0xdc34, 0xdaf1, + 0xd9b3, 0xd87b, 0xd748, 0xd61a, 0xd4f1, 0xd3cd, 0xd2ad, 0xd192, + 0xd07b, 0xcf69, 0xce5b, 0xcd51, 0xcc4a, 0xcb48, 0xca4a, 0xc94f, + 0xc858, 0xc764, 0xc674, 0xc587, 0xc49d, 0xc3b7, 0xc2d4, 0xc1f4, + 0xc116, 0xc03c, 0xbf65, 0xbe90, 0xbdbe, 0xbcef, 0xbc23, 0xbb59, + 0xba91, 0xb9cc, 0xb90a, 0xb84a, 0xb78c, 0xb6d0, 0xb617, 0xb560, +}; + #define partsN(NAME) glue(glue(glue(parts,N),_),NAME) #define FloatPartsN glue(FloatParts,N) #define FloatPartsW glue(FloatParts,W) @@ -3586,103 +3616,35 @@ float128 float128_scalbn(float128 a, int n, float_= status *status) =20 /* * Square Root - * - * The old softfloat code did an approximation step before zeroing in - * on the final result. However for simpleness we just compute the - * square root by iterating down from the implicit bit to enough extra - * bits to ensure we get a correctly rounded result. - * - * This does mean however the calculation is slower than before, - * especially for 64 bit floats. */ =20 -static FloatParts64 sqrt_float(FloatParts64 a, float_status *s, const Floa= tFmt *p) -{ - uint64_t a_frac, r_frac, s_frac; - int bit, last_bit; - - if (is_nan(a.cls)) { - parts_return_nan(&a, s); - return a; - } - if (a.cls =3D=3D float_class_zero) { - return a; /* sqrt(+-0) =3D +-0 */ - } - if (a.sign) { - float_raise(float_flag_invalid, s); - parts_default_nan(&a, s); - return a; - } - if (a.cls =3D=3D float_class_inf) { - return a; /* sqrt(+inf) =3D +inf */ - } - - assert(a.cls =3D=3D float_class_normal); - - /* We need two overflow bits at the top. Adding room for that is a - * right shift. If the exponent is odd, we can discard the low bit - * by multiplying the fraction by 2; that's a left shift. Combine - * those and we shift right by 1 if the exponent is odd, otherwise 2. - */ - a_frac =3D a.frac >> (2 - (a.exp & 1)); - a.exp >>=3D 1; - - /* Bit-by-bit computation of sqrt. */ - r_frac =3D 0; - s_frac =3D 0; - - /* Iterate from implicit bit down to the 3 extra bits to compute a - * properly rounded result. Remember we've inserted two more bits - * at the top, so these positions are two less. - */ - bit =3D DECOMPOSED_BINARY_POINT - 2; - last_bit =3D MAX(p->frac_shift - 4, 0); - do { - uint64_t q =3D 1ULL << bit; - uint64_t t_frac =3D s_frac + q; - if (t_frac <=3D a_frac) { - s_frac =3D t_frac + q; - a_frac -=3D t_frac; - r_frac +=3D q; - } - a_frac <<=3D 1; - } while (--bit >=3D last_bit); - - /* Undo the right shift done above. If there is any remaining - * fraction, the result is inexact. Set the sticky bit. - */ - a.frac =3D (r_frac << 2) + (a_frac !=3D 0); - - return a; -} - float16 QEMU_FLATTEN float16_sqrt(float16 a, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; =20 - float16_unpack_canonical(&pa, a, status); - pr =3D sqrt_float(pa, status, &float16_params); - return float16_round_pack_canonical(&pr, status); + float16_unpack_canonical(&p, a, status); + parts_sqrt(&p, status, &float16_params); + return float16_round_pack_canonical(&p, status); } =20 static float32 QEMU_SOFTFLOAT_ATTR soft_f32_sqrt(float32 a, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; =20 - float32_unpack_canonical(&pa, a, status); - pr =3D sqrt_float(pa, status, &float32_params); - return float32_round_pack_canonical(&pr, status); + float32_unpack_canonical(&p, a, status); + parts_sqrt(&p, status, &float32_params); + return float32_round_pack_canonical(&p, status); } =20 static float64 QEMU_SOFTFLOAT_ATTR soft_f64_sqrt(float64 a, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; =20 - float64_unpack_canonical(&pa, a, status); - pr =3D sqrt_float(pa, status, &float64_params); - return float64_round_pack_canonical(&pr, status); + float64_unpack_canonical(&p, a, status); + parts_sqrt(&p, status, &float64_params); + return float64_round_pack_canonical(&p, status); } =20 float32 QEMU_FLATTEN float32_sqrt(float32 xa, float_status *s) @@ -3741,11 +3703,20 @@ float64 QEMU_FLATTEN float64_sqrt(float64 xa, float= _status *s) =20 bfloat16 QEMU_FLATTEN bfloat16_sqrt(bfloat16 a, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; =20 - bfloat16_unpack_canonical(&pa, a, status); - pr =3D sqrt_float(pa, status, &bfloat16_params); - return bfloat16_round_pack_canonical(&pr, status); + bfloat16_unpack_canonical(&p, a, status); + parts_sqrt(&p, status, &bfloat16_params); + return bfloat16_round_pack_canonical(&p, status); +} + +float128 QEMU_FLATTEN float128_sqrt(float128 a, float_status *status) +{ + FloatParts128 p; + + float128_unpack_canonical(&p, a, status); + parts_sqrt(&p, status, &float128_params); + return float128_round_pack_canonical(&p, status); } =20 /*------------------------------------------------------------------------= ---- @@ -6473,74 +6444,6 @@ float128 float128_rem(float128 a, float128 b, float_= status *status) status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the square root of the quadruple-precision floating-point value = `a'. -| The operation is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float128 float128_sqrt(float128 a, float_status *status) -{ - bool aSign; - int32_t aExp, zExp; - uint64_t aSig0, aSig1, zSig0, zSig1, zSig2, doubleZSig0; - uint64_t rem0, rem1, rem2, rem3, term0, term1, term2, term3; - - aSig1 =3D extractFloat128Frac1( a ); - aSig0 =3D extractFloat128Frac0( a ); - aExp =3D extractFloat128Exp( a ); - aSign =3D extractFloat128Sign( a ); - if ( aExp =3D=3D 0x7FFF ) { - if (aSig0 | aSig1) { - return propagateFloat128NaN(a, a, status); - } - if ( ! aSign ) return a; - goto invalid; - } - if ( aSign ) { - if ( ( aExp | aSig0 | aSig1 ) =3D=3D 0 ) return a; - invalid: - float_raise(float_flag_invalid, status); - return float128_default_nan(status); - } - if ( aExp =3D=3D 0 ) { - if ( ( aSig0 | aSig1 ) =3D=3D 0 ) return packFloat128( 0, 0, 0, 0 = ); - normalizeFloat128Subnormal( aSig0, aSig1, &aExp, &aSig0, &aSig1 ); - } - zExp =3D ( ( aExp - 0x3FFF )>>1 ) + 0x3FFE; - aSig0 |=3D UINT64_C(0x0001000000000000); - zSig0 =3D estimateSqrt32( aExp, aSig0>>17 ); - shortShift128Left( aSig0, aSig1, 13 - ( aExp & 1 ), &aSig0, &aSig1 ); - zSig0 =3D estimateDiv128To64( aSig0, aSig1, zSig0<<32 ) + ( zSig0<<30 = ); - doubleZSig0 =3D zSig0<<1; - mul64To128( zSig0, zSig0, &term0, &term1 ); - sub128( aSig0, aSig1, term0, term1, &rem0, &rem1 ); - while ( (int64_t) rem0 < 0 ) { - --zSig0; - doubleZSig0 -=3D 2; - add128( rem0, rem1, zSig0>>63, doubleZSig0 | 1, &rem0, &rem1 ); - } - zSig1 =3D estimateDiv128To64( rem1, 0, doubleZSig0 ); - if ( ( zSig1 & 0x1FFF ) <=3D 5 ) { - if ( zSig1 =3D=3D 0 ) zSig1 =3D 1; - mul64To128( doubleZSig0, zSig1, &term1, &term2 ); - sub128( rem1, 0, term1, term2, &rem1, &rem2 ); - mul64To128( zSig1, zSig1, &term2, &term3 ); - sub192( rem1, rem2, 0, 0, term2, term3, &rem1, &rem2, &rem3 ); - while ( (int64_t) rem1 < 0 ) { - --zSig1; - shortShift128Left( 0, zSig1, 1, &term2, &term3 ); - term3 |=3D 1; - term2 |=3D doubleZSig0; - add192( rem1, rem2, rem3, 0, term2, term3, &rem1, &rem2, &rem3= ); - } - zSig1 |=3D ( ( rem1 | rem2 | rem3 ) !=3D 0 ); - } - shift128ExtraRightJamming( zSig0, zSig1, 0, 14, &zSig0, &zSig1, &zSig2= ); - return roundAndPackFloat128(0, zExp, zSig0, zSig1, zSig2, status); - -} - static inline FloatRelation floatx80_compare_internal(floatx80 a, floatx80 b, bool is_quiet, float_status *status) diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index bf935c4fc2..d69f357352 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -597,6 +597,212 @@ static FloatPartsN *partsN(div)(FloatPartsN *a, Float= PartsN *b, return a; } =20 +/* + * Square Root + * + * The base algorithm is lifted from + * https://git.musl-libc.org/cgit/musl/tree/src/math/sqrtf.c + * https://git.musl-libc.org/cgit/musl/tree/src/math/sqrt.c + * https://git.musl-libc.org/cgit/musl/tree/src/math/sqrtl.c + * and is thus MIT licenced. + */ +static void partsN(sqrt)(FloatPartsN *a, float_status *status, + const FloatFmt *fmt) +{ + const uint32_t three32 =3D 3u << 30; + const uint64_t three64 =3D 3ull << 62; + uint32_t d32, m32, r32, s32, u32; /* 32-bit computation */ + uint64_t d64, m64, r64, s64, u64; /* 64-bit computation */ + uint64_t dh, dl, rh, rl, sh, sl, uh, ul; /* 128-bit computation */ + uint64_t d0h, d0l, d1h, d1l, d2h, d2l; + uint64_t discard; + bool exp_odd; + size_t index; + + if (unlikely(a->cls !=3D float_class_normal)) { + switch (a->cls) { + case float_class_snan: + case float_class_qnan: + parts_return_nan(a, status); + return; + case float_class_zero: + return; + case float_class_inf: + if (unlikely(a->sign)) { + goto d_nan; + } + return; + default: + g_assert_not_reached(); + } + } + + if (unlikely(a->sign)) { + goto d_nan; + } + + /* + * Argument reduction. + * x =3D 4^e frac; with integer e, and frac in [1, 4) + * m =3D frac fixed point at bit 62, since we're in base 4. + * If base-2 exponent is odd, exchange that for multiply by 2, + * which results in no shift. + */ + exp_odd =3D a->exp & 1; + index =3D extract64(a->frac_hi, 57, 6) | (!exp_odd << 6); + if (!exp_odd) { + frac_shr(a, 1); + } + + /* + * Approximate r ~=3D 1/sqrt(m) and s ~=3D sqrt(m) when m in [1, 4). + * + * Initial estimate: + * 7-bit lookup table (1-bit exponent and 6-bit significand). + * + * The relative error (e =3D r0*sqrt(m)-1) of a linear estimate + * (r0 =3D a*m + b) is |e| < 0.085955 ~ 0x1.6p-4 at best; + * a table lookup is faster and needs one less iteration. + * The 7-bit table gives |e| < 0x1.fdp-9. + * + * A Newton-Raphson iteration for r is + * s =3D m*r + * d =3D s*r + * u =3D 3 - d + * r =3D r*u/2 + * + * Fixed point representations: + * m, s, d, u, three are all 2.30; r is 0.32 + */ + m64 =3D a->frac_hi; + m32 =3D m64 >> 32; + + r32 =3D rsqrt_tab[index] << 16; + /* |r*sqrt(m) - 1| < 0x1.FDp-9 */ + + s32 =3D ((uint64_t)m32 * r32) >> 32; + d32 =3D ((uint64_t)s32 * r32) >> 32; + u32 =3D three32 - d32; + + if (N =3D=3D 64) { + /* float64 or smaller */ + + r32 =3D ((uint64_t)r32 * u32) >> 31; + /* |r*sqrt(m) - 1| < 0x1.7Bp-16 */ + + s32 =3D ((uint64_t)m32 * r32) >> 32; + d32 =3D ((uint64_t)s32 * r32) >> 32; + u32 =3D three32 - d32; + + if (fmt->frac_size <=3D 23) { + /* float32 or smaller */ + + s32 =3D ((uint64_t)s32 * u32) >> 32; /* 3.29 */ + s32 =3D (s32 - 1) >> 6; /* 9.23 */ + /* s < sqrt(m) < s + 0x1.08p-23 */ + + /* compute nearest rounded result to 2.23 bits */ + uint32_t d0 =3D (m32 << 16) - s32 * s32; + uint32_t d1 =3D s32 - d0; + uint32_t d2 =3D d1 + s32 + 1; + s32 +=3D d1 >> 31; + a->frac_hi =3D (uint64_t)s32 << (64 - 25); + + /* increment or decrement for inexact */ + if (d2 !=3D 0) { + a->frac_hi +=3D ((int32_t)(d1 ^ d2) < 0 ? -1 : 1); + } + goto done; + } + + /* float64 */ + + r64 =3D (uint64_t)r32 * u32 * 2; + /* |r*sqrt(m) - 1| < 0x1.37-p29; convert to 64-bit arithmetic */ + mul64To128(m64, r64, &s64, &discard); + mul64To128(s64, r64, &d64, &discard); + u64 =3D three64 - d64; + + mul64To128(s64, u64, &s64, &discard); /* 3.61 */ + s64 =3D (s64 - 2) >> 9; /* 12.52 */ + + /* Compute nearest rounded result */ + uint64_t d0 =3D (m64 << 42) - s64 * s64; + uint64_t d1 =3D s64 - d0; + uint64_t d2 =3D d1 + s64 + 1; + s64 +=3D d1 >> 63; + a->frac_hi =3D s64 << (64 - 54); + + /* increment or decrement for inexact */ + if (d2 !=3D 0) { + a->frac_hi +=3D ((int64_t)(d1 ^ d2) < 0 ? -1 : 1); + } + goto done; + } + + r64 =3D (uint64_t)r32 * u32 * 2; + /* |r*sqrt(m) - 1| < 0x1.7Bp-16; convert to 64-bit arithmetic */ + + mul64To128(m64, r64, &s64, &discard); + mul64To128(s64, r64, &d64, &discard); + u64 =3D three64 - d64; + mul64To128(u64, r64, &r64, &discard); + r64 <<=3D 1; + /* |r*sqrt(m) - 1| < 0x1.a5p-31 */ + + mul64To128(m64, r64, &s64, &discard); + mul64To128(s64, r64, &d64, &discard); + u64 =3D three64 - d64; + mul64To128(u64, r64, &rh, &rl); + add128(rh, rl, rh, rl, &rh, &rl); + /* |r*sqrt(m) - 1| < 0x1.c001p-59; change to 128-bit arithmetic */ + + mul128To256(a->frac_hi, a->frac_lo, rh, rl, &sh, &sl, &discard, &disca= rd); + mul128To256(sh, sl, rh, rl, &dh, &dl, &discard, &discard); + sub128(three64, 0, dh, dl, &uh, &ul); + mul128To256(uh, ul, sh, sl, &sh, &sl, &discard, &discard); /* 3.125 */ + /* -0x1p-116 < s - sqrt(m) < 0x3.8001p-125 */ + + sub128(sh, sl, 0, 4, &sh, &sl); + shift128Right(sh, sl, 13, &sh, &sl); /* 16.112 */ + /* s < sqrt(m) < s + 1ulp */ + + /* Compute nearest rounded result */ + mul64To128(sl, sl, &d0h, &d0l); + d0h +=3D 2 * sh * sl; + sub128(a->frac_lo << 34, 0, d0h, d0l, &d0h, &d0l); + sub128(sh, sl, d0h, d0l, &d1h, &d1l); + add128(sh, sl, 0, 1, &d2h, &d2l); + add128(d2h, d2l, d1h, d1l, &d2h, &d2l); + add128(sh, sl, 0, d1h >> 63, &sh, &sl); + shift128Left(sh, sl, 128 - 114, &sh, &sl); + + /* increment or decrement for inexact */ + if (d2h | d2l) { + if ((int64_t)(d1h ^ d2h) < 0) { + sub128(sh, sl, 0, 1, &sh, &sl); + } else { + add128(sh, sl, 0, 1, &sh, &sl); + } + } + a->frac_lo =3D sl; + a->frac_hi =3D sh; + + done: + /* Convert back from base 4 to base 2. */ + a->exp >>=3D 1; + if (!(a->frac_hi & DECOMPOSED_IMPLICIT_BIT)) { + frac_add(a, a, a); + } else { + a->exp +=3D 1; + } + return; + + d_nan: + float_raise(float_flag_invalid, status); + parts_default_nan(a, status); +} + /* * Rounds the floating-point value `a' to an integer, and returns the * result as a floating-point value. The operation is performed --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756619; cv=none; d=zohomail.com; s=zohoarc; b=SNF8rBjSf5gPmu2MEbNARu+7vCO6mFu96Ir7SnmNR8xbsWHOCbBDXQbUsG/QNHq5cwBJfvfh9nKb0CXHs1ceMGlzIYsTMKuudtkpwOpMhebVNKujAvrL3qL4N3EOvFU19W/yf9IcfPpQK1vjpUWe0jzlzM6FwygDcMmamvNc6g8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756619; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=X7rkp8u5Uk7lnJ0IeUz2DjyUeUy9fzT1UPPQAOiqDA8=; b=Zyyzk2EHofXkkSKxexvyllcnN3lgf6hpgrPCIQPXYyfn/0+MTRcfWC6qCAPJBS9R66fuMUEiEL9RLa4o+hkhBkwTecsZLAYLmzdSOlXcb8KBUCpZwNNantbiwl/SsCBFpHCmJ+4jXDlgnOSnQFcVxVD/1SXf/DAcNTKrDXMzGVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756619037104.991490674396; Thu, 3 Jun 2021 14:43:39 -0700 (PDT) Received: from localhost ([::1]:52546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lov7p-0006zi-Rc for importer@patchew.org; Thu, 03 Jun 2021 17:43:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5x-00029k-V6 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:41 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:44772) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5w-00014W-2i for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:41 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 29so6148241pgu.11 for ; Thu, 03 Jun 2021 14:41:39 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:38 -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=X7rkp8u5Uk7lnJ0IeUz2DjyUeUy9fzT1UPPQAOiqDA8=; b=UZv6SVXsy9sTyZRnlyZjyODYqzlOChVUaAogKSHtq6KQ0lAzkVVd3C+r2erz2ec8Ik S0C5z46iK+RANLWOMKxWcMCtk0OIWX5kWoFEGaGQ7iw92g5+UtWpB6sxtgcD2N2vj/Po LHSRt+3ztwTpa+9SfpFmTQyBXeYHse/vVZ4dCXTOHEizPoMON6puNQ7q4qsgUcWz+NTp +Bk+Uht6TFy2MrLVvAwpMlu3HG0wQ2ZTuThdpspg47ioL2IqpRowoUUrxmUtxAAOfMDJ T8KP3p/97EpcFdwCQbNdDCPFZp3HcmawyCePAxAkzGV0nNnhNTHPRCyFLY1V9l8X+aet vNwQ== 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=X7rkp8u5Uk7lnJ0IeUz2DjyUeUy9fzT1UPPQAOiqDA8=; b=lzX1QHZ0V9L9+zeXuPTG4YeGRPQ1RMtiazKcMFxW0ipkTO56QkV5M6SBQ9fGmlmcSk G0P8O/25DBFRmOHUWQ7Uh1kvYhgvrqjVY1I41W22Z/DiuODeJUxNuf+zBgxE5LpaOhGm ybC+EorOCIC/mafYzWWxZCDkYrgqI8rLL2SIqPCh/jED5PpeX0gnEt1Yni742JKapJ98 LjehA9DOhO6pzEQ25mSseqU/B/q9RIuaHA6FUP9loQuny/RVCOcyIQbFYYsjUSXDDYwe i4gqytKMh9N/9rR/O2qhyZfooPJabzK5qgNw1C32yGvtmp8pyRz82CwY+LBjse62vZGm Jy4w== X-Gm-Message-State: AOAM531/5MQ8AHwrzEGh0kLvsUVM5gUkQbYJiUPWKzJeAurBh7Gg8PjU nGyjZdzSx2g646NYYRGsfl1+UrQLEDMfFw== X-Google-Smtp-Source: ABdhPJzVs+0BTaSNmGciC76faUZDoSFNjGkeMt1cRj0V7DTP72193DY8lzIt8zVujB9or9eQpV767Q== X-Received: by 2002:a63:fa51:: with SMTP id g17mr1503659pgk.340.1622756498802; Thu, 03 Jun 2021 14:41:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 09/29] softfloat: Split out parts_uncanon_normal Date: Thu, 3 Jun 2021 14:41:11 -0700 Message-Id: <20210603214131.629841-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) We will need to treat the non-normal cases of floatx80 specially, so split out the normal case that we can reuse. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 8 ++++++ fpu/softfloat-parts.c.inc | 59 +++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 0f2eed8d29..ea7ee13201 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -764,6 +764,14 @@ static void parts128_canonicalize(FloatParts128 *p, fl= oat_status *status, #define parts_canonicalize(A, S, F) \ PARTS_GENERIC_64_128(canonicalize, A)(A, S, F) =20 +static void parts64_uncanon_normal(FloatParts64 *p, float_status *status, + const FloatFmt *fmt); +static void parts128_uncanon_normal(FloatParts128 *p, float_status *status, + const FloatFmt *fmt); + +#define parts_uncanon_normal(A, S, F) \ + PARTS_GENERIC_64_128(uncanon_normal, A)(A, S, F) + static void parts64_uncanon(FloatParts64 *p, float_status *status, const FloatFmt *fmt); static void parts128_uncanon(FloatParts128 *p, float_status *status, diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index d69f357352..e05909db8c 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -140,8 +140,8 @@ static void partsN(canonicalize)(FloatPartsN *p, float_= status *status, * fraction; these bits will be removed. The exponent will be biased * by EXP_BIAS and must be bounded by [EXP_MAX-1, 0]. */ -static void partsN(uncanon)(FloatPartsN *p, float_status *s, - const FloatFmt *fmt) +static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, + const FloatFmt *fmt) { const int exp_max =3D fmt->exp_max; const int frac_shift =3D fmt->frac_shift; @@ -150,33 +150,9 @@ static void partsN(uncanon)(FloatPartsN *p, float_stat= us *s, const uint64_t round_mask =3D fmt->round_mask; const uint64_t roundeven_mask =3D fmt->roundeven_mask; uint64_t inc; - bool overflow_norm; + bool overflow_norm =3D false; int exp, flags =3D 0; =20 - if (unlikely(p->cls !=3D float_class_normal)) { - switch (p->cls) { - case float_class_zero: - p->exp =3D 0; - frac_clear(p); - return; - case float_class_inf: - g_assert(!fmt->arm_althp); - p->exp =3D fmt->exp_max; - frac_clear(p); - return; - case float_class_qnan: - case float_class_snan: - g_assert(!fmt->arm_althp); - p->exp =3D fmt->exp_max; - frac_shr(p, fmt->frac_shift); - return; - default: - break; - } - g_assert_not_reached(); - } - - overflow_norm =3D false; switch (s->float_rounding_mode) { case float_round_nearest_even: inc =3D ((p->frac_lo & roundeven_mask) !=3D frac_lsbm1 ? frac_lsbm= 1 : 0); @@ -284,6 +260,35 @@ static void partsN(uncanon)(FloatPartsN *p, float_stat= us *s, float_raise(flags, s); } =20 +static void partsN(uncanon)(FloatPartsN *p, float_status *s, + const FloatFmt *fmt) +{ + if (likely(p->cls =3D=3D float_class_normal)) { + parts_uncanon_normal(p, s, fmt); + } else { + switch (p->cls) { + case float_class_zero: + p->exp =3D 0; + frac_clear(p); + return; + case float_class_inf: + g_assert(!fmt->arm_althp); + p->exp =3D fmt->exp_max; + frac_clear(p); + return; + case float_class_qnan: + case float_class_snan: + g_assert(!fmt->arm_althp); + p->exp =3D fmt->exp_max; + frac_shr(p, fmt->frac_shift); + return; + default: + break; + } + g_assert_not_reached(); + } +} + /* * Returns the result of adding or subtracting the values of the * floating-point values `a' and `b'. The operation is performed --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756816; cv=none; d=zohomail.com; s=zohoarc; b=QW9sChwBsAlKt/5eCfoU1TKBsk3qPXnavTOXC2V3D1JcLaqQPG5gxj2XIKTp0oLAzCmLnbUMEcL4wUR656iCIW3epLo+5isn3rkSDxHvcStZCfG1TRd3sAnZJK6xREiCvJDqkNR/f1MtiLaloMzDsMX2l8qyvqKP3R8zYF/NDaY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756816; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ppZ1jH79N3swPQMu5gvh4yX8BmZmZOhaiSlhleLfgRI=; b=cfEbY9I3sKJcOMn1u+1EQKEAKZXL359N7rBBTmdFmjoncTeEJ94gzzpRg0q2SgopaFbWAl3Odk4upc8Wjq7Skupu63rzi/Ua2RikWuHD0hUbAvoQzCiWbTYjmjqLnddRGi2DNsu2U8nYixsUty8cUslEu304aHQdrZmrFipQ+90= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756816096515.9078744050621; Thu, 3 Jun 2021 14:46:56 -0700 (PDT) Received: from localhost ([::1]:38300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovB1-0007wi-1S for importer@patchew.org; Thu, 03 Jun 2021 17:46:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5z-0002Ex-Gq for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:43 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:44020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5w-00014r-Km for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:43 -0400 Received: by mail-pl1-x630.google.com with SMTP id v12so3580090plo.10 for ; Thu, 03 Jun 2021 14:41:40 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:39 -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=ppZ1jH79N3swPQMu5gvh4yX8BmZmZOhaiSlhleLfgRI=; b=WhqXS0Sn8Talgk2LHvsCcZ0eoJvIQSuH9KMIaqVPwzFt/CXUvmIBjNySjuzYC6Bogq mzuoosyX6GhaZa/e45hUP6GhjRRLYjmcE8kbu2kAtCeXxGasnunE/TZ8Gp6Nt5+x4nC6 /l3hecSz/CUQD8uMg+fkWJLW4xmSS8zd+MsMHlwoirJrpwMv0aslwqRChbgxPYznGaB1 8ZamjSTbe9x70w7cfCFtd4Pcu/DQDxbAiSEHLj1CS+9IVEsZLsRVL+Vy6CzdSomTAanR kQ6c40+jpsSRNhk9nqy4vbKOEqCZNqvNMe5n3pGq9t6fw7zocJ04O/1Uhmfn5Zq3Q7U7 d+bw== 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=ppZ1jH79N3swPQMu5gvh4yX8BmZmZOhaiSlhleLfgRI=; b=nizagitmPVRCXExu8KaGeqKtRZ8/9n0dG3GEaEZYWBNlKOSP2atWM8SONpzxr2lCM0 YuSEszSgsDJGw/ZnVKNI7iOSBc2EGeIPjV8Rf2YZSD54/wAz8Ahk+Cv89TzcbYjLWMnm H1SnBRGpKyuK9CHhbgO5BhzfYoMxIuoJtzR7K10GUAqzEtvk9PRr835kcAXJ/vwvzCD/ NxznkEBzxX8TvkxAJEjh2i6cIzaa4Bjz6q4xN8EReBiO1B7dEv8kFGCTlT7oVvVpX39+ Fot+OPdM6k9Npadlon8hKgDZHp5zPSJZtnbSwahw2+jzv5wkZBcz2y4yAsfekFG89b5L yl/w== X-Gm-Message-State: AOAM530cBmigjxrTy0eoPpST40iLSmmrzlioUJU+C2PBnQUOWXLniEzB +K8JB6V9BRGCDT5tGH3g1cakRWgvshyj2g== X-Google-Smtp-Source: ABdhPJwZa2oGLsIt0HYbKZNlbRPP5hcGj6plA0nu/zQhmMOoTPMHJZe1YVMtDjCAV1h2TPFWUSmKfg== X-Received: by 2002:a17:902:cec3:b029:10d:22fa:183c with SMTP id d3-20020a170902cec3b029010d22fa183cmr1189303plg.53.1622756499291; Thu, 03 Jun 2021 14:41:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 10/29] softfloat: Reduce FloatFmt Date: Thu, 3 Jun 2021 14:41:12 -0700 Message-Id: <20210603214131.629841-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Remove frac_lsb, frac_lsbm1, roundeven_mask. Compute these from round_mask in parts$N_uncanon_normal. With floatx80, round_mask will not be tied to frac_shift. Everything else is easily computable. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 29 ++++++++++++----------------- fpu/softfloat-parts.c.inc | 6 +++--- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ea7ee13201..741480c568 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -563,9 +563,7 @@ typedef struct { * frac_size: the size of the fraction field * frac_shift: shift to normalise the fraction with DECOMPOSED_BINARY_PO= INT * The following are computed based the size of fraction - * frac_lsb: least significant bit of fraction - * frac_lsbm1: the bit below the least significant bit (for rounding) - * round_mask/roundeven_mask: masks used for rounding + * round_mask: bits below lsb which must be rounded * The following optional modifiers are available: * arm_althp: handle ARM Alternative Half Precision */ @@ -575,24 +573,21 @@ typedef struct { int exp_max; int frac_size; int frac_shift; - uint64_t frac_lsb; - uint64_t frac_lsbm1; - uint64_t round_mask; - uint64_t roundeven_mask; bool arm_althp; + uint64_t round_mask; } FloatFmt; =20 /* Expand fields based on the size of exponent and fraction */ -#define FLOAT_PARAMS(E, F) \ - .exp_size =3D E, \ - .exp_bias =3D ((1 << E) - 1) >> 1, \ - .exp_max =3D (1 << E) - 1, \ - .frac_size =3D F, \ - .frac_shift =3D (-F - 1) & 63, \ - .frac_lsb =3D 1ull << ((-F - 1) & 63), \ - .frac_lsbm1 =3D 1ull << ((-F - 2) & 63), \ - .round_mask =3D (1ull << ((-F - 1) & 63)) - 1, \ - .roundeven_mask =3D (2ull << ((-F - 1) & 63)) - 1 +#define FLOAT_PARAMS_(E, F) \ + .exp_size =3D E, \ + .exp_bias =3D ((1 << E) - 1) >> 1, \ + .exp_max =3D (1 << E) - 1, \ + .frac_size =3D F + +#define FLOAT_PARAMS(E, F) \ + FLOAT_PARAMS_(E, F), \ + .frac_shift =3D (-F - 1) & 63, \ + .round_mask =3D (1ull << ((-F - 1) & 63)) - 1 =20 static const FloatFmt float16_params =3D { FLOAT_PARAMS(5, 10) diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index e05909db8c..a026581c33 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -145,10 +145,10 @@ static void partsN(uncanon_normal)(FloatPartsN *p, fl= oat_status *s, { const int exp_max =3D fmt->exp_max; const int frac_shift =3D fmt->frac_shift; - const uint64_t frac_lsb =3D fmt->frac_lsb; - const uint64_t frac_lsbm1 =3D fmt->frac_lsbm1; const uint64_t round_mask =3D fmt->round_mask; - const uint64_t roundeven_mask =3D fmt->roundeven_mask; + const uint64_t frac_lsb =3D round_mask + 1; + const uint64_t frac_lsbm1 =3D round_mask ^ (round_mask >> 1); + const uint64_t roundeven_mask =3D round_mask | frac_lsb; uint64_t inc; bool overflow_norm =3D false; int exp, flags =3D 0; --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757053; cv=none; d=zohomail.com; s=zohoarc; b=ibJNrlByq9kdeMbuCco+V7yx9xXDN+3PfD+VDp1d1tYybFvOlVMlMf/JO2NXLucp9HW4NWYtyw1bo2/l/Sp3UTn9AIcMi1YW8s8BbubcZ0rIlrAZ7ZNVqOsT0GFo2vK9E2hSG9j1ps6iYR7/qaHMb7nDUmJ4bLPrl+Ac9RvXVps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757053; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N/g7nU1jXwHYS7i47w36mxpzZE/kQjQsIkKUyVBW8ZU=; b=W455KiGLLK1rxXKefy82Pkx3aySd7729BQamKegP1cTWY6FxIHa+Rekk9GuCJCt6AupAaMh2XtPnuQ+z7vW91XkEBUVzXSflQKHYT1w3QaP7XvFxeD9ZVoRvJcQfYW+RY1Q/sgdMjO3cKHhJMK2djgXZ703BMx/SpqFyHDQZbwo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757053114369.6435640597565; Thu, 3 Jun 2021 14:50:53 -0700 (PDT) Received: from localhost ([::1]:55616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovEp-0002ck-SB for importer@patchew.org; Thu, 03 Jun 2021 17:50:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov62-0002NA-JS for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:47 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:50904) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5x-00015I-JF for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:46 -0400 Received: by mail-pj1-x102e.google.com with SMTP id i22so4471032pju.0 for ; Thu, 03 Jun 2021 14:41:41 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:39 -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=N/g7nU1jXwHYS7i47w36mxpzZE/kQjQsIkKUyVBW8ZU=; b=azS349mxBIsPXBB+njOgoREebbu5/nizgvZYSoxLjt9nQ8ClunTWdLYnvAJ23ylFlL CUO5Xr8aYmWuN1A+RgvDZWotGk9JIZR3mTK6DkR7bB8L/b3E+nKQhwTddzg1xN74Am/O JWUNk9EC48ecE1ZEjC+sbE4UYjR5NwD75ELBdNRR6H0I7ZTREPZz4JriR4VYi9D9z95w vM6zmhAFnDwwvl3gil9WENOUPCshEevR9vj8SnWvEkXVQwMqPPCw0Olg3s/HsBgrpPYm qdNvnfvNJiXyXKnjoGF2TG6c6AUHrCblKjGsezHZelDDWCSTgSD6sRYY+Lgz6FxfNxGT ceQA== 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=N/g7nU1jXwHYS7i47w36mxpzZE/kQjQsIkKUyVBW8ZU=; b=YVPjnGVfyOfoYZO1Bv7NLqYd8/B0Di3gt5A4+Podfe6H9e0fbP+TXibpoFhxVyloYf 752rf4JFeOfqHJaaAUsDdNUkayqwdBdPFWAC77/z19BB4x1B+GwDkXp+a2tzxDVsEsRR O4afFtdn2FNxVekgNQqbM1rB7Fn5Me6NdOhpBkbY6EEtzxBXw/KdkPhqjMcpApXDC5hR GQUoRWWzDbB39S6HsuRLb+sj+5Cp0k+xLCfP/qAg8uPOf8OMxdn0VoHYl5yhZP47jvOJ m8qZv5+A166neE+6OkMad2UIa9b+cMjfcr3JVLwvCb3CVDU+epbkOHj+r4+Re9IdA/Qx DQZQ== X-Gm-Message-State: AOAM530AluHh6UOjeuLVnQc8jQf/aO+XCbQTkc9nC568g1g4SYENWdk5 ZDGx2YsfTMHjwqVM9eTcm5nxT1kCGDUS9g== X-Google-Smtp-Source: ABdhPJz6Bg5FQhKAsC0+jqn6rfdlyrWpuuGw763ZnsP8B0QinlaSEiZr9lsX6yEeQzblFWnPCQTBKA== X-Received: by 2002:a17:90a:4817:: with SMTP id a23mr13703935pjh.192.1622756499982; Thu, 03 Jun 2021 14:41:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 11/29] softfloat: Introduce Floatx80RoundPrec Date: Thu, 3 Jun 2021 14:41:13 -0700 Message-Id: <20210603214131.629841-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Use an enumeration instead of raw 32/64/80 values. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- include/fpu/softfloat-helpers.h | 5 +- include/fpu/softfloat-types.h | 10 +++- include/fpu/softfloat.h | 4 +- fpu/softfloat.c | 32 ++++++------ linux-user/arm/nwfpe/fpa11.c | 41 +++++++-------- target/i386/tcg/fpu_helper.c | 79 +++++++++++++++++------------ target/m68k/fpu_helper.c | 50 +++++++++--------- target/m68k/softfloat.c | 90 ++++++++++++++++++++------------- tests/fp/fp-test.c | 5 +- 9 files changed, 182 insertions(+), 134 deletions(-) diff --git a/include/fpu/softfloat-helpers.h b/include/fpu/softfloat-helper= s.h index 2f0674fbdd..34f4cf92ae 100644 --- a/include/fpu/softfloat-helpers.h +++ b/include/fpu/softfloat-helpers.h @@ -69,7 +69,7 @@ static inline void set_float_exception_flags(int val, flo= at_status *status) status->float_exception_flags =3D val; } =20 -static inline void set_floatx80_rounding_precision(int val, +static inline void set_floatx80_rounding_precision(FloatX80RoundPrec val, float_status *status) { status->floatx80_rounding_precision =3D val; @@ -120,7 +120,8 @@ static inline int get_float_exception_flags(float_statu= s *status) return status->float_exception_flags; } =20 -static inline int get_floatx80_rounding_precision(float_status *status) +static inline FloatX80RoundPrec +get_floatx80_rounding_precision(float_status *status) { return status->floatx80_rounding_precision; } diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h index 3b757c3d6a..5bcbd041f7 100644 --- a/include/fpu/softfloat-types.h +++ b/include/fpu/softfloat-types.h @@ -154,6 +154,14 @@ enum { float_flag_output_denormal =3D 128 }; =20 +/* + * Rounding precision for floatx80. + */ +typedef enum __attribute__((__packed__)) { + floatx80_precision_x, + floatx80_precision_d, + floatx80_precision_s, +} FloatX80RoundPrec; =20 /* * Floating Point Status. Individual architectures may maintain @@ -165,7 +173,7 @@ enum { typedef struct float_status { FloatRoundMode float_rounding_mode; uint8_t float_exception_flags; - signed char floatx80_rounding_precision; + FloatX80RoundPrec floatx80_rounding_precision; bool tininess_before_rounding; /* should denormalised results go to zero and set the inexact flag? */ bool flush_to_zero; diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index ed32040aa9..ec7dca0960 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -1152,7 +1152,7 @@ floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b,= float_status *status); | Floating-Point Arithmetic. *-------------------------------------------------------------------------= ---*/ =20 -floatx80 roundAndPackFloatx80(int8_t roundingPrecision, bool zSign, +floatx80 roundAndPackFloatx80(FloatX80RoundPrec roundingPrecision, bool zS= ign, int32_t zExp, uint64_t zSig0, uint64_t zSig1, float_status *status); =20 @@ -1165,7 +1165,7 @@ floatx80 roundAndPackFloatx80(int8_t roundingPrecisio= n, bool zSign, | normalized. *-------------------------------------------------------------------------= ---*/ =20 -floatx80 normalizeRoundAndPackFloatx80(int8_t roundingPrecision, +floatx80 normalizeRoundAndPackFloatx80(FloatX80RoundPrec roundingPrecision, bool zSign, int32_t zExp, uint64_t zSig0, uint64_t zSig1, float_status *status); diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 741480c568..b6a50e5e95 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -4342,10 +4342,10 @@ void normalizeFloatx80Subnormal(uint64_t aSig, int3= 2_t *zExpPtr, | a subnormal number, and the underflow and inexact exceptions are raised = if | the abstract input cannot be represented exactly as a subnormal extended | double-precision floating-point number. -| If `roundingPrecision' is 32 or 64, the result is rounded to the same -| number of bits as single or double precision, respectively. Otherwise, = the -| result is rounded to the full precision of the extended double-precision -| format. +| If `roundingPrecision' is floatx80_precision_s or floatx80_precision= _d, +| the result is rounded to the same number of bits as single or double +| precision, respectively. Otherwise, the result is rounded to the full +| precision of the extended double-precision format. | The input significand must be normalized or smaller. If the input | significand is not normalized, `zExp' must be 0; in that case, the result | returned is a subnormal number, and it must not require rounding. The @@ -4353,27 +4353,29 @@ void normalizeFloatx80Subnormal(uint64_t aSig, int3= 2_t *zExpPtr, | Floating-Point Arithmetic. *-------------------------------------------------------------------------= ---*/ =20 -floatx80 roundAndPackFloatx80(int8_t roundingPrecision, bool zSign, +floatx80 roundAndPackFloatx80(FloatX80RoundPrec roundingPrecision, bool zS= ign, int32_t zExp, uint64_t zSig0, uint64_t zSig1, float_status *status) { - int8_t roundingMode; + FloatRoundMode roundingMode; bool roundNearestEven, increment, isTiny; int64_t roundIncrement, roundMask, roundBits; =20 roundingMode =3D status->float_rounding_mode; roundNearestEven =3D ( roundingMode =3D=3D float_round_nearest_even ); - if ( roundingPrecision =3D=3D 80 ) goto precision80; - if ( roundingPrecision =3D=3D 64 ) { + switch (roundingPrecision) { + case floatx80_precision_x: + goto precision80; + case floatx80_precision_d: roundIncrement =3D UINT64_C(0x0000000000000400); roundMask =3D UINT64_C(0x00000000000007FF); - } - else if ( roundingPrecision =3D=3D 32 ) { + break; + case floatx80_precision_s: roundIncrement =3D UINT64_C(0x0000008000000000); roundMask =3D UINT64_C(0x000000FFFFFFFFFF); - } - else { - goto precision80; + break; + default: + g_assert_not_reached(); } zSig0 |=3D ( zSig1 !=3D 0 ); switch (roundingMode) { @@ -4550,7 +4552,7 @@ floatx80 roundAndPackFloatx80(int8_t roundingPrecisio= n, bool zSign, | normalized. *-------------------------------------------------------------------------= ---*/ =20 -floatx80 normalizeRoundAndPackFloatx80(int8_t roundingPrecision, +floatx80 normalizeRoundAndPackFloatx80(FloatX80RoundPrec roundingPrecision, bool zSign, int32_t zExp, uint64_t zSig0, uint64_t zSig1, float_status *status) @@ -6203,7 +6205,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool= mod, uint64_t *quotient, } return normalizeRoundAndPackFloatx80( - 80, zSign, bExp + expDiff, aSig0, aSig1, status); + floatx80_precision_x, zSign, bExp + expDiff, aSig0, aSig1, sta= tus); =20 } =20 diff --git a/linux-user/arm/nwfpe/fpa11.c b/linux-user/arm/nwfpe/fpa11.c index f6f8163eab..9a93610d24 100644 --- a/linux-user/arm/nwfpe/fpa11.c +++ b/linux-user/arm/nwfpe/fpa11.c @@ -97,37 +97,38 @@ void SetRoundingMode(const unsigned int opcode) =20 void SetRoundingPrecision(const unsigned int opcode) { - int rounding_precision; - FPA11 *fpa11 =3D GET_FPA11(); + FloatX80RoundPrec rounding_precision; + FPA11 *fpa11 =3D GET_FPA11(); #ifdef MAINTAIN_FPCR - fpa11->fpcr &=3D ~MASK_ROUNDING_PRECISION; + fpa11->fpcr &=3D ~MASK_ROUNDING_PRECISION; #endif - switch (opcode & MASK_ROUNDING_PRECISION) - { - case ROUND_SINGLE: - rounding_precision =3D 32; + switch (opcode & MASK_ROUNDING_PRECISION) { + case ROUND_SINGLE: + rounding_precision =3D floatx80_precision_s; #ifdef MAINTAIN_FPCR - fpa11->fpcr |=3D ROUND_SINGLE; + fpa11->fpcr |=3D ROUND_SINGLE; #endif - break; + break; =20 - case ROUND_DOUBLE: - rounding_precision =3D 64; + case ROUND_DOUBLE: + rounding_precision =3D floatx80_precision_d; #ifdef MAINTAIN_FPCR - fpa11->fpcr |=3D ROUND_DOUBLE; + fpa11->fpcr |=3D ROUND_DOUBLE; #endif - break; + break; =20 - case ROUND_EXTENDED: - rounding_precision =3D 80; + case ROUND_EXTENDED: + rounding_precision =3D floatx80_precision_x; #ifdef MAINTAIN_FPCR - fpa11->fpcr |=3D ROUND_EXTENDED; + fpa11->fpcr |=3D ROUND_EXTENDED; #endif - break; + break; =20 - default: rounding_precision =3D 80; - } - set_floatx80_rounding_precision(rounding_precision, &fpa11->fp_status); + default: + rounding_precision =3D floatx80_precision_x; + break; + } + set_floatx80_rounding_precision(rounding_precision, &fpa11->fp_status); } =20 /* Emulate the instruction in the opcode. */ diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c index 1b30f1bb73..4e11965067 100644 --- a/target/i386/tcg/fpu_helper.c +++ b/target/i386/tcg/fpu_helper.c @@ -673,38 +673,40 @@ uint32_t helper_fnstcw(CPUX86State *env) =20 void update_fp_status(CPUX86State *env) { - int rnd_type; + FloatRoundMode rnd_mode; + FloatX80RoundPrec rnd_prec; =20 /* set rounding mode */ switch (env->fpuc & FPU_RC_MASK) { default: case FPU_RC_NEAR: - rnd_type =3D float_round_nearest_even; + rnd_mode =3D float_round_nearest_even; break; case FPU_RC_DOWN: - rnd_type =3D float_round_down; + rnd_mode =3D float_round_down; break; case FPU_RC_UP: - rnd_type =3D float_round_up; + rnd_mode =3D float_round_up; break; case FPU_RC_CHOP: - rnd_type =3D float_round_to_zero; + rnd_mode =3D float_round_to_zero; break; } - set_float_rounding_mode(rnd_type, &env->fp_status); + set_float_rounding_mode(rnd_mode, &env->fp_status); + switch ((env->fpuc >> 8) & 3) { case 0: - rnd_type =3D 32; + rnd_prec =3D floatx80_precision_s; break; case 2: - rnd_type =3D 64; + rnd_prec =3D floatx80_precision_d; break; case 3: default: - rnd_type =3D 80; + rnd_prec =3D floatx80_precision_x; break; } - set_floatx80_rounding_precision(rnd_type, &env->fp_status); + set_floatx80_rounding_precision(rnd_prec, &env->fp_status); } =20 void helper_fldcw(CPUX86State *env, uint32_t val) @@ -1074,7 +1076,8 @@ void helper_f2xm1(CPUX86State *env) &sig2); /* This result is inexact. */ sig1 |=3D 1; - ST0 =3D normalizeRoundAndPackFloatx80(80, sign, exp, sig0, sig= 1, + ST0 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, + sign, exp, sig0, sig1, &env->fp_status); } } else { @@ -1083,9 +1086,10 @@ void helper_f2xm1(CPUX86State *env) int32_t n, aexp, bexp; uint64_t asig0, asig1, asig2, bsig0, bsig1; FloatRoundMode save_mode =3D env->fp_status.float_rounding_mode; - signed char save_prec =3D env->fp_status.floatx80_rounding_precisi= on; + FloatX80RoundPrec save_prec =3D + env->fp_status.floatx80_rounding_precision; env->fp_status.float_rounding_mode =3D float_round_nearest_even; - env->fp_status.floatx80_rounding_precision =3D 80; + env->fp_status.floatx80_rounding_precision =3D floatx80_precision_= x; =20 /* Find the nearest multiple of 1/32 to the argument. */ tmp =3D floatx80_scalbn(ST0, 5, &env->fp_status); @@ -1183,7 +1187,8 @@ void helper_f2xm1(CPUX86State *env) env->fp_status.float_rounding_mode =3D save_mode; /* This result is inexact. */ asig1 |=3D 1; - ST0 =3D normalizeRoundAndPackFloatx80(80, asign, aexp, asig0, = asig1, + ST0 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, + asign, aexp, asig0, asig1, &env->fp_status); } =20 @@ -1301,8 +1306,9 @@ void helper_fpatan(CPUX86State *env) * division is exact, the result of fpatan is still inexact * (and underflowing where appropriate). */ - signed char save_prec =3D env->fp_status.floatx80_rounding_precisi= on; - env->fp_status.floatx80_rounding_precision =3D 80; + FloatX80RoundPrec save_prec =3D + env->fp_status.floatx80_rounding_precision; + env->fp_status.floatx80_rounding_precision =3D floatx80_precision_= x; ST1 =3D floatx80_div(ST1, ST0, &env->fp_status); env->fp_status.floatx80_rounding_precision =3D save_prec; if (!floatx80_is_zero(ST1) && @@ -1321,7 +1327,8 @@ void helper_fpatan(CPUX86State *env) if (exp =3D=3D 0) { normalizeFloatx80Subnormal(sig, &exp, &sig); } - ST1 =3D normalizeRoundAndPackFloatx80(80, sign, exp, sig - 1, + ST1 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, + sign, exp, sig - 1, -1, &env->fp_status); } } else { @@ -1377,9 +1384,10 @@ void helper_fpatan(CPUX86State *env) uint64_t azsig2, azsig3, axsig0, axsig1; floatx80 x8; FloatRoundMode save_mode =3D env->fp_status.float_rounding_mod= e; - signed char save_prec =3D env->fp_status.floatx80_rounding_pre= cision; + FloatX80RoundPrec save_prec =3D + env->fp_status.floatx80_rounding_precision; env->fp_status.float_rounding_mode =3D float_round_nearest_eve= n; - env->fp_status.floatx80_rounding_precision =3D 80; + env->fp_status.floatx80_rounding_precision =3D floatx80_precis= ion_x; =20 if (arg0_exp =3D=3D 0) { normalizeFloatx80Subnormal(arg0_sig, &arg0_exp, &arg0_sig); @@ -1448,7 +1456,8 @@ void helper_fpatan(CPUX86State *env) * Split x as x =3D t + y, where t =3D n/8 is the nearest * multiple of 1/8 to x. */ - x8 =3D normalizeRoundAndPackFloatx80(80, false, xexp + 3, xsig= 0, + x8 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, + false, xexp + 3, xsig0, xsig1, &env->fp_status); n =3D floatx80_to_int32(x8, &env->fp_status); if (n =3D=3D 0) { @@ -1569,7 +1578,7 @@ void helper_fpatan(CPUX86State *env) /* Compute z^2. */ mul128To256(zsig0, zsig1, zsig0, zsig1, &z2sig0, &z2sig1, &z2sig2, &z2sig3); - z2 =3D normalizeRoundAndPackFloatx80(80, false, + z2 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x,= false, zexp + zexp - 0x3ffe, z2sig0, z2sig1, &env->fp_status); @@ -1689,7 +1698,7 @@ void helper_fpatan(CPUX86State *env) } /* This result is inexact. */ rsig1 |=3D 1; - ST1 =3D normalizeRoundAndPackFloatx80(80, rsign, rexp, + ST1 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, rsign,= rexp, rsig0, rsig1, &env->fp_status); } =20 @@ -1890,7 +1899,8 @@ static void helper_fyl2x_common(CPUX86State *env, flo= atx80 arg, int32_t *exp, */ mul128To256(tsig0, tsig1, tsig0, tsig1, &t2sig0, &t2sig1, &t2sig2, &t2sig3); - t2 =3D normalizeRoundAndPackFloatx80(80, false, texp + texp - 0x3ffe, + t2 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, false, + texp + texp - 0x3ffe, t2sig0, t2sig1, &env->fp_status); =20 /* Compute the lower parts of the polynomial expansion. */ @@ -2004,15 +2014,17 @@ void helper_fyl2xp1(CPUX86State *env) exp +=3D arg1_exp - 0x3ffe; /* This result is inexact. */ sig1 |=3D 1; - ST1 =3D normalizeRoundAndPackFloatx80(80, arg0_sign ^ arg1_sign, e= xp, + ST1 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, + arg0_sign ^ arg1_sign, exp, sig0, sig1, &env->fp_status); } else { int32_t aexp; uint64_t asig0, asig1, asig2; FloatRoundMode save_mode =3D env->fp_status.float_rounding_mode; - signed char save_prec =3D env->fp_status.floatx80_rounding_precisi= on; + FloatX80RoundPrec save_prec =3D + env->fp_status.floatx80_rounding_precision; env->fp_status.float_rounding_mode =3D float_round_nearest_even; - env->fp_status.floatx80_rounding_precision =3D 80; + env->fp_status.floatx80_rounding_precision =3D floatx80_precision_= x; =20 helper_fyl2x_common(env, ST0, &aexp, &asig0, &asig1); /* @@ -2027,7 +2039,8 @@ void helper_fyl2xp1(CPUX86State *env) /* This result is inexact. */ asig1 |=3D 1; env->fp_status.float_rounding_mode =3D save_mode; - ST1 =3D normalizeRoundAndPackFloatx80(80, arg0_sign ^ arg1_sign, a= exp, + ST1 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, + arg0_sign ^ arg1_sign, aexp, asig0, asig1, &env->fp_status); env->fp_status.floatx80_rounding_precision =3D save_prec; } @@ -2111,9 +2124,10 @@ void helper_fyl2x(CPUX86State *env) int32_t int_exp; floatx80 arg0_m1; FloatRoundMode save_mode =3D env->fp_status.float_rounding_mode; - signed char save_prec =3D env->fp_status.floatx80_rounding_precisi= on; + FloatX80RoundPrec save_prec =3D + env->fp_status.floatx80_rounding_precision; env->fp_status.float_rounding_mode =3D float_round_nearest_even; - env->fp_status.floatx80_rounding_precision =3D 80; + env->fp_status.floatx80_rounding_precision =3D floatx80_precision_= x; =20 if (arg0_exp =3D=3D 0) { normalizeFloatx80Subnormal(arg0_sig, &arg0_exp, &arg0_sig); @@ -2170,7 +2184,8 @@ void helper_fyl2x(CPUX86State *env) /* This result is inexact. */ asig1 |=3D 1; env->fp_status.float_rounding_mode =3D save_mode; - ST1 =3D normalizeRoundAndPackFloatx80(80, asign ^ arg1_sign, a= exp, + ST1 =3D normalizeRoundAndPackFloatx80(floatx80_precision_x, + asign ^ arg1_sign, aexp, asig0, asig1, &env->fp_sta= tus); } =20 @@ -2252,12 +2267,12 @@ void helper_fscale(CPUX86State *env) } } else { int n; - signed char save =3D env->fp_status.floatx80_rounding_precision; + FloatX80RoundPrec save =3D env->fp_status.floatx80_rounding_precis= ion; uint8_t save_flags =3D get_float_exception_flags(&env->fp_status); set_float_exception_flags(0, &env->fp_status); n =3D floatx80_to_int32_round_to_zero(ST1, &env->fp_status); set_float_exception_flags(save_flags, &env->fp_status); - env->fp_status.floatx80_rounding_precision =3D 80; + env->fp_status.floatx80_rounding_precision =3D floatx80_precision_= x; ST0 =3D floatx80_scalbn(ST0, n, &env->fp_status); env->fp_status.floatx80_rounding_precision =3D save; } diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c index 797000e748..fdc4937e29 100644 --- a/target/m68k/fpu_helper.c +++ b/target/m68k/fpu_helper.c @@ -94,13 +94,13 @@ static void m68k_restore_precision_mode(CPUM68KState *e= nv) { switch (env->fpcr & FPCR_PREC_MASK) { case FPCR_PREC_X: /* extended */ - set_floatx80_rounding_precision(80, &env->fp_status); + set_floatx80_rounding_precision(floatx80_precision_x, &env->fp_sta= tus); break; case FPCR_PREC_S: /* single */ - set_floatx80_rounding_precision(32, &env->fp_status); + set_floatx80_rounding_precision(floatx80_precision_s, &env->fp_sta= tus); break; case FPCR_PREC_D: /* double */ - set_floatx80_rounding_precision(64, &env->fp_status); + set_floatx80_rounding_precision(floatx80_precision_d, &env->fp_sta= tus); break; case FPCR_PREC_U: /* undefined */ default: @@ -111,9 +111,9 @@ static void m68k_restore_precision_mode(CPUM68KState *e= nv) static void cf_restore_precision_mode(CPUM68KState *env) { if (env->fpcr & FPCR_PREC_S) { /* single */ - set_floatx80_rounding_precision(32, &env->fp_status); + set_floatx80_rounding_precision(floatx80_precision_s, &env->fp_sta= tus); } else { /* double */ - set_floatx80_rounding_precision(64, &env->fp_status); + set_floatx80_rounding_precision(floatx80_precision_d, &env->fp_sta= tus); } } =20 @@ -166,8 +166,8 @@ void HELPER(set_fpcr)(CPUM68KState *env, uint32_t val) =20 #define PREC_BEGIN(prec) \ do { \ - int old; \ - old =3D get_floatx80_rounding_precision(&env->fp_status); \ + FloatX80RoundPrec old =3D \ + get_floatx80_rounding_precision(&env->fp_status); \ set_floatx80_rounding_precision(prec, &env->fp_status) \ =20 #define PREC_END() \ @@ -176,14 +176,14 @@ void HELPER(set_fpcr)(CPUM68KState *env, uint32_t val) =20 void HELPER(fsround)(CPUM68KState *env, FPReg *res, FPReg *val) { - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); res->d =3D floatx80_round(val->d, &env->fp_status); PREC_END(); } =20 void HELPER(fdround)(CPUM68KState *env, FPReg *res, FPReg *val) { - PREC_BEGIN(64); + PREC_BEGIN(floatx80_precision_d); res->d =3D floatx80_round(val->d, &env->fp_status); PREC_END(); } @@ -195,14 +195,14 @@ void HELPER(fsqrt)(CPUM68KState *env, FPReg *res, FPR= eg *val) =20 void HELPER(fssqrt)(CPUM68KState *env, FPReg *res, FPReg *val) { - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); res->d =3D floatx80_sqrt(val->d, &env->fp_status); PREC_END(); } =20 void HELPER(fdsqrt)(CPUM68KState *env, FPReg *res, FPReg *val) { - PREC_BEGIN(64); + PREC_BEGIN(floatx80_precision_d); res->d =3D floatx80_sqrt(val->d, &env->fp_status); PREC_END(); } @@ -214,14 +214,14 @@ void HELPER(fabs)(CPUM68KState *env, FPReg *res, FPRe= g *val) =20 void HELPER(fsabs)(CPUM68KState *env, FPReg *res, FPReg *val) { - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); res->d =3D floatx80_round(floatx80_abs(val->d), &env->fp_status); PREC_END(); } =20 void HELPER(fdabs)(CPUM68KState *env, FPReg *res, FPReg *val) { - PREC_BEGIN(64); + PREC_BEGIN(floatx80_precision_d); res->d =3D floatx80_round(floatx80_abs(val->d), &env->fp_status); PREC_END(); } @@ -233,14 +233,14 @@ void HELPER(fneg)(CPUM68KState *env, FPReg *res, FPRe= g *val) =20 void HELPER(fsneg)(CPUM68KState *env, FPReg *res, FPReg *val) { - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); res->d =3D floatx80_round(floatx80_chs(val->d), &env->fp_status); PREC_END(); } =20 void HELPER(fdneg)(CPUM68KState *env, FPReg *res, FPReg *val) { - PREC_BEGIN(64); + PREC_BEGIN(floatx80_precision_d); res->d =3D floatx80_round(floatx80_chs(val->d), &env->fp_status); PREC_END(); } @@ -252,14 +252,14 @@ void HELPER(fadd)(CPUM68KState *env, FPReg *res, FPRe= g *val0, FPReg *val1) =20 void HELPER(fsadd)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); res->d =3D floatx80_add(val0->d, val1->d, &env->fp_status); PREC_END(); } =20 void HELPER(fdadd)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - PREC_BEGIN(64); + PREC_BEGIN(floatx80_precision_d); res->d =3D floatx80_add(val0->d, val1->d, &env->fp_status); PREC_END(); } @@ -271,14 +271,14 @@ void HELPER(fsub)(CPUM68KState *env, FPReg *res, FPRe= g *val0, FPReg *val1) =20 void HELPER(fssub)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); res->d =3D floatx80_sub(val1->d, val0->d, &env->fp_status); PREC_END(); } =20 void HELPER(fdsub)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - PREC_BEGIN(64); + PREC_BEGIN(floatx80_precision_d); res->d =3D floatx80_sub(val1->d, val0->d, &env->fp_status); PREC_END(); } @@ -290,14 +290,14 @@ void HELPER(fmul)(CPUM68KState *env, FPReg *res, FPRe= g *val0, FPReg *val1) =20 void HELPER(fsmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); res->d =3D floatx80_mul(val0->d, val1->d, &env->fp_status); PREC_END(); } =20 void HELPER(fdmul)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - PREC_BEGIN(64); + PREC_BEGIN(floatx80_precision_d); res->d =3D floatx80_mul(val0->d, val1->d, &env->fp_status); PREC_END(); } @@ -307,7 +307,7 @@ void HELPER(fsglmul)(CPUM68KState *env, FPReg *res, FPR= eg *val0, FPReg *val1) FloatRoundMode rounding_mode =3D get_float_rounding_mode(&env->fp_stat= us); floatx80 a, b; =20 - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); set_float_rounding_mode(float_round_to_zero, &env->fp_status); a =3D floatx80_round(val0->d, &env->fp_status); b =3D floatx80_round(val1->d, &env->fp_status); @@ -323,14 +323,14 @@ void HELPER(fdiv)(CPUM68KState *env, FPReg *res, FPRe= g *val0, FPReg *val1) =20 void HELPER(fsdiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); res->d =3D floatx80_div(val1->d, val0->d, &env->fp_status); PREC_END(); } =20 void HELPER(fddiv)(CPUM68KState *env, FPReg *res, FPReg *val0, FPReg *val1) { - PREC_BEGIN(64); + PREC_BEGIN(floatx80_precision_d); res->d =3D floatx80_div(val1->d, val0->d, &env->fp_status); PREC_END(); } @@ -340,7 +340,7 @@ void HELPER(fsgldiv)(CPUM68KState *env, FPReg *res, FPR= eg *val0, FPReg *val1) FloatRoundMode rounding_mode =3D get_float_rounding_mode(&env->fp_stat= us); floatx80 a, b; =20 - PREC_BEGIN(32); + PREC_BEGIN(floatx80_precision_s); set_float_rounding_mode(float_round_to_zero, &env->fp_status); a =3D floatx80_round(val1->d, &env->fp_status); b =3D floatx80_round(val0->d, &env->fp_status); diff --git a/target/m68k/softfloat.c b/target/m68k/softfloat.c index b6d0ed7acf..02dcc03d15 100644 --- a/target/m68k/softfloat.c +++ b/target/m68k/softfloat.c @@ -227,7 +227,8 @@ floatx80 floatx80_lognp1(floatx80 a, float_status *stat= us) int32_t aExp; uint64_t aSig, fSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, j, k; floatx80 fp0, fp1, fp2, fp3, f, logof2, klog2, saveu; @@ -270,7 +271,7 @@ floatx80 floatx80_lognp1(floatx80 a, float_status *stat= us) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 compact =3D floatx80_make_compact(aExp, aSig); =20 @@ -426,7 +427,8 @@ floatx80 floatx80_logn(floatx80 a, float_status *status) int32_t aExp; uint64_t aSig, fSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, j, k, adjk; floatx80 fp0, fp1, fp2, fp3, f, logof2, klog2, saveu; @@ -469,7 +471,7 @@ floatx80 floatx80_logn(floatx80 a, float_status *status) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 compact =3D floatx80_make_compact(aExp, aSig); =20 @@ -594,7 +596,8 @@ floatx80 floatx80_log10(floatx80 a, float_status *statu= s) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 floatx80 fp0, fp1; =20 @@ -626,7 +629,7 @@ floatx80 floatx80_log10(floatx80 a, float_status *statu= s) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 fp0 =3D floatx80_logn(a, status); fp1 =3D packFloatx80(0, 0x3FFD, UINT64_C(0xDE5BD8A937287195)); /* INV_= L10 */ @@ -651,7 +654,8 @@ floatx80 floatx80_log2(floatx80 a, float_status *status) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 floatx80 fp0, fp1; =20 @@ -686,7 +690,7 @@ floatx80 floatx80_log2(floatx80 a, float_status *status) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 if (aSig =3D=3D one_sig) { /* X is 2^k */ status->float_rounding_mode =3D user_rnd_mode; @@ -718,7 +722,8 @@ floatx80 floatx80_etox(floatx80 a, float_status *status) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, n, j, k, m, m1; floatx80 fp0, fp1, fp2, fp3, l2, scale, adjscale; @@ -746,7 +751,7 @@ floatx80 floatx80_etox(floatx80 a, float_status *status) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 adjflag =3D 0; =20 @@ -902,7 +907,8 @@ floatx80 floatx80_twotox(floatx80 a, float_status *stat= us) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, n, j, l, m, m1; floatx80 fp0, fp1, fp2, fp3, adjfact, fact1, fact2; @@ -929,7 +935,7 @@ floatx80 floatx80_twotox(floatx80 a, float_status *stat= us) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 fp0 =3D a; =20 @@ -1052,7 +1058,8 @@ floatx80 floatx80_tentox(floatx80 a, float_status *st= atus) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, n, j, l, m, m1; floatx80 fp0, fp1, fp2, fp3, adjfact, fact1, fact2; @@ -1079,7 +1086,7 @@ floatx80 floatx80_tentox(floatx80 a, float_status *st= atus) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 fp0 =3D a; =20 @@ -1207,7 +1214,8 @@ floatx80 floatx80_tan(floatx80 a, float_status *statu= s) int32_t aExp, xExp; uint64_t aSig, xSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, l, n, j; floatx80 fp0, fp1, fp2, fp3, fp4, fp5, invtwopi, twopi1, twopi2; @@ -1233,7 +1241,7 @@ floatx80 floatx80_tan(floatx80 a, float_status *statu= s) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 compact =3D floatx80_make_compact(aExp, aSig); =20 @@ -1417,7 +1425,8 @@ floatx80 floatx80_sin(floatx80 a, float_status *statu= s) int32_t aExp, xExp; uint64_t aSig, xSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, l, n, j; floatx80 fp0, fp1, fp2, fp3, fp4, fp5, x, invtwopi, twopi1, twopi2; @@ -1443,7 +1452,7 @@ floatx80 floatx80_sin(floatx80 a, float_status *statu= s) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 compact =3D floatx80_make_compact(aExp, aSig); =20 @@ -1656,7 +1665,8 @@ floatx80 floatx80_cos(floatx80 a, float_status *statu= s) int32_t aExp, xExp; uint64_t aSig, xSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, l, n, j; floatx80 fp0, fp1, fp2, fp3, fp4, fp5, x, invtwopi, twopi1, twopi2; @@ -1682,7 +1692,7 @@ floatx80 floatx80_cos(floatx80 a, float_status *statu= s) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 compact =3D floatx80_make_compact(aExp, aSig); =20 @@ -1893,7 +1903,8 @@ floatx80 floatx80_atan(floatx80 a, float_status *stat= us) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, tbl_index; floatx80 fp0, fp1, fp2, fp3, xsave; @@ -1920,7 +1931,7 @@ floatx80 floatx80_atan(floatx80 a, float_status *stat= us) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 if (compact < 0x3FFB8000 || compact > 0x4002FFFF) { /* |X| >=3D 16 or |X| < 1/16 */ @@ -2090,7 +2101,8 @@ floatx80 floatx80_asin(floatx80 a, float_status *stat= us) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact; floatx80 fp0, fp1, fp2, one; @@ -2124,7 +2136,7 @@ floatx80 floatx80_asin(floatx80 a, float_status *stat= us) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 one =3D packFloatx80(0, one_exp, one_sig); fp0 =3D a; @@ -2155,7 +2167,8 @@ floatx80 floatx80_acos(floatx80 a, float_status *stat= us) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact; floatx80 fp0, fp1, one; @@ -2193,7 +2206,7 @@ floatx80 floatx80_acos(floatx80 a, float_status *stat= us) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 one =3D packFloatx80(0, one_exp, one_sig); fp0 =3D a; @@ -2224,7 +2237,8 @@ floatx80 floatx80_atanh(floatx80 a, float_status *sta= tus) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact; floatx80 fp0, fp1, fp2, one; @@ -2257,7 +2271,7 @@ floatx80 floatx80_atanh(floatx80 a, float_status *sta= tus) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 one =3D packFloatx80(0, one_exp, one_sig); fp2 =3D packFloatx80(aSign, 0x3FFE, one_sig); /* SIGN(X) * (1/2) */ @@ -2289,7 +2303,8 @@ floatx80 floatx80_etoxm1(floatx80 a, float_status *st= atus) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact, n, j, m, m1; floatx80 fp0, fp1, fp2, fp3, l2, sc, onebysc; @@ -2316,7 +2331,7 @@ floatx80 floatx80_etoxm1(floatx80 a, float_status *st= atus) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 if (aExp >=3D 0x3FFD) { /* |X| >=3D 1/4 */ compact =3D floatx80_make_compact(aExp, aSig); @@ -2541,7 +2556,8 @@ floatx80 floatx80_tanh(floatx80 a, float_status *stat= us) int32_t aExp, vExp; uint64_t aSig, vSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact; floatx80 fp0, fp1; @@ -2565,7 +2581,7 @@ floatx80 floatx80_tanh(floatx80 a, float_status *stat= us) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 compact =3D floatx80_make_compact(aExp, aSig); =20 @@ -2656,7 +2672,8 @@ floatx80 floatx80_sinh(floatx80 a, float_status *stat= us) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact; floatx80 fp0, fp1, fp2; @@ -2681,7 +2698,7 @@ floatx80 floatx80_sinh(floatx80 a, float_status *stat= us) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 compact =3D floatx80_make_compact(aExp, aSig); =20 @@ -2744,7 +2761,8 @@ floatx80 floatx80_cosh(floatx80 a, float_status *stat= us) int32_t aExp; uint64_t aSig; =20 - int8_t user_rnd_mode, user_rnd_prec; + FloatRoundMode user_rnd_mode; + FloatX80RoundPrec user_rnd_prec; =20 int32_t compact; floatx80 fp0, fp1; @@ -2767,7 +2785,7 @@ floatx80 floatx80_cosh(floatx80 a, float_status *stat= us) user_rnd_mode =3D status->float_rounding_mode; user_rnd_prec =3D status->floatx80_rounding_precision; status->float_rounding_mode =3D float_round_nearest_even; - status->floatx80_rounding_precision =3D 80; + status->floatx80_rounding_precision =3D floatx80_precision_x; =20 compact =3D floatx80_make_compact(aExp, aSig); =20 diff --git a/tests/fp/fp-test.c b/tests/fp/fp-test.c index ff131afbde..1be3a9788a 100644 --- a/tests/fp/fp-test.c +++ b/tests/fp/fp-test.c @@ -963,18 +963,21 @@ static void QEMU_NORETURN run_test(void) verCases_usesExact =3D !!(attrs & FUNC_ARG_EXACT); =20 for (k =3D 0; k < 3; k++) { + FloatX80RoundPrec qsf_prec80 =3D floatx80_precision_s; int prec80 =3D 32; int l; =20 if (k =3D=3D 1) { prec80 =3D 64; + qsf_prec80 =3D floatx80_precision_d; } else if (k =3D=3D 2) { prec80 =3D 80; + qsf_prec80 =3D floatx80_precision_x; } =20 verCases_roundingPrecision =3D 0; slow_extF80_roundingPrecision =3D prec80; - qsf.floatx80_rounding_precision =3D prec80; + qsf.floatx80_rounding_precision =3D qsf_prec80; =20 if (attrs & FUNC_EFF_ROUNDINGPRECISION) { verCases_roundingPrecision =3D prec80; --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756944; cv=none; d=zohomail.com; s=zohoarc; b=f6lW9jY0Ah33oF16bATKWoU/SfFscKMVSpIOpK5B0JzvIyFfl9nZfdyMHOhZp7e76KfD94Tac7Wm7+Bud/ihscy2TE+esMGa8RHEySik+jmy/aaBDb/C/HDM8BGihm2fH8zPL2Kzput6Q+QPMrxIFKZg9FBAkA4rZfXWhvBfzQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756944; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=j87cuN4oaVGPOQrr81JQNoweh6RR6j9zmHwWvD1f2qc=; b=Nxk8/Zlw6L4Rn6YH7M57SWTbbXHBBLOTwEsKzONmqtZzUvNR8umCNhLPetIVz4YoMdPnu727YM0HWpeGMyPPMATF63riEfPu3/Ip2S/oTMZI69XLZHcLXO8FL0yqH+wdo6myXsWp1gktpOSqecEIvJkauivi1N/GPSDwx2USpGs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16227569442688.642059576035876; Thu, 3 Jun 2021 14:49:04 -0700 (PDT) Received: from localhost ([::1]:46880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovD5-0005Gd-79 for importer@patchew.org; Thu, 03 Jun 2021 17:49:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov61-0002L8-Pq for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:45 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:38644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5y-00015o-0B for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:45 -0400 Received: by mail-pj1-x102a.google.com with SMTP id m13-20020a17090b068db02901656cc93a75so6260034pjz.3 for ; Thu, 03 Jun 2021 14:41:41 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:40 -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=j87cuN4oaVGPOQrr81JQNoweh6RR6j9zmHwWvD1f2qc=; b=p++rPMhXyzBlFbk7pzdg7LIjaJw0oMzMDfr+VOHY9KCQo+pI2EP+5cjPY1M78LcIo6 TPP7pSq2L/3dPLXOGL0BJU1/2jEW5uOEo3bG6VzwF/Ru5b213cZOwYgwSzsm/dDqsict 7EdKwClekqJB5s+v8AUPQQZNyXKHZc/mY3g3yAruSuJI7hq8v6vASbwhxOchPEgTb7Id Q4k8XH6t1Sp3tXNoiGP3eDvxxMsBPAlRT9DBTPFnxgCxu1xYneSL4LZO7mp7FqgAp3nV Kww8lUFEsWDzPjuYxetpbYbSdLLYFELQk0HwriI8c+eAAbqkiULiFDex9Km6HnTFpike FNFw== 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=j87cuN4oaVGPOQrr81JQNoweh6RR6j9zmHwWvD1f2qc=; b=jrax/S20T4csW60x3NTmn0oBZP4Z+TLyjIy2JApHVB1Uf9o4vH061RS1Ajx/XSH4+Q oUV8lzqni+105JDhZJwvgDknZEypbKOyti3gIcFS2Fx9e2TZweGX+MJqiZUKjRvkDBkQ S7V5DifHuzkIRGFQax+jqYI5vTIIst0vHhTVG6Vh2I0zsBwIdu+k6uC8/z/Z5AAKgKe5 MphsZL7XKeEnG5XO+5R3ysRWwFYQCjsdIzF5mOijNXgqkuD5hgNhX49qphh11VP4Zi4i 6zxlVFU4KFyQsjFevmM1WPnGDkDjLkKrn4mmzyb2JyuBmfZWE0+97H3AhVLcdiriIQ4R d+0w== X-Gm-Message-State: AOAM533463Xsok7BynInarns27lFGLkNlgmxiGvv/m//0b6op//69dHP bRi8L1pp6TrgG/vG1k5P/AYK6a5hElT5Rw== X-Google-Smtp-Source: ABdhPJz56gmEMK6RPtDkPVXpBJKmFpvPAamDApmxN+npMK09FHZvD5g8L9BotBp2dPkvuOQDyEBYCw== X-Received: by 2002:a17:90a:1150:: with SMTP id d16mr1346065pje.180.1622756500644; Thu, 03 Jun 2021 14:41:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 12/29] softfloat: Adjust parts_uncanon_normal for floatx80 Date: Thu, 3 Jun 2021 14:41:14 -0700 Message-Id: <20210603214131.629841-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) With floatx80_precision_x, the rounding happens across the break between words. Notice this case with frac_lsb =3D round_mask + 1 -> 0 and check the bits in frac_hi as needed. In addition, since frac_shift =3D=3D 0, we won't implicitly clear round_mask via the right-shift, so explicitly clear those bits. This fixes rounding for floatx80_precision_[sd]. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat-parts.c.inc | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index a026581c33..efb81bbebe 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -155,7 +155,13 @@ static void partsN(uncanon_normal)(FloatPartsN *p, flo= at_status *s, =20 switch (s->float_rounding_mode) { case float_round_nearest_even: - inc =3D ((p->frac_lo & roundeven_mask) !=3D frac_lsbm1 ? frac_lsbm= 1 : 0); + if (N > 64 && frac_lsb =3D=3D 0) { + inc =3D ((p->frac_hi & 1) || (p->frac_lo & round_mask) !=3D fr= ac_lsbm1 + ? frac_lsbm1 : 0); + } else { + inc =3D ((p->frac_lo & roundeven_mask) !=3D frac_lsbm1 + ? frac_lsbm1 : 0); + } break; case float_round_ties_away: inc =3D frac_lsbm1; @@ -176,7 +182,11 @@ static void partsN(uncanon_normal)(FloatPartsN *p, flo= at_status *s, overflow_norm =3D true; /* fall through */ case float_round_to_odd_inf: - inc =3D p->frac_lo & frac_lsb ? 0 : round_mask; + if (N > 64 && frac_lsb =3D=3D 0) { + inc =3D p->frac_hi & 1 ? 0 : round_mask; + } else { + inc =3D p->frac_lo & frac_lsb ? 0 : round_mask; + } break; default: g_assert_not_reached(); @@ -191,8 +201,8 @@ static void partsN(uncanon_normal)(FloatPartsN *p, floa= t_status *s, p->frac_hi |=3D DECOMPOSED_IMPLICIT_BIT; exp++; } + p->frac_lo &=3D ~round_mask; } - frac_shr(p, frac_shift); =20 if (fmt->arm_althp) { /* ARM Alt HP eschews Inf and NaN for a wider exponent. */ @@ -201,18 +211,21 @@ static void partsN(uncanon_normal)(FloatPartsN *p, fl= oat_status *s, flags =3D float_flag_invalid; exp =3D exp_max; frac_allones(p); + p->frac_lo &=3D ~round_mask; } } else if (unlikely(exp >=3D exp_max)) { flags |=3D float_flag_overflow | float_flag_inexact; if (overflow_norm) { exp =3D exp_max - 1; frac_allones(p); + p->frac_lo &=3D ~round_mask; } else { p->cls =3D float_class_inf; exp =3D exp_max; frac_clear(p); } } + frac_shr(p, frac_shift); } else if (s->flush_to_zero) { flags |=3D float_flag_output_denormal; p->cls =3D float_class_zero; @@ -232,18 +245,29 @@ static void partsN(uncanon_normal)(FloatPartsN *p, fl= oat_status *s, /* Need to recompute round-to-even/round-to-odd. */ switch (s->float_rounding_mode) { case float_round_nearest_even: - inc =3D ((p->frac_lo & roundeven_mask) !=3D frac_lsbm1 - ? frac_lsbm1 : 0); + if (N > 64 && frac_lsb =3D=3D 0) { + inc =3D ((p->frac_hi & 1) || + (p->frac_lo & round_mask) !=3D frac_lsbm1 + ? frac_lsbm1 : 0); + } else { + inc =3D ((p->frac_lo & roundeven_mask) !=3D frac_lsbm1 + ? frac_lsbm1 : 0); + } break; case float_round_to_odd: case float_round_to_odd_inf: - inc =3D p->frac_lo & frac_lsb ? 0 : round_mask; + if (N > 64 && frac_lsb =3D=3D 0) { + inc =3D p->frac_hi & 1 ? 0 : round_mask; + } else { + inc =3D p->frac_lo & frac_lsb ? 0 : round_mask; + } break; default: break; } flags |=3D float_flag_inexact; frac_addi(p, p, inc); + p->frac_lo &=3D ~round_mask; } =20 exp =3D (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) !=3D 0; --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757048; cv=none; d=zohomail.com; s=zohoarc; b=khPBQ4nWxTG7zcEg8P43Z3R8EBWxuFIQIWlEtSTjJEcm1xIyTVVyv4/aFjC1UYTaHnw6r4VbdW7lHCGYtGbjtyFT3tDtxlTPcHYsCd4RqJe+1T+5RSw78zjzvFOnSPkjXpqTQeTYq4iGibJMlWusvMDrfoZR8NIzfMTw2Y4hGto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757048; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v63kiMKs6E/Jl628TTWBVtvYw6v1ob0t2PY/usIP/Gs=; b=ilQuuZgIwPAi3hpqozVe8AfSvvmoYp7cAxcPEUgEhjxxKqhaJGxfC3SnfwRDGSOCRAf1zkIITbJk+LZ6b51/eDtPbWOBorI4V7KPDMLp0hfN78XHkw1JwFOTxC6HfRq+zQjLZMDe+O3bbiQM/fpcEA7/GBiibrVtVqJSf3vNt1U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162275704799561.26435851729104; Thu, 3 Jun 2021 14:50:47 -0700 (PDT) Received: from localhost ([::1]:55180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovEl-0002Jm-01 for importer@patchew.org; Thu, 03 Jun 2021 17:50:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov60-0002I4-Cd for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:44 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:55112) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5y-00016d-H5 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:44 -0400 Received: by mail-pj1-x102f.google.com with SMTP id g24so4421130pji.4 for ; Thu, 03 Jun 2021 14:41:42 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:40 -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=v63kiMKs6E/Jl628TTWBVtvYw6v1ob0t2PY/usIP/Gs=; b=mnMbrQz2S8ISX8o9F8kxHblhgPWF71lExIx3xQ36W2tjozJqByN8XSCa9QCbhtVgnd 9k4tj1xmPraCKqNOoN6t2RyU2uO4N+hT+gC1JpA+JP0OyeTTpmDX3r/VhFlMp6KaDKiK t5DfOrus3HZ8tHUtzLcbLLWQ9vno+ooz1xDkf/shPvneglxyxgkM2nyEtvwBffJaNtNn SSphmmMdazqRcCtnY1RV1+nuCbqniby2wEgPYi9W66acXvHIdvK9qLOF35q/W3ARShit QSoMIGwhlwu5tG3mSbfYKKUn4QoVZq63rHXaoDYIV5at0jYmg0b6V8k3j0c/62/5r/OU uj4Q== 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=v63kiMKs6E/Jl628TTWBVtvYw6v1ob0t2PY/usIP/Gs=; b=QABSbAAcL3Y/wMOD4LeHgSX54TwwGMdCSUuOO0yOLKfMNusyz2El+9tLAo2oznAuS3 vopQYWuZbXyCAf7ugke0+27J1N5SdfKcchZpvqW7JDtq7OV9e7NSDUnXn7Tn5ac5DqCq O0zFk7RifXWQbKlLQL8kBAZaD4D/H0VJPvWsOeLqEr5wUCBpUOfhVCGc9jyl/lrJvW8a jA4AE1cwtCM1wbAXB4xaYwTyTDvfqDlaZRRwjnQUZQXpytbuNAdZ+T+zXJdVbpQYMnnr hyZTeV0y0Da2b+6TuvG/9LEZjqSTukam5eFqsrYjJHj//6YQVB47xOIjLJgJi7W1LEEy u1Ng== X-Gm-Message-State: AOAM530z3OkGoLkiFtrKmXXLC5fl63hPoYF+u8HqrxacgS1y5nxWSCVR KCHdTKLmagRROVSTCD9cW5GgHDqlS7xRCQ== X-Google-Smtp-Source: ABdhPJwZnZeZ30FFQdGaSi9BNr+jNhQvU0Uo37JSfuxLLBBaDtWoZ6CKQNcqSDN364g4Hgrol+XPhg== X-Received: by 2002:a17:902:c403:b029:106:7793:3fcc with SMTP id k3-20020a170902c403b029010677933fccmr1060530plk.81.1622756501138; Thu, 03 Jun 2021 14:41:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 13/29] tests/fp/fp-test: Reverse order of floatx80 precision tests Date: Thu, 3 Jun 2021 14:41:15 -0700 Message-Id: <20210603214131.629841-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Many qemu softfloat will check floatx80_rounding_precision even when berkeley testfloat will not. So begin with floatx80_precision_x, so that's the one we use when !FUNC_EFF_ROUNDINGPRECISION. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- tests/fp/fp-test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fp/fp-test.c b/tests/fp/fp-test.c index 1be3a9788a..352dd71c44 100644 --- a/tests/fp/fp-test.c +++ b/tests/fp/fp-test.c @@ -963,16 +963,16 @@ static void QEMU_NORETURN run_test(void) verCases_usesExact =3D !!(attrs & FUNC_ARG_EXACT); =20 for (k =3D 0; k < 3; k++) { - FloatX80RoundPrec qsf_prec80 =3D floatx80_precision_s; - int prec80 =3D 32; + FloatX80RoundPrec qsf_prec80 =3D floatx80_precision_x; + int prec80 =3D 80; int l; =20 if (k =3D=3D 1) { prec80 =3D 64; qsf_prec80 =3D floatx80_precision_d; } else if (k =3D=3D 2) { - prec80 =3D 80; - qsf_prec80 =3D floatx80_precision_x; + prec80 =3D 32; + qsf_prec80 =3D floatx80_precision_s; } =20 verCases_roundingPrecision =3D 0; --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757179; cv=none; d=zohomail.com; s=zohoarc; b=jGUVEJDZCX/ibuAuevXQGho8i9RJOXwfUlp4QEWZrwy0kkAfVOMkXOGcVJgojCFQ+Ol6if0mCeKris2RF3QI1QU2Wzmor2N7wZdL42iHY7GQy9os4s4NuTel6xW+ndlfsNlI9dMWTnI38aMGMcMG0JaK+yzjKv1oxqrtFPv2t6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757179; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zdB+URSmwAXojvo8XHizqXqw1GaDXnIRRudI5sdslWY=; b=IVp0v9J64BJ+x6ZzHctOr/uzwYJwaiSPodPBH2HNRjkhU7fWCbJgOwCfaLQZRkpgw9mifvq+NejUHT+/iPm5/iYl5OWeWB0iujx8yS88kyXY1QburXJTQk+y0uAHkGwxsKKc94/2i75JJ6smne1PoEgCmggsB9j3l49lGzeQ6GM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757179251949.2736625320188; Thu, 3 Jun 2021 14:52:59 -0700 (PDT) Received: from localhost ([::1]:35244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovGr-0007vo-PT for importer@patchew.org; Thu, 03 Jun 2021 17:52:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov66-0002WO-SV for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:51 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:43758) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5z-00017B-Gs for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:50 -0400 Received: by mail-pg1-x532.google.com with SMTP id e22so6157069pgv.10 for ; Thu, 03 Jun 2021 14:41:42 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:41 -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=zdB+URSmwAXojvo8XHizqXqw1GaDXnIRRudI5sdslWY=; b=yVLdHeCcT8I8Irb3DMBW427lsq1qyJAmm8vG6/tlOfTauhKQCMvxYMKiVLTmFquCan wPrs74hGl8bM8RAeSVFEyBRnzHZN3o1CxW3oxNEDtqGNC0PW51CGmEu5ZBuyDLpzu/9V ieskC84K61XLDIw/HXGe7pbtCto9Ots8G/51N1daX4H0CcqFpag/Cwe9cgUXpc5w9svi fCkdUw6fZTj2yBBMX2He5bbKr3Raz8UpRnpHxf1nynnZs9fIm/Zmnl0tInLRBKfZcQrN 7JXROHPCiwDilKT56ZZ0eOmftnLsi33I6L8zH7+cKbhoWuLN6i20PfP2ZjDMwn/7JYQ/ UBdA== 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=zdB+URSmwAXojvo8XHizqXqw1GaDXnIRRudI5sdslWY=; b=A12w28GVy8QQ6+0yUGnaSkuaRqq2UOeRA9IY2+Z1R/EfEWCCdYrfO5ampa7NIH3CZp /tpB/DtnWv600JnoNug4q8aSCzMwqp7g3LrAQy9nFGaFNJb+8T7nkRLUlY8/GPBtmPYj /aQjnTyQozLdiAyXe9scawUk7bG5Aw/4nQfq/UlEQdORMguCwBbM33u5Wf62h7EzlfeR X9PUVefgKJi/Ne6zjF8rYiOAJ3BVr95acD6pa/z9iSHZas8hY1gqpF3ufjau2Y2gJ+7w EqxFat+rKhn91V8BdsR5xfF2Vi1Tw3ADplxw+/3NU+nPclzyFb3udEyro0vB5SSKL3Dl Z4kQ== X-Gm-Message-State: AOAM531QFO3v0cShxmoAK7WpkhvKvjEZpDnXBDIZkBrYEtCw2nj5PnWp VuMtWozl54G/sCqWeKidnRdfrvfwjtRK8A== X-Google-Smtp-Source: ABdhPJzJTrvQSv6y1+jtwo33nOcBumbt5ivq8Ns62bGQXVG6NSxDl71csiqqLukqlOUkSBm/iJoedg== X-Received: by 2002:a63:5b66:: with SMTP id l38mr1467292pgm.241.1622756501976; Thu, 03 Jun 2021 14:41:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 14/29] softfloat: Convert floatx80_add/sub to FloatParts Date: Thu, 3 Jun 2021 14:41:16 -0700 Message-Id: <20210603214131.629841-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Since this is the first such, this includes all of the packing and unpacking routines as well. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 339 +++++++++++++++++++----------------------------- 1 file changed, 136 insertions(+), 203 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index b6a50e5e95..737f5d7701 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -578,14 +578,14 @@ typedef struct { } FloatFmt; =20 /* Expand fields based on the size of exponent and fraction */ -#define FLOAT_PARAMS_(E, F) \ +#define FLOAT_PARAMS_(E) \ .exp_size =3D E, \ .exp_bias =3D ((1 << E) - 1) >> 1, \ - .exp_max =3D (1 << E) - 1, \ - .frac_size =3D F + .exp_max =3D (1 << E) - 1 =20 #define FLOAT_PARAMS(E, F) \ - FLOAT_PARAMS_(E, F), \ + FLOAT_PARAMS_(E), \ + .frac_size =3D F, \ .frac_shift =3D (-F - 1) & 63, \ .round_mask =3D (1ull << ((-F - 1) & 63)) - 1 =20 @@ -614,6 +614,18 @@ static const FloatFmt float128_params =3D { FLOAT_PARAMS(15, 112) }; =20 +#define FLOATX80_PARAMS(R) \ + FLOAT_PARAMS_(15), \ + .frac_size =3D R =3D=3D 64 ? 63 : R, \ + .frac_shift =3D 0, \ + .round_mask =3D R =3D=3D 64 ? -1 : (1ull << ((-R - 1) & 63)) - 1 + +static const FloatFmt floatx80_params[3] =3D { + [floatx80_precision_s] =3D { FLOATX80_PARAMS(23) }, + [floatx80_precision_d] =3D { FLOATX80_PARAMS(52) }, + [floatx80_precision_x] =3D { FLOATX80_PARAMS(64) }, +}; + /* Unpack a float to parts, but do not canonicalize. */ static void unpack_raw64(FloatParts64 *r, const FloatFmt *fmt, uint64_t ra= w) { @@ -648,6 +660,16 @@ static inline void float64_unpack_raw(FloatParts64 *p,= float64 f) unpack_raw64(p, &float64_params, f); } =20 +static void floatx80_unpack_raw(FloatParts128 *p, floatx80 f) +{ + *p =3D (FloatParts128) { + .cls =3D float_class_unclassified, + .sign =3D extract32(f.high, 15, 1), + .exp =3D extract32(f.high, 0, 15), + .frac_hi =3D f.low + }; +} + static void float128_unpack_raw(FloatParts128 *p, float128 f) { const int f_size =3D float128_params.frac_size - 64; @@ -1536,6 +1558,92 @@ static float128 float128_round_pack_canonical(FloatP= arts128 *p, return float128_pack_raw(p); } =20 +/* Returns false if the encoding is invalid. */ +static bool floatx80_unpack_canonical(FloatParts128 *p, floatx80 f, + float_status *s) +{ + /* Ensure rounding precision is set before beginning. */ + switch (s->floatx80_rounding_precision) { + case floatx80_precision_x: + case floatx80_precision_d: + case floatx80_precision_s: + break; + default: + g_assert_not_reached(); + } + + if (unlikely(floatx80_invalid_encoding(f))) { + float_raise(float_flag_invalid, s); + return false; + } + + floatx80_unpack_raw(p, f); + + if (likely(p->exp !=3D floatx80_params[floatx80_precision_x].exp_max))= { + parts_canonicalize(p, s, &floatx80_params[floatx80_precision_x]); + } else { + /* The explicit integer bit is ignored, after invalid checks. */ + p->frac_hi &=3D MAKE_64BIT_MASK(0, 63); + p->cls =3D (p->frac_hi =3D=3D 0 ? float_class_inf + : parts_is_snan_frac(p->frac_hi, s) + ? float_class_snan : float_class_qnan); + } + return true; +} + +static floatx80 floatx80_round_pack_canonical(FloatParts128 *p, + float_status *s) +{ + const FloatFmt *fmt =3D &floatx80_params[s->floatx80_rounding_precisio= n]; + uint64_t frac; + int exp; + + switch (p->cls) { + case float_class_normal: + if (s->floatx80_rounding_precision =3D=3D floatx80_precision_x) { + parts_uncanon_normal(p, s, fmt); + frac =3D p->frac_hi; + exp =3D p->exp; + } else { + FloatParts64 p64; + + p64.sign =3D p->sign; + p64.exp =3D p->exp; + frac_truncjam(&p64, p); + parts_uncanon_normal(&p64, s, fmt); + frac =3D p64.frac; + exp =3D p64.exp; + } + if (exp !=3D fmt->exp_max) { + break; + } + /* rounded to inf -- fall through to set frac correctly */ + + case float_class_inf: + /* x86 and m68k differ in the setting of the integer bit. */ + frac =3D floatx80_infinity_low; + exp =3D fmt->exp_max; + break; + + case float_class_zero: + frac =3D 0; + exp =3D 0; + break; + + case float_class_snan: + case float_class_qnan: + /* NaNs have the integer bit set. */ + frac =3D p->frac_hi | (1ull << 63); + exp =3D fmt->exp_max; + break; + + default: + g_assert_not_reached(); + } + + return packFloatx80(p->sign, exp, frac); +} + /* * Addition and subtraction */ @@ -1725,6 +1833,30 @@ float128 float128_sub(float128 a, float128 b, float_= status *status) return float128_addsub(a, b, status, true); } =20 +static floatx80 QEMU_FLATTEN +floatx80_addsub(floatx80 a, floatx80 b, float_status *status, bool subtrac= t) +{ + FloatParts128 pa, pb, *pr; + + if (!floatx80_unpack_canonical(&pa, a, status) || + !floatx80_unpack_canonical(&pb, b, status)) { + return floatx80_default_nan(status); + } + + pr =3D parts_addsub(&pa, &pb, status, subtract); + return floatx80_round_pack_canonical(pr, status); +} + +floatx80 floatx80_add(floatx80 a, floatx80 b, float_status *status) +{ + return floatx80_addsub(a, b, status, false); +} + +floatx80 floatx80_sub(floatx80 a, floatx80 b, float_status *status) +{ + return floatx80_addsub(a, b, status, true); +} + /* * Multiplication */ @@ -5731,205 +5863,6 @@ floatx80 floatx80_round_to_int(floatx80 a, float_st= atus *status) =20 } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of adding the absolute values of the extended double- -| precision floating-point values `a' and `b'. If `zSign' is 1, the sum is -| negated before being returned. `zSign' is ignored if the result is a Na= N. -| The addition is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -static floatx80 addFloatx80Sigs(floatx80 a, floatx80 b, bool zSign, - float_status *status) -{ - int32_t aExp, bExp, zExp; - uint64_t aSig, bSig, zSig0, zSig1; - int32_t expDiff; - - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - bSig =3D extractFloatx80Frac( b ); - bExp =3D extractFloatx80Exp( b ); - expDiff =3D aExp - bExp; - if ( 0 < expDiff ) { - if ( aExp =3D=3D 0x7FFF ) { - if ((uint64_t)(aSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - return a; - } - if ( bExp =3D=3D 0 ) --expDiff; - shift64ExtraRightJamming( bSig, 0, expDiff, &bSig, &zSig1 ); - zExp =3D aExp; - } - else if ( expDiff < 0 ) { - if ( bExp =3D=3D 0x7FFF ) { - if ((uint64_t)(bSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - return packFloatx80(zSign, - floatx80_infinity_high, - floatx80_infinity_low); - } - if ( aExp =3D=3D 0 ) ++expDiff; - shift64ExtraRightJamming( aSig, 0, - expDiff, &aSig, &zSig1 ); - zExp =3D bExp; - } - else { - if ( aExp =3D=3D 0x7FFF ) { - if ( (uint64_t) ( ( aSig | bSig )<<1 ) ) { - return propagateFloatx80NaN(a, b, status); - } - return a; - } - zSig1 =3D 0; - zSig0 =3D aSig + bSig; - if ( aExp =3D=3D 0 ) { - if ((aSig | bSig) & UINT64_C(0x8000000000000000) && zSig0 < aS= ig) { - /* At least one of the values is a pseudo-denormal, - * and there is a carry out of the result. */ - zExp =3D 1; - goto shiftRight1; - } - if (zSig0 =3D=3D 0) { - return packFloatx80(zSign, 0, 0); - } - normalizeFloatx80Subnormal( zSig0, &zExp, &zSig0 ); - goto roundAndPack; - } - zExp =3D aExp; - goto shiftRight1; - } - zSig0 =3D aSig + bSig; - if ( (int64_t) zSig0 < 0 ) goto roundAndPack; - shiftRight1: - shift64ExtraRightJamming( zSig0, zSig1, 1, &zSig0, &zSig1 ); - zSig0 |=3D UINT64_C(0x8000000000000000); - ++zExp; - roundAndPack: - return roundAndPackFloatx80(status->floatx80_rounding_precision, - zSign, zExp, zSig0, zSig1, status); -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of subtracting the absolute values of the extended -| double-precision floating-point values `a' and `b'. If `zSign' is 1, the -| difference is negated before being returned. `zSign' is ignored if the -| result is a NaN. The subtraction is performed according to the IEC/IEEE -| Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -static floatx80 subFloatx80Sigs(floatx80 a, floatx80 b, bool zSign, - float_status *status) -{ - int32_t aExp, bExp, zExp; - uint64_t aSig, bSig, zSig0, zSig1; - int32_t expDiff; - - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - bSig =3D extractFloatx80Frac( b ); - bExp =3D extractFloatx80Exp( b ); - expDiff =3D aExp - bExp; - if ( 0 < expDiff ) goto aExpBigger; - if ( expDiff < 0 ) goto bExpBigger; - if ( aExp =3D=3D 0x7FFF ) { - if ( (uint64_t) ( ( aSig | bSig )<<1 ) ) { - return propagateFloatx80NaN(a, b, status); - } - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - if ( aExp =3D=3D 0 ) { - aExp =3D 1; - bExp =3D 1; - } - zSig1 =3D 0; - if ( bSig < aSig ) goto aBigger; - if ( aSig < bSig ) goto bBigger; - return packFloatx80(status->float_rounding_mode =3D=3D float_round_dow= n, 0, 0); - bExpBigger: - if ( bExp =3D=3D 0x7FFF ) { - if ((uint64_t)(bSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - return packFloatx80(zSign ^ 1, floatx80_infinity_high, - floatx80_infinity_low); - } - if ( aExp =3D=3D 0 ) ++expDiff; - shift128RightJamming( aSig, 0, - expDiff, &aSig, &zSig1 ); - bBigger: - sub128( bSig, 0, aSig, zSig1, &zSig0, &zSig1 ); - zExp =3D bExp; - zSign ^=3D 1; - goto normalizeRoundAndPack; - aExpBigger: - if ( aExp =3D=3D 0x7FFF ) { - if ((uint64_t)(aSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - return a; - } - if ( bExp =3D=3D 0 ) --expDiff; - shift128RightJamming( bSig, 0, expDiff, &bSig, &zSig1 ); - aBigger: - sub128( aSig, 0, bSig, zSig1, &zSig0, &zSig1 ); - zExp =3D aExp; - normalizeRoundAndPack: - return normalizeRoundAndPackFloatx80(status->floatx80_rounding_precisi= on, - zSign, zExp, zSig0, zSig1, status= ); -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of adding the extended double-precision floating-point -| values `a' and `b'. The operation is performed according to the IEC/IEEE -| Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_add(floatx80 a, floatx80 b, float_status *status) -{ - bool aSign, bSign; - - if (floatx80_invalid_encoding(a) || floatx80_invalid_encoding(b)) { - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - aSign =3D extractFloatx80Sign( a ); - bSign =3D extractFloatx80Sign( b ); - if ( aSign =3D=3D bSign ) { - return addFloatx80Sigs(a, b, aSign, status); - } - else { - return subFloatx80Sigs(a, b, aSign, status); - } - -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of subtracting the extended double-precision floating- -| point values `a' and `b'. The operation is performed according to the -| IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_sub(floatx80 a, floatx80 b, float_status *status) -{ - bool aSign, bSign; - - if (floatx80_invalid_encoding(a) || floatx80_invalid_encoding(b)) { - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - aSign =3D extractFloatx80Sign( a ); - bSign =3D extractFloatx80Sign( b ); - if ( aSign =3D=3D bSign ) { - return subFloatx80Sigs(a, b, aSign, status); - } - else { - return addFloatx80Sigs(a, b, aSign, status); - } - -} - /*------------------------------------------------------------------------= ---- | Returns the result of multiplying the extended double-precision floating- | point values `a' and `b'. The operation is performed according to the --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757313; cv=none; d=zohomail.com; s=zohoarc; b=dupfOPysl7azrBXU35306GjG0X/NTsNDNuTYNYj0qXLuZ29bbk17OKI2PK7AMwDnP6ZKPOU+G/Df31bu3Xd9uEhK9ljf2/EbHG6C13nQH9BCtDQV6VfIKdnnWDLes9cgzMrApa4/KoRaK9DXOR3XlaGhtTy35qL6ZLqsmrtniio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757313; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=q8lAbNppcyHGJO57X+8D3vs8Lmd+nrqoL0h5uKHL3jg=; b=dZsX4Ea9MG0LMO+vowy7WQ/zOP9VLM/0GCE8TtplgmQ9WDFUjLni1wAzlCJM/41Dt15zyVEmvGffCBDTAmIBq6XI3JH+5VCN8oLpgKfvDONn36feu0BVVeGAnuVSLgTszMki8QOSEAndgXMLkMdRbEchdDwF8hkZJ/WWUXuNLAk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757313164950.6587731979821; Thu, 3 Jun 2021 14:55:13 -0700 (PDT) Received: from localhost ([::1]:47172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovJ2-0007PA-3o for importer@patchew.org; Thu, 03 Jun 2021 17:55:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6C-0002hg-TI for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:56 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:42719) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5z-00017q-Pb for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:56 -0400 Received: by mail-pj1-x102f.google.com with SMTP id l23-20020a17090a0717b029016ae774f973so4044548pjl.1 for ; Thu, 03 Jun 2021 14:41:43 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:42 -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=q8lAbNppcyHGJO57X+8D3vs8Lmd+nrqoL0h5uKHL3jg=; b=f0h9kkYQtht//enboMld31rdes5z4fiTZoCk/iov1xAG5M6QK7hNQUnjZ1+jWTRAbG 5ocuDuvsM+te9U/A6WhCR0UShI0szqcX1AfOk9c/R55Gx5SQoBSP7TG78SSsv3zrJ/Db Oxeq5iGgRTa0vboZoUfcbdZJk83zXBlreINrsWl5BhDzd/ao52UtgSlvCkMM5kqsznwh EkTfvhcL/SfhHyX76HaxZhYtDGRumkfB6paahONnfa859OY2fPeo4FC+YOwgry1Ygt2X /4V3sggAmmQbOumJHaSpsG8ODYMzNF8erjQBdvzBtX7VIcLcOuTmZJnveUYjGS+XT84P oGjQ== 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=q8lAbNppcyHGJO57X+8D3vs8Lmd+nrqoL0h5uKHL3jg=; b=m9UbV+U6l2XzRjQRyJ3Y9E9tj6fNT6jW9jOZuVJF730Fp1Hw6pJ8/nC4vQBqSt4S+V sSfOxZW/8KqSM5q6HI/3N+9n6FpYl86LtI4iGhcYS8MOqlibfM0bTCIGjqKiR3HHgwH8 2joyd2ZNvcJkqjst5qDiDTQvy+GWvYkWoxg8YgK0gpwi2s/LACYMdKIgEVY8zI+92TfA LRAI31/Bf1Ih5mYanYJbkRxj9eQT1xFhEP9K8YSkwo+/2Qp8tlrlrsIm6a+yzYeuXwLU 495IMgeJGgNNnYn8t8ir3OrW+/7SqzFLNNMcpvGbnfqhBrgrHOSlQ858y2xuQKQfa+6k DB/Q== X-Gm-Message-State: AOAM531KwIPLcyIvjcWEHxr+jA38+JaUuMKeBLbIXzHwJQsP132jzXRH mVcvQXz8n9tRwIbaTnPvpK2qtesfsw7y6g== X-Google-Smtp-Source: ABdhPJy36mmdunt0y84HYGehvZmqqjU+412xtFHabcjoGxn2+wxyRXIdiaKY/KRJALYsatuCjiTcbA== X-Received: by 2002:a17:902:ee8c:b029:fe:dc5f:564 with SMTP id a12-20020a170902ee8cb02900fedc5f0564mr1176093pld.71.1622756502496; Thu, 03 Jun 2021 14:41:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 15/29] softfloat: Convert floatx80_mul to FloatParts Date: Thu, 3 Jun 2021 14:41:17 -0700 Message-Id: <20210603214131.629841-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 76 +++++++++---------------------------------------- 1 file changed, 14 insertions(+), 62 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 737f5d7701..ae2e7aa274 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1944,6 +1944,20 @@ float128_mul(float128 a, float128 b, float_status *s= tatus) return float128_round_pack_canonical(pr, status); } =20 +floatx80 QEMU_FLATTEN +floatx80_mul(floatx80 a, floatx80 b, float_status *status) +{ + FloatParts128 pa, pb, *pr; + + if (!floatx80_unpack_canonical(&pa, a, status) || + !floatx80_unpack_canonical(&pb, b, status)) { + return floatx80_default_nan(status); + } + + pr =3D parts_mul(&pa, &pb, status); + return floatx80_round_pack_canonical(pr, status); +} + /* * Fused multiply-add */ @@ -5863,68 +5877,6 @@ floatx80 floatx80_round_to_int(floatx80 a, float_sta= tus *status) =20 } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of multiplying the extended double-precision floating- -| point values `a' and `b'. The operation is performed according to the -| IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_mul(floatx80 a, floatx80 b, float_status *status) -{ - bool aSign, bSign, zSign; - int32_t aExp, bExp, zExp; - uint64_t aSig, bSig, zSig0, zSig1; - - if (floatx80_invalid_encoding(a) || floatx80_invalid_encoding(b)) { - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - bSig =3D extractFloatx80Frac( b ); - bExp =3D extractFloatx80Exp( b ); - bSign =3D extractFloatx80Sign( b ); - zSign =3D aSign ^ bSign; - if ( aExp =3D=3D 0x7FFF ) { - if ( (uint64_t) ( aSig<<1 ) - || ( ( bExp =3D=3D 0x7FFF ) && (uint64_t) ( bSig<<1 ) ) ) { - return propagateFloatx80NaN(a, b, status); - } - if ( ( bExp | bSig ) =3D=3D 0 ) goto invalid; - return packFloatx80(zSign, floatx80_infinity_high, - floatx80_infinity_low); - } - if ( bExp =3D=3D 0x7FFF ) { - if ((uint64_t)(bSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - if ( ( aExp | aSig ) =3D=3D 0 ) { - invalid: - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - return packFloatx80(zSign, floatx80_infinity_high, - floatx80_infinity_low); - } - if ( aExp =3D=3D 0 ) { - if ( aSig =3D=3D 0 ) return packFloatx80( zSign, 0, 0 ); - normalizeFloatx80Subnormal( aSig, &aExp, &aSig ); - } - if ( bExp =3D=3D 0 ) { - if ( bSig =3D=3D 0 ) return packFloatx80( zSign, 0, 0 ); - normalizeFloatx80Subnormal( bSig, &bExp, &bSig ); - } - zExp =3D aExp + bExp - 0x3FFE; - mul64To128( aSig, bSig, &zSig0, &zSig1 ); - if ( 0 < (int64_t) zSig0 ) { - shortShift128Left( zSig0, zSig1, 1, &zSig0, &zSig1 ); - --zExp; - } - return roundAndPackFloatx80(status->floatx80_rounding_precision, - zSign, zExp, zSig0, zSig1, status); -} - /*------------------------------------------------------------------------= ---- | Returns the result of dividing the extended double-precision floating-po= int | value `a' by the corresponding value `b'. The operation is performed --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757224; cv=none; d=zohomail.com; s=zohoarc; b=IOYQF1SFoGZUNaAT+tyzSaA3cMOPIgaW17TyQ2ezG5/cOkzbVBskuh1gCBj+XCFHjfVmWNLguQ6FGptTEGn/b1NnJBFFEv/04tLER68IerzjAPxn9p1qoVnL2IhOKYylP4EzmFFtL9bImWLQ3svCwNx4WP4LN0sTH3Cku/KjsQE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757224; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jsR0mGCWglTMXoS6de3IaqXp8GNTb2/ROWC0tZcxiWk=; b=WG/piIVmZA88a2A+kErZ/YJqdUTpxn8SuznVFACKglZA1hP08vpOrEoGTQ5u/eBf7JEGVmLjm36h6w8eC+vnburCA3jDHxxXiwbUS0WQSAbfzbQZ+Hs0k7OJlI8Xx/lLjbSM7cS4fjKxLvRdsMNmK/jEAX+6UfPc3q5KWvrEM8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757224893392.3117262763691; Thu, 3 Jun 2021 14:53:44 -0700 (PDT) Received: from localhost ([::1]:39074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovHb-00023F-Sk for importer@patchew.org; Thu, 03 Jun 2021 17:53:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov67-0002Yf-LP for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:53 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:41805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov60-000186-Dy for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:51 -0400 Received: by mail-pf1-x431.google.com with SMTP id x73so5921289pfc.8 for ; Thu, 03 Jun 2021 14:41:43 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:42 -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=jsR0mGCWglTMXoS6de3IaqXp8GNTb2/ROWC0tZcxiWk=; b=UrFi3pSveaG22A0ssi1yj502GiL63JDT39ZLaSptjkLbp4evKPZ0ZJv5T72dzO057I x+V9ek6FJJzeSL4kUkB8ESkzEWC7YytzoApfR1NtaGY25BVQNZHpvJBgFoRcoR46AKTs 3tfWYlYEeOpe/zLjI21d3pMVrExaaHfL/w5wp7seeKvZ/zUojMHIMCH/R3JLU0Em4WZx yDezCZsZRl3o4JhUtNM11CPrWy4/LZ4UBuG3kteR4pZaPj5TwqUKTH0gb2/c+/bksVJV IwUOk9Vh5z1i3uDGiOBWFfBlJpmraqRr93E+sp6nv04Ri7wXr08t6LWzIjfRQshECCbj BJAg== 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=jsR0mGCWglTMXoS6de3IaqXp8GNTb2/ROWC0tZcxiWk=; b=FZ88/M4BuhHFuj31xAYne6F1VZ4WEskeJ5RlJ0alpSeXwU8NQpLE9yW1S7afasDaF2 hcq24Z8u+gmhyVcelsLOpp4uSw1EAzUkV1oyccpB4yS94L5i0xrBhSJFuIml8uYvcbjP cCiGpXwXl4y3+Mj8g8RBCD/DTKAqiaZQUn5ByxWe0pLHzKv8KXxDytinqqNof0e5PLWu DZlt4E9N/z4kJafQaig22RDWo2bkKeW0fDXVQqNfkWGBRkeWz3XH6jilljT5emnGbez7 pue9n3JRLhPjusE4DkLr6heVjIQWSzodsOmjE4iAGLWj9zpDbmf8bjVUBszgvl0dd9wM tGHQ== X-Gm-Message-State: AOAM531XzvGTVd6K6Mm8SBWSvcOvqWteISwQcUyLfAV30dSPqBFcFXXK DSqqyyMxbl8dILa9HYiNMxQ4z/3Hd+IOCQ== X-Google-Smtp-Source: ABdhPJy/hzqLluUPIv8iQoclV0s+atnW+Zz6I+exQb7Sx+R2EJB7p27Iz4QRP+ms2t4jKgfVyf1ZYg== X-Received: by 2002:a63:bc19:: with SMTP id q25mr1483310pge.211.1622756503107; Thu, 03 Jun 2021 14:41:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 16/29] softfloat: Convert floatx80_div to FloatParts Date: Thu, 3 Jun 2021 14:41:18 -0700 Message-Id: <20210603214131.629841-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 100 +++++++----------------------------------------- 1 file changed, 13 insertions(+), 87 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index ae2e7aa274..9c26ba5960 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -2294,6 +2294,19 @@ float128_div(float128 a, float128 b, float_status *s= tatus) return float128_round_pack_canonical(pr, status); } =20 +floatx80 floatx80_div(floatx80 a, floatx80 b, float_status *status) +{ + FloatParts128 pa, pb, *pr; + + if (!floatx80_unpack_canonical(&pa, a, status) || + !floatx80_unpack_canonical(&pb, b, status)) { + return floatx80_default_nan(status); + } + + pr =3D parts_div(&pa, &pb, status); + return floatx80_round_pack_canonical(pr, status); +} + /* * Float to Float conversions * @@ -5877,93 +5890,6 @@ floatx80 floatx80_round_to_int(floatx80 a, float_sta= tus *status) =20 } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of dividing the extended double-precision floating-po= int -| value `a' by the corresponding value `b'. The operation is performed -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_div(floatx80 a, floatx80 b, float_status *status) -{ - bool aSign, bSign, zSign; - int32_t aExp, bExp, zExp; - uint64_t aSig, bSig, zSig0, zSig1; - uint64_t rem0, rem1, rem2, term0, term1, term2; - - if (floatx80_invalid_encoding(a) || floatx80_invalid_encoding(b)) { - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - bSig =3D extractFloatx80Frac( b ); - bExp =3D extractFloatx80Exp( b ); - bSign =3D extractFloatx80Sign( b ); - zSign =3D aSign ^ bSign; - if ( aExp =3D=3D 0x7FFF ) { - if ((uint64_t)(aSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - if ( bExp =3D=3D 0x7FFF ) { - if ((uint64_t)(bSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - goto invalid; - } - return packFloatx80(zSign, floatx80_infinity_high, - floatx80_infinity_low); - } - if ( bExp =3D=3D 0x7FFF ) { - if ((uint64_t)(bSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - return packFloatx80( zSign, 0, 0 ); - } - if ( bExp =3D=3D 0 ) { - if ( bSig =3D=3D 0 ) { - if ( ( aExp | aSig ) =3D=3D 0 ) { - invalid: - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - float_raise(float_flag_divbyzero, status); - return packFloatx80(zSign, floatx80_infinity_high, - floatx80_infinity_low); - } - normalizeFloatx80Subnormal( bSig, &bExp, &bSig ); - } - if ( aExp =3D=3D 0 ) { - if ( aSig =3D=3D 0 ) return packFloatx80( zSign, 0, 0 ); - normalizeFloatx80Subnormal( aSig, &aExp, &aSig ); - } - zExp =3D aExp - bExp + 0x3FFE; - rem1 =3D 0; - if ( bSig <=3D aSig ) { - shift128Right( aSig, 0, 1, &aSig, &rem1 ); - ++zExp; - } - zSig0 =3D estimateDiv128To64( aSig, rem1, bSig ); - mul64To128( bSig, zSig0, &term0, &term1 ); - sub128( aSig, rem1, term0, term1, &rem0, &rem1 ); - while ( (int64_t) rem0 < 0 ) { - --zSig0; - add128( rem0, rem1, 0, bSig, &rem0, &rem1 ); - } - zSig1 =3D estimateDiv128To64( rem1, 0, bSig ); - if ( (uint64_t) ( zSig1<<1 ) <=3D 8 ) { - mul64To128( bSig, zSig1, &term1, &term2 ); - sub128( rem1, 0, term1, term2, &rem1, &rem2 ); - while ( (int64_t) rem1 < 0 ) { - --zSig1; - add128( rem1, rem2, 0, bSig, &rem1, &rem2 ); - } - zSig1 |=3D ( ( rem1 | rem2 ) !=3D 0 ); - } - return roundAndPackFloatx80(status->floatx80_rounding_precision, - zSign, zExp, zSig0, zSig1, status); -} - /*------------------------------------------------------------------------= ---- | Returns the remainder of the extended double-precision floating-point va= lue | `a' with respect to the corresponding value `b'. The operation is perfo= rmed --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756997; cv=none; d=zohomail.com; s=zohoarc; b=OFCGQBhMwi2qkz44GcmGYn4NJ6Z9h74TnEQgjUN5kvZtLzWlSmJTI2ZhYOsVQKI/z1mJOUGib2D3EtHW4gNaZzp1g1c+QFCzJEeCEPzgSU4+t+7kT8eeth3kyWWjAcnVr8AhkmFQe68XNfPfHR0IZtjKw4S4g/++/58k9+fwB/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756997; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JCtl3D+YOh8X1zQYr/wZ8dY/TYd7h1wTuPlU6E6ST7c=; b=bEOtjBmRvNBJjlpCDicFgKUSN2nFqgEapWjkTph2NHYGIWQdGXUNsl/ElVknN5vThcycvN3ODkKeKaeUnjsnO6l3soy1uj8uShVHcbj11MM4y86byLYnWbVX6i1YOJWBHkumuf0m0P39iYtx9GKwgTfLPqnLRY0yzxS7zHCow0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756997152924.6125036188503; Thu, 3 Jun 2021 14:49:57 -0700 (PDT) Received: from localhost ([::1]:50136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovDu-0007Pn-3s for importer@patchew.org; Thu, 03 Jun 2021 17:49:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6B-0002gK-CR for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:56 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:36422) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov61-00018E-Fo for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:55 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 27so6185220pgy.3 for ; Thu, 03 Jun 2021 14:41:44 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:43 -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=JCtl3D+YOh8X1zQYr/wZ8dY/TYd7h1wTuPlU6E6ST7c=; b=LFSWzP1RsHR87z55Pf+z5JcHJqYYlIjXi332fm7PJMiVsw6wJ/D+eXlqlF59pW2oJ7 Y/GxX3LWRJxVDBBA4FmZrQtj/1re7e7+Q5YQoBbL26dcBO53n6KrpP3ZQ2oVPH80tYXH IO4TPgLvoGp+eqLSEy7oum66PpspSDrl9JZC6hHAatdXbYssdsaAIMpBsiXBCd1I6xDq q7PTPrqfj5BiDQbKH5p45yzMJO6n5h5CMAuAHZ+jnmT1kNCUAWMh/L3eytlOrNJWeUEJ /CgJJxMMTv1lqGGoLrxJoo4zw8gCAkGIX7oJSjLcEY0A9W+2MgksaaXPXsLRk8hgB0cr grKA== 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=JCtl3D+YOh8X1zQYr/wZ8dY/TYd7h1wTuPlU6E6ST7c=; b=nKmYwzdaXeln4yri7H18kNJdPJ331zTCs6bWiaoGGRuzXn+XFEMXutmKVK5FjVg2KI YQCCxGWGa5LA9Ja96cytj7OPS2tOm4S4RTGv9lkUmUZX3BTdjzOxI2gihWKHkbyqCH4g YwJJGKZgrygJr5LhHMGo1RMryAoq54+MP5E8pC5z7c+iiwrdHHbQ+d7FFDOwLWWPYk6x jNWm/YwlDgEM5n5S0sWZXQnmONgET1hPEN+KCUNjfhD0TMcjS1SFvRZsnMqW+PHYOnSL Inf+jr++1Q+0TZR/KoPw+8O4z+KWfAFT02mcD8+EA951BHd49ALkSSlkzJQ8Qj1f1ld+ I/iA== X-Gm-Message-State: AOAM532Ih98cxKIBC8Em9kHByvQFhOeQlcyYNTGoKeNPG0l1+KAgGWri tUa8x0LN2S6wm1SNCSG9wMLVz1iUR9s1Dw== X-Google-Smtp-Source: ABdhPJy9VMAj+OVonhtbFm9l1wHJ10GZxson0o+8Ay4haXv4uVFU92wA9CcK5ojljinxETgI2pqhCA== X-Received: by 2002:a63:fc06:: with SMTP id j6mr1501156pgi.226.1622756503686; Thu, 03 Jun 2021 14:41:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 17/29] softfloat: Convert floatx80_sqrt to FloatParts Date: Thu, 3 Jun 2021 14:41:19 -0700 Message-Id: <20210603214131.629841-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 82 +++++++------------------------------------------ 1 file changed, 11 insertions(+), 71 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 9c26ba5960..5a320e5302 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3881,6 +3881,17 @@ float128 QEMU_FLATTEN float128_sqrt(float128 a, floa= t_status *status) return float128_round_pack_canonical(&p, status); } =20 +floatx80 floatx80_sqrt(floatx80 a, float_status *s) +{ + FloatParts128 p; + + if (!floatx80_unpack_canonical(&p, a, s)) { + return floatx80_default_nan(s); + } + parts_sqrt(&p, s, &floatx80_params[s->floatx80_rounding_precision]); + return floatx80_round_pack_canonical(&p, s); +} + /*------------------------------------------------------------------------= ---- | The pattern for a default generated NaN. *-------------------------------------------------------------------------= ---*/ @@ -6044,77 +6055,6 @@ floatx80 floatx80_mod(floatx80 a, floatx80 b, float_= status *status) return floatx80_modrem(a, b, true, "ient, status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the square root of the extended double-precision floating-point -| value `a'. The operation is performed according to the IEC/IEEE Standard -| for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_sqrt(floatx80 a, float_status *status) -{ - bool aSign; - int32_t aExp, zExp; - uint64_t aSig0, aSig1, zSig0, zSig1, doubleZSig0; - uint64_t rem0, rem1, rem2, rem3, term0, term1, term2, term3; - - if (floatx80_invalid_encoding(a)) { - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - aSig0 =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - if ( aExp =3D=3D 0x7FFF ) { - if ((uint64_t)(aSig0 << 1)) { - return propagateFloatx80NaN(a, a, status); - } - if ( ! aSign ) return a; - goto invalid; - } - if ( aSign ) { - if ( ( aExp | aSig0 ) =3D=3D 0 ) return a; - invalid: - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - if ( aExp =3D=3D 0 ) { - if ( aSig0 =3D=3D 0 ) return packFloatx80( 0, 0, 0 ); - normalizeFloatx80Subnormal( aSig0, &aExp, &aSig0 ); - } - zExp =3D ( ( aExp - 0x3FFF )>>1 ) + 0x3FFF; - zSig0 =3D estimateSqrt32( aExp, aSig0>>32 ); - shift128Right( aSig0, 0, 2 + ( aExp & 1 ), &aSig0, &aSig1 ); - zSig0 =3D estimateDiv128To64( aSig0, aSig1, zSig0<<32 ) + ( zSig0<<30 = ); - doubleZSig0 =3D zSig0<<1; - mul64To128( zSig0, zSig0, &term0, &term1 ); - sub128( aSig0, aSig1, term0, term1, &rem0, &rem1 ); - while ( (int64_t) rem0 < 0 ) { - --zSig0; - doubleZSig0 -=3D 2; - add128( rem0, rem1, zSig0>>63, doubleZSig0 | 1, &rem0, &rem1 ); - } - zSig1 =3D estimateDiv128To64( rem1, 0, doubleZSig0 ); - if ( ( zSig1 & UINT64_C(0x3FFFFFFFFFFFFFFF) ) <=3D 5 ) { - if ( zSig1 =3D=3D 0 ) zSig1 =3D 1; - mul64To128( doubleZSig0, zSig1, &term1, &term2 ); - sub128( rem1, 0, term1, term2, &rem1, &rem2 ); - mul64To128( zSig1, zSig1, &term2, &term3 ); - sub192( rem1, rem2, 0, 0, term2, term3, &rem1, &rem2, &rem3 ); - while ( (int64_t) rem1 < 0 ) { - --zSig1; - shortShift128Left( 0, zSig1, 1, &term2, &term3 ); - term3 |=3D 1; - term2 |=3D doubleZSig0; - add192( rem1, rem2, rem3, 0, term2, term3, &rem1, &rem2, &rem3= ); - } - zSig1 |=3D ( ( rem1 | rem2 | rem3 ) !=3D 0 ); - } - shortShift128Left( 0, zSig1, 1, &zSig0, &zSig1 ); - zSig0 |=3D doubleZSig0; - return roundAndPackFloatx80(status->floatx80_rounding_precision, - 0, zExp, zSig0, zSig1, status); -} - /*------------------------------------------------------------------------= ---- | Returns the result of converting the quadruple-precision floating-point | value `a' to the extended double-precision floating-point format. The --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756869; cv=none; d=zohomail.com; s=zohoarc; b=M2r1Vfd5dxdzBfcmJ5nzj/XRFE6Nfke7xZpNF/yeYazak1QgzAZWQcASDsecMUH5P3S3lALExzKGv9kwxk7bc+NnWhWJGsYd1b9NMkXEzrNzJNMM7N1vYCxmfSkWV2akPLk5uY0VJwVUOAdFGcNl0xIEdHz4DfQ7S0YYeGrxKUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756869; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xiaeGJWLl6eo+VnxnfAKjpi1RICpcWro/dd/W10uCac=; b=CRBHZuSU8QvjfnvYOYdvHh49YBN88/RNHmILN1bj+NFVrVIebo0bTbH4ds8acUj/TkYRaW04xhc6Offs+VbZvR1a8tGqc5D1uEU/gFdT9eQxxMeuwzeh6oj+tpUm4UO9h5btfyU3HJWnV8PLgqsJmblsvVHgRWgY9hfyKUwknaw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756869753279.20029555233145; Thu, 3 Jun 2021 14:47:49 -0700 (PDT) Received: from localhost ([::1]:41602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovBs-0001je-LT for importer@patchew.org; Thu, 03 Jun 2021 17:47:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov67-0002Xq-Ey for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:51 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:40745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov62-00019F-0m for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:51 -0400 Received: by mail-pg1-x533.google.com with SMTP id j12so6159930pgh.7 for ; Thu, 03 Jun 2021 14:41:45 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:44 -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=xiaeGJWLl6eo+VnxnfAKjpi1RICpcWro/dd/W10uCac=; b=SkOxuTcJFwIo33ri2Ti2wRBTizyCiXTNfoBj+UmEySa9YiitHYXbtDr6y+YSUNBjja ssEH/DjqRHZl77xBzubgnPGP7e16lTMUmhq/aZY90hM5ZBaaxt+zgVK29I01CcobfLBT QxsMrGpHpUVZs6U8b3e9sT7uWHn1r6hvWMGViFyZwJWejkVnr2Q1roqQ50HUPrza3dDR NpAgTAdY8AQJwlcM8DYSTs/RzYK4EGv0q4xded1qevTeA/lhr7CbinzkRJe3DQqj0ues 6GN6KIf9+tjgVMXI/XGVJu18/ZVEjzq3Knlk//Y2NSStZ2qMUxDT4W7334UtQPWSVpHJ ACYQ== 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=xiaeGJWLl6eo+VnxnfAKjpi1RICpcWro/dd/W10uCac=; b=RvsRhikAu4iFCFM724ovjZxzHllhB8r/r+OlcBS3g2yLFyEYFIOrKSorp4qvOcCJj1 orlNuwwHwFMxBnpTZI4ro5Go6NxiluhTm9vx6rhPdeHv9VCtoxtuJVNK1SGUkxYD3wYg 1pJIbG2QB1ajnJZI7Oa5UsG0e8Ov6Vu+2Jk00ofNi3aNx9sPOLCuzC2JE6RSrrhxzU+M yorbCg/2lj7GuT8bYMWEW6GJ0oJzADx3DsD5t7/pjyeqNQgl8BTnK7lw8tlp9gvuxhz5 6yrnx7fBJI/cQ0x0+2JweGXjZbaqP4Wux3yJOZ/v7ZFnnXlL7z4jY6nkVMH8dyLSqhKv nMWw== X-Gm-Message-State: AOAM533/Zh9IDeu7Wts5gmsHwjl8cBd0oiFQCvkaajOpQHNDXxsUwLnj 4w0Fx790iaZQ86Qk6dWJZEjYPaAapVqWqA== X-Google-Smtp-Source: ABdhPJz2ZqIqmIojysHNs4aR37Zz0MAFQELGxQhI9sWndScQtjNZ6lNn4l9F1bXJdYBt94dsUhUwkQ== X-Received: by 2002:a63:2dc4:: with SMTP id t187mr1537722pgt.80.1622756504356; Thu, 03 Jun 2021 14:41:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 18/29] softfloat: Convert floatx80_round to FloatParts Date: Thu, 3 Jun 2021 14:41:20 -0700 Message-Id: <20210603214131.629841-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 5a320e5302..74787d5a6e 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5792,10 +5792,12 @@ float128 floatx80_to_float128(floatx80 a, float_sta= tus *status) =20 floatx80 floatx80_round(floatx80 a, float_status *status) { - return roundAndPackFloatx80(status->floatx80_rounding_precision, - extractFloatx80Sign(a), - extractFloatx80Exp(a), - extractFloatx80Frac(a), 0, status); + FloatParts128 p; + + if (!floatx80_unpack_canonical(&p, a, status)) { + return floatx80_default_nan(status); + } + return floatx80_round_pack_canonical(&p, status); } =20 /*------------------------------------------------------------------------= ---- --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622756903; cv=none; d=zohomail.com; s=zohoarc; b=ZDklm6F3R4Tlz9fyzjETljqjIxocvQhucnILL3pWYCnQwk+eCH0hlZJ+knTHRowzst+yHodE7HB6Bo3FLJ1x/uhKEUK7zYSR/WHvSoCLS/usK9/BzB9w4y0hCjL3gm4Vww9c6Au5D+YAfQdPWga2PLvsSbJulThnOBAd6VyVSKc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622756903; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fUuOVml+4w79a3bxuCGZ23LxhkzpodhkprttyZbQk2E=; b=XFrTd7fjhcgN9B/p4ytMl/nP/VdOf3NcPEMz+UlYUyZdW3AFoGNYXuioNqAGKxc8hgWDlBj0fGAYJnHcqTqsD9esWMhsVW4pdYN/TlUMSOxn7UoMo0sfON3G7zKgVpi9DXMF2yqVE1saGD1K8b/tl/88GAV7JK2zkY8YQSSoZM0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622756903653918.9808804648297; Thu, 3 Jun 2021 14:48:23 -0700 (PDT) Received: from localhost ([::1]:44398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovCQ-0003bF-KU for importer@patchew.org; Thu, 03 Jun 2021 17:48:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6A-0002do-QC for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:54 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:40900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov62-00019a-EZ for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:54 -0400 Received: by mail-pj1-x1029.google.com with SMTP id jz2-20020a17090b14c2b0290162cf0b5a35so6234952pjb.5 for ; Thu, 03 Jun 2021 14:41:46 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:44 -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=fUuOVml+4w79a3bxuCGZ23LxhkzpodhkprttyZbQk2E=; b=g63K/xb/Dkn1IpwTV0AkxycAjdOnZXPLHj4tw14bzLKwRdbChNJcmCJ/Ti08d8WDxa zxeufoRcAvvkvvZqyOyJoPRuWYIEC11gb9NpNtRfeXp4TkWkwfetsmvG5gT/O3waEML1 dduiIQxZ9K3vQAuzneIJ3tUEJfw9wSjpjkCXqtH8UWoU4Q27polpIFksc7VKMeZ485qz lwXCFqIpj1dZORMu8N8ljZtW2ECU4W/JwIP608Ba/9JBmLn8nKkoMASbh/FKvJDHAOUf ygTlAN9ciH0HeupZnW2mbGSF15WpMfMK829Bm/wBQhH5taTLIvx4qFC9LgLMXGPSW0PH ncgQ== 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=fUuOVml+4w79a3bxuCGZ23LxhkzpodhkprttyZbQk2E=; b=XI/+a+Eu09sThMisDyKQBcBajTLIjq6mYuk7PKh2o8RnIuHIYOK9WdSyhaeKxJ5BlO 7jKR4qIJmILcQmmIssS0jGwKAmmkDzMbEmOUChVKXFGoD6dVEnGdA1ao5NvNKWyzB7zv x7DkA1wPgMP/HPVmq5W9y3zgxCYdSBy+EWROC3wRBOfY2ngwlfpJJi+mkQOzHoew37eA SYVNbNLPguji7nw4CI9JncFCNbG8VSYdumSbSTwTbddr+Txi7hqf+JOVHf/RQFFsfeUd iM6rbJMOpU2IRCgHA6fKwqdahwmGZdqHTYO8A2Ic/ErEBPnJo5JxyHkcdTr3RHmXyVPV pGYg== X-Gm-Message-State: AOAM530LBTxuY7aoHtgjkH12E9tEyUjHLiNmBoTxonYKb2f4ASa1UnhF p+qk305zcwzYPGvYxLBGF5n4hJNDqyeP9Q== X-Google-Smtp-Source: ABdhPJx1UminKBa41qFHDlbSkW2bUyXkBVFwD+qptjJ20VtjzeZe+pJnODO7MvxJ9uKNtFfOqr16Ww== X-Received: by 2002:a17:902:bb92:b029:f4:4a28:3ed0 with SMTP id m18-20020a170902bb92b02900f44a283ed0mr1216920pls.48.1622756505134; Thu, 03 Jun 2021 14:41:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 19/29] softfloat: Convert floatx80_round_to_int to FloatParts Date: Thu, 3 Jun 2021 14:41:21 -0700 Message-Id: <20210603214131.629841-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 116 ++++++------------------------------------------ 1 file changed, 13 insertions(+), 103 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 74787d5a6e..9caf1ecf9c 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -2610,6 +2610,19 @@ float128 float128_round_to_int(float128 a, float_sta= tus *s) return float128_round_pack_canonical(&p, s); } =20 +floatx80 floatx80_round_to_int(floatx80 a, float_status *status) +{ + FloatParts128 p; + + if (!floatx80_unpack_canonical(&p, a, status)) { + return floatx80_default_nan(status); + } + + parts_round_to_int(&p, status->float_rounding_mode, 0, status, + &floatx80_params[status->floatx80_rounding_precisio= n]); + return floatx80_round_pack_canonical(&p, status); +} + /* * Floating-point to signed integer conversions */ @@ -5800,109 +5813,6 @@ floatx80 floatx80_round(floatx80 a, float_status *s= tatus) return floatx80_round_pack_canonical(&p, status); } =20 -/*------------------------------------------------------------------------= ---- -| Rounds the extended double-precision floating-point value `a' to an inte= ger, -| and returns the result as an extended quadruple-precision floating-point -| value. The operation is performed according to the IEC/IEEE Standard for -| Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_round_to_int(floatx80 a, float_status *status) -{ - bool aSign; - int32_t aExp; - uint64_t lastBitMask, roundBitsMask; - floatx80 z; - - if (floatx80_invalid_encoding(a)) { - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - aExp =3D extractFloatx80Exp( a ); - if ( 0x403E <=3D aExp ) { - if ( ( aExp =3D=3D 0x7FFF ) && (uint64_t) ( extractFloatx80Frac( a= )<<1 ) ) { - return propagateFloatx80NaN(a, a, status); - } - return a; - } - if ( aExp < 0x3FFF ) { - if ( ( aExp =3D=3D 0 ) - && ( (uint64_t) ( extractFloatx80Frac( a ) ) =3D=3D 0 ) ) { - return a; - } - float_raise(float_flag_inexact, status); - aSign =3D extractFloatx80Sign( a ); - switch (status->float_rounding_mode) { - case float_round_nearest_even: - if ( ( aExp =3D=3D 0x3FFE ) && (uint64_t) ( extractFloatx80Fra= c( a )<<1 ) - ) { - return - packFloatx80( aSign, 0x3FFF, UINT64_C(0x80000000000000= 00)); - } - break; - case float_round_ties_away: - if (aExp =3D=3D 0x3FFE) { - return packFloatx80(aSign, 0x3FFF, UINT64_C(0x800000000000= 0000)); - } - break; - case float_round_down: - return - aSign ? - packFloatx80( 1, 0x3FFF, UINT64_C(0x8000000000000000= )) - : packFloatx80( 0, 0, 0 ); - case float_round_up: - return - aSign ? packFloatx80( 1, 0, 0 ) - : packFloatx80( 0, 0x3FFF, UINT64_C(0x8000000000000000)); - - case float_round_to_zero: - break; - default: - g_assert_not_reached(); - } - return packFloatx80( aSign, 0, 0 ); - } - lastBitMask =3D 1; - lastBitMask <<=3D 0x403E - aExp; - roundBitsMask =3D lastBitMask - 1; - z =3D a; - switch (status->float_rounding_mode) { - case float_round_nearest_even: - z.low +=3D lastBitMask>>1; - if ((z.low & roundBitsMask) =3D=3D 0) { - z.low &=3D ~lastBitMask; - } - break; - case float_round_ties_away: - z.low +=3D lastBitMask >> 1; - break; - case float_round_to_zero: - break; - case float_round_up: - if (!extractFloatx80Sign(z)) { - z.low +=3D roundBitsMask; - } - break; - case float_round_down: - if (extractFloatx80Sign(z)) { - z.low +=3D roundBitsMask; - } - break; - default: - abort(); - } - z.low &=3D ~ roundBitsMask; - if ( z.low =3D=3D 0 ) { - ++z.high; - z.low =3D UINT64_C(0x8000000000000000); - } - if (z.low !=3D a.low) { - float_raise(float_flag_inexact, status); - } - return z; - -} - /*------------------------------------------------------------------------= ---- | Returns the remainder of the extended double-precision floating-point va= lue | `a' with respect to the corresponding value `b'. The operation is perfo= rmed --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757516; cv=none; d=zohomail.com; s=zohoarc; b=Ck89JcEEW6bBorDMXshf6WXd8xSzTvWuCxEDsg/CqteXtWWPs5qZ52J+FqrA6OYl9vdEYU8lKP3GjMDg8eV1m+0OfL6+wpXn37aorbEE002XpsxbSRqDpE8foy7e24EgsYZR0JLmFuVwOFbKBJVnh0BlkYbTOpM2Wf/f0/5Q4ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757516; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KMHyBtePJctFFVLhiljAsXW1cd3DwdhgWcEK6bYLQDk=; b=gYfu8JceLVn/wLHX3de8gz7el7DiOK3KIgLPeLDmFWFVHodLHf+5/0SiC0V9QcEIsllnwcS43YxzU85u6g64UbfIH3us3tDniKOItrgv1GchV5z5j9/U79vpGgPxwRiCHlhP0SosZ3VBqz4lqeNx12Fay7Qu8jBcs6ozO3up6Tk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757516752135.92160482678082; Thu, 3 Jun 2021 14:58:36 -0700 (PDT) Received: from localhost ([::1]:57924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovMJ-0006Ev-B8 for importer@patchew.org; Thu, 03 Jun 2021 17:58:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58520) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6F-0002pn-6T for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:59 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:47034) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov63-00019h-NI for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:58 -0400 Received: by mail-pf1-x435.google.com with SMTP id u126so1936059pfu.13 for ; Thu, 03 Jun 2021 14:41:46 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:45 -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=KMHyBtePJctFFVLhiljAsXW1cd3DwdhgWcEK6bYLQDk=; b=JRpLLMtdiRutBWGRjBoQ5FVYOqY+o9dGY+FOgAROcQ2hv1+bqJZ9XzipCMgER2RvNL odT0UAkgNuL36jYvoJmFJUnEWO1yPfKbYzc62OWwqTO5k5VY3FZWPPd0brBmetg8hhBK b0aNdvBzSQ9wPtLbQTboEzTWwfcIyElbwFlH5eNxOfrG+hGdNCuIuey1e+pAJQVdXKWM xpfh1mnWWHDuCBEf5viEg4qNbJfGxoylHDdNQc9aih7srm/aXXgxj205RfeHCG3XRbPI KFr2b9dIWoH3aBSlBEYqbUkBdGQfp3rqu2HziW5n1/zBu8mJF0cxrezLSUvGySjqsMvf kyBA== 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=KMHyBtePJctFFVLhiljAsXW1cd3DwdhgWcEK6bYLQDk=; b=W09kyp2w75Y620Se5kr0eS2QzcE/PzODmx9YloyuANsanAJIuWAurvwTwqwNXrM1n5 ZOUlkjVOkLyPHVOdhmQ1aBbbnJFE66jUti+WOPjG7Qr78xdc8o8PgtNX303j00s1o/Rx p2HRGysmVCWLCNBx4erxa2nC/jUID4LbvkRdnFchtrtOQEZOX1pj2GmhwnJJXZCWemmc ZOV6QB0Dc4/BFZDvm1mOZSuViestjuSmrjEXFjoSWa/AbM18Yoh/ADRV6xW1SM+TOVbw 0TbOUzfJWWffbuLbBs+mTacYtibtDAEBTYbtZTx3ytGx1IBnCwU5qeFG54jWsXIwehKF +bwQ== X-Gm-Message-State: AOAM531C6i3QA8/ModJILKnBkcOVI+6qYkL8/1V3IdN+ugo90VZLejLx b1EnrPal4lLcrvKQQSQDXwfV1k+P4F/mKw== X-Google-Smtp-Source: ABdhPJyA9sc5eNSW7jO6cqh6fwUTJwAX5i4VclmCtLWWoHw2FKgJdzGAHeW8t8HpAzOxhBgPhG6Skw== X-Received: by 2002:a63:914b:: with SMTP id l72mr1495174pge.99.1622756505694; Thu, 03 Jun 2021 14:41:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 20/29] softfloat: Convert integer to floatx80 to FloatParts Date: Thu, 3 Jun 2021 14:41:22 -0700 Message-Id: <20210603214131.629841-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 58 +++++++++++-------------------------------------- 1 file changed, 13 insertions(+), 45 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 9caf1ecf9c..be7583780d 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3345,6 +3345,19 @@ float128 int32_to_float128(int32_t a, float_status *= status) return int64_to_float128(a, status); } =20 +floatx80 int64_to_floatx80(int64_t a, float_status *status) +{ + FloatParts128 p; + + parts_sint_to_float(&p, a, 0, status); + return floatx80_round_pack_canonical(&p, status); +} + +floatx80 int32_to_floatx80(int32_t a, float_status *status) +{ + return int64_to_floatx80(a, status); +} + /* * Unsigned Integer to floating-point conversions */ @@ -5033,51 +5046,6 @@ static float128 normalizeRoundAndPackFloat128(bool z= Sign, int32_t zExp, =20 } =20 - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the 32-bit two's complement integer `a' -| to the extended double-precision floating-point format. The conversion -| is performed according to the IEC/IEEE Standard for Binary Floating-Point -| Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 int32_to_floatx80(int32_t a, float_status *status) -{ - bool zSign; - uint32_t absA; - int8_t shiftCount; - uint64_t zSig; - - if ( a =3D=3D 0 ) return packFloatx80( 0, 0, 0 ); - zSign =3D ( a < 0 ); - absA =3D zSign ? - a : a; - shiftCount =3D clz32(absA) + 32; - zSig =3D absA; - return packFloatx80( zSign, 0x403E - shiftCount, zSig< (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757025136333.1790438982356; Thu, 3 Jun 2021 14:50:25 -0700 (PDT) Received: from localhost ([::1]:53078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovEN-0000va-WC for importer@patchew.org; Thu, 03 Jun 2021 17:50:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6E-0002n6-BW for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:58 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:46710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov65-00019t-Df for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:58 -0400 Received: by mail-pg1-x52a.google.com with SMTP id n12so6135335pgs.13 for ; Thu, 03 Jun 2021 14:41:47 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:46 -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=twxGPFxgWB1P5xQ1RYx4pfDaFXjrIGQz83jyD9yknr8=; b=Aml6nMmyEnTkoq2DjSRWzEHpIbXUJXJjdaiDZvE2JF4e+QwJBF0mZ6gUgaIXLFtxjY x5eNLIZtz2Re5GEp0snW/Ggr9XDUZ6IyhCMWSTBIE6swRyNvWNA6LeRmSbqgg2WzdzPp 2OVdWekRZ+kS+ejbAAkh7WCP6IoeyREbkAGwh0oQdgu+pqKJL1tp3apfmKv1DViWLFpj 9CvLtx02t5ULn+MHhf0ffYkKTgM27Wg4bFOY8o2eaCP4+vKdXCMBgScRxefEU8R6tj61 QADPJLVSK+o+6Pus591cQ0Ef3GOcY8WVKWy/aGqVmMt14HRLylPCEMZ7UUgNbAtecfb2 KImg== 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=twxGPFxgWB1P5xQ1RYx4pfDaFXjrIGQz83jyD9yknr8=; b=E8P4nm15bm0swbvME+yri9f5UYn6DRKY4wy1lPpJr+h08D0fg5KcCHsdcYiDifZ62O JCqaKYaC/Re9sVDiHkbafh4s4ofFYN/zCORQ8RpOn5YYxAcUQ5XidQJ659TSWhv/yIqp Wv2kQ2WCbbB/UKYU2nZy31nHN2/nZw4n6R1MZL1MAYBFiRw69nP4bPKM5X4aExlIAeJi /SKTYXdpcbevx+LaK6/X6H9jFJrdnTADRxXARJhCDlfxDD0eOWi1K1xgW91MvZ+7lbWC 6DjjMMFOhtXvI7d4a7fa9qvPn96/L5ACUqoN+6YjLg+joOI+Z95o6WWKsOHiArC3xQjW Ed8A== X-Gm-Message-State: AOAM530W82+OXN2pANZ5Q2TTmO1uCfqPutEm9kWOiWy/NNimnznVNW7o SLBufaDAdfyWA5YKc+HZjtH3kHgtbwxR/w== X-Google-Smtp-Source: ABdhPJwwV3b9vf5ZcpTQljpzEYTdHpwG2H/30VcyLkSiTc3shdVDzT8Lttu3bhnEDxta+gb/Nj8JkA== X-Received: by 2002:a63:7e11:: with SMTP id z17mr1479444pgc.9.1622756506431; Thu, 03 Jun 2021 14:41:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 21/29] softfloat: Convert floatx80 float conversions to FloatParts Date: Thu, 3 Jun 2021 14:41:23 -0700 Message-Id: <20210603214131.629841-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) This is the last use of commonNaNT and all of the routines that use it, so remove all of them for Werror. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 276 ++++++++------------------------- fpu/softfloat-specialize.c.inc | 175 --------------------- 2 files changed, 67 insertions(+), 384 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index be7583780d..acaab6a127 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -2561,6 +2561,73 @@ float128 float64_to_float128(float64 a, float_status= *s) return float128_round_pack_canonical(&p128, s); } =20 +float32 floatx80_to_float32(floatx80 a, float_status *s) +{ + FloatParts64 p64; + FloatParts128 p128; + + if (floatx80_unpack_canonical(&p128, a, s)) { + parts_float_to_float_narrow(&p64, &p128, s); + } else { + parts_default_nan(&p64, s); + } + return float32_round_pack_canonical(&p64, s); +} + +float64 floatx80_to_float64(floatx80 a, float_status *s) +{ + FloatParts64 p64; + FloatParts128 p128; + + if (floatx80_unpack_canonical(&p128, a, s)) { + parts_float_to_float_narrow(&p64, &p128, s); + } else { + parts_default_nan(&p64, s); + } + return float64_round_pack_canonical(&p64, s); +} + +float128 floatx80_to_float128(floatx80 a, float_status *s) +{ + FloatParts128 p; + + if (floatx80_unpack_canonical(&p, a, s)) { + parts_float_to_float(&p, s); + } else { + parts_default_nan(&p, s); + } + return float128_round_pack_canonical(&p, s); +} + +floatx80 float32_to_floatx80(float32 a, float_status *s) +{ + FloatParts64 p64; + FloatParts128 p128; + + float32_unpack_canonical(&p64, a, s); + parts_float_to_float_widen(&p128, &p64, s); + return floatx80_round_pack_canonical(&p128, s); +} + +floatx80 float64_to_floatx80(float64 a, float_status *s) +{ + FloatParts64 p64; + FloatParts128 p128; + + float64_unpack_canonical(&p64, a, s); + parts_float_to_float_widen(&p128, &p64, s); + return floatx80_round_pack_canonical(&p128, s); +} + +floatx80 float128_to_floatx80(float128 a, float_status *s) +{ + FloatParts128 p; + + float128_unpack_canonical(&p, a, s); + parts_float_to_float(&p, s); + return floatx80_round_pack_canonical(&p, s); +} + /* * Round to integral value */ @@ -5046,42 +5113,6 @@ static float128 normalizeRoundAndPackFloat128(bool z= Sign, int32_t zExp, =20 } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the single-precision floating-point val= ue -| `a' to the extended double-precision floating-point format. The convers= ion -| is performed according to the IEC/IEEE Standard for Binary Floating-Point -| Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 float32_to_floatx80(float32 a, float_status *status) -{ - bool aSign; - int aExp; - uint32_t aSig; - - a =3D float32_squash_input_denormal(a, status); - aSig =3D extractFloat32Frac( a ); - aExp =3D extractFloat32Exp( a ); - aSign =3D extractFloat32Sign( a ); - if ( aExp =3D=3D 0xFF ) { - if (aSig) { - floatx80 res =3D commonNaNToFloatx80(float32ToCommonNaN(a, sta= tus), - status); - return floatx80_silence_nan(res, status); - } - return packFloatx80(aSign, - floatx80_infinity_high, - floatx80_infinity_low); - } - if ( aExp =3D=3D 0 ) { - if ( aSig =3D=3D 0 ) return packFloatx80( aSign, 0, 0 ); - normalizeFloat32Subnormal( aSig, &aExp, &aSig ); - } - aSig |=3D 0x00800000; - return packFloatx80( aSign, aExp + 0x3F80, ( (uint64_t) aSig )<<40 ); - -} - /*------------------------------------------------------------------------= ---- | Returns the remainder of the single-precision floating-point value `a' | with respect to the corresponding value `b'. The operation is performed @@ -5318,43 +5349,6 @@ float32 float32_log2(float32 a, float_status *status) return normalizeRoundAndPackFloat32(zSign, 0x85, zSig, status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the double-precision floating-point val= ue -| `a' to the extended double-precision floating-point format. The convers= ion -| is performed according to the IEC/IEEE Standard for Binary Floating-Point -| Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 float64_to_floatx80(float64 a, float_status *status) -{ - bool aSign; - int aExp; - uint64_t aSig; - - a =3D float64_squash_input_denormal(a, status); - aSig =3D extractFloat64Frac( a ); - aExp =3D extractFloat64Exp( a ); - aSign =3D extractFloat64Sign( a ); - if ( aExp =3D=3D 0x7FF ) { - if (aSig) { - floatx80 res =3D commonNaNToFloatx80(float64ToCommonNaN(a, sta= tus), - status); - return floatx80_silence_nan(res, status); - } - return packFloatx80(aSign, - floatx80_infinity_high, - floatx80_infinity_low); - } - if ( aExp =3D=3D 0 ) { - if ( aSig =3D=3D 0 ) return packFloatx80( aSign, 0, 0 ); - normalizeFloat64Subnormal( aSig, &aExp, &aSig ); - } - return - packFloatx80( - aSign, aExp + 0x3C00, (aSig | UINT64_C(0x0010000000000000)) <<= 11); - -} - /*------------------------------------------------------------------------= ---- | Returns the remainder of the double-precision floating-point value `a' | with respect to the corresponding value `b'. The operation is performed @@ -5665,104 +5659,6 @@ int64_t floatx80_to_int64_round_to_zero(floatx80 a,= float_status *status) =20 } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the extended double-precision floating- -| point value `a' to the single-precision floating-point format. The -| conversion is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float32 floatx80_to_float32(floatx80 a, float_status *status) -{ - bool aSign; - int32_t aExp; - uint64_t aSig; - - if (floatx80_invalid_encoding(a)) { - float_raise(float_flag_invalid, status); - return float32_default_nan(status); - } - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - if ( aExp =3D=3D 0x7FFF ) { - if ( (uint64_t) ( aSig<<1 ) ) { - float32 res =3D commonNaNToFloat32(floatx80ToCommonNaN(a, stat= us), - status); - return float32_silence_nan(res, status); - } - return packFloat32( aSign, 0xFF, 0 ); - } - shift64RightJamming( aSig, 33, &aSig ); - if ( aExp || aSig ) aExp -=3D 0x3F81; - return roundAndPackFloat32(aSign, aExp, aSig, status); - -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the extended double-precision floating- -| point value `a' to the double-precision floating-point format. The -| conversion is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float64 floatx80_to_float64(floatx80 a, float_status *status) -{ - bool aSign; - int32_t aExp; - uint64_t aSig, zSig; - - if (floatx80_invalid_encoding(a)) { - float_raise(float_flag_invalid, status); - return float64_default_nan(status); - } - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - if ( aExp =3D=3D 0x7FFF ) { - if ( (uint64_t) ( aSig<<1 ) ) { - float64 res =3D commonNaNToFloat64(floatx80ToCommonNaN(a, stat= us), - status); - return float64_silence_nan(res, status); - } - return packFloat64( aSign, 0x7FF, 0 ); - } - shift64RightJamming( aSig, 1, &zSig ); - if ( aExp || aSig ) aExp -=3D 0x3C01; - return roundAndPackFloat64(aSign, aExp, zSig, status); - -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the extended double-precision floating- -| point value `a' to the quadruple-precision floating-point format. The -| conversion is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float128 floatx80_to_float128(floatx80 a, float_status *status) -{ - bool aSign; - int aExp; - uint64_t aSig, zSig0, zSig1; - - if (floatx80_invalid_encoding(a)) { - float_raise(float_flag_invalid, status); - return float128_default_nan(status); - } - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - if ( ( aExp =3D=3D 0x7FFF ) && (uint64_t) ( aSig<<1 ) ) { - float128 res =3D commonNaNToFloat128(floatx80ToCommonNaN(a, status= ), - status); - return float128_silence_nan(res, status); - } - shift128Right( aSig<<1, 0, 16, &zSig0, &zSig1 ); - return packFloat128( aSign, aExp, zSig0, zSig1 ); - -} - /*------------------------------------------------------------------------= ---- | Rounds the extended double-precision floating-point value `a' | to the precision provided by floatx80_rounding_precision and returns the @@ -5935,44 +5831,6 @@ floatx80 floatx80_mod(floatx80 a, floatx80 b, float_= status *status) return floatx80_modrem(a, b, true, "ient, status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the quadruple-precision floating-point -| value `a' to the extended double-precision floating-point format. The -| conversion is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 float128_to_floatx80(float128 a, float_status *status) -{ - bool aSign; - int32_t aExp; - uint64_t aSig0, aSig1; - - aSig1 =3D extractFloat128Frac1( a ); - aSig0 =3D extractFloat128Frac0( a ); - aExp =3D extractFloat128Exp( a ); - aSign =3D extractFloat128Sign( a ); - if ( aExp =3D=3D 0x7FFF ) { - if ( aSig0 | aSig1 ) { - floatx80 res =3D commonNaNToFloatx80(float128ToCommonNaN(a, st= atus), - status); - return floatx80_silence_nan(res, status); - } - return packFloatx80(aSign, floatx80_infinity_high, - floatx80_infinity_low); - } - if ( aExp =3D=3D 0 ) { - if ( ( aSig0 | aSig1 ) =3D=3D 0 ) return packFloatx80( aSign, 0, 0= ); - normalizeFloat128Subnormal( aSig0, aSig1, &aExp, &aSig0, &aSig1 ); - } - else { - aSig0 |=3D UINT64_C(0x0001000000000000); - } - shortShift128Left( aSig0, aSig1, 15, &aSig0, &aSig1 ); - return roundAndPackFloatx80(80, aSign, aExp, aSig0, aSig1, status); - -} - /*------------------------------------------------------------------------= ---- | Returns the remainder of the quadruple-precision floating-point value `a' | with respect to the corresponding value `b'. The operation is performed diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc index c895733e79..95e5325f67 100644 --- a/fpu/softfloat-specialize.c.inc +++ b/fpu/softfloat-specialize.c.inc @@ -256,14 +256,6 @@ floatx80 floatx80_default_nan(float_status *status) const floatx80 floatx80_infinity =3D make_floatx80_init(floatx80_infinity_high, floatx80_infinity_low); =20 -/*------------------------------------------------------------------------= ---- -| Internal canonical NaN format. -*-------------------------------------------------------------------------= ---*/ -typedef struct { - bool sign; - uint64_t high, low; -} commonNaNT; - /*------------------------------------------------------------------------= ---- | Returns 1 if the half-precision floating-point value `a' is a quiet | NaN; otherwise returns 0. @@ -379,46 +371,6 @@ bool float32_is_signaling_nan(float32 a_, float_status= *status) } } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the single-precision floating-point NaN -| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid -| exception is raised. -*-------------------------------------------------------------------------= ---*/ - -static commonNaNT float32ToCommonNaN(float32 a, float_status *status) -{ - commonNaNT z; - - if (float32_is_signaling_nan(a, status)) { - float_raise(float_flag_invalid, status); - } - z.sign =3D float32_val(a) >> 31; - z.low =3D 0; - z.high =3D ((uint64_t)float32_val(a)) << 41; - return z; -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the canonical NaN `a' to the single- -| precision floating-point format. -*-------------------------------------------------------------------------= ---*/ - -static float32 commonNaNToFloat32(commonNaNT a, float_status *status) -{ - uint32_t mantissa =3D a.high >> 41; - - if (status->default_nan_mode) { - return float32_default_nan(status); - } - - if (mantissa) { - return make_float32( - (((uint32_t)a.sign) << 31) | 0x7F800000 | (a.high >> 41)); - } else { - return float32_default_nan(status); - } -} - /*------------------------------------------------------------------------= ---- | Select which NaN to propagate for a two-input operation. | IEEE754 doesn't specify all the details of this, so the @@ -785,48 +737,6 @@ bool float64_is_signaling_nan(float64 a_, float_status= *status) } } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the double-precision floating-point NaN -| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid -| exception is raised. -*-------------------------------------------------------------------------= ---*/ - -static commonNaNT float64ToCommonNaN(float64 a, float_status *status) -{ - commonNaNT z; - - if (float64_is_signaling_nan(a, status)) { - float_raise(float_flag_invalid, status); - } - z.sign =3D float64_val(a) >> 63; - z.low =3D 0; - z.high =3D float64_val(a) << 12; - return z; -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the canonical NaN `a' to the double- -| precision floating-point format. -*-------------------------------------------------------------------------= ---*/ - -static float64 commonNaNToFloat64(commonNaNT a, float_status *status) -{ - uint64_t mantissa =3D a.high >> 12; - - if (status->default_nan_mode) { - return float64_default_nan(status); - } - - if (mantissa) { - return make_float64( - (((uint64_t) a.sign) << 63) - | UINT64_C(0x7FF0000000000000) - | (a.high >> 12)); - } else { - return float64_default_nan(status); - } -} - /*------------------------------------------------------------------------= ---- | Takes two double-precision floating-point values `a' and `b', one of whi= ch | is a NaN, and returns the appropriate NaN result. If either `a' or `b' = is a @@ -946,55 +856,6 @@ floatx80 floatx80_silence_nan(floatx80 a, float_status= *status) return a; } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the extended double-precision floating- -| point NaN `a' to the canonical NaN format. If `a' is a signaling NaN, t= he -| invalid exception is raised. -*-------------------------------------------------------------------------= ---*/ - -static commonNaNT floatx80ToCommonNaN(floatx80 a, float_status *status) -{ - floatx80 dflt; - commonNaNT z; - - if (floatx80_is_signaling_nan(a, status)) { - float_raise(float_flag_invalid, status); - } - if (a.low >> 63) { - z.sign =3D a.high >> 15; - z.low =3D 0; - z.high =3D a.low << 1; - } else { - dflt =3D floatx80_default_nan(status); - z.sign =3D dflt.high >> 15; - z.low =3D 0; - z.high =3D dflt.low << 1; - } - return z; -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the canonical NaN `a' to the extended -| double-precision floating-point format. -*-------------------------------------------------------------------------= ---*/ - -static floatx80 commonNaNToFloatx80(commonNaNT a, float_status *status) -{ - floatx80 z; - - if (status->default_nan_mode) { - return floatx80_default_nan(status); - } - - if (a.high >> 1) { - z.low =3D UINT64_C(0x8000000000000000) | a.high >> 1; - z.high =3D (((uint16_t)a.sign) << 15) | 0x7FFF; - } else { - z =3D floatx80_default_nan(status); - } - return z; -} - /*------------------------------------------------------------------------= ---- | Takes two extended double-precision floating-point values `a' and `b', o= ne | of which is a NaN, and returns the appropriate NaN result. If either `a= ' or @@ -1087,42 +948,6 @@ bool float128_is_signaling_nan(float128 a, float_stat= us *status) } } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the quadruple-precision floating-point = NaN -| `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid -| exception is raised. -*-------------------------------------------------------------------------= ---*/ - -static commonNaNT float128ToCommonNaN(float128 a, float_status *status) -{ - commonNaNT z; - - if (float128_is_signaling_nan(a, status)) { - float_raise(float_flag_invalid, status); - } - z.sign =3D a.high >> 63; - shortShift128Left(a.high, a.low, 16, &z.high, &z.low); - return z; -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the canonical NaN `a' to the quadruple- -| precision floating-point format. -*-------------------------------------------------------------------------= ---*/ - -static float128 commonNaNToFloat128(commonNaNT a, float_status *status) -{ - float128 z; - - if (status->default_nan_mode) { - return float128_default_nan(status); - } - - shift128Right(a.high, a.low, 16, &z.high, &z.low); - z.high |=3D (((uint64_t)a.sign) << 63) | UINT64_C(0x7FFF000000000000); - return z; -} - /*------------------------------------------------------------------------= ---- | Takes two quadruple-precision floating-point values `a' and `b', one of | which is a NaN, and returns the appropriate NaN result. If either `a' or --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757430; cv=none; d=zohomail.com; s=zohoarc; b=EQ/IV1GgoOHf96Z84J8gAb3/XQabnS7oHwqu+TfJeziYsDGBeM5s8bC1FfsXnMKkxBumPQOmYC3ZERt44XxqRM0AZS1HNQaem+CCrFw71F7RRYKTYjLvBd62AQ2avTc+JC66ofyVVV3aOPp+oHWy+XK8FkYtyGlTDi4aJGr8or8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757430; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eDlW17rU8x/GJbEZkz3v/6Nuf9ddIpOuVKL6VdfQvSc=; b=mYT4KwbD/zWCYYXcYvlg4KB/8Xb6vEVwR6LDLXo6knSn3asiXBcg0iNvujCvJhtTeg2G3Svod8wqzxDaur3U/1cwj4d3os1XdAoMIVQUuQ6R91wggkr8px17gU2g/XPNzndEaFLmZX/9ZWn2pav5GQ19tQbwvkkgx9wuxc0Kw7w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757430328464.89848095208345; Thu, 3 Jun 2021 14:57:10 -0700 (PDT) Received: from localhost ([::1]:53534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovKv-0003HX-5I for importer@patchew.org; Thu, 03 Jun 2021 17:57:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6E-0002mB-0e for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:58 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:43698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov65-00019x-Dn for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:57 -0400 Received: by mail-pj1-x102d.google.com with SMTP id l10-20020a17090a150ab0290162974722f2so4698503pja.2 for ; Thu, 03 Jun 2021 14:41:48 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:46 -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=eDlW17rU8x/GJbEZkz3v/6Nuf9ddIpOuVKL6VdfQvSc=; b=B1jqC3pH0WXJBFPhb9AbXf2X67Cd/mvjZfX7Ir1wV1+ZnKOfLdy/+gu4Jmrj6D8Whg XugecYvY54nL4j6SVaI1Jo+m3jmCSd/UR/I8HkieRhXkQJ04TxrPIPaQACRqN8GCq8BR fuQ1hkzPv6fv4zrl6SdkiEvahMtIpa2hYCX7Y5gzomBTcIdK5aE/T2sq/i4usqciqhds MrLvMe3D/WYim8YOEHiwYld0k83a+TbUxUOHhPHmEg/xePYRmxWABpJ44SEh5pzV9XYo +2qGh+pY201pAgLh+7nHJpUxBXa+Uw0QIsmQt7GpXw4QSt8XShY7OMlkfe4CzO08H9Ae WH0A== 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=eDlW17rU8x/GJbEZkz3v/6Nuf9ddIpOuVKL6VdfQvSc=; b=B0Lc6UvK2yva3mO8oGKBvQNA3E013GLJggxJbYzqjSu0kAGwoj4Fod0V4DGHGn0z93 FHELoTP27qysNjheuTK5H7qIrew+BaAqmsfjsaXFg1/J6LlX+/3dYkWR4RqiFKDoWd+z mWW5VfbPYGINw60H1Z2gH67swvpBFSGXYb05ly35QNormj7y7pcD1Os27SzAGUQRgDF0 hAezcu3hj2uk3aExkquc7l2ny8B07yIafHlYECMoQyy1ypztbZGHHuJC8R4TDhw8/A/X LjApuQlPvN/dYfLEXnE6YehUhddN2SnT73mPJ8HZfonr2w437UinRgwtqhgKvIZvfcnW yTnA== X-Gm-Message-State: AOAM5316TpPkAP6sIG1Bz/L289v+QJdMhnCLY8WGjeiv3P3rke0DNl7i 7+fUh++8HXJ0PZoT+pfdzag1ZA0RkFS00A== X-Google-Smtp-Source: ABdhPJykl6ATaiz7M2EQyGJG+GxvqO0xUISIWzPUBtdiYKq8E0pUxJ/9EZykmBigsLbplUOzt4s36A== X-Received: by 2002:a17:902:d643:b029:ef:62cd:eeed with SMTP id y3-20020a170902d643b02900ef62cdeeedmr1120652plh.42.1622756507220; Thu, 03 Jun 2021 14:41:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 22/29] softfloat: Convert floatx80 to integer to FloatParts Date: Thu, 3 Jun 2021 14:41:24 -0700 Message-Id: <20210603214131.629841-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 336 ++++++------------------------------------------ 1 file changed, 42 insertions(+), 294 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index acaab6a127..5a2a872408 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -2829,6 +2829,28 @@ static int64_t float128_to_int64_scalbn(float128 a, = FloatRoundMode rmode, return parts_float_to_sint(&p, rmode, scale, INT64_MIN, INT64_MAX, s); } =20 +static int32_t floatx80_to_int32_scalbn(floatx80 a, FloatRoundMode rmode, + int scale, float_status *s) +{ + FloatParts128 p; + + if (!floatx80_unpack_canonical(&p, a, s)) { + parts_default_nan(&p, s); + } + return parts_float_to_sint(&p, rmode, scale, INT32_MIN, INT32_MAX, s); +} + +static int64_t floatx80_to_int64_scalbn(floatx80 a, FloatRoundMode rmode, + int scale, float_status *s) +{ + FloatParts128 p; + + if (!floatx80_unpack_canonical(&p, a, s)) { + parts_default_nan(&p, s); + } + return parts_float_to_sint(&p, rmode, scale, INT64_MIN, INT64_MAX, s); +} + int8_t float16_to_int8(float16 a, float_status *s) { return float16_to_int8_scalbn(a, s->float_rounding_mode, 0, s); @@ -2889,6 +2911,16 @@ int64_t float128_to_int64(float128 a, float_status *= s) return float128_to_int64_scalbn(a, s->float_rounding_mode, 0, s); } =20 +int32_t floatx80_to_int32(floatx80 a, float_status *s) +{ + return floatx80_to_int32_scalbn(a, s->float_rounding_mode, 0, s); +} + +int64_t floatx80_to_int64(floatx80 a, float_status *s) +{ + return floatx80_to_int64_scalbn(a, s->float_rounding_mode, 0, s); +} + int16_t float16_to_int16_round_to_zero(float16 a, float_status *s) { return float16_to_int16_scalbn(a, float_round_to_zero, 0, s); @@ -2944,6 +2976,16 @@ int64_t float128_to_int64_round_to_zero(float128 a, = float_status *s) return float128_to_int64_scalbn(a, float_round_to_zero, 0, s); } =20 +int32_t floatx80_to_int32_round_to_zero(floatx80 a, float_status *s) +{ + return floatx80_to_int32_scalbn(a, float_round_to_zero, 0, s); +} + +int64_t floatx80_to_int64_round_to_zero(floatx80 a, float_status *s) +{ + return floatx80_to_int64_scalbn(a, float_round_to_zero, 0, s); +} + int16_t bfloat16_to_int16(bfloat16 a, float_status *s) { return bfloat16_to_int16_scalbn(a, s->float_rounding_mode, 0, s); @@ -4160,127 +4202,6 @@ bfloat16 bfloat16_squash_input_denormal(bfloat16 a,= float_status *status) return a; } =20 -/*------------------------------------------------------------------------= ---- -| Takes a 64-bit fixed-point value `absZ' with binary point between bits 6 -| and 7, and returns the properly rounded 32-bit integer corresponding to = the -| input. If `zSign' is 1, the input is negated before being converted to = an -| integer. Bit 63 of `absZ' must be zero. Ordinarily, the fixed-point in= put -| is simply rounded to an integer, with the inexact exception raised if the -| input cannot be represented exactly as an integer. However, if the fixe= d- -| point input is too large, the invalid exception is raised and the largest -| positive or negative integer is returned. -*-------------------------------------------------------------------------= ---*/ - -static int32_t roundAndPackInt32(bool zSign, uint64_t absZ, - float_status *status) -{ - int8_t roundingMode; - bool roundNearestEven; - int8_t roundIncrement, roundBits; - int32_t z; - - roundingMode =3D status->float_rounding_mode; - roundNearestEven =3D ( roundingMode =3D=3D float_round_nearest_even ); - switch (roundingMode) { - case float_round_nearest_even: - case float_round_ties_away: - roundIncrement =3D 0x40; - break; - case float_round_to_zero: - roundIncrement =3D 0; - break; - case float_round_up: - roundIncrement =3D zSign ? 0 : 0x7f; - break; - case float_round_down: - roundIncrement =3D zSign ? 0x7f : 0; - break; - case float_round_to_odd: - roundIncrement =3D absZ & 0x80 ? 0 : 0x7f; - break; - default: - abort(); - } - roundBits =3D absZ & 0x7F; - absZ =3D ( absZ + roundIncrement )>>7; - if (!(roundBits ^ 0x40) && roundNearestEven) { - absZ &=3D ~1; - } - z =3D absZ; - if ( zSign ) z =3D - z; - if ( ( absZ>>32 ) || ( z && ( ( z < 0 ) ^ zSign ) ) ) { - float_raise(float_flag_invalid, status); - return zSign ? INT32_MIN : INT32_MAX; - } - if (roundBits) { - float_raise(float_flag_inexact, status); - } - return z; - -} - -/*------------------------------------------------------------------------= ---- -| Takes the 128-bit fixed-point value formed by concatenating `absZ0' and -| `absZ1', with binary point between bits 63 and 64 (between the input wor= ds), -| and returns the properly rounded 64-bit integer corresponding to the inp= ut. -| If `zSign' is 1, the input is negated before being converted to an integ= er. -| Ordinarily, the fixed-point input is simply rounded to an integer, with -| the inexact exception raised if the input cannot be represented exactly = as -| an integer. However, if the fixed-point input is too large, the invalid -| exception is raised and the largest positive or negative integer is -| returned. -*-------------------------------------------------------------------------= ---*/ - -static int64_t roundAndPackInt64(bool zSign, uint64_t absZ0, uint64_t absZ= 1, - float_status *status) -{ - int8_t roundingMode; - bool roundNearestEven, increment; - int64_t z; - - roundingMode =3D status->float_rounding_mode; - roundNearestEven =3D ( roundingMode =3D=3D float_round_nearest_even ); - switch (roundingMode) { - case float_round_nearest_even: - case float_round_ties_away: - increment =3D ((int64_t) absZ1 < 0); - break; - case float_round_to_zero: - increment =3D 0; - break; - case float_round_up: - increment =3D !zSign && absZ1; - break; - case float_round_down: - increment =3D zSign && absZ1; - break; - case float_round_to_odd: - increment =3D !(absZ0 & 1) && absZ1; - break; - default: - abort(); - } - if ( increment ) { - ++absZ0; - if ( absZ0 =3D=3D 0 ) goto overflow; - if (!(absZ1 << 1) && roundNearestEven) { - absZ0 &=3D ~1; - } - } - z =3D absZ0; - if ( zSign ) z =3D - z; - if ( z && ( ( z < 0 ) ^ zSign ) ) { - overflow: - float_raise(float_flag_invalid, status); - return zSign ? INT64_MIN : INT64_MAX; - } - if (absZ1) { - float_raise(float_flag_inexact, status); - } - return z; - -} - /*------------------------------------------------------------------------= ---- | Normalizes the subnormal single-precision floating-point value represent= ed | by the denormalized significand `aSig'. The normalized exponent and @@ -5486,179 +5407,6 @@ float64 float64_log2(float64 a, float_status *statu= s) return normalizeRoundAndPackFloat64(zSign, 0x408, zSig, status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the extended double-precision floating- -| point value `a' to the 32-bit two's complement integer format. The -| conversion is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic---which means in particular that the conversion -| is rounded according to the current rounding mode. If `a' is a NaN, the -| largest positive integer is returned. Otherwise, if the conversion -| overflows, the largest integer with the same sign as `a' is returned. -*-------------------------------------------------------------------------= ---*/ - -int32_t floatx80_to_int32(floatx80 a, float_status *status) -{ - bool aSign; - int32_t aExp, shiftCount; - uint64_t aSig; - - if (floatx80_invalid_encoding(a)) { - float_raise(float_flag_invalid, status); - return 1 << 31; - } - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - if ( ( aExp =3D=3D 0x7FFF ) && (uint64_t) ( aSig<<1 ) ) aSign =3D 0; - shiftCount =3D 0x4037 - aExp; - if ( shiftCount <=3D 0 ) shiftCount =3D 1; - shift64RightJamming( aSig, shiftCount, &aSig ); - return roundAndPackInt32(aSign, aSig, status); - -} - -/*------------------------------------------------------------------------= ---- -| Returns the result of converting the extended double-precision floating- -| point value `a' to the 32-bit two's complement integer format. The -| conversion is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic, except that the conversion is always rounded -| toward zero. If `a' is a NaN, the largest positive integer is returned. -| Otherwise, if the conversion overflows, the largest integer with the same -| sign as `a' is returned. -*-------------------------------------------------------------------------= ---*/ - -int32_t floatx80_to_int32_round_to_zero(floatx80 a, float_status *status) -{ - bool aSign; - int32_t aExp, shiftCount; - uint64_t aSig, savedASig; - int32_t z; - - if (floatx80_invalid_encoding(a)) { - float_raise(float_flag_invalid, status); - return 1 << 31; - } - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - if ( 0x401E < aExp ) { - if ( ( aExp =3D=3D 0x7FFF ) && (uint64_t) ( aSig<<1 ) ) aSign =3D = 0; - goto invalid; - } - else if ( aExp < 0x3FFF ) { - if (aExp || aSig) { - float_raise(float_flag_inexact, status); - } - return 0; - } - shiftCount =3D 0x403E - aExp; - savedASig =3D aSig; - aSig >>=3D shiftCount; - z =3D aSig; - if ( aSign ) z =3D - z; - if ( ( z < 0 ) ^ aSign ) { - invalid: - float_raise(float_flag_invalid, status); - return aSign ? (int32_t) 0x80000000 : 0x7FFFFFFF; - } - if ( ( aSig<>( - shiftCount ); - if ( (uint64_t) ( aSig<<( shiftCount & 63 ) ) ) { - float_raise(float_flag_inexact, status); - } - if ( aSign ) z =3D - z; - return z; - -} - /*------------------------------------------------------------------------= ---- | Rounds the extended double-precision floating-point value `a' | to the precision provided by floatx80_rounding_precision and returns the --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757279; cv=none; d=zohomail.com; s=zohoarc; b=RCVJQWV2eP/4tkhOWRpZsEkznwj9cPQWp5YEb6y3SFuHrJQWzdq6O0kYNFhheREW3OTPwMeV7sTTDD+an4LXwW/07Wkw6lyf8ISv5CZa8psT9R+7OUc1zNEkoe0zeBpsT90n+LCvsMQYTKCdGuqiW2XQlyJZ+2AuWt8fgtPFwFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757279; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yd4dLoXzc3PD/+c2UeVfTupk0478G5r8aHb9S8Vv7U0=; b=gXkmGYKjg7pRqCg02DC52ivFxZ7Kl7NvqplX90sQVpL2Ea+FVt/rdt+LbSXyueRFx2FDuF72QKGoOjHRZd7NFQRT57S5ysX68CwRSv7p+K+CUqqxSVS1eUAG5MZmeoYigOs/hg3SbnN7zyDQMt/2+QkxY0+cJQRoSQSnO0k7B0k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757279315772.3607373523284; Thu, 3 Jun 2021 14:54:39 -0700 (PDT) Received: from localhost ([::1]:43896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovIU-0005DX-72 for importer@patchew.org; Thu, 03 Jun 2021 17:54:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6G-0002w7-PQ for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:00 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:41935) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov65-0001A1-GA for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:00 -0400 Received: by mail-pj1-x102d.google.com with SMTP id b15-20020a17090a550fb029015dad75163dso4725539pji.0 for ; Thu, 03 Jun 2021 14:41:48 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:47 -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=yd4dLoXzc3PD/+c2UeVfTupk0478G5r8aHb9S8Vv7U0=; b=VOBzVp+d9NYSWRstBYsOl3BRTKMl8Mh5bkXe9gZH8VAg6dAPYLOjKol/tgt6T8Q2W8 gMufoTuZLiH2NlwbGTIji/9EHaMJdkhl7PwvW6UfXUsCbyDJI/fpb0Cphpd7mPyp7Azw VwJa3KynxdlIFNdrqL/WM3gre4MFtnVvljF/X4I82zy3OyccBjx+/TCxr57jEJNDlCpL 2gpyg0MQtlLzRKYBF7xLy8BoGkpzuV2/KRNBQkqFM5MHjdZtukx96PEgmm58RrItQRJm zkIC2975eEkuObacqN6SnpJ0T48cd6MIH7DInOuefe9KgQ8RMwZUN8Ef1O9XBP2ZKvC1 4Lpw== 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=yd4dLoXzc3PD/+c2UeVfTupk0478G5r8aHb9S8Vv7U0=; b=XAqVR7m4K1vITlZ7TnyXJjMkpT6+5cvQiav0glqOB2pq5ULK40wgUum6OKIJlQX9Hy rHXy9TbbgxuPVBVXMGFCloSA40na5t8ircg+y6M2nss5gOOWf+oliSKJXQAqe69r9vwE vC7qKEsBEe1IzQnVFXCxiocB6ffR1Z6MY/LJsoSTQHmkbXWqEg71TCHqMFKI1XTu9G8p sgaD+doWOpcodQWtwIoHWhEc+4l9cixNK4fnA8+rYrozYMaIwAewFjL3WxJOkWOqE5t1 48Ae52lONtHW0ML8QbmBMOwP7DJhycVIyo+AGttEA3/nhRsxWEcVhEwmuF8XP0zdN/qu 9ruw== X-Gm-Message-State: AOAM533Zt/HquJfwAg0m7TiheYxVWftkih4TrJt4Y3+ZJVF2t+Jr5/4+ c18SMrsXhPNZRazm4gcqfefsHSNbTrkG8w== X-Google-Smtp-Source: ABdhPJxffu3kZmgSiRscWmPCZnlEuJ+q71Ukazk9lIQATwblqKQlwBb9agNkdBfP+LwQmwOI6+5New== X-Received: by 2002:a17:90a:6285:: with SMTP id d5mr13892385pjj.4.1622756507861; Thu, 03 Jun 2021 14:41:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 23/29] softfloat: Convert floatx80_scalbn to FloatParts Date: Thu, 3 Jun 2021 14:41:25 -0700 Message-Id: <20210603214131.629841-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 50 +++++++++++-------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 5a2a872408..770badd447 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3911,6 +3911,17 @@ float128 float128_scalbn(float128 a, int n, float_st= atus *status) return float128_round_pack_canonical(&p, status); } =20 +floatx80 floatx80_scalbn(floatx80 a, int n, float_status *status) +{ + FloatParts128 p; + + if (!floatx80_unpack_canonical(&p, a, status)) { + return floatx80_default_nan(status); + } + parts_scalbn(&p, n, status); + return floatx80_round_pack_canonical(&p, status); +} + /* * Square Root */ @@ -5745,45 +5756,6 @@ FloatRelation floatx80_compare_quiet(floatx80 a, flo= atx80 b, return floatx80_compare_internal(a, b, 1, status); } =20 -floatx80 floatx80_scalbn(floatx80 a, int n, float_status *status) -{ - bool aSign; - int32_t aExp; - uint64_t aSig; - - if (floatx80_invalid_encoding(a)) { - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - aSig =3D extractFloatx80Frac( a ); - aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - - if ( aExp =3D=3D 0x7FFF ) { - if ( aSig<<1 ) { - return propagateFloatx80NaN(a, a, status); - } - return a; - } - - if (aExp =3D=3D 0) { - if (aSig =3D=3D 0) { - return a; - } - aExp++; - } - - if (n > 0x10000) { - n =3D 0x10000; - } else if (n < -0x10000) { - n =3D -0x10000; - } - - aExp +=3D n; - return normalizeRoundAndPackFloatx80(status->floatx80_rounding_precisi= on, - aSign, aExp, aSig, 0, status); -} - static void __attribute__((constructor)) softfloat_init(void) { union_float64 ua, ub, uc, ur; --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757150; cv=none; d=zohomail.com; s=zohoarc; b=FOZZ/Cvjv+8MBPu64c8bOU+QxFzJfpmZMoe+ZLlLwYweU4GaWS8dDU/qs6ShxGwBbadKbWFC2EYdyLFleDMj9iz5ztJ8GXDTgiMKnpumMvBrht9K+eR8oB7frTb60xDOXirI9Yunl/yNaALYYILicuv0U/DDDOxWcSBsXlZOX1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757150; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ndVa83SIfMh7/NYhgST6dDyuB+J+HvB1UgKzExjE9v8=; b=PATt9dtG1n0qtcufJkQnHJMaHiTwp4OHWFlmLUQDRdXUeZbDuw6zzMNqKuszOO7urmI4NgptuDmRbVsJjLCWvte5PHc/7I3Iq1JBteZab9KSAgIba65MiW3r1ToUjsfbaC5poxOTES1Ae/deKiFk9fsUqqbVWRdncYlmg0/9+pg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757150400641.2084614378649; Thu, 3 Jun 2021 14:52:30 -0700 (PDT) Received: from localhost ([::1]:33212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovGO-0006aG-Vm for importer@patchew.org; Thu, 03 Jun 2021 17:52:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6F-0002qP-BX for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:59 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:41883) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov65-0001A7-HU for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:59 -0400 Received: by mail-pg1-x52e.google.com with SMTP id r1so6165568pgk.8 for ; Thu, 03 Jun 2021 14:41:49 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:48 -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=ndVa83SIfMh7/NYhgST6dDyuB+J+HvB1UgKzExjE9v8=; b=qrpAHubuOPfTL1yxgHwgrzkF/fMrBaJzUWnxWaCJnhMUgipGZ8Ibkg/noq4M1T0xpN Zby1WhTVqjaU4uxItGlf7saaleTOtanK8FsUTyCpqUu8WQOOMK4bWTLDIgwGaTzffVeu 19Fj9bHlwMkMZ7uTlnpGDtObqVtLB88XV9MFaOMImA2ZENKcso29oBqsczNU1JWYIlz+ vO7tbxoAK6RyBex/QPXdVlPUPDbEXVjfRniPtyfQbmofFI/jo8fTiag5CXpMS6zetn+0 Sj0jEDPhNZs/QTvrvl14oqHMiUcSOSLAppKMYbvamVFiwD2O22Hv0LBBwVQLNsqZvXva 50CA== 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=ndVa83SIfMh7/NYhgST6dDyuB+J+HvB1UgKzExjE9v8=; b=stcmT1F9r2y7k6vfxGXqDHkIu5st84IKHP36DOS8xdwI/qSjaChvgI6VlG/f1QqVU+ txmW3QxXvetsWYxe7Y6WZd93Nt4FczN8teZpjl+4+WjK69/0Adw0UQYEFlf6FAIhCGHX NPbooXicxfFKI25wvL7iZrdhh2wuRD/gF7wVELdEa8Sj4F+agosLzpK8ZIn2eCwpf4Uc WA2Ppg0LCDluRBeeMBcaDbnXhIbM22xJX75nYndmsDUeVIMJ5SHpoMe6+beUhkMQ4DFv +tpJ3LYqZq7Z9tkViuF+cWo4QAyrfZzjm9gKMtDZx+EnUVbkkkB+a+BaZYkCe0VUP8a+ +r+Q== X-Gm-Message-State: AOAM531D5TwL463QyzO0F79Le1t7dxjuCRxDegNzuq5RVnkRtB8/ZOyk FPb3Djjm+P6oDk2iIUr4rvXpOO7pKVR3cQ== X-Google-Smtp-Source: ABdhPJzab6JPv2ZPjM3k0EnLAJwZmv39tDc+ZsdkZLc7vEJZUb5lNkEMk0IMBlcOJdgLwRKDQHqfjA== X-Received: by 2002:a05:6a00:10c2:b029:2de:7333:1343 with SMTP id d2-20020a056a0010c2b02902de73331343mr1381577pfu.42.1622756508387; Thu, 03 Jun 2021 14:41:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 24/29] softfloat: Convert floatx80 compare to FloatParts Date: Thu, 3 Jun 2021 14:41:26 -0700 Message-Id: <20210603214131.629841-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 82 +++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 60 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 770badd447..c32b1c7113 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3862,6 +3862,28 @@ FloatRelation float128_compare_quiet(float128 a, flo= at128 b, float_status *s) return float128_do_compare(a, b, s, true); } =20 +static FloatRelation QEMU_FLATTEN +floatx80_do_compare(floatx80 a, floatx80 b, float_status *s, bool is_quiet) +{ + FloatParts128 pa, pb; + + if (!floatx80_unpack_canonical(&pa, a, s) || + !floatx80_unpack_canonical(&pb, b, s)) { + return float_relation_unordered; + } + return parts_compare(&pa, &pb, s, is_quiet); +} + +FloatRelation floatx80_compare(floatx80 a, floatx80 b, float_status *s) +{ + return floatx80_do_compare(a, b, s, false); +} + +FloatRelation floatx80_compare_quiet(floatx80 a, floatx80 b, float_status = *s) +{ + return floatx80_do_compare(a, b, s, true); +} + /* * Scale by 2**N */ @@ -5696,66 +5718,6 @@ float128 float128_rem(float128 a, float128 b, float_= status *status) return normalizeRoundAndPackFloat128(aSign ^ zSign, bExp - 4, aSig0, a= Sig1, status); } - -static inline FloatRelation -floatx80_compare_internal(floatx80 a, floatx80 b, bool is_quiet, - float_status *status) -{ - bool aSign, bSign; - - if (floatx80_invalid_encoding(a) || floatx80_invalid_encoding(b)) { - float_raise(float_flag_invalid, status); - return float_relation_unordered; - } - if (( ( extractFloatx80Exp( a ) =3D=3D 0x7fff ) && - ( extractFloatx80Frac( a )<<1 ) ) || - ( ( extractFloatx80Exp( b ) =3D=3D 0x7fff ) && - ( extractFloatx80Frac( b )<<1 ) )) { - if (!is_quiet || - floatx80_is_signaling_nan(a, status) || - floatx80_is_signaling_nan(b, status)) { - float_raise(float_flag_invalid, status); - } - return float_relation_unordered; - } - aSign =3D extractFloatx80Sign( a ); - bSign =3D extractFloatx80Sign( b ); - if ( aSign !=3D bSign ) { - - if ( ( ( (uint16_t) ( ( a.high | b.high ) << 1 ) ) =3D=3D 0) && - ( ( a.low | b.low ) =3D=3D 0 ) ) { - /* zero case */ - return float_relation_equal; - } else { - return 1 - (2 * aSign); - } - } else { - /* Normalize pseudo-denormals before comparison. */ - if ((a.high & 0x7fff) =3D=3D 0 && a.low & UINT64_C(0x8000000000000= 000)) { - ++a.high; - } - if ((b.high & 0x7fff) =3D=3D 0 && b.low & UINT64_C(0x8000000000000= 000)) { - ++b.high; - } - if (a.low =3D=3D b.low && a.high =3D=3D b.high) { - return float_relation_equal; - } else { - return 1 - 2 * (aSign ^ ( lt128( a.high, a.low, b.high, b.low = ) )); - } - } -} - -FloatRelation floatx80_compare(floatx80 a, floatx80 b, float_status *statu= s) -{ - return floatx80_compare_internal(a, b, 0, status); -} - -FloatRelation floatx80_compare_quiet(floatx80 a, floatx80 b, - float_status *status) -{ - return floatx80_compare_internal(a, b, 1, status); -} - static void __attribute__((constructor)) softfloat_init(void) { union_float64 ua, ub, uc, ur; --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757510; cv=none; d=zohomail.com; s=zohoarc; b=hhst7SSDHmRTrauhNkxwvEora66tYW80986v2DBb7g4SIqAv8HruGkLbPwPwmvCfiOekorXulsROuU5zumQxGzTeUvNeJ45ZehJyAxzc8Xh4RUDBPSdkm8yNThF7GkUc1fmG77t4p+JQ+1eI9nmGSTiDihUbONk50JJFhK9Zf50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757510; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=96c6uJZ3c+bY6czT9boE4Qd+QkQsfFNNXC+3KlgI5bI=; b=GkL5MbSoEPy8O15Z21KcEPAXZxUZEqrr4r6JMm+Z7WHWp6j2QAbn4MqVk8N7itMBNOzE7D3yvN7WHG96DEEmpUr32RrnDmZrU0R4wtGIAP5HhhN2JckjK+chcplnZLc7Vh2oItfU6+WkV0bRFOcsOQdNBM3FUWmm16QcqLjVJxE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757510134334.3889668179014; Thu, 3 Jun 2021 14:58:30 -0700 (PDT) Received: from localhost ([::1]:57554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovMD-0005zj-31 for importer@patchew.org; Thu, 03 Jun 2021 17:58:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6J-00038S-RI for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:03 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:38650) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov66-0001AC-IB for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:03 -0400 Received: by mail-pj1-x1030.google.com with SMTP id m13-20020a17090b068db02901656cc93a75so6260193pjz.3 for ; Thu, 03 Jun 2021 14:41:49 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:48 -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=96c6uJZ3c+bY6czT9boE4Qd+QkQsfFNNXC+3KlgI5bI=; b=BM6d3PSuznr1qtaq+jeJeZCPFmK2oO0q8oIZ4QuuUUuXE0sZaRnfRKc4mnY3QuKNzx XkRNKSdm67CDTE9UabSoIkYX6zkXA2kBCkX+VXBBz5b880mvu2MLuOYCM6z2M7H2FmEx 2GqRcSd9E39VcLqTMi/eHaCoskHB/6tdoppD7hHKXUTQ4FoKKutttwI+dQtdv1feBI3M uxCFyTXgaij8a8kqxhZ8iwFkDHz7AqrqvUa01uXrQ5xHwLu7HEn4ThoB0B0gKS5wuzop /+i4SFBr9ibqmORnbS1XrmH94gMovIHE4YpAO10V+ekyJOKBjp2sG6OJsMnRqX/P0u8W AMrQ== 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=96c6uJZ3c+bY6czT9boE4Qd+QkQsfFNNXC+3KlgI5bI=; b=GJG2HM+tRDRBM6kYBfalsWWerwWcn+TL8Pf2KuvOEKYUpG+/+bEmh0NmwFCbb5nJLa 8QcM+rhzZ4tl0d6Tw27rwbsA+AlLjo9jGpWGq5ekcS7lP0bBnFuYwHbeY//VH9dIaEOW b6nViB0/EtQnxH6WFQnr+P1fkKOMIEXB+WgkQbwlrWmE17QsDYUDeQ1gf1qfG10cbqwT 9b5CGRvkpM2UFe32QpWpH7A2/UnsM03QaRTxvz3Jn80Zpng1yzfXRiCcak6tBp2INIr8 VeQl9aYbUiwMeAlC6LHGZaOIu3ECDXidBWmCVJWDf3gLeZwuY+EWKC+vOI/1CVUa4Hph 11BQ== X-Gm-Message-State: AOAM533BBOeZTcqdIN3eGSAH4Ok7XbmbxqjLXHIC33U9Xoge6Eu3a7v6 OpbU1tiASF4cyuhQzuXVwOrOGc116+c98A== X-Google-Smtp-Source: ABdhPJze5wDqtLtv8oITz2Pt84vMv9OhJmBf3pjqu3Vmjq2TnO3+TpIGKvGhB3JCRMIucCEWnOJb4g== X-Received: by 2002:a17:90a:b782:: with SMTP id m2mr5154492pjr.147.1622756509057; Thu, 03 Jun 2021 14:41:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 25/29] softfloat: Convert float32_exp2 to FloatParts Date: Thu, 3 Jun 2021 14:41:27 -0700 Message-Id: <20210603214131.629841-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Keep the intermediate results in FloatParts instead of converting back and forth between float64. Use muladd instead of separate mul+add. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 53 +++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index c32b1c7113..27306d6a93 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -5210,47 +5210,40 @@ static const float64 float32_exp2_coefficients[15] = =3D =20 float32 float32_exp2(float32 a, float_status *status) { - bool aSign; - int aExp; - uint32_t aSig; - float64 r, x, xn; + FloatParts64 xp, xnp, tp, rp; int i; - a =3D float32_squash_input_denormal(a, status); =20 - aSig =3D extractFloat32Frac( a ); - aExp =3D extractFloat32Exp( a ); - aSign =3D extractFloat32Sign( a ); - - if ( aExp =3D=3D 0xFF) { - if (aSig) { - return propagateFloat32NaN(a, float32_zero, status); + float32_unpack_canonical(&xp, a, status); + if (unlikely(xp.cls !=3D float_class_normal)) { + switch (xp.cls) { + case float_class_snan: + case float_class_qnan: + parts_return_nan(&xp, status); + return float32_round_pack_canonical(&xp, status); + case float_class_inf: + return xp.sign ? float32_zero : a; + case float_class_zero: + return float32_one; + default: + break; } - return (aSign) ? float32_zero : a; - } - if (aExp =3D=3D 0) { - if (aSig =3D=3D 0) return float32_one; + g_assert_not_reached(); } =20 float_raise(float_flag_inexact, status); =20 - /* ******************************* */ - /* using float64 for approximation */ - /* ******************************* */ - x =3D float32_to_float64(a, status); - x =3D float64_mul(x, float64_ln2, status); + float64_unpack_canonical(&xnp, float64_ln2, status); + xp =3D *parts_mul(&xp, &tp, status); + xnp =3D xp; =20 - xn =3D x; - r =3D float64_one; + float64_unpack_canonical(&rp, float64_one, status); for (i =3D 0 ; i < 15 ; i++) { - float64 f; - - f =3D float64_mul(xn, float32_exp2_coefficients[i], status); - r =3D float64_add(r, f, status); - - xn =3D float64_mul(xn, x, status); + float64_unpack_canonical(&tp, float32_exp2_coefficients[i], status= ); + rp =3D *parts_muladd(&tp, &xp, &rp, 0, status); + xnp =3D *parts_mul(&xnp, &xp, status); } =20 - return float64_to_float32(r, status); + return float32_round_pack_canonical(&rp, status); } =20 /*------------------------------------------------------------------------= ---- --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757341; cv=none; d=zohomail.com; s=zohoarc; b=Y4jr8wsgE7kOzHz4xKcal2z9CzeV+dUj7S65g6MphR0UeRW2zaSAkB8TpfOQsdiJWWa2u3WGbryLAYqZAO4lHeAxmgheSagGmI407EiEYreieVKnTTJuYLN/VLqlrFh570L1Y9qq37k1nD/MatxGpKn0t0a7bUnoTeNuaD3HAXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757341; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9oe7TH/FOyKvHqZI98/sVuSYHE/+p3BdMoPYUl0hOx4=; b=NvI+NzlSJkJz5ykMmz4PaSPvwQULfNg3bAc4nxXAIySIw7YVNJIhmjJZqDiFtfL3EYjKMfMdTEutq6HQ2x6cMZxtjiQqGu2V2Td8SFRSKNhzyL9xR+esygaDUZe582Tr3aKnCFHwTY2QmWwcasU6yKUL+loQ9Gkc4ioAuhTFBLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757341129688.1007999619032; Thu, 3 Jun 2021 14:55:41 -0700 (PDT) Received: from localhost ([::1]:49116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovJT-0000Ee-VL for importer@patchew.org; Thu, 03 Jun 2021 17:55:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6J-000353-1H for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:03 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:43756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov67-0001Ar-51 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:02 -0400 Received: by mail-pg1-x52f.google.com with SMTP id e22so6157262pgv.10 for ; Thu, 03 Jun 2021 14:41:50 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:49 -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=9oe7TH/FOyKvHqZI98/sVuSYHE/+p3BdMoPYUl0hOx4=; b=ccZCkOfruGcESAEyA9y5KbZnxJHg53XbzSsFf0LtTCGjrwrfJ8CxKwFc1zDHLGLrhJ l7UugNqSIe9prc/MmT6PLJYhJLKaDu+aKqWWFLBM/BbBJlLXoIVW/YRKqpPSEAXKKGVH vA6LtGu2TQwXXHvG7E+me9F61hLc1PZepQK3MO0Q58H4xN1yaA7Q++1fUeR8xe3jTJ+x vxOmaTjtW19bXCHxw4+lAndwnJ/TrClAWOafhVOLQESkJ1L+AR3waIi6bUFvLhxLR+IL 7n6gg7hoXio3zavvrG1qDpidJyc8EbxeeQf6ha/lXUlN8w3Mt1x2SegWB/EE833r0sj5 U2cA== 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=9oe7TH/FOyKvHqZI98/sVuSYHE/+p3BdMoPYUl0hOx4=; b=qYiTOaX7FvGtM9o880lwJYaSCmw1FOGRovjW0flOTzKfNdLApDmWlcWdPpE5iSYtUd QoW+2Hmob6/gzJK9eb5XvUw1QRWrHWhb2p2w8cf7igcc5qkXH1HxruoKF6iJa/NKZ888 dJiTbn3hz9KrXxf72LJgmtML75wKAYFHfvq3EF4O7E1ac2BA4dBwp2sZWh7xjTS67GGe FGkKKH5PZQJO6i/B9b6Q4HYFHCN5ChYH9n6s1wTsuyNoPK1GCHdCbdZl6UZ0cEsNFK4k jxCNY/4UEHyDR+Y7jt4o7Wi5ZqL/n3yad8HpcRPBsrLZeSe3kkZESaMquXCQIoCVCQ1R MC5A== X-Gm-Message-State: AOAM533DSuKtBpgE8HozOQzIbpu1XJUyTPSK7NmfAjFvFxF13P67J5vq GaRjLgh+FMm3hTN2wvYdyCg7PIy7X7D4YQ== X-Google-Smtp-Source: ABdhPJxo4PIfDHKPOQaRKJoAK+R8AjNWrHPpByysREWODb2CMaT6wi6g17cBqoDJXd8A/7CdMhDI9A== X-Received: by 2002:a62:2944:0:b029:2e9:8ce5:b044 with SMTP id p65-20020a6229440000b02902e98ce5b044mr1344822pfp.3.1622756509674; Thu, 03 Jun 2021 14:41:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 26/29] softfloat: Move floatN_log2 to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:28 -0700 Message-Id: <20210603214131.629841-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Rename to parts$N_log2. Though this is partly a ruse, since I do not believe the code will succeed for float128 without work. Which is ok for now, because we do not need this for more than float32 and float64. Since berkeley-testfloat-3 doesn't support log2, compare float64_log2 vs the system log2. Fix the errors for inputs near 1.0: test: 3ff00000000000b0 +0x1.00000000000b0p+0 sf: 3d2fa00000000000 +0x1.fa00000000000p-45 libm: 3d2fbd422b1bd36f +0x1.fbd422b1bd36fp-45 Error in fraction: 32170028290927 ulp test: 3feec24f6770b100 +0x1.ec24f6770b100p-1 sf: bfad3740d13c9ec0 -0x1.d3740d13c9ec0p-5 libm: bfad3740d13c9e98 -0x1.d3740d13c9e98p-5 Error in fraction: 40 ulp Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 126 ++++++++------------------------------ tests/fp/fp-test-log2.c | 118 +++++++++++++++++++++++++++++++++++ fpu/softfloat-parts.c.inc | 125 +++++++++++++++++++++++++++++++++++++ tests/fp/meson.build | 11 ++++ 4 files changed, 281 insertions(+), 99 deletions(-) create mode 100644 tests/fp/fp-test-log2.c diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 27306d6a93..c0fe191f4d 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -927,6 +927,12 @@ static void parts128_scalbn(FloatParts128 *a, int n, f= loat_status *s); #define parts_scalbn(A, N, S) \ PARTS_GENERIC_64_128(scalbn, A)(A, N, S) =20 +static void parts64_log2(FloatParts64 *a, float_status *s, const FloatFmt = *f); +static void parts128_log2(FloatParts128 *a, float_status *s, const FloatFm= t *f); + +#define parts_log2(A, S, F) \ + PARTS_GENERIC_64_128(log2, A)(A, S, F) + /* * Helper functions for softfloat-parts.c.inc, per-size operations. */ @@ -4060,6 +4066,27 @@ floatx80 floatx80_sqrt(floatx80 a, float_status *s) return floatx80_round_pack_canonical(&p, s); } =20 +/* + * log2 + */ +float32 float32_log2(float32 a, float_status *status) +{ + FloatParts64 p; + + float32_unpack_canonical(&p, a, status); + parts_log2(&p, status, &float32_params); + return float32_round_pack_canonical(&p, status); +} + +float64 float64_log2(float64 a, float_status *status) +{ + FloatParts64 p; + + float64_unpack_canonical(&p, a, status); + parts_log2(&p, status, &float64_params); + return float64_round_pack_canonical(&p, status); +} + /*------------------------------------------------------------------------= ---- | The pattern for a default generated NaN. *-------------------------------------------------------------------------= ---*/ @@ -5246,56 +5273,6 @@ float32 float32_exp2(float32 a, float_status *status) return float32_round_pack_canonical(&rp, status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the binary log of the single-precision floating-point value `a'. -| The operation is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ -float32 float32_log2(float32 a, float_status *status) -{ - bool aSign, zSign; - int aExp; - uint32_t aSig, zSig, i; - - a =3D float32_squash_input_denormal(a, status); - aSig =3D extractFloat32Frac( a ); - aExp =3D extractFloat32Exp( a ); - aSign =3D extractFloat32Sign( a ); - - if ( aExp =3D=3D 0 ) { - if ( aSig =3D=3D 0 ) return packFloat32( 1, 0xFF, 0 ); - normalizeFloat32Subnormal( aSig, &aExp, &aSig ); - } - if ( aSign ) { - float_raise(float_flag_invalid, status); - return float32_default_nan(status); - } - if ( aExp =3D=3D 0xFF ) { - if (aSig) { - return propagateFloat32NaN(a, float32_zero, status); - } - return a; - } - - aExp -=3D 0x7F; - aSig |=3D 0x00800000; - zSign =3D aExp < 0; - zSig =3D aExp << 23; - - for (i =3D 1 << 22; i > 0; i >>=3D 1) { - aSig =3D ( (uint64_t)aSig * aSig ) >> 23; - if ( aSig & 0x01000000 ) { - aSig >>=3D 1; - zSig |=3D i; - } - } - - if ( zSign ) - zSig =3D -zSig; - - return normalizeRoundAndPackFloat32(zSign, 0x85, zSig, status); -} - /*------------------------------------------------------------------------= ---- | Returns the remainder of the double-precision floating-point value `a' | with respect to the corresponding value `b'. The operation is performed @@ -5384,55 +5361,6 @@ float64 float64_rem(float64 a, float64 b, float_stat= us *status) =20 } =20 -/*------------------------------------------------------------------------= ---- -| Returns the binary log of the double-precision floating-point value `a'. -| The operation is performed according to the IEC/IEEE Standard for Binary -| Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ -float64 float64_log2(float64 a, float_status *status) -{ - bool aSign, zSign; - int aExp; - uint64_t aSig, aSig0, aSig1, zSig, i; - a =3D float64_squash_input_denormal(a, status); - - aSig =3D extractFloat64Frac( a ); - aExp =3D extractFloat64Exp( a ); - aSign =3D extractFloat64Sign( a ); - - if ( aExp =3D=3D 0 ) { - if ( aSig =3D=3D 0 ) return packFloat64( 1, 0x7FF, 0 ); - normalizeFloat64Subnormal( aSig, &aExp, &aSig ); - } - if ( aSign ) { - float_raise(float_flag_invalid, status); - return float64_default_nan(status); - } - if ( aExp =3D=3D 0x7FF ) { - if (aSig) { - return propagateFloat64NaN(a, float64_zero, status); - } - return a; - } - - aExp -=3D 0x3FF; - aSig |=3D UINT64_C(0x0010000000000000); - zSign =3D aExp < 0; - zSig =3D (uint64_t)aExp << 52; - for (i =3D 1LL << 51; i > 0; i >>=3D 1) { - mul64To128( aSig, aSig, &aSig0, &aSig1 ); - aSig =3D ( aSig0 << 12 ) | ( aSig1 >> 52 ); - if ( aSig & UINT64_C(0x0020000000000000) ) { - aSig >>=3D 1; - zSig |=3D i; - } - } - - if ( zSign ) - zSig =3D -zSig; - return normalizeRoundAndPackFloat64(zSign, 0x408, zSig, status); -} - /*------------------------------------------------------------------------= ---- | Rounds the extended double-precision floating-point value `a' | to the precision provided by floatx80_rounding_precision and returns the diff --git a/tests/fp/fp-test-log2.c b/tests/fp/fp-test-log2.c new file mode 100644 index 0000000000..4eae93eb7c --- /dev/null +++ b/tests/fp/fp-test-log2.c @@ -0,0 +1,118 @@ +/* + * fp-test-log2.c - test QEMU's softfloat log2 + * + * Copyright (C) 2020, Linaro, Ltd. + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef HW_POISON_H +#error Must define HW_POISON_H to work around TARGET_* poisoning +#endif + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include +#include "fpu/softfloat.h" + +typedef union { + double d; + float64 i; +} ufloat64; + +static int errors; + +static void compare(ufloat64 test, ufloat64 real, ufloat64 soft, bool exac= t) +{ + int msb; + uint64_t ulp =3D UINT64_MAX; + + if (real.i =3D=3D soft.i) { + return; + } + msb =3D 63 - __builtin_clzll(real.i ^ soft.i); + + if (msb < 52) { + if (real.i > soft.i) { + ulp =3D real.i - soft.i; + } else { + ulp =3D soft.i - real.i; + } + } + + /* glibc allows 3 ulp error in its libm-test-ulps; allow 4 here */ + if (!exact && ulp <=3D 4) { + return; + } + + printf("test: %016" PRIx64 " %+.13a\n" + " sf: %016" PRIx64 " %+.13a\n" + "libm: %016" PRIx64 " %+.13a\n", + test.i, test.d, soft.i, soft.d, real.i, real.d); + + if (msb =3D=3D 63) { + printf("Error in sign!\n\n"); + } else if (msb >=3D 52) { + printf("Error in exponent: %d\n\n", + (int)(soft.i >> 52) - (int)(real.i >> 52)); + } else { + printf("Error in fraction: %" PRIu64 " ulp\n\n", ulp); + } + + if (++errors =3D=3D 20) { + exit(1); + } +} + +int main(int ac, char **av) +{ + ufloat64 test, real, soft; + float_status qsf =3D {0}; + int i; + + set_float_rounding_mode(float_round_nearest_even, &qsf); + + test.d =3D 0.0; + real.d =3D -__builtin_inf(); + soft.i =3D float64_log2(test.i, &qsf); + compare(test, real, soft, true); + + test.d =3D 1.0; + real.d =3D 0.0; + soft.i =3D float64_log2(test.i, &qsf); + compare(test, real, soft, true); + + test.d =3D 2.0; + real.d =3D 1.0; + soft.i =3D float64_log2(test.i, &qsf); + compare(test, real, soft, true); + + test.d =3D 4.0; + real.d =3D 2.0; + soft.i =3D float64_log2(test.i, &qsf); + compare(test, real, soft, true); + + test.d =3D 0x1p64; + real.d =3D 64.0; + soft.i =3D float64_log2(test.i, &qsf); + compare(test, real, soft, true); + + test.d =3D __builtin_inf(); + real.d =3D __builtin_inf(); + soft.i =3D float64_log2(test.i, &qsf); + compare(test, real, soft, true); + + for (i =3D 0; i < 10000; ++i) { + test.d =3D drand48() + 1.0; /* [1.0, 2.0) */ + real.d =3D log2(test.d); + soft.i =3D float64_log2(test.i, &qsf); + compare(test, real, soft, false); + + test.d =3D drand48() * 100; /* [0.0, 100) */ + real.d =3D log2(test.d); + soft.i =3D float64_log2(test.i, &qsf); + compare(test, real, soft, false); + } + + return 0; +} diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index efb81bbebe..d1bd5c6edf 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -1331,3 +1331,128 @@ static void partsN(scalbn)(FloatPartsN *a, int n, f= loat_status *s) g_assert_not_reached(); } } + +/* + * Return log2(A) + */ +static void partsN(log2)(FloatPartsN *a, float_status *s, const FloatFmt *= fmt) +{ + uint64_t a0, a1, r, t, ign; + FloatPartsN f; + int i, n, a_exp, f_exp; + + if (unlikely(a->cls !=3D float_class_normal)) { + switch (a->cls) { + case float_class_snan: + case float_class_qnan: + parts_return_nan(a, s); + return; + case float_class_zero: + /* log2(0) =3D -inf */ + a->cls =3D float_class_inf; + a->sign =3D 1; + return; + case float_class_inf: + if (unlikely(a->sign)) { + goto d_nan; + } + return; + default: + break; + } + g_assert_not_reached(); + } + if (unlikely(a->sign)) { + goto d_nan; + } + + /* TODO: This algorithm looses bits too quickly for float128. */ + g_assert(N =3D=3D 64); + + a_exp =3D a->exp; + f_exp =3D -1; + + r =3D 0; + t =3D DECOMPOSED_IMPLICIT_BIT; + a0 =3D a->frac_hi; + a1 =3D 0; + + n =3D fmt->frac_size + 2; + if (unlikely(a_exp =3D=3D -1)) { + /* + * When a_exp =3D=3D -1, we're computing the log2 of a value [0.5,= 1.0). + * When the value is very close to 1.0, there are lots of 1's in + * the msb parts of the fraction. At the end, when we subtract + * this value from -1.0, we can see a catastrophic loss of precisi= on, + * as 0x800..000 - 0x7ff..ffx becomes 0x000..00y, leaving only the + * bits of y in the final result. To minimize this, compute as ma= ny + * digits as we can. + * ??? This case needs another algorithm to avoid this. + */ + n =3D fmt->frac_size * 2 + 2; + /* Don't compute a value overlapping the sticky bit */ + n =3D MIN(n, 62); + } + + for (i =3D 0; i < n; i++) { + if (a1) { + mul128To256(a0, a1, a0, a1, &a0, &a1, &ign, &ign); + } else if (a0 & 0xffffffffull) { + mul64To128(a0, a0, &a0, &a1); + } else if (a0 & ~DECOMPOSED_IMPLICIT_BIT) { + a0 >>=3D 32; + a0 *=3D a0; + } else { + goto exact; + } + + if (a0 & DECOMPOSED_IMPLICIT_BIT) { + if (unlikely(a_exp =3D=3D 0 && r =3D=3D 0)) { + /* + * When a_exp =3D=3D 0, we're computing the log2 of a value + * [1.0,2.0). When the value is very close to 1.0, there + * are lots of 0's in the msb parts of the fraction. + * We need to compute more digits to produce a correct + * result -- restart at the top of the fraction. + * ??? This is likely to lose precision quickly, as for + * float128; we may need another method. + */ + f_exp -=3D i; + t =3D r =3D DECOMPOSED_IMPLICIT_BIT; + i =3D 0; + } else { + r |=3D t; + } + } else { + add128(a0, a1, a0, a1, &a0, &a1); + } + t >>=3D 1; + } + + /* Set sticky for inexact. */ + r |=3D (a1 || a0 & ~DECOMPOSED_IMPLICIT_BIT); + + exact: + parts_sint_to_float(a, a_exp, 0, s); + if (r =3D=3D 0) { + return; + } + + memset(&f, 0, sizeof(f)); + f.cls =3D float_class_normal; + f.frac_hi =3D r; + f.exp =3D f_exp - frac_normalize(&f); + + if (a_exp < 0) { + parts_sub_normal(a, &f); + } else if (a_exp > 0) { + parts_add_normal(a, &f); + } else { + *a =3D f; + } + return; + + d_nan: + float_raise(float_flag_invalid, s); + parts_default_nan(a, s); +} diff --git a/tests/fp/meson.build b/tests/fp/meson.build index 1c3eee9955..9218bfd3b0 100644 --- a/tests/fp/meson.build +++ b/tests/fp/meson.build @@ -634,3 +634,14 @@ fpbench =3D executable( include_directories: [sfinc, include_directories(tfdir)], c_args: fpcflags, ) + +fptestlog2 =3D executable( + 'fp-test-log2', + ['fp-test-log2.c', '../../fpu/softfloat.c'], + link_with: [libsoftfloat], + dependencies: [qemuutil], + include_directories: [sfinc], + c_args: fpcflags, +) +test('fp-test-log2', fptestlog2, + suite: ['softfloat', 'softfloat-ops']) --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757113; cv=none; d=zohomail.com; s=zohoarc; b=TGKVo8f/sRGn2tMZBYLIgeTNfB6Qq5lZ11LAFe6YG7zswVeRJBhAJuNFkdscysW+dTJ+Kv4YZiULE1XWaFuvcApWoxMDoFIgBWa+EO72UM01EG0GQbZ33OgBZkdtHNM789qpbEmu0NiQtbzRDSiOMdqJ+LaAuhGSC5y8V5PvnFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757113; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PYPaf/j9AHT9fcW+1JhpwV4TzbljbGsjiwi3XwcqOTc=; b=QJPNTKkP0dlLhXo32pLYpsLYOzycy5FwqORD/FG2i7WBJYsX9LKMiFi1njRTWqJI/ua0moNrHeOTHHL2ACZkY3lgVwaaRpwu3ytRn+ZbAk4iHzmur0EHIEgyGqud0t+M51MZMCzbgut/yjm7iNSi1c9+rSiDIvrP1PK2RKw7410= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757113172332.534079771944; Thu, 3 Jun 2021 14:51:53 -0700 (PDT) Received: from localhost ([::1]:59048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovFn-00050T-UA for importer@patchew.org; Thu, 03 Jun 2021 17:51:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58582) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6L-0003EO-5h for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:05 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:44845) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov68-0001BF-Se for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:04 -0400 Received: by mail-pj1-x1033.google.com with SMTP id h12-20020a17090aa88cb029016400fd8ad8so4683039pjq.3 for ; Thu, 03 Jun 2021 14:41:52 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:50 -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=PYPaf/j9AHT9fcW+1JhpwV4TzbljbGsjiwi3XwcqOTc=; b=ewFf7mWYNjU2Dbd5H05g+3/Wzxj6M6YmXqmCSDu15ym+wtOJPMvZs4ltepZFo2PKAM o2HxZJK6c09NSX6UXvDj8maJpjfA7PK0dhTwGFhuPgYwyPL/n1BSJvApWQJ6krF8/nCy 5N/ap885CSxv0kDPAQmHY6Ek1AIZ8jA8cl2qIYufubQpWc/5HH8mXBgPp3E3LMQp7S/K zqaBdwF4wv3e8rOgD+Xu5g6tnKQSTo93v9vNPQPP4EEsdKBFq2VCL8XoE+fjUUiJ8HV0 pElK5W2xabDxL9fBmXSGSrWp0OgdfbEHmiyS1T4clxqQqHu1q11FTk2EgRlsD7uciEQX ESwQ== 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=PYPaf/j9AHT9fcW+1JhpwV4TzbljbGsjiwi3XwcqOTc=; b=DKN3EX0YfY4bgH62206+H4yKbaoG26Iy8IRyy4Q7pMM4ZRKTd7fsUdmVZR6+LOWW8i dl8fGu8gmy7Lxqy0NkKOIQHKJ9UJrwImxop2ClOOU2WTILbQzSsFtzu+NxJ3xogCFxfo Q1wr26fFzYPZ9wH/d2S92FUThzn1rwOWR72B4ezbKgUtIHvSaGALAcakbTaxogp1CWPc mOJsH5eUeLDteZnFzG4SIkYU2nI4/j0p1hkuc9rxfgqDMkJd4Vl6u1oFXAG9q0/WVc2V CmrTIVtEgO8YTi9IH2Kwde7buRVNPG4CVVh/b2COaEeJ842a1utH/3y7qBnc7sOwG/Um sM1g== X-Gm-Message-State: AOAM533qqkPKMacYOlhrPyCFROiK/jCXNAj1IqmFhO942QUxl+R8JKHR 7pkC2J0X+uU8h2tGGGep+BhlZQiswOoSLw== X-Google-Smtp-Source: ABdhPJxVP4Dk532zGdBPEtW4PNOPHEOkpmjEW80i/dz1E67khmFOdL98cGnRBUbcdnRu98Ke+xaPaA== X-Received: by 2002:a17:90a:8d82:: with SMTP id d2mr13359307pjo.106.1622756510446; Thu, 03 Jun 2021 14:41:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 27/29] softfloat: Convert modrem operations to FloatParts Date: Thu, 3 Jun 2021 14:41:29 -0700 Message-Id: <20210603214131.629841-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Rename to parts$N_modrem. This was the last use of a lot of the legacy infrastructure, so remove it as required. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- include/fpu/softfloat-macros.h | 34 + fpu/softfloat.c | 1339 +++++++------------------------- fpu/softfloat-parts.c.inc | 34 + fpu/softfloat-specialize.c.inc | 165 ---- 4 files changed, 329 insertions(+), 1243 deletions(-) diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h index ec4e27a595..81c3fe8256 100644 --- a/include/fpu/softfloat-macros.h +++ b/include/fpu/softfloat-macros.h @@ -745,4 +745,38 @@ static inline bool ne128(uint64_t a0, uint64_t a1, uin= t64_t b0, uint64_t b1) return a0 !=3D b0 || a1 !=3D b1; } =20 +/* + * Similarly, comparisons of 192-bit values. + */ + +static inline bool eq192(uint64_t a0, uint64_t a1, uint64_t a2, + uint64_t b0, uint64_t b1, uint64_t b2) +{ + return ((a0 ^ b0) | (a1 ^ b1) | (a2 ^ b2)) =3D=3D 0; +} + +static inline bool le192(uint64_t a0, uint64_t a1, uint64_t a2, + uint64_t b0, uint64_t b1, uint64_t b2) +{ + if (a0 !=3D b0) { + return a0 < b0; + } + if (a1 !=3D b1) { + return a1 < b1; + } + return a2 <=3D b2; +} + +static inline bool lt192(uint64_t a0, uint64_t a1, uint64_t a2, + uint64_t b0, uint64_t b1, uint64_t b2) +{ + if (a0 !=3D b0) { + return a0 < b0; + } + if (a1 !=3D b1) { + return a1 < b1; + } + return a2 < b2; +} + #endif diff --git a/fpu/softfloat.c b/fpu/softfloat.c index c0fe191f4d..5026f518b0 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -401,60 +401,6 @@ float64_gen2(float64 xa, float64 xb, float_status *s, return soft(ua.s, ub.s, s); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the fraction bits of the single-precision floating-point value `= a'. -*-------------------------------------------------------------------------= ---*/ - -static inline uint32_t extractFloat32Frac(float32 a) -{ - return float32_val(a) & 0x007FFFFF; -} - -/*------------------------------------------------------------------------= ---- -| Returns the exponent bits of the single-precision floating-point value `= a'. -*-------------------------------------------------------------------------= ---*/ - -static inline int extractFloat32Exp(float32 a) -{ - return (float32_val(a) >> 23) & 0xFF; -} - -/*------------------------------------------------------------------------= ---- -| Returns the sign bit of the single-precision floating-point value `a'. -*-------------------------------------------------------------------------= ---*/ - -static inline bool extractFloat32Sign(float32 a) -{ - return float32_val(a) >> 31; -} - -/*------------------------------------------------------------------------= ---- -| Returns the fraction bits of the double-precision floating-point value `= a'. -*-------------------------------------------------------------------------= ---*/ - -static inline uint64_t extractFloat64Frac(float64 a) -{ - return float64_val(a) & UINT64_C(0x000FFFFFFFFFFFFF); -} - -/*------------------------------------------------------------------------= ---- -| Returns the exponent bits of the double-precision floating-point value `= a'. -*-------------------------------------------------------------------------= ---*/ - -static inline int extractFloat64Exp(float64 a) -{ - return (float64_val(a) >> 52) & 0x7FF; -} - -/*------------------------------------------------------------------------= ---- -| Returns the sign bit of the double-precision floating-point value `a'. -*-------------------------------------------------------------------------= ---*/ - -static inline bool extractFloat64Sign(float64 a) -{ - return float64_val(a) >> 63; -} - /* * Classify a floating point number. Everything above float_class_qnan * is a NaN so cls >=3D float_class_qnan is any NaN. @@ -845,6 +791,14 @@ static FloatParts128 *parts128_div(FloatParts128 *a, F= loatParts128 *b, #define parts_div(A, B, S) \ PARTS_GENERIC_64_128(div, A)(A, B, S) =20 +static FloatParts64 *parts64_modrem(FloatParts64 *a, FloatParts64 *b, + uint64_t *mod_quot, float_status *s); +static FloatParts128 *parts128_modrem(FloatParts128 *a, FloatParts128 *b, + uint64_t *mod_quot, float_status *s); + +#define parts_modrem(A, B, Q, S) \ + PARTS_GENERIC_64_128(modrem, A)(A, B, Q, S) + static void parts64_sqrt(FloatParts64 *a, float_status *s, const FloatFmt = *f); static void parts128_sqrt(FloatParts128 *a, float_status *s, const FloatFm= t *f); =20 @@ -1229,6 +1183,186 @@ static int frac256_normalize(FloatParts256 *a) =20 #define frac_normalize(A) FRAC_GENERIC_64_128_256(normalize, A)(A) =20 +static void frac64_modrem(FloatParts64 *a, FloatParts64 *b, uint64_t *mod_= quot) +{ + uint64_t a0, a1, b0, t0, t1, q, quot; + int exp_diff =3D a->exp - b->exp; + int shift; + + a0 =3D a->frac; + a1 =3D 0; + + if (exp_diff < -1) { + if (mod_quot) { + *mod_quot =3D 0; + } + return; + } + if (exp_diff =3D=3D -1) { + a0 >>=3D 1; + exp_diff =3D 0; + } + + b0 =3D b->frac; + quot =3D q =3D b0 <=3D a0; + if (q) { + a0 -=3D b0; + } + + exp_diff -=3D 64; + while (exp_diff > 0) { + q =3D estimateDiv128To64(a0, a1, b0); + q =3D q > 2 ? q - 2 : 0; + mul64To128(b0, q, &t0, &t1); + sub128(a0, a1, t0, t1, &a0, &a1); + shortShift128Left(a0, a1, 62, &a0, &a1); + exp_diff -=3D 62; + quot =3D (quot << 62) + q; + } + + exp_diff +=3D 64; + if (exp_diff > 0) { + q =3D estimateDiv128To64(a0, a1, b0); + q =3D q > 2 ? (q - 2) >> (64 - exp_diff) : 0; + mul64To128(b0, q << (64 - exp_diff), &t0, &t1); + sub128(a0, a1, t0, t1, &a0, &a1); + shortShift128Left(0, b0, 64 - exp_diff, &t0, &t1); + while (le128(t0, t1, a0, a1)) { + ++q; + sub128(a0, a1, t0, t1, &a0, &a1); + } + quot =3D (exp_diff < 64 ? quot << exp_diff : 0) + q; + } else { + t0 =3D b0; + t1 =3D 0; + } + + if (mod_quot) { + *mod_quot =3D quot; + } else { + sub128(t0, t1, a0, a1, &t0, &t1); + if (lt128(t0, t1, a0, a1) || + (eq128(t0, t1, a0, a1) && (q & 1))) { + a0 =3D t0; + a1 =3D t1; + a->sign =3D !a->sign; + } + } + + if (likely(a0)) { + shift =3D clz64(a0); + shortShift128Left(a0, a1, shift, &a0, &a1); + } else if (likely(a1)) { + shift =3D clz64(a1); + a0 =3D a1 << shift; + a1 =3D 0; + shift +=3D 64; + } else { + a->cls =3D float_class_zero; + return; + } + + a->exp =3D b->exp + exp_diff - shift; + a->frac =3D a0 | (a1 !=3D 0); +} + +static void frac128_modrem(FloatParts128 *a, FloatParts128 *b, + uint64_t *mod_quot) +{ + uint64_t a0, a1, a2, b0, b1, t0, t1, t2, q, quot; + int exp_diff =3D a->exp - b->exp; + int shift; + + a0 =3D a->frac_hi; + a1 =3D a->frac_lo; + a2 =3D 0; + + if (exp_diff < -1) { + if (mod_quot) { + *mod_quot =3D 0; + } + return; + } + if (exp_diff =3D=3D -1) { + shift128Right(a0, a1, 1, &a0, &a1); + exp_diff =3D 0; + } + + b0 =3D b->frac_hi; + b1 =3D b->frac_lo; + + quot =3D q =3D le128(b0, b1, a0, a1); + if (q) { + sub128(a0, a1, b0, b1, &a0, &a1); + } + + exp_diff -=3D 64; + while (exp_diff > 0) { + q =3D estimateDiv128To64(a0, a1, b0); + q =3D q > 4 ? q - 4 : 0; + mul128By64To192(b0, b1, q, &t0, &t1, &t2); + sub192(a0, a1, a2, t0, t1, t2, &a0, &a1, &a2); + shortShift192Left(a0, a1, a2, 61, &a0, &a1, &a2); + exp_diff -=3D 61; + quot =3D (quot << 61) + q; + } + + exp_diff +=3D 64; + if (exp_diff > 0) { + q =3D estimateDiv128To64(a0, a1, b0); + q =3D q > 4 ? (q - 4) >> (64 - exp_diff) : 0; + mul128By64To192(b0, b1, q << (64 - exp_diff), &t0, &t1, &t2); + sub192(a0, a1, a2, t0, t1, t2, &a0, &a1, &a2); + shortShift192Left(0, b0, b1, 64 - exp_diff, &t0, &t1, &t2); + while (le192(t0, t1, t2, a0, a1, a2)) { + ++q; + sub192(a0, a1, a2, t0, t1, t2, &a0, &a1, &a2); + } + quot =3D (exp_diff < 64 ? quot << exp_diff : 0) + q; + } else { + t0 =3D b0; + t1 =3D b1; + t2 =3D 0; + } + + if (mod_quot) { + *mod_quot =3D quot; + } else { + sub192(t0, t1, t2, a0, a1, a2, &t0, &t1, &t2); + if (lt192(t0, t1, t2, a0, a1, a2) || + (eq192(t0, t1, t2, a0, a1, a2) && (q & 1))) { + a0 =3D t0; + a1 =3D t1; + a2 =3D t2; + a->sign =3D !a->sign; + } + } + + if (likely(a0)) { + shift =3D clz64(a0); + shortShift192Left(a0, a1, a2, shift, &a0, &a1, &a2); + } else if (likely(a1)) { + shift =3D clz64(a1); + shortShift128Left(a1, a2, shift, &a0, &a1); + a2 =3D 0; + shift +=3D 64; + } else if (likely(a2)) { + shift =3D clz64(a2); + a0 =3D a2 << shift; + a1 =3D a2 =3D 0; + shift +=3D 128; + } else { + a->cls =3D float_class_zero; + return; + } + + a->exp =3D b->exp + exp_diff - shift; + a->frac_hi =3D a0; + a->frac_lo =3D a1 | (a2 !=3D 0); +} + +#define frac_modrem(A, B, Q) FRAC_GENERIC_64_128(modrem, A)(A, B, Q) + static void frac64_shl(FloatParts64 *a, int c) { a->frac <<=3D c; @@ -2313,6 +2447,79 @@ floatx80 floatx80_div(floatx80 a, floatx80 b, float_= status *status) return floatx80_round_pack_canonical(pr, status); } =20 +/* + * Remainder + */ + +float32 float32_rem(float32 a, float32 b, float_status *status) +{ + FloatParts64 pa, pb, *pr; + + float32_unpack_canonical(&pa, a, status); + float32_unpack_canonical(&pb, b, status); + pr =3D parts_modrem(&pa, &pb, NULL, status); + + return float32_round_pack_canonical(pr, status); +} + +float64 float64_rem(float64 a, float64 b, float_status *status) +{ + FloatParts64 pa, pb, *pr; + + float64_unpack_canonical(&pa, a, status); + float64_unpack_canonical(&pb, b, status); + pr =3D parts_modrem(&pa, &pb, NULL, status); + + return float64_round_pack_canonical(pr, status); +} + +float128 float128_rem(float128 a, float128 b, float_status *status) +{ + FloatParts128 pa, pb, *pr; + + float128_unpack_canonical(&pa, a, status); + float128_unpack_canonical(&pb, b, status); + pr =3D parts_modrem(&pa, &pb, NULL, status); + + return float128_round_pack_canonical(pr, status); +} + +/* + * Returns the remainder of the extended double-precision floating-point v= alue + * `a' with respect to the corresponding value `b'. + * If 'mod' is false, the operation is performed according to the IEC/IEEE + * Standard for Binary Floating-Point Arithmetic. If 'mod' is true, return + * the remainder based on truncating the quotient toward zero instead and + * *quotient is set to the low 64 bits of the absolute value of the integer + * quotient. + */ +floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, + uint64_t *quotient, float_status *status) +{ + FloatParts128 pa, pb, *pr; + + *quotient =3D 0; + if (!floatx80_unpack_canonical(&pa, a, status) || + !floatx80_unpack_canonical(&pb, b, status)) { + return floatx80_default_nan(status); + } + pr =3D parts_modrem(&pa, &pb, mod ? quotient : NULL, status); + + return floatx80_round_pack_canonical(pr, status); +} + +floatx80 floatx80_rem(floatx80 a, floatx80 b, float_status *status) +{ + uint64_t quotient; + return floatx80_modrem(a, b, false, "ient, status); +} + +floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status) +{ + uint64_t quotient; + return floatx80_modrem(a, b, true, "ient, status); +} + /* * Float to Float conversions * @@ -4262,300 +4469,6 @@ bfloat16 bfloat16_squash_input_denormal(bfloat16 a,= float_status *status) return a; } =20 -/*------------------------------------------------------------------------= ---- -| Normalizes the subnormal single-precision floating-point value represent= ed -| by the denormalized significand `aSig'. The normalized exponent and -| significand are stored at the locations pointed to by `zExpPtr' and -| `zSigPtr', respectively. -*-------------------------------------------------------------------------= ---*/ - -static void - normalizeFloat32Subnormal(uint32_t aSig, int *zExpPtr, uint32_t *zSigPtr) -{ - int8_t shiftCount; - - shiftCount =3D clz32(aSig) - 8; - *zSigPtr =3D aSig<float_rounding_mode; - roundNearestEven =3D ( roundingMode =3D=3D float_round_nearest_even ); - switch (roundingMode) { - case float_round_nearest_even: - case float_round_ties_away: - roundIncrement =3D 0x40; - break; - case float_round_to_zero: - roundIncrement =3D 0; - break; - case float_round_up: - roundIncrement =3D zSign ? 0 : 0x7f; - break; - case float_round_down: - roundIncrement =3D zSign ? 0x7f : 0; - break; - case float_round_to_odd: - roundIncrement =3D zSig & 0x80 ? 0 : 0x7f; - break; - default: - abort(); - break; - } - roundBits =3D zSig & 0x7F; - if ( 0xFD <=3D (uint16_t) zExp ) { - if ( ( 0xFD < zExp ) - || ( ( zExp =3D=3D 0xFD ) - && ( (int32_t) ( zSig + roundIncrement ) < 0 ) ) - ) { - bool overflow_to_inf =3D roundingMode !=3D float_round_to_odd = && - roundIncrement !=3D 0; - float_raise(float_flag_overflow | float_flag_inexact, status); - return packFloat32(zSign, 0xFF, -!overflow_to_inf); - } - if ( zExp < 0 ) { - if (status->flush_to_zero) { - float_raise(float_flag_output_denormal, status); - return packFloat32(zSign, 0, 0); - } - isTiny =3D status->tininess_before_rounding - || (zExp < -1) - || (zSig + roundIncrement < 0x80000000); - shift32RightJamming( zSig, - zExp, &zSig ); - zExp =3D 0; - roundBits =3D zSig & 0x7F; - if (isTiny && roundBits) { - float_raise(float_flag_underflow, status); - } - if (roundingMode =3D=3D float_round_to_odd) { - /* - * For round-to-odd case, the roundIncrement depends on - * zSig which just changed. - */ - roundIncrement =3D zSig & 0x80 ? 0 : 0x7f; - } - } - } - if (roundBits) { - float_raise(float_flag_inexact, status); - } - zSig =3D ( zSig + roundIncrement )>>7; - if (!(roundBits ^ 0x40) && roundNearestEven) { - zSig &=3D ~1; - } - if ( zSig =3D=3D 0 ) zExp =3D 0; - return packFloat32( zSign, zExp, zSig ); - -} - -/*------------------------------------------------------------------------= ---- -| Takes an abstract floating-point value having sign `zSign', exponent `zE= xp', -| and significand `zSig', and returns the proper single-precision floating- -| point value corresponding to the abstract input. This routine is just l= ike -| `roundAndPackFloat32' except that `zSig' does not have to be normalized. -| Bit 31 of `zSig' must be zero, and `zExp' must be 1 less than the ``true= '' -| floating-point exponent. -*-------------------------------------------------------------------------= ---*/ - -static float32 - normalizeRoundAndPackFloat32(bool zSign, int zExp, uint32_t zSig, - float_status *status) -{ - int8_t shiftCount; - - shiftCount =3D clz32(zSig) - 1; - return roundAndPackFloat32(zSign, zExp - shiftCount, zSig<float_rounding_mode; - roundNearestEven =3D ( roundingMode =3D=3D float_round_nearest_even ); - switch (roundingMode) { - case float_round_nearest_even: - case float_round_ties_away: - roundIncrement =3D 0x200; - break; - case float_round_to_zero: - roundIncrement =3D 0; - break; - case float_round_up: - roundIncrement =3D zSign ? 0 : 0x3ff; - break; - case float_round_down: - roundIncrement =3D zSign ? 0x3ff : 0; - break; - case float_round_to_odd: - roundIncrement =3D (zSig & 0x400) ? 0 : 0x3ff; - break; - default: - abort(); - } - roundBits =3D zSig & 0x3FF; - if ( 0x7FD <=3D (uint16_t) zExp ) { - if ( ( 0x7FD < zExp ) - || ( ( zExp =3D=3D 0x7FD ) - && ( (int64_t) ( zSig + roundIncrement ) < 0 ) ) - ) { - bool overflow_to_inf =3D roundingMode !=3D float_round_to_odd = && - roundIncrement !=3D 0; - float_raise(float_flag_overflow | float_flag_inexact, status); - return packFloat64(zSign, 0x7FF, -(!overflow_to_inf)); - } - if ( zExp < 0 ) { - if (status->flush_to_zero) { - float_raise(float_flag_output_denormal, status); - return packFloat64(zSign, 0, 0); - } - isTiny =3D status->tininess_before_rounding - || (zExp < -1) - || (zSig + roundIncrement < UINT64_C(0x8000000000000000)= ); - shift64RightJamming( zSig, - zExp, &zSig ); - zExp =3D 0; - roundBits =3D zSig & 0x3FF; - if (isTiny && roundBits) { - float_raise(float_flag_underflow, status); - } - if (roundingMode =3D=3D float_round_to_odd) { - /* - * For round-to-odd case, the roundIncrement depends on - * zSig which just changed. - */ - roundIncrement =3D (zSig & 0x400) ? 0 : 0x3ff; - } - } - } - if (roundBits) { - float_raise(float_flag_inexact, status); - } - zSig =3D ( zSig + roundIncrement )>>10; - if (!(roundBits ^ 0x200) && roundNearestEven) { - zSig &=3D ~1; - } - if ( zSig =3D=3D 0 ) zExp =3D 0; - return packFloat64( zSign, zExp, zSig ); - -} - -/*------------------------------------------------------------------------= ---- -| Takes an abstract floating-point value having sign `zSign', exponent `zE= xp', -| and significand `zSig', and returns the proper double-precision floating- -| point value corresponding to the abstract input. This routine is just l= ike -| `roundAndPackFloat64' except that `zSig' does not have to be normalized. -| Bit 63 of `zSig' must be zero, and `zExp' must be 1 less than the ``true= '' -| floating-point exponent. -*-------------------------------------------------------------------------= ---*/ - -static float64 - normalizeRoundAndPackFloat64(bool zSign, int zExp, uint64_t zSig, - float_status *status) -{ - int8_t shiftCount; - - shiftCount =3D clz64(zSig) - 1; - return roundAndPackFloat64(zSign, zExp - shiftCount, zSig<>48 ) & 0x7FFF; - -} - -/*------------------------------------------------------------------------= ---- -| Returns the sign bit of the quadruple-precision floating-point value `a'. -*-------------------------------------------------------------------------= ---*/ - -static inline bool extractFloat128Sign(float128 a) -{ - return a.high >> 63; -} - -/*------------------------------------------------------------------------= ---- -| Normalizes the subnormal quadruple-precision floating-point value -| represented by the denormalized significand formed by the concatenation = of -| `aSig0' and `aSig1'. The normalized exponent is stored at the location -| pointed to by `zExpPtr'. The most significant 49 bits of the normalized -| significand are stored at the location pointed to by `zSig0Ptr', and the -| least significant 64 bits of the normalized significand are stored at the -| location pointed to by `zSig1Ptr'. -*-------------------------------------------------------------------------= ---*/ - -static void - normalizeFloat128Subnormal( - uint64_t aSig0, - uint64_t aSig1, - int32_t *zExpPtr, - uint64_t *zSig0Ptr, - uint64_t *zSig1Ptr - ) -{ - int8_t shiftCount; - - if ( aSig0 =3D=3D 0 ) { - shiftCount =3D clz64(aSig1) - 15; - if ( shiftCount < 0 ) { - *zSig0Ptr =3D aSig1>>( - shiftCount ); - *zSig1Ptr =3D aSig1<<( shiftCount & 63 ); - } - else { - *zSig0Ptr =3D aSig1<float_rounding_mode; - roundNearestEven =3D ( roundingMode =3D=3D float_round_nearest_even ); - switch (roundingMode) { - case float_round_nearest_even: - case float_round_ties_away: - increment =3D ((int64_t)zSig2 < 0); - break; - case float_round_to_zero: - increment =3D 0; - break; - case float_round_up: - increment =3D !zSign && zSig2; - break; - case float_round_down: - increment =3D zSign && zSig2; - break; - case float_round_to_odd: - increment =3D !(zSig1 & 0x1) && zSig2; - break; - default: - abort(); - } - if ( 0x7FFD <=3D (uint32_t) zExp ) { - if ( ( 0x7FFD < zExp ) - || ( ( zExp =3D=3D 0x7FFD ) - && eq128( - UINT64_C(0x0001FFFFFFFFFFFF), - UINT64_C(0xFFFFFFFFFFFFFFFF), - zSig0, - zSig1 - ) - && increment - ) - ) { - float_raise(float_flag_overflow | float_flag_inexact, status); - if ( ( roundingMode =3D=3D float_round_to_zero ) - || ( zSign && ( roundingMode =3D=3D float_round_up ) ) - || ( ! zSign && ( roundingMode =3D=3D float_round_down ) ) - || (roundingMode =3D=3D float_round_to_odd) - ) { - return - packFloat128( - zSign, - 0x7FFE, - UINT64_C(0x0000FFFFFFFFFFFF), - UINT64_C(0xFFFFFFFFFFFFFFFF) - ); - } - return packFloat128( zSign, 0x7FFF, 0, 0 ); - } - if ( zExp < 0 ) { - if (status->flush_to_zero) { - float_raise(float_flag_output_denormal, status); - return packFloat128(zSign, 0, 0, 0); - } - isTiny =3D status->tininess_before_rounding - || (zExp < -1) - || !increment - || lt128(zSig0, zSig1, - UINT64_C(0x0001FFFFFFFFFFFF), - UINT64_C(0xFFFFFFFFFFFFFFFF)); - shift128ExtraRightJamming( - zSig0, zSig1, zSig2, - zExp, &zSig0, &zSig1, &zSig2 ); - zExp =3D 0; - if (isTiny && zSig2) { - float_raise(float_flag_underflow, status); - } - switch (roundingMode) { - case float_round_nearest_even: - case float_round_ties_away: - increment =3D ((int64_t)zSig2 < 0); - break; - case float_round_to_zero: - increment =3D 0; - break; - case float_round_up: - increment =3D !zSign && zSig2; - break; - case float_round_down: - increment =3D zSign && zSig2; - break; - case float_round_to_odd: - increment =3D !(zSig1 & 0x1) && zSig2; - break; - default: - abort(); - } - } - } - if (zSig2) { - float_raise(float_flag_inexact, status); - } - if ( increment ) { - add128( zSig0, zSig1, 0, 1, &zSig0, &zSig1 ); - if ((zSig2 + zSig2 =3D=3D 0) && roundNearestEven) { - zSig1 &=3D ~1; - } - } - else { - if ( ( zSig0 | zSig1 ) =3D=3D 0 ) zExp =3D 0; - } - return packFloat128( zSign, zExp, zSig0, zSig1 ); - -} - -/*------------------------------------------------------------------------= ---- -| Takes an abstract floating-point value having sign `zSign', exponent `zE= xp', -| and significand formed by the concatenation of `zSig0' and `zSig1', and -| returns the proper quadruple-precision floating-point value corresponding -| to the abstract input. This routine is just like `roundAndPackFloat128' -| except that the input significand has fewer bits and does not have to be -| normalized. In all cases, `zExp' must be 1 less than the ``true'' float= ing- -| point exponent. -*-------------------------------------------------------------------------= ---*/ - -static float128 normalizeRoundAndPackFloat128(bool zSign, int32_t zExp, - uint64_t zSig0, uint64_t zSi= g1, - float_status *status) -{ - int8_t shiftCount; - uint64_t zSig2; - - if ( zSig0 =3D=3D 0 ) { - zSig0 =3D zSig1; - zSig1 =3D 0; - zExp -=3D 64; - } - shiftCount =3D clz64(zSig0) - 15; - if ( 0 <=3D shiftCount ) { - zSig2 =3D 0; - shortShift128Left( zSig0, zSig1, shiftCount, &zSig0, &zSig1 ); - } - else { - shift128ExtraRightJamming( - zSig0, zSig1, 0, - shiftCount, &zSig0, &zSig1, &zSig2 ); - } - zExp -=3D shiftCount; - return roundAndPackFloat128(zSign, zExp, zSig0, zSig1, zSig2, status); - -} - -/*------------------------------------------------------------------------= ---- -| Returns the remainder of the single-precision floating-point value `a' -| with respect to the corresponding value `b'. The operation is performed -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float32 float32_rem(float32 a, float32 b, float_status *status) -{ - bool aSign, zSign; - int aExp, bExp, expDiff; - uint32_t aSig, bSig; - uint32_t q; - uint64_t aSig64, bSig64, q64; - uint32_t alternateASig; - int32_t sigMean; - a =3D float32_squash_input_denormal(a, status); - b =3D float32_squash_input_denormal(b, status); - - aSig =3D extractFloat32Frac( a ); - aExp =3D extractFloat32Exp( a ); - aSign =3D extractFloat32Sign( a ); - bSig =3D extractFloat32Frac( b ); - bExp =3D extractFloat32Exp( b ); - if ( aExp =3D=3D 0xFF ) { - if ( aSig || ( ( bExp =3D=3D 0xFF ) && bSig ) ) { - return propagateFloat32NaN(a, b, status); - } - float_raise(float_flag_invalid, status); - return float32_default_nan(status); - } - if ( bExp =3D=3D 0xFF ) { - if (bSig) { - return propagateFloat32NaN(a, b, status); - } - return a; - } - if ( bExp =3D=3D 0 ) { - if ( bSig =3D=3D 0 ) { - float_raise(float_flag_invalid, status); - return float32_default_nan(status); - } - normalizeFloat32Subnormal( bSig, &bExp, &bSig ); - } - if ( aExp =3D=3D 0 ) { - if ( aSig =3D=3D 0 ) return a; - normalizeFloat32Subnormal( aSig, &aExp, &aSig ); - } - expDiff =3D aExp - bExp; - aSig |=3D 0x00800000; - bSig |=3D 0x00800000; - if ( expDiff < 32 ) { - aSig <<=3D 8; - bSig <<=3D 8; - if ( expDiff < 0 ) { - if ( expDiff < -1 ) return a; - aSig >>=3D 1; - } - q =3D ( bSig <=3D aSig ); - if ( q ) aSig -=3D bSig; - if ( 0 < expDiff ) { - q =3D ( ( (uint64_t) aSig )<<32 ) / bSig; - q >>=3D 32 - expDiff; - bSig >>=3D 2; - aSig =3D ( ( aSig>>1 )<<( expDiff - 1 ) ) - bSig * q; - } - else { - aSig >>=3D 2; - bSig >>=3D 2; - } - } - else { - if ( bSig <=3D aSig ) aSig -=3D bSig; - aSig64 =3D ( (uint64_t) aSig )<<40; - bSig64 =3D ( (uint64_t) bSig )<<40; - expDiff -=3D 64; - while ( 0 < expDiff ) { - q64 =3D estimateDiv128To64( aSig64, 0, bSig64 ); - q64 =3D ( 2 < q64 ) ? q64 - 2 : 0; - aSig64 =3D - ( ( bSig * q64 )<<38 ); - expDiff -=3D 62; - } - expDiff +=3D 64; - q64 =3D estimateDiv128To64( aSig64, 0, bSig64 ); - q64 =3D ( 2 < q64 ) ? q64 - 2 : 0; - q =3D q64>>( 64 - expDiff ); - bSig <<=3D 6; - aSig =3D ( ( aSig64>>33 )<<( expDiff - 1 ) ) - bSig * q; - } - do { - alternateASig =3D aSig; - ++q; - aSig -=3D bSig; - } while ( 0 <=3D (int32_t) aSig ); - sigMean =3D aSig + alternateASig; - if ( ( sigMean < 0 ) || ( ( sigMean =3D=3D 0 ) && ( q & 1 ) ) ) { - aSig =3D alternateASig; - } - zSign =3D ( (int32_t) aSig < 0 ); - if ( zSign ) aSig =3D - aSig; - return normalizeRoundAndPackFloat32(aSign ^ zSign, bExp, aSig, status); -} - - - /*------------------------------------------------------------------------= ---- | Returns the binary exponential of the single-precision floating-point va= lue | `a'. The operation is performed according to the IEC/IEEE Standard for @@ -5273,94 +4804,6 @@ float32 float32_exp2(float32 a, float_status *status) return float32_round_pack_canonical(&rp, status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the remainder of the double-precision floating-point value `a' -| with respect to the corresponding value `b'. The operation is performed -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float64 float64_rem(float64 a, float64 b, float_status *status) -{ - bool aSign, zSign; - int aExp, bExp, expDiff; - uint64_t aSig, bSig; - uint64_t q, alternateASig; - int64_t sigMean; - - a =3D float64_squash_input_denormal(a, status); - b =3D float64_squash_input_denormal(b, status); - aSig =3D extractFloat64Frac( a ); - aExp =3D extractFloat64Exp( a ); - aSign =3D extractFloat64Sign( a ); - bSig =3D extractFloat64Frac( b ); - bExp =3D extractFloat64Exp( b ); - if ( aExp =3D=3D 0x7FF ) { - if ( aSig || ( ( bExp =3D=3D 0x7FF ) && bSig ) ) { - return propagateFloat64NaN(a, b, status); - } - float_raise(float_flag_invalid, status); - return float64_default_nan(status); - } - if ( bExp =3D=3D 0x7FF ) { - if (bSig) { - return propagateFloat64NaN(a, b, status); - } - return a; - } - if ( bExp =3D=3D 0 ) { - if ( bSig =3D=3D 0 ) { - float_raise(float_flag_invalid, status); - return float64_default_nan(status); - } - normalizeFloat64Subnormal( bSig, &bExp, &bSig ); - } - if ( aExp =3D=3D 0 ) { - if ( aSig =3D=3D 0 ) return a; - normalizeFloat64Subnormal( aSig, &aExp, &aSig ); - } - expDiff =3D aExp - bExp; - aSig =3D (aSig | UINT64_C(0x0010000000000000)) << 11; - bSig =3D (bSig | UINT64_C(0x0010000000000000)) << 11; - if ( expDiff < 0 ) { - if ( expDiff < -1 ) return a; - aSig >>=3D 1; - } - q =3D ( bSig <=3D aSig ); - if ( q ) aSig -=3D bSig; - expDiff -=3D 64; - while ( 0 < expDiff ) { - q =3D estimateDiv128To64( aSig, 0, bSig ); - q =3D ( 2 < q ) ? q - 2 : 0; - aSig =3D - ( ( bSig>>2 ) * q ); - expDiff -=3D 62; - } - expDiff +=3D 64; - if ( 0 < expDiff ) { - q =3D estimateDiv128To64( aSig, 0, bSig ); - q =3D ( 2 < q ) ? q - 2 : 0; - q >>=3D 64 - expDiff; - bSig >>=3D 2; - aSig =3D ( ( aSig>>1 )<<( expDiff - 1 ) ) - bSig * q; - } - else { - aSig >>=3D 2; - bSig >>=3D 2; - } - do { - alternateASig =3D aSig; - ++q; - aSig -=3D bSig; - } while ( 0 <=3D (int64_t) aSig ); - sigMean =3D aSig + alternateASig; - if ( ( sigMean < 0 ) || ( ( sigMean =3D=3D 0 ) && ( q & 1 ) ) ) { - aSig =3D alternateASig; - } - zSign =3D ( (int64_t) aSig < 0 ); - if ( zSign ) aSig =3D - aSig; - return normalizeRoundAndPackFloat64(aSign ^ zSign, bExp, aSig, status); - -} - /*------------------------------------------------------------------------= ---- | Rounds the extended double-precision floating-point value `a' | to the precision provided by floatx80_rounding_precision and returns the @@ -5379,266 +4822,6 @@ floatx80 floatx80_round(floatx80 a, float_status *s= tatus) return floatx80_round_pack_canonical(&p, status); } =20 -/*------------------------------------------------------------------------= ---- -| Returns the remainder of the extended double-precision floating-point va= lue -| `a' with respect to the corresponding value `b'. The operation is perfo= rmed -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic, -| if 'mod' is false; if 'mod' is true, return the remainder based on trunc= ating -| the quotient toward zero instead. '*quotient' is set to the low 64 bits= of -| the absolute value of the integer quotient. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, uint64_t *quoti= ent, - float_status *status) -{ - bool aSign, zSign; - int32_t aExp, bExp, expDiff, aExpOrig; - uint64_t aSig0, aSig1, bSig; - uint64_t q, term0, term1, alternateASig0, alternateASig1; - - *quotient =3D 0; - if (floatx80_invalid_encoding(a) || floatx80_invalid_encoding(b)) { - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - aSig0 =3D extractFloatx80Frac( a ); - aExpOrig =3D aExp =3D extractFloatx80Exp( a ); - aSign =3D extractFloatx80Sign( a ); - bSig =3D extractFloatx80Frac( b ); - bExp =3D extractFloatx80Exp( b ); - if ( aExp =3D=3D 0x7FFF ) { - if ( (uint64_t) ( aSig0<<1 ) - || ( ( bExp =3D=3D 0x7FFF ) && (uint64_t) ( bSig<<1 ) ) ) { - return propagateFloatx80NaN(a, b, status); - } - goto invalid; - } - if ( bExp =3D=3D 0x7FFF ) { - if ((uint64_t)(bSig << 1)) { - return propagateFloatx80NaN(a, b, status); - } - if (aExp =3D=3D 0 && aSig0 >> 63) { - /* - * Pseudo-denormal argument must be returned in normalized - * form. - */ - return packFloatx80(aSign, 1, aSig0); - } - return a; - } - if ( bExp =3D=3D 0 ) { - if ( bSig =3D=3D 0 ) { - invalid: - float_raise(float_flag_invalid, status); - return floatx80_default_nan(status); - } - normalizeFloatx80Subnormal( bSig, &bExp, &bSig ); - } - if ( aExp =3D=3D 0 ) { - if ( aSig0 =3D=3D 0 ) return a; - normalizeFloatx80Subnormal( aSig0, &aExp, &aSig0 ); - } - zSign =3D aSign; - expDiff =3D aExp - bExp; - aSig1 =3D 0; - if ( expDiff < 0 ) { - if ( mod || expDiff < -1 ) { - if (aExp =3D=3D 1 && aExpOrig =3D=3D 0) { - /* - * Pseudo-denormal argument must be returned in - * normalized form. - */ - return packFloatx80(aSign, aExp, aSig0); - } - return a; - } - shift128Right( aSig0, 0, 1, &aSig0, &aSig1 ); - expDiff =3D 0; - } - *quotient =3D q =3D ( bSig <=3D aSig0 ); - if ( q ) aSig0 -=3D bSig; - expDiff -=3D 64; - while ( 0 < expDiff ) { - q =3D estimateDiv128To64( aSig0, aSig1, bSig ); - q =3D ( 2 < q ) ? q - 2 : 0; - mul64To128( bSig, q, &term0, &term1 ); - sub128( aSig0, aSig1, term0, term1, &aSig0, &aSig1 ); - shortShift128Left( aSig0, aSig1, 62, &aSig0, &aSig1 ); - expDiff -=3D 62; - *quotient <<=3D 62; - *quotient +=3D q; - } - expDiff +=3D 64; - if ( 0 < expDiff ) { - q =3D estimateDiv128To64( aSig0, aSig1, bSig ); - q =3D ( 2 < q ) ? q - 2 : 0; - q >>=3D 64 - expDiff; - mul64To128( bSig, q<<( 64 - expDiff ), &term0, &term1 ); - sub128( aSig0, aSig1, term0, term1, &aSig0, &aSig1 ); - shortShift128Left( 0, bSig, 64 - expDiff, &term0, &term1 ); - while ( le128( term0, term1, aSig0, aSig1 ) ) { - ++q; - sub128( aSig0, aSig1, term0, term1, &aSig0, &aSig1 ); - } - if (expDiff < 64) { - *quotient <<=3D expDiff; - } else { - *quotient =3D 0; - } - *quotient +=3D q; - } - else { - term1 =3D 0; - term0 =3D bSig; - } - if (!mod) { - sub128( term0, term1, aSig0, aSig1, &alternateASig0, &alternateASi= g1 ); - if ( lt128( alternateASig0, alternateASig1, aSig0, aSig1 ) - || ( eq128( alternateASig0, alternateASig1, aSig0, aSig= 1 ) - && ( q & 1 ) ) - ) { - aSig0 =3D alternateASig0; - aSig1 =3D alternateASig1; - zSign =3D ! zSign; - ++*quotient; - } - } - return - normalizeRoundAndPackFloatx80( - floatx80_precision_x, zSign, bExp + expDiff, aSig0, aSig1, sta= tus); - -} - -/*------------------------------------------------------------------------= ---- -| Returns the remainder of the extended double-precision floating-point va= lue -| `a' with respect to the corresponding value `b'. The operation is perfo= rmed -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_rem(floatx80 a, floatx80 b, float_status *status) -{ - uint64_t quotient; - return floatx80_modrem(a, b, false, "ient, status); -} - -/*------------------------------------------------------------------------= ---- -| Returns the remainder of the extended double-precision floating-point va= lue -| `a' with respect to the corresponding value `b', with the quotient trunc= ated -| toward zero. -*-------------------------------------------------------------------------= ---*/ - -floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status) -{ - uint64_t quotient; - return floatx80_modrem(a, b, true, "ient, status); -} - -/*------------------------------------------------------------------------= ---- -| Returns the remainder of the quadruple-precision floating-point value `a' -| with respect to the corresponding value `b'. The operation is performed -| according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. -*-------------------------------------------------------------------------= ---*/ - -float128 float128_rem(float128 a, float128 b, float_status *status) -{ - bool aSign, zSign; - int32_t aExp, bExp, expDiff; - uint64_t aSig0, aSig1, bSig0, bSig1, q, term0, term1, term2; - uint64_t allZero, alternateASig0, alternateASig1, sigMean1; - int64_t sigMean0; - - aSig1 =3D extractFloat128Frac1( a ); - aSig0 =3D extractFloat128Frac0( a ); - aExp =3D extractFloat128Exp( a ); - aSign =3D extractFloat128Sign( a ); - bSig1 =3D extractFloat128Frac1( b ); - bSig0 =3D extractFloat128Frac0( b ); - bExp =3D extractFloat128Exp( b ); - if ( aExp =3D=3D 0x7FFF ) { - if ( ( aSig0 | aSig1 ) - || ( ( bExp =3D=3D 0x7FFF ) && ( bSig0 | bSig1 ) ) ) { - return propagateFloat128NaN(a, b, status); - } - goto invalid; - } - if ( bExp =3D=3D 0x7FFF ) { - if (bSig0 | bSig1) { - return propagateFloat128NaN(a, b, status); - } - return a; - } - if ( bExp =3D=3D 0 ) { - if ( ( bSig0 | bSig1 ) =3D=3D 0 ) { - invalid: - float_raise(float_flag_invalid, status); - return float128_default_nan(status); - } - normalizeFloat128Subnormal( bSig0, bSig1, &bExp, &bSig0, &bSig1 ); - } - if ( aExp =3D=3D 0 ) { - if ( ( aSig0 | aSig1 ) =3D=3D 0 ) return a; - normalizeFloat128Subnormal( aSig0, aSig1, &aExp, &aSig0, &aSig1 ); - } - expDiff =3D aExp - bExp; - if ( expDiff < -1 ) return a; - shortShift128Left( - aSig0 | UINT64_C(0x0001000000000000), - aSig1, - 15 - ( expDiff < 0 ), - &aSig0, - &aSig1 - ); - shortShift128Left( - bSig0 | UINT64_C(0x0001000000000000), bSig1, 15, &bSig0, &bSig1 ); - q =3D le128( bSig0, bSig1, aSig0, aSig1 ); - if ( q ) sub128( aSig0, aSig1, bSig0, bSig1, &aSig0, &aSig1 ); - expDiff -=3D 64; - while ( 0 < expDiff ) { - q =3D estimateDiv128To64( aSig0, aSig1, bSig0 ); - q =3D ( 4 < q ) ? q - 4 : 0; - mul128By64To192( bSig0, bSig1, q, &term0, &term1, &term2 ); - shortShift192Left( term0, term1, term2, 61, &term1, &term2, &allZe= ro ); - shortShift128Left( aSig0, aSig1, 61, &aSig0, &allZero ); - sub128( aSig0, 0, term1, term2, &aSig0, &aSig1 ); - expDiff -=3D 61; - } - if ( -64 < expDiff ) { - q =3D estimateDiv128To64( aSig0, aSig1, bSig0 ); - q =3D ( 4 < q ) ? q - 4 : 0; - q >>=3D - expDiff; - shift128Right( bSig0, bSig1, 12, &bSig0, &bSig1 ); - expDiff +=3D 52; - if ( expDiff < 0 ) { - shift128Right( aSig0, aSig1, - expDiff, &aSig0, &aSig1 ); - } - else { - shortShift128Left( aSig0, aSig1, expDiff, &aSig0, &aSig1 ); - } - mul128By64To192( bSig0, bSig1, q, &term0, &term1, &term2 ); - sub128( aSig0, aSig1, term1, term2, &aSig0, &aSig1 ); - } - else { - shift128Right( aSig0, aSig1, 12, &aSig0, &aSig1 ); - shift128Right( bSig0, bSig1, 12, &bSig0, &bSig1 ); - } - do { - alternateASig0 =3D aSig0; - alternateASig1 =3D aSig1; - ++q; - sub128( aSig0, aSig1, bSig0, bSig1, &aSig0, &aSig1 ); - } while ( 0 <=3D (int64_t) aSig0 ); - add128( - aSig0, aSig1, alternateASig0, alternateASig1, (uint64_t *)&sigMean= 0, &sigMean1 ); - if ( ( sigMean0 < 0 ) - || ( ( ( sigMean0 | sigMean1 ) =3D=3D 0 ) && ( q & 1 ) ) ) { - aSig0 =3D alternateASig0; - aSig1 =3D alternateASig1; - } - zSign =3D ( (int64_t) aSig0 < 0 ); - if ( zSign ) sub128( 0, 0, aSig0, aSig1, &aSig0, &aSig1 ); - return normalizeRoundAndPackFloat128(aSign ^ zSign, bExp - 4, aSig0, a= Sig1, - status); -} static void __attribute__((constructor)) softfloat_init(void) { union_float64 ua, ub, uc, ur; diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index d1bd5c6edf..dddee92d6e 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -626,6 +626,40 @@ static FloatPartsN *partsN(div)(FloatPartsN *a, FloatP= artsN *b, return a; } =20 +/* + * Floating point remainder, per IEC/IEEE, or modulus. + */ +static FloatPartsN *partsN(modrem)(FloatPartsN *a, FloatPartsN *b, + uint64_t *mod_quot, float_status *s) +{ + int ab_mask =3D float_cmask(a->cls) | float_cmask(b->cls); + + if (likely(ab_mask =3D=3D float_cmask_normal)) { + frac_modrem(a, b, mod_quot); + return a; + } + + if (mod_quot) { + *mod_quot =3D 0; + } + + /* All the NaN cases */ + if (unlikely(ab_mask & float_cmask_anynan)) { + return parts_pick_nan(a, b, s); + } + + /* Inf % N; N % 0 */ + if (a->cls =3D=3D float_class_inf || b->cls =3D=3D float_class_zero) { + float_raise(float_flag_invalid, s); + parts_default_nan(a, s); + return a; + } + + /* N % Inf; 0 % N */ + g_assert(b->cls =3D=3D float_class_inf || a->cls =3D=3D float_class_ze= ro); + return a; +} + /* * Square Root * diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc index 95e5325f67..12467bb9bb 100644 --- a/fpu/softfloat-specialize.c.inc +++ b/fpu/softfloat-specialize.c.inc @@ -641,62 +641,6 @@ static int pickNaNMulAdd(FloatClass a_cls, FloatClass = b_cls, FloatClass c_cls, #endif } =20 -/*------------------------------------------------------------------------= ---- -| Takes two single-precision floating-point values `a' and `b', one of whi= ch -| is a NaN, and returns the appropriate NaN result. If either `a' or `b' = is a -| signaling NaN, the invalid exception is raised. -*-------------------------------------------------------------------------= ---*/ - -static float32 propagateFloat32NaN(float32 a, float32 b, float_status *sta= tus) -{ - bool aIsLargerSignificand; - uint32_t av, bv; - FloatClass a_cls, b_cls; - - /* This is not complete, but is good enough for pickNaN. */ - a_cls =3D (!float32_is_any_nan(a) - ? float_class_normal - : float32_is_signaling_nan(a, status) - ? float_class_snan - : float_class_qnan); - b_cls =3D (!float32_is_any_nan(b) - ? float_class_normal - : float32_is_signaling_nan(b, status) - ? float_class_snan - : float_class_qnan); - - av =3D float32_val(a); - bv =3D float32_val(b); - - if (is_snan(a_cls) || is_snan(b_cls)) { - float_raise(float_flag_invalid, status); - } - - if (status->default_nan_mode) { - return float32_default_nan(status); - } - - if ((uint32_t)(av << 1) < (uint32_t)(bv << 1)) { - aIsLargerSignificand =3D 0; - } else if ((uint32_t)(bv << 1) < (uint32_t)(av << 1)) { - aIsLargerSignificand =3D 1; - } else { - aIsLargerSignificand =3D (av < bv) ? 1 : 0; - } - - if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) { - if (is_snan(b_cls)) { - return float32_silence_nan(b, status); - } - return b; - } else { - if (is_snan(a_cls)) { - return float32_silence_nan(a, status); - } - return a; - } -} - /*------------------------------------------------------------------------= ---- | Returns 1 if the double-precision floating-point value `a' is a quiet | NaN; otherwise returns 0. @@ -737,62 +681,6 @@ bool float64_is_signaling_nan(float64 a_, float_status= *status) } } =20 -/*------------------------------------------------------------------------= ---- -| Takes two double-precision floating-point values `a' and `b', one of whi= ch -| is a NaN, and returns the appropriate NaN result. If either `a' or `b' = is a -| signaling NaN, the invalid exception is raised. -*-------------------------------------------------------------------------= ---*/ - -static float64 propagateFloat64NaN(float64 a, float64 b, float_status *sta= tus) -{ - bool aIsLargerSignificand; - uint64_t av, bv; - FloatClass a_cls, b_cls; - - /* This is not complete, but is good enough for pickNaN. */ - a_cls =3D (!float64_is_any_nan(a) - ? float_class_normal - : float64_is_signaling_nan(a, status) - ? float_class_snan - : float_class_qnan); - b_cls =3D (!float64_is_any_nan(b) - ? float_class_normal - : float64_is_signaling_nan(b, status) - ? float_class_snan - : float_class_qnan); - - av =3D float64_val(a); - bv =3D float64_val(b); - - if (is_snan(a_cls) || is_snan(b_cls)) { - float_raise(float_flag_invalid, status); - } - - if (status->default_nan_mode) { - return float64_default_nan(status); - } - - if ((uint64_t)(av << 1) < (uint64_t)(bv << 1)) { - aIsLargerSignificand =3D 0; - } else if ((uint64_t)(bv << 1) < (uint64_t)(av << 1)) { - aIsLargerSignificand =3D 1; - } else { - aIsLargerSignificand =3D (av < bv) ? 1 : 0; - } - - if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) { - if (is_snan(b_cls)) { - return float64_silence_nan(b, status); - } - return b; - } else { - if (is_snan(a_cls)) { - return float64_silence_nan(a, status); - } - return a; - } -} - /*------------------------------------------------------------------------= ---- | Returns 1 if the extended double-precision floating-point value `a' is a | quiet NaN; otherwise returns 0. This slightly differs from the same @@ -947,56 +835,3 @@ bool float128_is_signaling_nan(float128 a, float_statu= s *status) } } } - -/*------------------------------------------------------------------------= ---- -| Takes two quadruple-precision floating-point values `a' and `b', one of -| which is a NaN, and returns the appropriate NaN result. If either `a' or -| `b' is a signaling NaN, the invalid exception is raised. -*-------------------------------------------------------------------------= ---*/ - -static float128 propagateFloat128NaN(float128 a, float128 b, - float_status *status) -{ - bool aIsLargerSignificand; - FloatClass a_cls, b_cls; - - /* This is not complete, but is good enough for pickNaN. */ - a_cls =3D (!float128_is_any_nan(a) - ? float_class_normal - : float128_is_signaling_nan(a, status) - ? float_class_snan - : float_class_qnan); - b_cls =3D (!float128_is_any_nan(b) - ? float_class_normal - : float128_is_signaling_nan(b, status) - ? float_class_snan - : float_class_qnan); - - if (is_snan(a_cls) || is_snan(b_cls)) { - float_raise(float_flag_invalid, status); - } - - if (status->default_nan_mode) { - return float128_default_nan(status); - } - - if (lt128(a.high << 1, a.low, b.high << 1, b.low)) { - aIsLargerSignificand =3D 0; - } else if (lt128(b.high << 1, b.low, a.high << 1, a.low)) { - aIsLargerSignificand =3D 1; - } else { - aIsLargerSignificand =3D (a.high < b.high) ? 1 : 0; - } - - if (pickNaN(a_cls, b_cls, aIsLargerSignificand, status)) { - if (is_snan(b_cls)) { - return float128_silence_nan(b, status); - } - return b; - } else { - if (is_snan(a_cls)) { - return float128_silence_nan(a, status); - } - return a; - } -} --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757257; cv=none; d=zohomail.com; s=zohoarc; b=f0gryO2PRoozzfb1rDf3Fbi4x5VJcWmR2Y5Y+6XJSFwYpUZO/mN9vQwF0CdUW0wlxX0TE9/v2pve78nxVI5bSA8VIMprYDBUDJcP8dBjtu9/fsD2GgT4pRVDB4C7mKb80PDcpwOsMxXYHK2DkRG32VTuEgUjY8UfMXAdwlo8Txg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757257; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0sbWGfdi+vZU0+T2mHM/iN4YQ8XRnXrlumJZuqrhiwA=; b=RzPWjMmamRytJDjY4IyjGkH7m7EhlU4R2iP32t6Rq7PXn6ZEdCfoL/lPr7nyIedCKVmV7+R4nPB39nPoyBUaFyF9/C5iPj9ms3Xn7Rggzg1I3A6M7Pvsoh0nNSCtu6MZQEbkwqHROGNFT2ym36wIgo5xj5DR8QaMke7zBvamQyg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622757257685859.7580992718152; Thu, 3 Jun 2021 14:54:17 -0700 (PDT) Received: from localhost ([::1]:41660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovI8-0003lE-IE for importer@patchew.org; Thu, 03 Jun 2021 17:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6H-0002xL-2G for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:01 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:34473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov68-0001BB-Rm for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:00 -0400 Received: by mail-pg1-x52e.google.com with SMTP id l1so6188282pgm.1 for ; Thu, 03 Jun 2021 14:41:51 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:50 -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=0sbWGfdi+vZU0+T2mHM/iN4YQ8XRnXrlumJZuqrhiwA=; b=HDrhq4+vlG3C5GOmc5mI2ax4oOXMXjxNVVGWj4BVRttcXz6RsZ4Uh3eQirI28jZjrC mAvjckDWm6Q9yPj95Rpuikvth498KEbizIAbukspe5m7UkMur+fMnox6qQHRG9eTpIDz C/p0+3H4aXpDP30YtBZFkxE+O2kfrD26y3A94qf9W0l0GpxVE1LyPG3hY+fFc4L0SPdv mQbGFB2q6be1NI8VBEyfwtguDYIm+sUKMNELFU5psAInh7qxblGxwfuem/Dbs5OHgL1q 3qWeHDmvjSdZw2hVhX1u2jhpa+7aiQUuTZ6sPB4w/kP5cO+qYlD7ZN9rPEz5168MEKAi EWmw== 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=0sbWGfdi+vZU0+T2mHM/iN4YQ8XRnXrlumJZuqrhiwA=; b=cw0Ev0sR9eci6LjrV1SotVbs2Vbhji+p2+ZFL4INJ+ab2s5zMY3B2YcwmKXieouoLN w6CKBWonSJcmu5ysv3hcmankubyzMe3PhplV9bUCo370uZYZHWi31hxPFP0BlFWG0/Vi AKfylOUM2+KKI5pljGR2ysd1YKa/yLJ0gGYSVNloRdWhT46v4S17+RxsqiSrIVIDH/Av ItwI/ogcp66rYRmBp7SzDHo6hI+1GdmZsnXjQjB5+2ey+KVwvWzfKNarDDL6eV2uqdGA 8sborcvxIjeYje/Q8Klfg5B5B2bVbeJEVIayBwELOmkLAZTIvdU+tV8+ic9SW0u1+/Bx 8a/g== X-Gm-Message-State: AOAM530tb1q2UfU+AMfVHpKh1pDiJuAhTSSI0RsPUQHXu6vZQTD25YLT y6syyrAe6h/Y3+BnF/sZmFOnMKRY9F79Qw== X-Google-Smtp-Source: ABdhPJxS2NT4C7ii9K1y86ZbXmwf1Z7PhMCFycGyxUf5SPAOdwBMkZntIJAQY5kRUqGH00Un4EjdWw== X-Received: by 2002:a63:8f4a:: with SMTP id r10mr1494928pgn.242.1622756511005; Thu, 03 Jun 2021 14:41:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 28/29] tests/fp: Enable more tests Date: Thu, 3 Jun 2021 14:41:30 -0700 Message-Id: <20210603214131.629841-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) From: Alex Benn=C3=A9e Fix the trivial typo in extF80_lt_quiet, and re-enable all of the floatx80 tests that are now fixed. Signed-off-by: Alex Benn=C3=A9e Message-ID: <87bl9iyahr.fsf@linaro.org> [rth: Squash the fix for lt_quiet, and enable that too.] Signed-off-by: Richard Henderson --- tests/fp/wrap.c.inc | 2 +- tests/fp/meson.build | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/fp/wrap.c.inc b/tests/fp/wrap.c.inc index cb1bb77e4c..9ff884c140 100644 --- a/tests/fp/wrap.c.inc +++ b/tests/fp/wrap.c.inc @@ -643,7 +643,7 @@ WRAP_CMP80(qemu_extF80M_eq, floatx80_eq_quiet) WRAP_CMP80(qemu_extF80M_le, floatx80_le) WRAP_CMP80(qemu_extF80M_lt, floatx80_lt) WRAP_CMP80(qemu_extF80M_le_quiet, floatx80_le_quiet) -WRAP_CMP80(qemu_extF80M_lt_quiet, floatx80_le_quiet) +WRAP_CMP80(qemu_extF80M_lt_quiet, floatx80_lt_quiet) #undef WRAP_CMP80 =20 #define WRAP_CMP128(name, func) \ diff --git a/tests/fp/meson.build b/tests/fp/meson.build index 9218bfd3b0..07e2cdc8d2 100644 --- a/tests/fp/meson.build +++ b/tests/fp/meson.build @@ -556,7 +556,9 @@ softfloat_conv_tests =3D { 'extF80_to_f64 extF80_to_f128 ' + 'f128_to_f16', 'int-to-float': 'i32_to_f16 i64_to_f16 i32_to_f32 i64_to_f32 ' + - 'i32_to_f64 i64_to_f64 i32_to_f128 i64_to_f128', + 'i32_to_f64 i64_to_f64 ' + + 'i32_to_extF80 i64_to_extF80 ' + + 'i32_to_f128 i64_to_f128', 'uint-to-float': 'ui32_to_f16 ui64_to_f16 ui32_to_f32 ui64_to_f32 ' + 'ui32_to_f64 ui64_to_f64 ui64_to_f128 ' + 'ui32_to_extF80 ui64_to_extF80', @@ -581,7 +583,7 @@ softfloat_conv_tests =3D { 'extF80_to_ui64 extF80_to_ui64_r_minMag ' + 'f128_to_ui64 f128_to_ui64_r_minMag', 'round-to-integer': 'f16_roundToInt f32_roundToInt ' + - 'f64_roundToInt f128_roundToInt' + 'f64_roundToInt extF80_roundToInt f128_roundToInt' } softfloat_tests =3D { 'eq_signaling' : 'compare', @@ -602,24 +604,20 @@ fptest_args =3D ['-s', '-l', '1'] fptest_rounding_args =3D ['-r', 'all'] =20 # Conversion Routines: -# FIXME: i32_to_extF80 (broken), i64_to_extF80 (broken) -# extF80_roundToInt (broken) foreach k, v : softfloat_conv_tests test('fp-test-' + k, fptest, args: fptest_args + fptest_rounding_args + v.split(), suite: ['softfloat', 'softfloat-conv']) endforeach =20 -# FIXME: extF80_{lt_quiet, rem} (broken), -# extF80_{mulAdd} (missing) foreach k, v : softfloat_tests - extF80_broken =3D ['lt_quiet', 'rem'].contains(k) test('fp-test-' + k, fptest, args: fptest_args + fptest_rounding_args + - ['f16_' + k, 'f32_' + k, 'f64_' + k, 'f128_' + k] + - (extF80_broken ? [] : ['extF80_' + k]), + ['f16_' + k, 'f32_' + k, 'f64_' + k, 'f128_' + k, 'extF80_' += k], suite: ['softfloat', 'softfloat-' + v]) endforeach + +# FIXME: extF80_{mulAdd} (missing) test('fp-test-mulAdd', fptest, # no fptest_rounding_args args: fptest_args + --=20 2.25.1 From nobody Sat May 18 15:08:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1622757406; cv=none; d=zohomail.com; s=zohoarc; b=n2MlQmbHSMoC0/UHMMFDt5x3GvWQ0pHeipJc/3x5PD5c9vNVo9pxGPrTEYrdIGvSYUZWY7MZP3Os1HDXMSdsdNPLAyA7rZcUgMSlSkTpTR8McxYsWnqOkQYUPpWb227FQF9bhNaG5j3DB610xz4HEVzE14D8Uzjr0xySnn76gt8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622757406; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ori3kQInJnhP2zXvcphOploFKdQaCYd2KPPI3jAHsoY=; b=MjQ38KMCwo8aI0EsQCFsTIV/FP1O1oQsW/GcAEWYqye/bTTPXsQEoaItU0O8F9rwPfziz/C7ICrFCkr01giE9YyBplZfa1wMvtvY3qmf14A9u09ORfrgaERNBPduWjmwbI1sJbwjT2MTG+LoFQ5p2g6a5qJ3sVWWm9d6EHhY7Ks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16227574065511002.3643109775993; Thu, 3 Jun 2021 14:56:46 -0700 (PDT) Received: from localhost ([::1]:53034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovKX-0002vi-FC for importer@patchew.org; Thu, 03 Jun 2021 17:56:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov6I-00031Q-0E for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:02 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:51717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov68-0001BK-SU for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:42:01 -0400 Received: by mail-pj1-x1032.google.com with SMTP id k5so4450753pjj.1 for ; Thu, 03 Jun 2021 14:41:52 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:51 -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=ori3kQInJnhP2zXvcphOploFKdQaCYd2KPPI3jAHsoY=; b=boTVXF1OxYGm20ZWUQdw9ZBqE2YGnoJKqBela9vUfdP4AYOsE9cY88A5iCOH3Fnk2M jWbQILkygqIMezBp+y5BSlIOT/11JUrd9Ureos/H1mAodpYk6CRctGsgVb6pLK6lGmgk 2Cy7bnaEKAwqWsXDKpsQdh2SSNS3Vk3ll/CYE6rcKFZtP20EYBJPIPQ/Of+smOzzPpsD g++gC6JTD79V2cXM8Fmf39Di4sGfwioFZGyu8fHBaZcE9koC+t+3l3AwcN58hF12s9qE 5A1L1FYjrpFsL0QlJ76OdbW6oQcXA5gewI6BnljBP6aTLjfcsaW40m6AFM/GFhIJJ5/q WsYw== 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=ori3kQInJnhP2zXvcphOploFKdQaCYd2KPPI3jAHsoY=; b=JcdkqNKDs3iyAe3LK7dryiSE+tRCw683MWakRw/MRHSbxzQSjZ7sj2Zvhcjq8rZLRl KkPwOcQ8Sw0162ylDT7s7BTs3X1zaL6XhujwVesJ76nWyfG3Sce2KIKT+iYvH/YE4+CI 6yzuCE+eX4KNb+FdTMt2XzD1Cj54xj7IAkzYLYnlspeYK/eBDb66F04Fomhsx3VgiCS8 Iau0osdBshx8P8+TkvU1hPjRXw/7wlUz3U6182Va4cwRBotUdVcOrjYvEudVcP9GNv6R KjbcTtdVP9IWItbVtbswIc+9/rOAf42XNKYZm5TT3sy3q7WvORpZor2c+JJxKWgTvVeU PX1g== X-Gm-Message-State: AOAM532X7ik+5TEE1PUrLbdq6giudb0e2ZewHxX5OSmOdG4DfgTkQXpf ZcsoICeapHKiRujgrJaWq2YItnqyJSmMaw== X-Google-Smtp-Source: ABdhPJwP0jiS65FvNqN3nklSu9UEclf5lNONEo4sEynz1e3LINbd2gcfoXXLBhukbYqQAyirw/EdbQ== X-Received: by 2002:a17:90a:b885:: with SMTP id o5mr13366707pjr.91.1622756511533; Thu, 03 Jun 2021 14:41:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 29/29] softfloat: Use hard-float for {u}int64_to_float{32,64} Date: Thu, 3 Jun 2021 14:41:31 -0700 Message-Id: <20210603214131.629841-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) For the normal case of no additional scaling, this reduces the profile contribution of int64_to_float64 to the testcase in the linked issue from 0.81% to 0.04%. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/134 Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- fpu/softfloat.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 5026f518b0..1cb162882b 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -3559,6 +3559,13 @@ float32 int64_to_float32_scalbn(int64_t a, int scale= , float_status *status) { FloatParts64 p; =20 + /* Without scaling, there are no overflow concerns. */ + if (likely(scale =3D=3D 0) && can_use_fpu(status)) { + union_float32 ur; + ur.h =3D a; + return ur.s; + } + parts64_sint_to_float(&p, a, scale, status); return float32_round_pack_canonical(&p, status); } @@ -3592,6 +3599,13 @@ float64 int64_to_float64_scalbn(int64_t a, int scale= , float_status *status) { FloatParts64 p; =20 + /* Without scaling, there are no overflow concerns. */ + if (likely(scale =3D=3D 0) && can_use_fpu(status)) { + union_float64 ur; + ur.h =3D a; + return ur.s; + } + parts_sint_to_float(&p, a, scale, status); return float64_round_pack_canonical(&p, status); } @@ -3726,6 +3740,13 @@ float32 uint64_to_float32_scalbn(uint64_t a, int sca= le, float_status *status) { FloatParts64 p; =20 + /* Without scaling, there are no overflow concerns. */ + if (likely(scale =3D=3D 0) && can_use_fpu(status)) { + union_float32 ur; + ur.h =3D a; + return ur.s; + } + parts_uint_to_float(&p, a, scale, status); return float32_round_pack_canonical(&p, status); } @@ -3759,6 +3780,13 @@ float64 uint64_to_float64_scalbn(uint64_t a, int sca= le, float_status *status) { FloatParts64 p; =20 + /* Without scaling, there are no overflow concerns. */ + if (likely(scale =3D=3D 0) && can_use_fpu(status)) { + union_float64 ur; + ur.h =3D a; + return ur.s; + } + parts_uint_to_float(&p, a, scale, status); return float64_round_pack_canonical(&p, status); } --=20 2.25.1