From nobody Sun Apr 12 02:52:17 2026 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=1771835006; cv=none; d=zohomail.com; s=zohoarc; b=TGcE4PNQYqmzodSGDLfiEtTcIR85KDqXrYcwbzy1wYC7oEYC3tlLtgtumaYSoPBUR5+NvBI485Mexvh677xZG/QiCf0mB2ETHnVzQM1jtch21Bgqk6Gu/Ty373xteThDtJMKb3FMv606p5HxSAHqw6RNMo9tTzkRCGkrQ6FuwV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771835006; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7svS/Rh77Kfa8iIXf30fKW59Bgc3MJuDhuxENPk//BU=; b=kUNohh14fL4TvEso9ME6JhSLtVreWkU4Rzc51kBFRr/OvroLFi483nKbjd79+acyL3uUh+xkoTp8A1LqFL1V9ZvbJECvFFN1UBiMkTK7AnZMeeC63HWPafYQGTjz2RRZfyXXW5cuXBTHPaNrAKvj0Qo6CN526FGeiJS/ckysmyg= 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771835005993809.2556362847453; Mon, 23 Feb 2026 00:23:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vuRD5-0002He-EX; Mon, 23 Feb 2026 03:22:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vuRD3-0002Dk-0y for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:22:29 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vuRD1-0008DD-1a for qemu-devel@nongnu.org; Mon, 23 Feb 2026 03:22:28 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2a91215c158so26961705ad.0 for ; Mon, 23 Feb 2026 00:22:26 -0800 (PST) Received: from stoup.. (123-243-199-74.static.tpgi.com.au. [123.243.199.74]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ad74f5dd7asm86543625ad.28.2026.02.23.00.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Feb 2026 00:22:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1771834946; x=1772439746; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7svS/Rh77Kfa8iIXf30fKW59Bgc3MJuDhuxENPk//BU=; b=SKvabT0he+0zT8ve4GzO4XYfsa4gH3/nJsF4gZwJcIDYVeAfieJ9QKvAPY6omRzPHJ +cVOTuFJMXhyXSmT0K5O5sIx+iZZmiXHlqZVPkIWy8H8Sq61WgBOtKclL/iNiLJyVID4 rj1bVoq23GSimzq1Wl2iEDjoecDIQ7VF5Sfhb0EhoX/ObD9/UlHFPPR0nMOFAyLc8730 UcspKSXkvXFxjrkrkBJlDJn5ZDUvJ24CDUVgAflzYMXlus34FzheW6Os1l3zT0HSHQL5 Kg8ZSDzNaCEnaoEG846UiTTggRNQNprqzVvGlhxSONCcHi6mlZvqgHTq9exhJMuXdTYP yW4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771834946; x=1772439746; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7svS/Rh77Kfa8iIXf30fKW59Bgc3MJuDhuxENPk//BU=; b=cfwrK9jQmbLfihgTP1fKdmMz85jUwovg6Hb5bvd6V5VeEZSbEPbQChTIcaiTpxpwKt G3K7yp62atkqqTRMs+WMiYLoP027yli4P1ba0D1zr0djW+wZkQ6QuBzT7T9MY42zBymF V6CSdSiD8B3B/l8xupnb8r/nn6G+BSEgWfdXIlwWj/3dce4KSpRinFQX7WbdYwRlHiH0 NSdKUmibsJKU2xQ7KS60UKWsKLFjGxNsWTwuXXfd83HeunSkSsbicM4tNDNzye/UKokG n9hyNmhe4CKeXBdCeLBhqjj7UCQcVdmB93Hx6paksUlZWXSBVqduzjFzaP8RYVaGtxXW YaxQ== X-Gm-Message-State: AOJu0YwomffG1g/xN0NPo+4mrHEb6gd5nC0RLf5abkzZmfq33hq6W5Cp ORpgpfa4fLovgFG2z8XVtuQbBHDga4TnQKE8j2PhDTVBxXDVgVT8jmZitJSXLIXLZdzkzm6e0Jr 3bYMhxpE= X-Gm-Gg: ATEYQzxe6YK3HMOuA1XzMHlJIhFdoctbw5I/EjA4IuOpo9tYiNZCLqtyL9360Y3E9d/ mpeBSH1WomeiprUjZ7l8ChRP8p66hNred9bUWmqA12lY3uxsJmN1MQqMyikg3y7OH5EDz48x6uM 5d7iPw7tBdaXLvtYgRF5XG2vVEYjBR5pmyFji217cbWnGVzE/lJW9L9Fv/lAYu+d6ssCZzxfUM6 +MCLMMzOb3u6ED6BrraLZ0nqsUtqOTg21uVabmULCQ0XM5ACDk9iEWvRXyWbV5K9X0WYF/HCrIN gqY4IIYAsikaqzuy1UZZ5l684BCfqiQT5voBV1Mg90bRl+/onmFtlHiFm69pWPoJ/GayHeigif+ /IGPhGxA1L+qGZPfksm4cKRQ9FvY94C4TPUjmZCdgGv27pad+GkdloRQuv62ogSTsbAlQ7umrpO 2KSptTboihlnSuOmlvFy29hQg0hKSnNbNZ6b2tAM5gL0Gc91VcVoZ4an9vimX1gAm0hA== X-Received: by 2002:a17:902:e787:b0:2aa:cfee:a47c with SMTP id d9443c01a7336-2ad7456550emr67358325ad.52.1771834945381; Mon, 23 Feb 2026 00:22:25 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: max.chou@sifive.com, chao.liu.zevorn@gmail.com Subject: [PATCH v5 6/9] fpu: Add saturate parameter to parts_uncanon Date: Mon, 23 Feb 2026 19:21:51 +1100 Message-ID: <20260223082154.5623-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260223082154.5623-1-richard.henderson@linaro.org> References: <20260223082154.5623-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::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1771835007823158500 Content-Type: text/plain; charset="utf-8" From: Max Chou The OCP FP8 conversion operations have a parameter to control saturate vs overflow. Add a parameter, currently always false. Signed-off-by: Max Chou [rth: Split out of a larger patch] Signed-off-by: Richard Henderson Reviewed-by: Chao Liu --- fpu/softfloat.c | 46 +++++++++++++++++++-------------------- fpu/softfloat-parts.c.inc | 15 ++++++++----- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 9d06a1bb59..b3c4104854 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -771,20 +771,20 @@ static void parts128_canonicalize(FloatParts128 *p, f= loat_status *status, PARTS_GENERIC_64_128(canonicalize, A)(A, S, F) =20 static void parts64_uncanon_normal(FloatParts64 *p, float_status *status, - const FloatFmt *fmt); + const FloatFmt *fmt, bool saturate); static void parts128_uncanon_normal(FloatParts128 *p, float_status *status, - const FloatFmt *fmt); + const FloatFmt *fmt, bool saturate); =20 -#define parts_uncanon_normal(A, S, F) \ - PARTS_GENERIC_64_128(uncanon_normal, A)(A, S, F) +#define parts_uncanon_normal(A, S, F, X) \ + PARTS_GENERIC_64_128(uncanon_normal, A)(A, S, F, X) =20 static void parts64_uncanon(FloatParts64 *p, float_status *status, - const FloatFmt *fmt); + const FloatFmt *fmt, bool saturate); static void parts128_uncanon(FloatParts128 *p, float_status *status, - const FloatFmt *fmt); + const FloatFmt *fmt, bool saturate); =20 -#define parts_uncanon(A, S, F) \ - PARTS_GENERIC_64_128(uncanon, A)(A, S, F) +#define parts_uncanon(A, S, F, X) \ + PARTS_GENERIC_64_128(uncanon, A)(A, S, F, X) =20 static void parts64_add_normal(FloatParts64 *a, FloatParts64 *b); static void parts128_add_normal(FloatParts128 *a, FloatParts128 *b); @@ -1699,7 +1699,7 @@ static float16 float16a_round_pack_canonical(FloatPar= ts64 *p, float_status *s, const FloatFmt *params) { - parts_uncanon(p, s, params); + parts_uncanon(p, s, params, false); return float16_pack_raw(p); } =20 @@ -1712,7 +1712,7 @@ static float16 float16_round_pack_canonical(FloatPart= s64 *p, static bfloat16 bfloat16_round_pack_canonical(FloatParts64 *p, float_status *s) { - parts_uncanon(p, s, &bfloat16_params); + parts_uncanon(p, s, &bfloat16_params, false); return bfloat16_pack_raw(p); } =20 @@ -1726,7 +1726,7 @@ static void float32_unpack_canonical(FloatParts64 *p,= float32 f, static float32 float32_round_pack_canonical(FloatParts64 *p, float_status *s) { - parts_uncanon(p, s, &float32_params); + parts_uncanon(p, s, &float32_params, false); return float32_pack_raw(p); } =20 @@ -1740,7 +1740,7 @@ static void float64_unpack_canonical(FloatParts64 *p,= float64 f, static float64 float64_round_pack_canonical(FloatParts64 *p, float_status *s) { - parts_uncanon(p, s, &float64_params); + parts_uncanon(p, s, &float64_params, false); return float64_pack_raw(p); } =20 @@ -1789,7 +1789,7 @@ static float64 float64r32_pack_raw(FloatParts64 *p) static float64 float64r32_round_pack_canonical(FloatParts64 *p, float_status *s) { - parts_uncanon(p, s, &float32_params); + parts_uncanon(p, s, &float32_params, false); return float64r32_pack_raw(p); } =20 @@ -1803,7 +1803,7 @@ static void float128_unpack_canonical(FloatParts128 *= p, float128 f, static float128 float128_round_pack_canonical(FloatParts128 *p, float_status *s) { - parts_uncanon(p, s, &float128_params); + parts_uncanon(p, s, &float128_params, false); return float128_pack_raw(p); } =20 @@ -1851,7 +1851,7 @@ static floatx80 floatx80_round_pack_canonical(FloatPa= rts128 *p, case float_class_normal: case float_class_denormal: if (s->floatx80_rounding_precision =3D=3D floatx80_precision_x) { - parts_uncanon_normal(p, s, fmt); + parts_uncanon_normal(p, s, fmt, false); frac =3D p->frac_hi; exp =3D p->exp; } else { @@ -1860,7 +1860,7 @@ static floatx80 floatx80_round_pack_canonical(FloatPa= rts128 *p, p64.sign =3D p->sign; p64.exp =3D p->exp; frac_truncjam(&p64, p); - parts_uncanon_normal(&p64, s, fmt); + parts_uncanon_normal(&p64, s, fmt, false); frac =3D p64.frac; exp =3D p64.exp; } @@ -2258,7 +2258,7 @@ float16_muladd_scalbn(float16 a, float16 b, float16 c, pr =3D parts_muladd_scalbn(&pa, &pb, &pc, scale, flags, status); =20 /* Round before applying negate result. */ - parts_uncanon(pr, status, &float16_params); + parts_uncanon(pr, status, &float16_params, false); if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { pr->sign ^=3D 1; } @@ -2283,7 +2283,7 @@ float32_muladd_scalbn(float32 a, float32 b, float32 c, pr =3D parts_muladd_scalbn(&pa, &pb, &pc, scale, flags, status); =20 /* Round before applying negate result. */ - parts_uncanon(pr, status, &float32_params); + parts_uncanon(pr, status, &float32_params, false); if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { pr->sign ^=3D 1; } @@ -2302,7 +2302,7 @@ float64_muladd_scalbn(float64 a, float64 b, float64 c, pr =3D parts_muladd_scalbn(&pa, &pb, &pc, scale, flags, status); =20 /* Round before applying negate result. */ - parts_uncanon(pr, status, &float64_params); + parts_uncanon(pr, status, &float64_params, false); if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { pr->sign ^=3D 1; } @@ -2461,7 +2461,7 @@ float64 float64r32_muladd(float64 a, float64 b, float= 64 c, pr =3D parts_muladd_scalbn(&pa, &pb, &pc, 0, flags, status); =20 /* Round before applying negate result. */ - parts_uncanon(pr, status, &float32_params); + parts_uncanon(pr, status, &float32_params, false); if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { pr->sign ^=3D 1; } @@ -2479,7 +2479,7 @@ bfloat16 QEMU_FLATTEN bfloat16_muladd(bfloat16 a, bfl= oat16 b, bfloat16 c, pr =3D parts_muladd_scalbn(&pa, &pb, &pc, 0, flags, status); =20 /* Round before applying negate result. */ - parts_uncanon(pr, status, &bfloat16_params); + parts_uncanon(pr, status, &bfloat16_params, false); if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { pr->sign ^=3D 1; } @@ -2497,7 +2497,7 @@ float128 QEMU_FLATTEN float128_muladd(float128 a, flo= at128 b, float128 c, pr =3D parts_muladd_scalbn(&pa, &pb, &pc, 0, flags, status); =20 /* Round before applying negate result. */ - parts_uncanon(pr, status, &float128_params); + parts_uncanon(pr, status, &float128_params, false); if ((flags & float_muladd_negate_result) && !is_nan(pr->cls)) { pr->sign ^=3D 1; } @@ -5435,7 +5435,7 @@ static void parts_s390_divide_to_integer(FloatParts64= *a, FloatParts64 *b, /* Round remainder to the target format */ *r =3D *r_precise; status->float_exception_flags =3D 0; - parts_uncanon(r, status, fmt); + parts_uncanon(r, status, fmt, false); r_flags =3D status->float_exception_flags; r->frac &=3D (1ULL << fmt->frac_size) - 1; parts_canonicalize(r, status, fmt); diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 4909ff7418..09be686645 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -258,9 +258,12 @@ static void partsN(canonicalize)(FloatPartsN *p, float= _status *status, * are FRAC_SHIFT bits that may require rounding at the bottom of the * fraction; these bits will be removed. The exponent will be biased * by EXP_BIAS and must be bounded by [EXP_MAX-1, 0]. + * + * The saturate parameter controls saturation behavior for formats that + * support it -- when true, overflow produces max normal instead of infini= ty. */ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, - const FloatFmt *fmt) + const FloatFmt *fmt, bool saturate) { const int exp_max =3D fmt->exp_max; const int frac_shift =3D fmt->frac_shift; @@ -269,7 +272,7 @@ static void partsN(uncanon_normal)(FloatPartsN *p, floa= t_status *s, 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; + bool overflow_norm =3D saturate; int exp, flags =3D 0; =20 switch (s->float_rounding_mode) { @@ -294,11 +297,11 @@ static void partsN(uncanon_normal)(FloatPartsN *p, fl= oat_status *s, break; case float_round_up: inc =3D p->sign ? 0 : round_mask; - overflow_norm =3D p->sign; + overflow_norm |=3D p->sign; break; case float_round_down: inc =3D p->sign ? round_mask : 0; - overflow_norm =3D !p->sign; + overflow_norm |=3D !p->sign; break; case float_round_to_odd: overflow_norm =3D true; @@ -445,10 +448,10 @@ static void partsN(uncanon_normal)(FloatPartsN *p, fl= oat_status *s, } =20 static void partsN(uncanon)(FloatPartsN *p, float_status *s, - const FloatFmt *fmt) + const FloatFmt *fmt, bool saturate) { if (likely(is_anynorm(p->cls))) { - parts_uncanon_normal(p, s, fmt); + parts_uncanon_normal(p, s, fmt, saturate); } else { switch (p->cls) { case float_class_zero: --=20 2.43.0