From patchwork Sat Sep 16 03:30:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 723541 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp708578wro; Fri, 15 Sep 2023 20:31:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyoiTsXr3UpO0axLBocl2HUTf0pryIqknUQMJhHxFYnc0O7GK17FNq/iN+zbM/M8L7mLi/ X-Received: by 2002:a05:6214:9c9:b0:653:5736:c0b4 with SMTP id dp9-20020a05621409c900b006535736c0b4mr3651334qvb.54.1694835090205; Fri, 15 Sep 2023 20:31:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694835090; cv=none; d=google.com; s=arc-20160816; b=03Cg/h5npAZB86Rp3fQDZ/KRr7Z1uqVkVVh8FD2mB48t73DxgV606jmvRJF8rrHOYY mDHx7DsSK7FYvbrmeNv8qQYUyR6W6OqkPPCqsnu5hcoHwX1BbIJGHdk/dMBmxUixkDG5 HsTK9ErXNRWdW4lZLO2i4c9pnB9hJhZPmsCSCs+5NIyjYAPuw1MEwGIMDd3MoQj2nkiI l5EOhsHAP8uwWKGbttv4mddYw71Ehfw08OxBAvuR4ZuVlHAY1eaRfZIqAzoAFmw7BPXK h0th5Xq2yZrrO0at+24l1PlSMclywDY6tB+gBlZrG09rmu9393I6JGPEYs9SC9dkw/rX aezg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc:to :from:dkim-signature; bh=0yXBn3psA6RGuVIWmV+RXep3irMbo8iT6cJNTGZjdHU=; fh=gmHlaZIMMboJ2MqxTgcMNAggxV68YaGaSfcBwyCSkVg=; b=F+h8z/74hsb4CE3UIq2kQ9ajyDNd/Xqt7mUAnO4fRdGr+eXVGVrPkKaSQFwsvhsnnw fJxEeHkM8lJXs6xLUgdoeJYlPCyvc/+5giuD/pkz9wKDA+w5TLFkGjUkU6RGff0GO0jv Kf0FRMEPmxV4ICJxCyWhee5kApgqks7FghAOeoMsl+NiCElnmBLEdYk3ZO01i5e+XgDa 6YIivWMhQ8QjsUhlWNwpy0MrD5ElZRC3rOKT5ZmzXtkrot8UBrJ0VoBoodkWqMp4q7d9 dghPhZbHznMADdXPx7LIvrqsW6RUN5x0L0I7ya2VsNKhb0lFnRJUjcX6RrZg74RXle1P oh2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LO1xghAK; 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 a20-20020a0ce354000000b0064a4cfb4c2bsi3120784qvm.283.2023.09.15.20.31.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Sep 2023 20:31:30 -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=LO1xghAK; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhM1B-00069s-H5; Fri, 15 Sep 2023 23:30:49 -0400 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 1qhM1A-000699-8p for qemu-devel@nongnu.org; Fri, 15 Sep 2023 23:30:48 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhM18-00086I-G5 for qemu-devel@nongnu.org; Fri, 15 Sep 2023 23:30:48 -0400 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68fbbea0dfeso2356465b3a.0 for ; Fri, 15 Sep 2023 20:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694835045; x=1695439845; 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=0yXBn3psA6RGuVIWmV+RXep3irMbo8iT6cJNTGZjdHU=; b=LO1xghAKSt1iT3xzUkyH23dNxKxMeKlrGxziMur81I1RIRmg0n/GMv5zRolr1rCyni eHY3qr9WWVyjuUQVMXpnaJwqxPakqHHpb+k9uuP1S3PgRMx8czM+gyhrjTeLrlJiZklX qgqPinBBytSHtYGpY5Cuq1Sky4127cXLKarZyXTQABpyXJUZ6Gnn+ZP1VfQMrraKEFzJ KEKOiYdJ1riMqlDgxFdcdx+9LxZdZwRLWMJyQUVHPIi1DQtWxpsiVjzvVQdDU6MIHohm XO9RtY/jyr8dqjq6pNjTly5NrQXt8qBwv22gPUY4Aldh9kap+DDYqmQl0609y3R6fkx+ UcBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694835045; x=1695439845; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0yXBn3psA6RGuVIWmV+RXep3irMbo8iT6cJNTGZjdHU=; b=jIy0YbhsYgHSj6E5A/k1Yv/znSoH6W1F/tUndHfUN4hJ/LOULyQarGFdlqhwYW+xUj hC3MgTan7Nvjm7vgmuj+qH9XkCyfefudLFLuJYtyFUNyYKyUwHiJzm/s9UYH4Bmo2jk6 ZV2R6hHz+Nkqplh9V9OU0zQ3/9Zviuh9qYomTUiI64arAu/cSd4JdLmsws8SftcyuHcW bPjWuXFA4grujvg1kKEYGpvpzE5G3hhqY9ZRYxrqARV6Xtx8FN17fDq5pcf/4hzuxIj/ T5E7JRV+GnMFLFrIZf7OSRUjvkc3EVmc9Mitkamv1dgyi6Io7AzaqeE7AEc+XDthFmFr jEAA== X-Gm-Message-State: AOJu0YwBnhzyZUmRRYdQzYX4sqw+z4lU6f++n0Df9gLxZd6G2dVmOV6X 3XIdHp30kAFTyDE3fJert//4UajVy2sdQhB2PlM= X-Received: by 2002:a05:6a00:cd1:b0:68a:4261:ab7f with SMTP id b17-20020a056a000cd100b0068a4261ab7fmr3839811pfv.31.1694835045218; Fri, 15 Sep 2023 20:30:45 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id j26-20020aa783da000000b00687a4b70d1esm3577320pfn.218.2023.09.15.20.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 20:30:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Keith Packard , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 35/39] fpu: Handle m68k extended precision denormals properly Date: Fri, 15 Sep 2023 20:30:07 -0700 Message-Id: <20230916033011.479144-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230916033011.479144-1-richard.henderson@linaro.org> References: <20230916033011.479144-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Motorola treats denormals with explicit integer bit set as having unbiased exponent 0, unlike Intel which treats it as having unbiased exponent 1 (more like all other IEEE formats that have no explicit integer bit). Add a flag on FloatFmt to differentiate the behaviour. Reported-by: Keith Packard Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- fpu/softfloat.c | 9 +++++- tests/tcg/m68k/denormal.c | 53 ++++++++++++++++++++++++++++++++++ fpu/softfloat-parts.c.inc | 7 +++-- tests/tcg/m68k/Makefile.target | 2 +- 4 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 tests/tcg/m68k/denormal.c diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 2a33967094..027a8e576d 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -517,6 +517,7 @@ typedef struct { * round_mask: bits below lsb which must be rounded * The following optional modifiers are available: * arm_althp: handle ARM Alternative Half Precision + * m68k_denormal: explicit integer bit for extended precision may be 1 */ typedef struct { int exp_size; @@ -526,6 +527,7 @@ typedef struct { int frac_size; int frac_shift; bool arm_althp; + bool m68k_denormal; uint64_t round_mask; } FloatFmt; @@ -576,7 +578,12 @@ static const FloatFmt float128_params = { static const FloatFmt floatx80_params[3] = { [floatx80_precision_s] = { FLOATX80_PARAMS(23) }, [floatx80_precision_d] = { FLOATX80_PARAMS(52) }, - [floatx80_precision_x] = { FLOATX80_PARAMS(64) }, + [floatx80_precision_x] = { + FLOATX80_PARAMS(64), +#ifdef TARGET_M68K + .m68k_denormal = true, +#endif + }, }; /* Unpack a float to parts, but do not canonicalize. */ diff --git a/tests/tcg/m68k/denormal.c b/tests/tcg/m68k/denormal.c new file mode 100644 index 0000000000..20bd8c7332 --- /dev/null +++ b/tests/tcg/m68k/denormal.c @@ -0,0 +1,53 @@ +/* + * Test m68k extended double denormals. + */ + +#include +#include + +#define TEST(X, Y) { X, Y, X * Y } + +static volatile long double test[][3] = { + TEST(0x1p+16383l, 0x1p-16446l), + TEST(0x1.1p-8223l, 0x1.1p-8224l), + TEST(1.0l, 0x1p-16383l), +}; + +#undef TEST + +static void dump_ld(const char *label, long double ld) +{ + union { + long double d; + struct { + uint32_t exp:16; + uint32_t space:16; + uint32_t h; + uint32_t l; + }; + } u; + + u.d = ld; + printf("%12s: % -27La 0x%04x 0x%08x 0x%08x\n", label, u.d, u.exp, u.h, u.l); +} + +int main(void) +{ + int i, n = sizeof(test) / sizeof(test[0]), err = 0; + + for (i = 0; i < n; ++i) { + long double x = test[i][0]; + long double y = test[i][1]; + long double build_mul = test[i][2]; + long double runtime_mul = x * y; + + if (runtime_mul != build_mul) { + dump_ld("x", x); + dump_ld("y", y); + dump_ld("build_mul", build_mul); + dump_ld("runtime_mul", runtime_mul); + err = 1; + } + } + return err; +} diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 527e15e6ab..a44649f4f4 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -118,7 +118,8 @@ static void partsN(canonicalize)(FloatPartsN *p, float_status *status, } else { int shift = frac_normalize(p); p->cls = float_class_normal; - p->exp = fmt->frac_shift - fmt->exp_bias - shift + 1; + p->exp = fmt->frac_shift - fmt->exp_bias + - shift + !fmt->m68k_denormal; } } else if (likely(p->exp < fmt->exp_max) || fmt->arm_althp) { p->cls = float_class_normal; @@ -256,7 +257,7 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, is_tiny = !frac_addi(&discard, p, inc); } - frac_shrjam(p, 1 - exp); + frac_shrjam(p, !fmt->m68k_denormal - exp); if (p->frac_lo & round_mask) { /* Need to recompute round-to-even/round-to-odd. */ @@ -287,7 +288,7 @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, p->frac_lo &= ~round_mask; } - exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) != 0; + exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) && !fmt->m68k_denormal; frac_shr(p, frac_shift); if (is_tiny && (flags & float_flag_inexact)) { diff --git a/tests/tcg/m68k/Makefile.target b/tests/tcg/m68k/Makefile.target index 1163c7ef03..6ff214e60a 100644 --- a/tests/tcg/m68k/Makefile.target +++ b/tests/tcg/m68k/Makefile.target @@ -4,7 +4,7 @@ # VPATH += $(SRC_PATH)/tests/tcg/m68k -TESTS += trap +TESTS += trap denormal # On m68k Linux supports 4k and 8k pages (but 8k is currently broken) EXTRA_RUNS+=run-test-mmap-4096 # run-test-mmap-8192