From patchwork Thu Jun 3 21:41:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 453308 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp625989jao; Thu, 3 Jun 2021 14:42:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhpIjYAsUtn1XzfHlEnemVGumAcnsee6R+ilfakZ1A1gVn3ixk6CNE/OIXiSQhdjBirQo0 X-Received: by 2002:a92:1310:: with SMTP id 16mr1280221ilt.60.1622756520371; Thu, 03 Jun 2021 14:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622756520; cv=none; d=google.com; s=arc-20160816; b=f0by9/8DW+J0x8Pj4Jxymu6QfsGF9nhrLBGg0BEyFqTLh+mqNWrT21ZJJOh+myEiyR 8BrD2Ozt1NGw7co4mkIwcmo0D9IwoNWZnFcFq8JFaUhd7yFClya5jvkiQR0cYc4y4EYZ r00idRayLPxSQvDtTXA32rbm5fZbJ4aeNpqWJDAQYlCTwCByoWaKbbsyeWMu5JX1u+BC X3cK8Fd4NI0c3071V8vnMTNxCkjYi0JKhzdLeDAErlUt8y2t4BEEG9V3GkalN+ukoo0R HLNBrEo07VV6gMLh8hUv9TBuZQpk1itO1vT5II9NboBfeM+rRMQCuLGptvD38esNRISn YlOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=jExZoW94fQf1KTDSzPZo60kTKr+L9V1ApVnhdi+DwN4=; b=EkedQlbDNsR5yGLATCDVAgCQOjxsKfhjHTsMb/tti+0l3R4XiQ45iYsAC+HM+Z8QXT zeKBEl6837uk4KF481CRNRtFk6B+ri1fmFwrD3yvVJ/kQ21Lezdv1663nUTHlhjSvgla aRcTKC8hXOm3xqCmJDxNcg+0aEzr5ywAKJR9CecOH0v/gJIblQLbxuQIQz89FdV5GPik Xb0SlOoVxjPI0Ip+wFIaFZ0ZmymFv4p+rZ687VL593spjqYmiqNTUocm5J1oZur+uhzC hTj2nu44vawh2aZB2qoPZsKvxaEoDFgJe0zlojTj/e2yzWq4k3LBJdB6ZwQ4umB+HTLJ MimA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=omRWt91q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q10si4426544ilu.60.2021.06.03.14.42.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jun 2021 14:42:00 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=omRWt91q; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lov6F-00023g-PC for patch@linaro.org; Thu, 03 Jun 2021 17:41:59 -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) 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-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) 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) 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 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_Benn=C3=A9e?= , David Hildenbrand Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rename to parts$N_sint_to_float. Reimplement int{32,64}_to_float128 with FloatParts128. Reviewed-by: Alex Bennée 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(-) -- 2.25.1 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) +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) } /* - * 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 */ -static FloatParts64 int_to_float(int64_t a, int scale, float_status *status) -{ - FloatParts64 r = { .sign = false }; - - if (a == 0) { - r.cls = float_class_zero; - } else { - uint64_t f = a; - int shift; - - r.cls = float_class_normal; - if (a < 0) { - f = -f; - r.sign = true; - } - shift = clz64(f); - scale = MIN(MAX(scale, -0x10000), 0x10000); - - r.exp = DECOMPOSED_BINARY_POINT - shift + scale; - r.frac = f << shift; - } - - return r; -} - float16 int64_to_float16_scalbn(int64_t a, int scale, float_status *status) { - FloatParts64 pa = 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); } 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 *status) float32 int64_to_float32_scalbn(int64_t a, int scale, float_status *status) { - FloatParts64 pa = 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); } 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 *status) float64 int64_to_float64_scalbn(int64_t a, int scale, float_status *status) { - FloatParts64 pa = 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); } 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 *status) return int64_to_float64_scalbn(a, 0, status); } -/* - * 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 *status) { - FloatParts64 pa = 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); } bfloat16 int32_to_bfloat16_scalbn(int32_t a, int scale, float_status *status) @@ -3106,6 +3088,19 @@ bfloat16 int16_to_bfloat16(int16_t a, float_status *status) return int64_to_bfloat16_scalbn(a, 0, status); } +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) } -/*---------------------------------------------------------------------------- -| Returns the result of converting the 32-bit two's complement integer `a' to -| the quadruple-precision floating-point format. The conversion is performed -| 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 == 0 ) return packFloat128( 0, 0, 0, 0 ); - zSign = ( a < 0 ); - absA = zSign ? - a : a; - shiftCount = clz32(absA) + 17; - zSig0 = absA; - return packFloat128( zSign, 0x402E - shiftCount, zSig0<cls = float_class_zero; + return; + } + + p->cls = float_class_normal; + if (a < 0) { + f = -f; + p->sign = true; + } + shift = clz64(f); + scale = MIN(MAX(scale, -0x10000), 0x10000); + + p->exp = DECOMPOSED_BINARY_POINT - shift + scale; + p->frac_hi = f << shift; +}