Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/1475720/?format=api
{ "id": 1475720, "url": "http://patchwork.ozlabs.org/api/patches/1475720/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20210508014802.892561-7-richard.henderson@linaro.org/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20210508014802.892561-7-richard.henderson@linaro.org>", "list_archive_url": null, "date": "2021-05-08T01:46:56", "name": "[06/72] softfloat: Move the binary point to the msb", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "8ab615f03696b2c072eeaec39c9af1f934cf622d", "submitter": { "id": 72104, "url": "http://patchwork.ozlabs.org/api/people/72104/?format=api", "name": "Richard Henderson", "email": "richard.henderson@linaro.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20210508014802.892561-7-richard.henderson@linaro.org/mbox/", "series": [ { "id": 242770, "url": "http://patchwork.ozlabs.org/api/series/242770/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=242770", "date": "2021-05-08T01:46:53", "name": "Convert floatx80 and float128 to FloatParts", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/242770/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/1475720/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/1475720/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": [ "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=<UNKNOWN>)", "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256\n header.s=google header.b=M0SObHiq;\n\tdkim-atps=neutral" ], "Received": [ "from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 4FcVvr0rbsz9sWp\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 8 May 2021 12:03:04 +1000 (AEST)", "from localhost ([::1]:49332 helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1lfCJ4-00022O-3q\n\tfor incoming@patchwork.ozlabs.org; Fri, 07 May 2021 22:03:02 -0400", "from eggs.gnu.org ([2001:470:142:3::10]:40534)\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <richard.henderson@linaro.org>)\n id 1lfC4j-00045a-C2\n for qemu-devel@nongnu.org; Fri, 07 May 2021 21:48:13 -0400", "from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:47030)\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <richard.henderson@linaro.org>)\n id 1lfC4f-0003Wa-71\n for qemu-devel@nongnu.org; Fri, 07 May 2021 21:48:13 -0400", "by mail-pj1-x1032.google.com with SMTP id\n fa21-20020a17090af0d5b0290157eb6b590fso6550563pjb.5\n for <qemu-devel@nongnu.org>; Fri, 07 May 2021 18:48:08 -0700 (PDT)", "from localhost.localdomain ([71.212.144.24])\n by smtp.gmail.com with ESMTPSA id t4sm5819681pfq.165.2021.05.07.18.48.07\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 07 May 2021 18:48:07 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n h=from:to:cc:subject:date:message-id:in-reply-to:references\n :mime-version:content-transfer-encoding;\n bh=Tsoe+BVssAGH6OVs2DygacO7h0Tml9zLW3atLp8I1f0=;\n b=M0SObHiq5cUl63fpaTJvnw93HEdnbdJKH5tVoPtE5grl+Ze6KTdWc1LFB6S17lZrfE\n 8JXI5hJRIu0AMndr1cSN/rEwTuoqullWgyf/MNL54vCnMAofi5XHx+Mm91mkmX0LZmzJ\n YVPiCtX/+kjC42UCML7g1c2cQiAfmvEVTBj3gWtCo0OCzpgPwEF+jpz4yAxYFKtjn8ZM\n t+sIL64v0Uu5TDCTHiISmCU87XnizkRJmDB5PJoiTExTn/SjS7wArGmzLeSWjHTA56a/\n yxDvCxzSAMK5ZpkpAc0VbRLP2GiPWG/oSXdew1p1CzzR+vW87Nnvo2w4e0RfZJFCLJHL\n 8H3A==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20161025;\n h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n :references:mime-version:content-transfer-encoding;\n bh=Tsoe+BVssAGH6OVs2DygacO7h0Tml9zLW3atLp8I1f0=;\n b=jeOAoskseuduh1ofCtgkGbYGj5mPu66sfXkk44NkqEUHWpvYmJnNOmJD0Ai28sUhQs\n /hBELqM6d3Cxg4ZARPmkSy7hX2JjFCx9GlkBe0kus7ofkXmxQUllGBu5IysOk/VEYMKf\n +9BvVioQ7zE034+m0HImVQD0khkfwDq+6NuzbSc1dCq0+oms0IwMK/pej5SmGjGboB2P\n FHkLKcPb1DtXyUXWvvb6MIzkjfIcf8O+qoAmJkGEkpl4ZU4Hq8mE3tucG8B9rOTMS1Eq\n LlmmmFcxO9BOs2hC/lIWm3uQSg+TD64VHkJ9SpXaZw6Jsfr4YypfsI4/Mk2TlYtIk/Us\n y3oA==", "X-Gm-Message-State": "AOAM533RkVi25u3sk3wuWELzE3eIV5GSWVDPrypA+Xvlr4+K73ZkG5nV\n 1C53CpDHDetpGdyOpD1/XF0pXI5oD+v5Rw==", "X-Google-Smtp-Source": "\n ABdhPJx4cm4K54SBVzYM0fysXjAkYnXtPDHmreewAMJCzN94guPSZgYeezV9GtzmOgTofu3+A3s12g==", "X-Received": "by 2002:a17:90a:8410:: with SMTP id\n j16mr13555454pjn.120.1620438487891;\n Fri, 07 May 2021 18:48:07 -0700 (PDT)", "From": "Richard Henderson <richard.henderson@linaro.org>", "To": "qemu-devel@nongnu.org", "Subject": "[PATCH 06/72] softfloat: Move the binary point to the msb", "Date": "Fri, 7 May 2021 18:46:56 -0700", "Message-Id": "<20210508014802.892561-7-richard.henderson@linaro.org>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20210508014802.892561-1-richard.henderson@linaro.org>", "References": "<20210508014802.892561-1-richard.henderson@linaro.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Received-SPF": "pass client-ip=2607:f8b0:4864:20::1032;\n 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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n 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": "<qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Cc": "alex.bennee@linaro.org, david@redhat.com", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "\"Qemu-devel\"\n <qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>" }, "content": "Rather than point the binary point at msb-1, put it at the msb.\nUse uadd64_overflow to detect when addition overflows instead\nof DECOMPOSED_OVERFLOW_BIT.\n\nThis reduces the number of special cases within the code, such\nas shifting an int64_t either left or right during conversion.\n\nSigned-off-by: Richard Henderson <richard.henderson@linaro.org>\n---\n fpu/softfloat.c | 169 +++++++++++++++++++-----------------------------\n 1 file changed, 66 insertions(+), 103 deletions(-)", "diff": "diff --git a/fpu/softfloat.c b/fpu/softfloat.c\nindex 67cfa0fd82..cd777743f1 100644\n--- a/fpu/softfloat.c\n+++ b/fpu/softfloat.c\n@@ -503,9 +503,8 @@ typedef struct {\n bool sign;\n } FloatParts;\n \n-#define DECOMPOSED_BINARY_POINT (64 - 2)\n+#define DECOMPOSED_BINARY_POINT 63\n #define DECOMPOSED_IMPLICIT_BIT (1ull << DECOMPOSED_BINARY_POINT)\n-#define DECOMPOSED_OVERFLOW_BIT (DECOMPOSED_IMPLICIT_BIT << 1)\n \n /* Structure holding all of the relevant parameters for a format.\n * exp_size: the size of the exponent field\n@@ -657,7 +656,7 @@ static FloatParts sf_canonicalize(FloatParts part, const FloatFmt *parm,\n part.cls = float_class_zero;\n part.frac = 0;\n } else {\n- int shift = clz64(part.frac) - 1;\n+ int shift = clz64(part.frac);\n part.cls = float_class_normal;\n part.exp = parm->frac_shift - parm->exp_bias - shift + 1;\n part.frac <<= shift;\n@@ -727,9 +726,8 @@ static FloatParts round_canonical(FloatParts p, float_status *s,\n if (likely(exp > 0)) {\n if (frac & round_mask) {\n flags |= float_flag_inexact;\n- frac += inc;\n- if (frac & DECOMPOSED_OVERFLOW_BIT) {\n- frac >>= 1;\n+ if (uadd64_overflow(frac, inc, &frac)) {\n+ frac = (frac >> 1) | DECOMPOSED_IMPLICIT_BIT;\n exp++;\n }\n }\n@@ -758,9 +756,12 @@ static FloatParts round_canonical(FloatParts p, float_status *s,\n p.cls = float_class_zero;\n goto do_zero;\n } else {\n- bool is_tiny = s->tininess_before_rounding\n- || (exp < 0)\n- || !((frac + inc) & DECOMPOSED_OVERFLOW_BIT);\n+ bool is_tiny = s->tininess_before_rounding || (exp < 0);\n+\n+ if (!is_tiny) {\n+ uint64_t discard;\n+ is_tiny = !uadd64_overflow(frac, inc, &discard);\n+ }\n \n shift64RightJamming(frac, 1 - exp, &frac);\n if (frac & round_mask) {\n@@ -985,7 +986,7 @@ static FloatParts addsub_floats(FloatParts a, FloatParts b, bool subtract,\n a.cls = float_class_zero;\n a.sign = s->float_rounding_mode == float_round_down;\n } else {\n- int shift = clz64(a.frac) - 1;\n+ int shift = clz64(a.frac);\n a.frac = a.frac << shift;\n a.exp = a.exp - shift;\n a.sign = a_sign;\n@@ -1022,9 +1023,10 @@ static FloatParts addsub_floats(FloatParts a, FloatParts b, bool subtract,\n shift64RightJamming(a.frac, b.exp - a.exp, &a.frac);\n a.exp = b.exp;\n }\n- a.frac += b.frac;\n- if (a.frac & DECOMPOSED_OVERFLOW_BIT) {\n+\n+ if (uadd64_overflow(a.frac, b.frac, &a.frac)) {\n shift64RightJamming(a.frac, 1, &a.frac);\n+ a.frac |= DECOMPOSED_IMPLICIT_BIT;\n a.exp += 1;\n }\n return a;\n@@ -1219,16 +1221,17 @@ static FloatParts mul_floats(FloatParts a, FloatParts b, float_status *s)\n int exp = a.exp + b.exp;\n \n mul64To128(a.frac, b.frac, &hi, &lo);\n- shift128RightJamming(hi, lo, DECOMPOSED_BINARY_POINT, &hi, &lo);\n- if (lo & DECOMPOSED_OVERFLOW_BIT) {\n- shift64RightJamming(lo, 1, &lo);\n+ if (hi & DECOMPOSED_IMPLICIT_BIT) {\n exp += 1;\n+ } else {\n+ hi <<= 1;\n }\n+ hi |= (lo != 0);\n \n /* Re-use a */\n a.exp = exp;\n a.sign = sign;\n- a.frac = lo;\n+ a.frac = hi;\n return a;\n }\n /* handle all the NaN cases */\n@@ -1411,56 +1414,41 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c,\n \n p_exp = a.exp + b.exp;\n \n- /* Multiply of 2 62-bit numbers produces a (2*62) == 124-bit\n- * result.\n- */\n mul64To128(a.frac, b.frac, &hi, &lo);\n- /* binary point now at bit 124 */\n \n- /* check for overflow */\n- if (hi & (1ULL << (DECOMPOSED_BINARY_POINT * 2 + 1 - 64))) {\n- shift128RightJamming(hi, lo, 1, &hi, &lo);\n+ /* Renormalize to the msb. */\n+ if (hi & DECOMPOSED_IMPLICIT_BIT) {\n p_exp += 1;\n+ } else {\n+ shortShift128Left(hi, lo, 1, &hi, &lo);\n }\n \n /* + add/sub */\n- if (c.cls == float_class_zero) {\n- /* move binary point back to 62 */\n- shift128RightJamming(hi, lo, DECOMPOSED_BINARY_POINT, &hi, &lo);\n- } else {\n+ if (c.cls != float_class_zero) {\n int exp_diff = p_exp - c.exp;\n if (p_sign == c.sign) {\n /* Addition */\n if (exp_diff <= 0) {\n- shift128RightJamming(hi, lo,\n- DECOMPOSED_BINARY_POINT - exp_diff,\n- &hi, &lo);\n- lo += c.frac;\n+ shift64RightJamming(hi, -exp_diff, &hi);\n p_exp = c.exp;\n+ if (uadd64_overflow(hi, c.frac, &hi)) {\n+ shift64RightJamming(hi, 1, &hi);\n+ hi |= DECOMPOSED_IMPLICIT_BIT;\n+ p_exp += 1;\n+ }\n } else {\n- uint64_t c_hi, c_lo;\n- /* shift c to the same binary point as the product (124) */\n- c_hi = c.frac >> 2;\n- c_lo = 0;\n- shift128RightJamming(c_hi, c_lo,\n- exp_diff,\n- &c_hi, &c_lo);\n- add128(hi, lo, c_hi, c_lo, &hi, &lo);\n- /* move binary point back to 62 */\n- shift128RightJamming(hi, lo, DECOMPOSED_BINARY_POINT, &hi, &lo);\n+ uint64_t c_hi, c_lo, over;\n+ shift128RightJamming(c.frac, 0, exp_diff, &c_hi, &c_lo);\n+ add192(0, hi, lo, 0, c_hi, c_lo, &over, &hi, &lo);\n+ if (over) {\n+ shift64RightJamming(hi, 1, &hi);\n+ hi |= DECOMPOSED_IMPLICIT_BIT;\n+ p_exp += 1;\n+ }\n }\n-\n- if (lo & DECOMPOSED_OVERFLOW_BIT) {\n- shift64RightJamming(lo, 1, &lo);\n- p_exp += 1;\n- }\n-\n } else {\n /* Subtraction */\n- uint64_t c_hi, c_lo;\n- /* make C binary point match product at bit 124 */\n- c_hi = c.frac >> 2;\n- c_lo = 0;\n+ uint64_t c_hi = c.frac, c_lo = 0;\n \n if (exp_diff <= 0) {\n shift128RightJamming(hi, lo, -exp_diff, &hi, &lo);\n@@ -1495,20 +1483,15 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c,\n /* Normalizing to a binary point of 124 is the\n correct adjust for the exponent. However since we're\n shifting, we might as well put the binary point back\n- at 62 where we really want it. Therefore shift as\n+ at 63 where we really want it. Therefore shift as\n if we're leaving 1 bit at the top of the word, but\n adjust the exponent as if we're leaving 3 bits. */\n- shift -= 1;\n- if (shift >= 64) {\n- lo = lo << (shift - 64);\n- } else {\n- hi = (hi << shift) | (lo >> (64 - shift));\n- lo = hi | ((lo << shift) != 0);\n- }\n- p_exp -= shift - 2;\n+ shift128Left(hi, lo, shift, &hi, &lo);\n+ p_exp -= shift;\n }\n }\n }\n+ hi |= (lo != 0);\n \n if (flags & float_muladd_halve_result) {\n p_exp -= 1;\n@@ -1518,7 +1501,7 @@ static FloatParts muladd_floats(FloatParts a, FloatParts b, FloatParts c,\n a.cls = float_class_normal;\n a.sign = p_sign ^ sign_flip;\n a.exp = p_exp;\n- a.frac = lo;\n+ a.frac = hi;\n \n return a;\n }\n@@ -1742,25 +1725,17 @@ static FloatParts div_floats(FloatParts a, FloatParts b, float_status *s)\n * exponent to match.\n *\n * The udiv_qrnnd algorithm that we're using requires normalization,\n- * i.e. the msb of the denominator must be set. Since we know that\n- * DECOMPOSED_BINARY_POINT is msb-1, the inputs must be shifted left\n- * by one (more), and the remainder must be shifted right by one.\n+ * i.e. the msb of the denominator must be set, which is already true.\n */\n if (a.frac < b.frac) {\n exp -= 1;\n- shift128Left(0, a.frac, DECOMPOSED_BINARY_POINT + 2, &n1, &n0);\n- } else {\n shift128Left(0, a.frac, DECOMPOSED_BINARY_POINT + 1, &n1, &n0);\n+ } else {\n+ shift128Left(0, a.frac, DECOMPOSED_BINARY_POINT, &n1, &n0);\n }\n- q = udiv_qrnnd(&r, n1, n0, b.frac << 1);\n+ q = udiv_qrnnd(&r, n1, n0, b.frac);\n \n- /*\n- * Set lsb if there is a remainder, to set inexact.\n- * As mentioned above, to find the actual value of the remainder we\n- * would need to shift right, but (1) we are only concerned about\n- * non-zero-ness, and (2) the remainder will always be even because\n- * both inputs to the division primitive are even.\n- */\n+ /* Set lsb if there is a remainder, to set inexact. */\n a.frac = q | (r != 0);\n a.sign = sign;\n a.exp = exp;\n@@ -2135,12 +2110,12 @@ static FloatParts round_to_int(FloatParts a, FloatRoundMode rmode,\n \n if (a.frac & rnd_mask) {\n s->float_exception_flags |= float_flag_inexact;\n- a.frac += inc;\n- a.frac &= ~rnd_mask;\n- if (a.frac & DECOMPOSED_OVERFLOW_BIT) {\n+ if (uadd64_overflow(a.frac, inc, &a.frac)) {\n a.frac >>= 1;\n+ a.frac |= DECOMPOSED_IMPLICIT_BIT;\n a.exp++;\n }\n+ a.frac &= ~rnd_mask;\n }\n }\n break;\n@@ -2213,10 +2188,8 @@ static int64_t round_to_int_and_pack(FloatParts in, FloatRoundMode rmode,\n case float_class_zero:\n return 0;\n case float_class_normal:\n- if (p.exp < DECOMPOSED_BINARY_POINT) {\n+ if (p.exp <= DECOMPOSED_BINARY_POINT) {\n r = p.frac >> (DECOMPOSED_BINARY_POINT - p.exp);\n- } else if (p.exp - DECOMPOSED_BINARY_POINT < 2) {\n- r = p.frac << (p.exp - DECOMPOSED_BINARY_POINT);\n } else {\n r = UINT64_MAX;\n }\n@@ -2498,10 +2471,8 @@ static uint64_t round_to_uint_and_pack(FloatParts in, FloatRoundMode rmode,\n return 0;\n }\n \n- if (p.exp < DECOMPOSED_BINARY_POINT) {\n+ if (p.exp <= DECOMPOSED_BINARY_POINT) {\n r = p.frac >> (DECOMPOSED_BINARY_POINT - p.exp);\n- } else if (p.exp - DECOMPOSED_BINARY_POINT < 2) {\n- r = p.frac << (p.exp - DECOMPOSED_BINARY_POINT);\n } else {\n s->float_exception_flags = orig_flags | float_flag_invalid;\n return max;\n@@ -2765,11 +2736,11 @@ static FloatParts int_to_float(int64_t a, int scale, float_status *status)\n f = -f;\n r.sign = true;\n }\n- shift = clz64(f) - 1;\n+ shift = clz64(f);\n scale = MIN(MAX(scale, -0x10000), 0x10000);\n \n r.exp = DECOMPOSED_BINARY_POINT - shift + scale;\n- r.frac = (shift < 0 ? DECOMPOSED_IMPLICIT_BIT : f << shift);\n+ r.frac = f << shift;\n }\n \n return r;\n@@ -2920,21 +2891,16 @@ bfloat16 int16_to_bfloat16(int16_t a, float_status *status)\n static FloatParts uint_to_float(uint64_t a, int scale, float_status *status)\n {\n FloatParts r = { .sign = false };\n+ int shift;\n \n if (a == 0) {\n r.cls = float_class_zero;\n } else {\n scale = MIN(MAX(scale, -0x10000), 0x10000);\n+ shift = clz64(a);\n r.cls = float_class_normal;\n- if ((int64_t)a < 0) {\n- r.exp = DECOMPOSED_BINARY_POINT + 1 + scale;\n- shift64RightJamming(a, 1, &a);\n- r.frac = a;\n- } else {\n- int shift = clz64(a) - 1;\n- r.exp = DECOMPOSED_BINARY_POINT - shift + scale;\n- r.frac = a << shift;\n- }\n+ r.exp = DECOMPOSED_BINARY_POINT - shift + scale;\n+ r.frac = a << shift;\n }\n \n return r;\n@@ -3475,12 +3441,9 @@ static FloatParts sqrt_float(FloatParts a, float_status *s, const FloatFmt *p)\n /* We need two overflow bits at the top. Adding room for that is a\n * right shift. If the exponent is odd, we can discard the low bit\n * by multiplying the fraction by 2; that's a left shift. Combine\n- * those and we shift right if the exponent is even.\n+ * those and we shift right by 1 if the exponent is odd, otherwise 2.\n */\n- a_frac = a.frac;\n- if (!(a.exp & 1)) {\n- a_frac >>= 1;\n- }\n+ a_frac = a.frac >> (2 - (a.exp & 1));\n a.exp >>= 1;\n \n /* Bit-by-bit computation of sqrt. */\n@@ -3488,10 +3451,10 @@ static FloatParts sqrt_float(FloatParts a, float_status *s, const FloatFmt *p)\n s_frac = 0;\n \n /* Iterate from implicit bit down to the 3 extra bits to compute a\n- * properly rounded result. Remember we've inserted one more bit\n- * at the top, so these positions are one less.\n+ * properly rounded result. Remember we've inserted two more bits\n+ * at the top, so these positions are two less.\n */\n- bit = DECOMPOSED_BINARY_POINT - 1;\n+ bit = DECOMPOSED_BINARY_POINT - 2;\n last_bit = MAX(p->frac_shift - 4, 0);\n do {\n uint64_t q = 1ULL << bit;\n@@ -3507,7 +3470,7 @@ static FloatParts sqrt_float(FloatParts a, float_status *s, const FloatFmt *p)\n /* Undo the right shift done above. If there is any remaining\n * fraction, the result is inexact. Set the sticky bit.\n */\n- a.frac = (r_frac << 1) + (a_frac != 0);\n+ a.frac = (r_frac << 2) + (a_frac != 0);\n \n return a;\n }\n", "prefixes": [ "06/72" ] }