From patchwork Tue Aug 20 20:48:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1974597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EUxc7gAq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WpM5j70drz1ydn for ; Wed, 21 Aug 2024 06:49:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A2503870857 for ; Tue, 20 Aug 2024 20:49:28 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id BBD0E3858420 for ; Tue, 20 Aug 2024 20:49:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBD0E3858420 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BBD0E3858420 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724186947; cv=none; b=CI4Oi8RLAyA6zmjOHTBK5OWnqNedxMQLb+loKbLv6zO8iktt4CajjxkDPbAzaWXZXuE/6sI65kc39TTXDIG0n15qfwPWlgQpz/1hO0NJMNthpr5k54NZzoMoKVT+YvEExJ1HDjiFkkVyiasbFGqg+cSW0hIkk+UQdUSfGwpUCEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724186947; c=relaxed/simple; bh=1rydIu4EARNmQ+5GEllMo9uVPSAtNorG+uxDACjmLfM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=ELHylTNvKlPg0p1W+RZ9omFdbNliAP16o2LffJ69VK5e1s6/vvqM41ITYgqpZkHs7jNlXb6BeR4JrP3/mGEdSPp1CRc3uNTH0jFPnQJn0riPWbztr4CKH0QQ7uIoMjwvMrVv5+/hvVuaiPPHJk+ujhARLDqcwJU6s97Hq8n+hGg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724186945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=+kLYP9/uk/IHtX87BVjcS9CpWbKwb62RhmItChzkGqQ=; b=EUxc7gAqwOUqdag6wbmYUqQmeSFo7+pIgsZ2IoPPpJlP2/DsG8atceJX3qFA0Flop/FSmi a8y6lxqGksUvary9GEdBU+2pa1ITu9HIZxIVZlVMM0l/b/CvFnOQdg3RLtmL2P5Tozq7SS IIxyMHlV1PynXKVW7dwDClg3gNBsGqE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-7SFaUUyqPsKj8olpv4FizQ-1; Tue, 20 Aug 2024 16:49:04 -0400 X-MC-Unique: 7SFaUUyqPsKj8olpv4FizQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4280d8e685eso50353355e9.1 for ; Tue, 20 Aug 2024 13:49:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724186943; x=1724791743; h=mime-version:message-id:subject:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=+kLYP9/uk/IHtX87BVjcS9CpWbKwb62RhmItChzkGqQ=; b=DhP5KVxng/IRAmbezKaGcBpn0eJX9D1z0nMaDznYzYxB3/hK01fJWdLLP1IyVQR3r2 ch8x+dOHwTe/UZmba2sLv/Cc8LKajzk/46jL5D2U6tEyMAxBXe0Ys1/SuNk/+RPN/Aj7 emgXV9qQbIoycqUPs4qDkUCNS3owA5/O9/4bTjU1S76LN6YhzGb5ifgrKFYMaU7Ux98V midBDZFglnl/GxqSIbTDBMpUnP1Q3v0j9AWHmrXr6xf10zRWpgN5hUSikRUNSpfxWE1L VoGrSMZnnJuYh7xYFh8aLIggtlG6NdsTjOwEPrJokrWXJ81blqF1sDVv+XLM/z2y49BN 7kOw== X-Gm-Message-State: AOJu0YwS6UGli6f9oRLgpHOQ+GfQnikqd2ARw2UcdKEUraq0p8FyMJ7U 7ffTbPhhp/hBjlc6tJ2Qyycgb5wZ6/Fx5Pc5wLC0n8/IX14XiJTGumG+ak09k6KDJJ5p3FEabaW yIYYMGOlJxfjbHCpzriXbSNljf1X2wnqn/mlLZBoDbhy+00ZWKMUWcYSt12KtKlIzc06uhBkzGY 2zHJ3BgDWL8JC14He4XlESBhRNhtDonStv6l6vmgGQ/g== X-Received: by 2002:a05:600c:46cf:b0:426:647b:1bf7 with SMTP id 5b1f17b1804b1-42abf0a9391mr113105e9.32.1724186942790; Tue, 20 Aug 2024 13:49:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeF7/w8LNdqeNLVA+SZ4wfzbTkRcJYF8XZOgn5Z6TtnzugyIDWaHoFX70uFkWM44U7o+eCZA== X-Received: by 2002:a05:600c:46cf:b0:426:647b:1bf7 with SMTP id 5b1f17b1804b1-42abf0a9391mr112915e9.32.1724186941691; Tue, 20 Aug 2024 13:49:01 -0700 (PDT) Received: from digraph.polyomino.org.uk (digraph.polyomino.org.uk. [2001:8b0:bf73:93f7::51bb:e332]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37189849b08sm13849050f8f.43.2024.08.20.13.49.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 13:49:01 -0700 (PDT) Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.95) (envelope-from ) id 1sgVlr-003Cub-At for libc-alpha@sourceware.org; Tue, 20 Aug 2024 20:48:03 +0000 Date: Tue, 20 Aug 2024 20:48:03 +0000 (UTC) From: Joseph Myers To: libc-alpha@sourceware.org Subject: Improve NaN payload testing Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org There are two separate sets of tests of NaN payloads in glibc: * libm-test-{get,set}payload* verify that getpayload, setpayload, setpayloadsig and __builtin_nan functions are consistent in their payload handling. * test-nan-payload verifies that strtod-family functions and the not-built-in nan functions are consistent in their payload handling. Nothing, however, connects the two sets of functions (i.e., verifies that strtod / nan are consistent with getpayload / setpayload / __builin_nan). Improve test-nan-payload to check actual payload value with getpayload rather than just verifying that the strtod and nan functions produce the same NaN. Also check that the NaNs produced aren't signaling and extend the tests to cover _FloatN / _FloatNx. Tested for x86_64. diff --git a/math/test-nan-payload.c b/math/test-nan-payload.c index 4a81dc348b..55c13de14e 100644 --- a/math/test-nan-payload.c +++ b/math/test-nan-payload.c @@ -16,6 +16,8 @@ License along with the GNU C Library; if not, see . */ +#define _LIBC_TEST 1 +#define __STDC_WANT_IEC_60559_TYPES_EXT__ #include #include #include @@ -31,7 +33,7 @@ #define CHECK_IS_NAN(TYPE, A) \ do \ { \ - if (isnan (A)) \ + if (isnan (A) && !issignaling (A)) \ puts ("PASS: " #TYPE " " #A); \ else \ { \ @@ -41,6 +43,19 @@ } \ while (0) +#define CHECK_PAYLOAD(TYPE, FUNC, A, P) \ + do \ + { \ + if (FUNC (&(A)) == (P)) \ + puts ("PASS: " #TYPE " payload " #A); \ + else \ + { \ + puts ("FAIL: " #TYPE " payload " #A); \ + result = 1; \ + } \ + } \ + while (0) + #define CHECK_SAME_NAN(TYPE, A, B) \ do \ { \ @@ -71,7 +86,7 @@ bits. */ #define CAN_TEST_EQ(MANT_DIG) ((MANT_DIG) != 64 && (MANT_DIG) != 106) -#define RUN_TESTS(TYPE, SFUNC, FUNC, MANT_DIG) \ +#define RUN_TESTS(TYPE, SFUNC, FUNC, PLFUNC, MANT_DIG) \ do \ { \ TYPE n123 = WRAP_NAN (FUNC, "123"); \ @@ -82,6 +97,10 @@ CHECK_IS_NAN (TYPE, n456); \ TYPE s456 = WRAP_STRTO (SFUNC, "NAN(456)"); \ CHECK_IS_NAN (TYPE, s456); \ + TYPE nh123 = WRAP_NAN (FUNC, "0x123"); \ + CHECK_IS_NAN (TYPE, nh123); \ + TYPE sh123 = WRAP_STRTO (SFUNC, "NAN(0x123)"); \ + CHECK_IS_NAN (TYPE, sh123); \ TYPE n123x = WRAP_NAN (FUNC, "123)"); \ CHECK_IS_NAN (TYPE, n123x); \ TYPE nemp = WRAP_NAN (FUNC, ""); \ @@ -92,8 +111,16 @@ CHECK_IS_NAN (TYPE, sx); \ if (CAN_TEST_EQ (MANT_DIG)) \ CHECK_SAME_NAN (TYPE, n123, s123); \ + CHECK_PAYLOAD (TYPE, PLFUNC, n123, 123); \ + CHECK_PAYLOAD (TYPE, PLFUNC, s123, 123); \ if (CAN_TEST_EQ (MANT_DIG)) \ CHECK_SAME_NAN (TYPE, n456, s456); \ + CHECK_PAYLOAD (TYPE, PLFUNC, n456, 456); \ + CHECK_PAYLOAD (TYPE, PLFUNC, s456, 456); \ + if (CAN_TEST_EQ (MANT_DIG)) \ + CHECK_SAME_NAN (TYPE, nh123, sh123); \ + CHECK_PAYLOAD (TYPE, PLFUNC, nh123, 0x123); \ + CHECK_PAYLOAD (TYPE, PLFUNC, sh123, 0x123); \ if (CAN_TEST_EQ (MANT_DIG)) \ CHECK_SAME_NAN (TYPE, nemp, semp); \ if (CAN_TEST_EQ (MANT_DIG)) \ @@ -110,9 +137,31 @@ static int do_test (void) { int result = 0; - RUN_TESTS (float, strtof, nanf, FLT_MANT_DIG); - RUN_TESTS (double, strtod, nan, DBL_MANT_DIG); - RUN_TESTS (long double, strtold, nanl, LDBL_MANT_DIG); + RUN_TESTS (float, strtof, nanf, getpayloadf, FLT_MANT_DIG); + RUN_TESTS (double, strtod, nan, getpayload, DBL_MANT_DIG); + RUN_TESTS (long double, strtold, nanl, getpayloadl, LDBL_MANT_DIG); +#if __HAVE_FLOAT16 + RUN_TESTS (_Float16, strtof16, nanf16, getpayloadf16, FLT16_MANT_DIG); +#endif +#if __HAVE_FLOAT32 + RUN_TESTS (_Float32, strtof32, nanf32, getpayloadf32, FLT32_MANT_DIG); +#endif +#if __HAVE_FLOAT64 + RUN_TESTS (_Float64, strtof64, nanf64, getpayloadf64, FLT64_MANT_DIG); +#endif +#if __HAVE_FLOAT128 + RUN_TESTS (_Float128, strtof128, nanf128, getpayloadf128, FLT128_MANT_DIG); +#endif +#if __HAVE_FLOAT32X + RUN_TESTS (_Float32x, strtof32x, nanf32x, getpayloadf32x, FLT32X_MANT_DIG); +#endif +#if __HAVE_FLOAT64X + RUN_TESTS (_Float64x, strtof64x, nanf64x, getpayloadf64x, FLT64X_MANT_DIG); +#endif +#if __HAVE_FLOAT128X + RUN_TESTS (_Float128x, strtof128x, nanf128x, getpayloadf128x, + FLT128X_MANT_DIG); +#endif return result; }