From patchwork Thu Jun 3 21:41:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 453318 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp628861jao; Thu, 3 Jun 2021 14:47:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyN2wY2gAQiXLQkIRge+UzNpjPJEneUeLl9by4+N/tJ1c94bn+rdaxTF+cqd94SY8bHFWQJ X-Received: by 2002:ad4:5943:: with SMTP id eo3mr1649194qvb.40.1622756831694; Thu, 03 Jun 2021 14:47:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622756831; cv=none; d=google.com; s=arc-20160816; b=a4zPLjfBfFKrxLzfkgfZgL0dDr5/BGBVX8yUj7U+EgugPXDVeiZre/hUmEGAnbGoUV qGyqZHlBnxBBiO2vM3TeXfVw6/xgBHnbAp5lhEV74NvvThH3V4lR7QMCQO9R8oRsnpVP /rXlGUx9WZZ+Vn7NgbDQrUamh3UXDOjE6MFUZpqabkGX4oqE2vpEJvDiEz5XngY117Ok wYajdyc/P1MZ92oIF0plRypMzerLa4VLUP8IwD1dFSk+bh5oVGwpeaBMjDZa79z6cNiu LZAHMd2fmW+vxzFPquIwVauoD0t0wYrJwum6xBYZ9H8GQjB2i8mlF+xruFTS0RwTHk/C oJDA== 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=fUuOVml+4w79a3bxuCGZ23LxhkzpodhkprttyZbQk2E=; b=0M53PDyVQG1x+l3Npv7y68sOimTTWFxc+i99Jo3uxeD7v1dFntXN1e7KHjQSyg7a27 mNkXqKQZyqdxb4ktu1I7f9TR/6oF4lrM3I4Ev6dOh2BWaioiDxM8I0w9HTsbMTFaSEyD K2OtPOKP2/Ub3YT4YqQmBfQHKdMMy8Hbn8OWeEHzWfD0UInennDfJ39IBfEsCgjfKJzt zlTtZ142UHMvwJnX93cONoDqHsaOwrBuXm26zROx08t+KvPwnZFMZMUxsxwSqmQE1O6S tz5sI34Z9WjY0Y5z7aGDWSCBY2+UaY4elg9Jx1pHtqXcDxy2vlnEdwmyAdKAh0IT+XnA hHDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="g63K/xb/"; 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 s28si319514qkj.102.2021.06.03.14.47.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jun 2021 14:47:11 -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="g63K/xb/"; 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]:40346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lovBH-0000tp-2V for patch@linaro.org; Thu, 03 Jun 2021 17:47:11 -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) 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-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) 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) 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 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_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- fpu/softfloat.c | 116 ++++++------------------------------------------ 1 file changed, 13 insertions(+), 103 deletions(-) -- 2.25.1 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_status *s) return float128_round_pack_canonical(&p, s); } +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_precision]); + return floatx80_round_pack_canonical(&p, status); +} + /* * Floating-point to signed integer conversions */ @@ -5800,109 +5813,6 @@ floatx80 floatx80_round(floatx80 a, float_status *status) return floatx80_round_pack_canonical(&p, status); } -/*---------------------------------------------------------------------------- -| Rounds the extended double-precision floating-point value `a' to an integer, -| 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 = extractFloatx80Exp( a ); - if ( 0x403E <= aExp ) { - if ( ( aExp == 0x7FFF ) && (uint64_t) ( extractFloatx80Frac( a )<<1 ) ) { - return propagateFloatx80NaN(a, a, status); - } - return a; - } - if ( aExp < 0x3FFF ) { - if ( ( aExp == 0 ) - && ( (uint64_t) ( extractFloatx80Frac( a ) ) == 0 ) ) { - return a; - } - float_raise(float_flag_inexact, status); - aSign = extractFloatx80Sign( a ); - switch (status->float_rounding_mode) { - case float_round_nearest_even: - if ( ( aExp == 0x3FFE ) && (uint64_t) ( extractFloatx80Frac( a )<<1 ) - ) { - return - packFloatx80( aSign, 0x3FFF, UINT64_C(0x8000000000000000)); - } - break; - case float_round_ties_away: - if (aExp == 0x3FFE) { - return packFloatx80(aSign, 0x3FFF, UINT64_C(0x8000000000000000)); - } - 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 = 1; - lastBitMask <<= 0x403E - aExp; - roundBitsMask = lastBitMask - 1; - z = a; - switch (status->float_rounding_mode) { - case float_round_nearest_even: - z.low += lastBitMask>>1; - if ((z.low & roundBitsMask) == 0) { - z.low &= ~lastBitMask; - } - break; - case float_round_ties_away: - z.low += lastBitMask >> 1; - break; - case float_round_to_zero: - break; - case float_round_up: - if (!extractFloatx80Sign(z)) { - z.low += roundBitsMask; - } - break; - case float_round_down: - if (extractFloatx80Sign(z)) { - z.low += roundBitsMask; - } - break; - default: - abort(); - } - z.low &= ~ roundBitsMask; - if ( z.low == 0 ) { - ++z.high; - z.low = UINT64_C(0x8000000000000000); - } - if (z.low != a.low) { - float_raise(float_flag_inexact, status); - } - return z; - -} - /*---------------------------------------------------------------------------- | Returns the remainder of the extended double-precision floating-point value | `a' with respect to the corresponding value `b'. The operation is performed