From nobody Tue Feb 10 07:42:30 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=1770290263; cv=none; d=zohomail.com; s=zohoarc; b=dBou/1wYWFsEe685+KCWKu9/wNM789p1h2pFnubavB8603HoaWdlu4grHHx2/TA8WZVfqCvTiwicKA44v6VaCh29nt0PmEGnDtMF4hxtD/g2DQFPjmfuVh0AWsr5/FwvywuHYaVzEKJy4cXDwC5UTAI3Kr1kYobN1DlX3W8nlvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770290263; 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=gMibsSFmr8930GLdEf6auOmzhfpvG0IZCKbbW9pih4Q=; b=a+sBRoAJMMYqd186WEmzfizy+lwTcVfLoLzNcBUy8XO3RhUdzLb9XhUCAcGyvT0I/slf4MAcKBYPqzAR5sTH9lcf1e2fjf1G5oSKZLHhiPgVjlCvPeAAnEc5xPD4P7zeS+VZwmYzS+y2wqGixWXMc23xhklnKZ42VTa2MmzQATI= 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 1770290263315150.74376539467642; Thu, 5 Feb 2026 03:17:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnxMV-00050D-4h; Thu, 05 Feb 2026 06:17:27 -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 1vnxLp-0004lU-6x for qemu-devel@nongnu.org; Thu, 05 Feb 2026 06:16:45 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vnxLl-0003ng-84 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 06:16:42 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2a7a9b8ed69so9200615ad.2 for ; Thu, 05 Feb 2026 03:16:39 -0800 (PST) Received: from stoup.. ([2401:d002:dc0f:2100:7515:513c:b646:18b8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a933851685sm51088435ad.13.2026.02.05.03.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 03:16:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770290198; x=1770894998; 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=gMibsSFmr8930GLdEf6auOmzhfpvG0IZCKbbW9pih4Q=; b=s9aw9fbdMircau///uh6Kpg1Z8oK+Pz56gahtP0B1GRUU47sivLL2oa08T23GyNbE0 OCR572u64Q6MPLEHfxaw/1sBsbdu691pJcFN2mvYJHwB5/v5dLh+kTqXVVaMvog/iuHA ICzKVQFimKyJSjqVYgGh4INiMB635eC7tFTqCOorNnIcKqqfdeR6WFRFqywvM2JMYTN8 DRXYGjQaUgNLMxMrQBFCwr3u6GISZrYOfX8wmq2D+tRPqRatdv9hQIQlWNtqPCz7IjeE 2HrmZ0Km/NJkzLPWGHZcNSPBCpfjVn1kTECvu6BWEr/T0MB8iA6nspXtQjy8ta5Ooef9 DFzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770290198; x=1770894998; 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=gMibsSFmr8930GLdEf6auOmzhfpvG0IZCKbbW9pih4Q=; b=wQjMHWb3pOQjdDnTvIxviI1bai9xkXGyu6Y1tGrlqFiys+CFZ9VPGqEQPhccu9XnRj HoR1o3AHvllF72Y8Q9+k1JWdCPA2VHcux4RgW/7UAGUcFXiCwCKS9VZ/PDqF00SgWV6Q 2KRQ5hjO/7/9ih1Dsnu/kjJupoednZRPk/3719D4L8zk7qN1/GIB/Ho7N7sn2jQuC4hH Rd4feF7Td1zidl6wYhihIhYb6DQH9j5mygfuQt+0XAPDpIY9oPUj2xtdRnID1LcbLsFS HJ5G2ArLjv5xZPjgs6ll9nLc+YDodO9AkoLisuNhaNWY3w1o12645haqwPcNOFZelnVt NfqQ== X-Gm-Message-State: AOJu0Yy3RHJAeBSvK5rnjaP07HWA49dU44E7yddOyxctac2TPs25eMuU dlviqn/5d0YUHDAjOw4yFV/+NxHkM8w6fv1CPf/Np8Nt6pCkQ35I2h3glAmZ3Rg8Nu+80PZglol fnJOplkk5xw== X-Gm-Gg: AZuq6aJzhfYkXljMHm2b/f/fHCfuCSicQAPB31q9hdN7svB0JdHMJ09HIfj5JwVscss Qp0uS0WCvE3Bsb7Sjr6Wa7CGx4iO2FZlG29J9FvMzP0ykhP0yDH7BW3how0SQlj9OYwnH+hpFjL 5QcM0XH7JwuyQ9j+YeC5KO/EFbluiC3vg4oV5M/hLkLeOXaZGBLaV1DlWcS7vUzyOkiNvFQoa2/ 8f2yiN2o7hMtjf/wbd/mkmsDSTTcS7Xd9fvP0/l9fyV5FVNiFAkFVazZw68jsDgQiB6vGLnYMdD X6z1duRF6OiP5FfpdYTp1jPrswhm+5w5uBHKUuFj9w+XeWxEESkSfLE9mifxfd75MwYHBsYHmsA Cr07utmMD9qmNq04LD5n0lnFWECwqzAbjvztwqQoWxp8NhvpgPjxYmaOGRJELz3Qjo/bCbSy+2e r4BgOOMkEZrhtfOnPqFwBB X-Received: by 2002:a17:902:cecc:b0:2a1:3cd9:a737 with SMTP id d9443c01a7336-2a933eaa8d3mr64698475ad.36.1770290197820; Thu, 05 Feb 2026 03:16:37 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: max.chou@sifive.com Subject: [PATCH v4 4/9] fpu: Introduce FloatFmtExpMaxKind Date: Thu, 5 Feb 2026 21:16:17 +1000 Message-ID: <20260205111622.461497-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260205111622.461497-1-richard.henderson@linaro.org> References: <20260205111622.461497-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::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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: 1770290264574154100 Content-Type: text/plain; charset="utf-8" Generalize arm_althp to indicate how exp=3D=3Dmax should be handled for the format. Reorganize canonicalize and uncanon_normal to use a switch statement, allowing more cases to be added trivially. Signed-off-by: Richard Henderson --- fpu/softfloat.c | 17 ++++++-- fpu/softfloat-parts.c.inc | 92 ++++++++++++++++++++++++--------------- 2 files changed, 69 insertions(+), 40 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 8094358c2e..18098c4cdd 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -522,7 +522,16 @@ typedef struct { #define DECOMPOSED_BINARY_POINT 63 #define DECOMPOSED_IMPLICIT_BIT (1ull << DECOMPOSED_BINARY_POINT) =20 -/* Structure holding all of the relevant parameters for a format. +/* Format-specific handling of exp =3D=3D exp_max */ +typedef enum __attribute__((__packed__)) { + /* exp=3D=3Dmax, frac=3D=3D0 ? infinity : nan; this is ieee standard. = */ + float_expmax_ieee, + /* exp=3D=3Dmax is a normal number; no infinity or nan representation.= */ + float_expmax_normal, +} FloatFmtExpMaxKind; + +/* + * Structure holding all of the relevant parameters for a format. * exp_size: the size of the exponent field * exp_bias: the offset applied to the exponent field * exp_max: the maximum normalised exponent @@ -531,7 +540,7 @@ typedef struct { * The following are computed based the size of fraction * round_mask: bits below lsb which must be rounded * The following optional modifiers are available: - * arm_althp: handle ARM Alternative Half Precision + * exp_max_kind: affects how exp =3D=3D exp_max is interpreted * has_explicit_bit: has an explicit integer bit; this affects whether * the float_status floatx80_behaviour handling applies */ @@ -542,7 +551,7 @@ typedef struct { int exp_max; int frac_size; int frac_shift; - bool arm_althp; + FloatFmtExpMaxKind exp_max_kind; bool has_explicit_bit; uint64_t round_mask; } FloatFmt; @@ -566,7 +575,7 @@ static const FloatFmt float16_params =3D { =20 static const FloatFmt float16_params_ahp =3D { FLOAT_PARAMS(5, 10), - .arm_althp =3D true + .exp_max_kind =3D float_expmax_normal, }; =20 static const FloatFmt bfloat16_params =3D { diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 5e0438fc0b..d3c9c7a913 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -227,18 +227,30 @@ static void partsN(canonicalize)(FloatPartsN *p, floa= t_status *status, p->exp =3D fmt->frac_shift - fmt->exp_bias - shift + !has_pseudo_denormals; } - } else if (likely(p->exp < fmt->exp_max) || fmt->arm_althp) { - p->cls =3D float_class_normal; - p->exp -=3D fmt->exp_bias; - frac_shl(p, fmt->frac_shift); - p->frac_hi |=3D DECOMPOSED_IMPLICIT_BIT; - } else if (likely(frac_eqz(p))) { - p->cls =3D float_class_inf; - } else { - frac_shl(p, fmt->frac_shift); - p->cls =3D (parts_is_snan_frac(p->frac_hi, status) - ? float_class_snan : float_class_qnan); + return; } + if (unlikely(p->exp =3D=3D fmt->exp_max)) { + switch (fmt->exp_max_kind) { + case float_expmax_ieee: + if (likely(frac_eqz(p))) { + p->cls =3D float_class_inf; + } else { + frac_shl(p, fmt->frac_shift); + p->cls =3D (parts_is_snan_frac(p->frac_hi, status) + ? float_class_snan : float_class_qnan); + } + return; + case float_expmax_normal: + break; + default: + g_assert_not_reached(); + } + } + + p->cls =3D float_class_normal; + p->exp -=3D fmt->exp_bias; + frac_shl(p, fmt->frac_shift); + p->frac_hi |=3D DECOMPOSED_IMPLICIT_BIT; } =20 /* @@ -314,29 +326,37 @@ static void partsN(uncanon_normal)(FloatPartsN *p, fl= oat_status *s, p->frac_lo &=3D ~round_mask; } =20 - if (fmt->arm_althp) { - /* ARM Alt HP eschews Inf and NaN for a wider exponent. */ - if (unlikely(exp > exp_max)) { - /* Overflow. Return the maximum normal. */ - 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; - if (s->rebias_overflow) { - exp -=3D fmt->exp_re_bias; - } else if (overflow_norm) { - flags |=3D float_flag_inexact; - exp =3D exp_max - 1; - frac_allones(p); - p->frac_lo &=3D ~round_mask; - } else { - flags |=3D float_flag_inexact; - p->cls =3D float_class_inf; - exp =3D exp_max; - frac_clear(p); + if (unlikely(exp >=3D exp_max)) { + switch (fmt->exp_max_kind) { + case float_expmax_ieee: + flags |=3D float_flag_overflow; + if (s->rebias_overflow) { + exp -=3D fmt->exp_re_bias; + } else if (overflow_norm) { + flags |=3D float_flag_inexact; + exp =3D exp_max - 1; + frac_allones(p); + p->frac_lo &=3D ~round_mask; + } else { + flags |=3D float_flag_inexact; + p->cls =3D float_class_inf; + exp =3D exp_max; + frac_clear(p); + } + break; + + case float_expmax_normal: + if (unlikely(exp > exp_max)) { + /* Overflow. Return the maximum normal. */ + flags =3D float_flag_invalid; + exp =3D exp_max; + frac_allones(p); + p->frac_lo &=3D ~round_mask; + } + break; + + default: + g_assert_not_reached(); } } frac_shr(p, frac_shift); @@ -434,13 +454,13 @@ static void partsN(uncanon)(FloatPartsN *p, float_sta= tus *s, frac_clear(p); return; case float_class_inf: - g_assert(!fmt->arm_althp); + assert(fmt->exp_max_kind =3D=3D float_expmax_ieee); p->exp =3D fmt->exp_max; frac_clear(p); return; case float_class_qnan: case float_class_snan: - g_assert(!fmt->arm_althp); + assert(fmt->exp_max_kind !=3D float_expmax_normal); p->exp =3D fmt->exp_max; frac_shr(p, fmt->frac_shift); return; --=20 2.43.0