From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id C1CD2385B836 for ; Tue, 20 Jul 2021 16:12:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C1CD2385B836 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=keithp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=keithp.com Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id C126B3F301B3; Tue, 20 Jul 2021 09:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1626797541; bh=FKTSdQkKYtTrpcoC6OwkTJ+4mruuGxzF85MH7euWPss=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=v7CPQpq+AS2N887SLLk0Vko7BaJtSE14sgm/8RFvYhLlgCZ3vvwPP165PgJ16VT4q nAsO8ymKtqoyxQyA9wb4l64uKfgeYd2eRJg/GDtExUGt4A6bbI4lLACclKFl0J4HTA bfOCiEs2InbD0N3AQG9mJ5TFLPjAEhzV9QJEWp/KSZXM9K2EipLH3vq+NOANdxQs7Y ztt9+XVzdZc2QB6WXM9TGUyM6vj6MdfNBIMx24uKfPSmAUuiPJUH3rlAXWCu7GklZS OwemviDc6HDrDNQ4vDTo9qO3Zyu3tj/NTsXnBBMBN7aZnOHTE5/opsb2CREFeW905h vJcZP81vv7pbQ== X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id kRAtTaMFAhBL; Tue, 20 Jul 2021 09:12:21 -0700 (PDT) Received: from keithp.com (koto.keithp.com [192.168.11.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 488513F2F90C; Tue, 20 Jul 2021 09:12:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1626797541; bh=FKTSdQkKYtTrpcoC6OwkTJ+4mruuGxzF85MH7euWPss=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=v7CPQpq+AS2N887SLLk0Vko7BaJtSE14sgm/8RFvYhLlgCZ3vvwPP165PgJ16VT4q nAsO8ymKtqoyxQyA9wb4l64uKfgeYd2eRJg/GDtExUGt4A6bbI4lLACclKFl0J4HTA bfOCiEs2InbD0N3AQG9mJ5TFLPjAEhzV9QJEWp/KSZXM9K2EipLH3vq+NOANdxQs7Y ztt9+XVzdZc2QB6WXM9TGUyM6vj6MdfNBIMx24uKfPSmAUuiPJUH3rlAXWCu7GklZS OwemviDc6HDrDNQ4vDTo9qO3Zyu3tj/NTsXnBBMBN7aZnOHTE5/opsb2CREFeW905h vJcZP81vv7pbQ== Received: by keithp.com (Postfix, from userid 1000) id 9D95B1E60111; Tue, 20 Jul 2021 09:12:36 -0700 (PDT) From: Keith Packard To: Kito Cheng , newlib@sourceware.org, kito.cheng@gmail.com, Aldy Hernandez , Andrew MacLeod Cc: Kito Cheng Subject: Re: [PATCH] libm: Fixing overflow handling issue for scalbnf and scalbn In-Reply-To: <20210719085022.8157-1-kito.cheng@sifive.com> References: <20210719085022.8157-1-kito.cheng@sifive.com> Date: Tue, 20 Jul 2021 09:12:36 -0700 Message-ID: <87wnplnevf.fsf@keithp.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jul 2021 16:12:40 -0000 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Kito Cheng writes: > cc Aldy Hernandez and Andrew MacLeod , > they are author of new VRP analysis for GCC, just to make sure I didn't > mis-understanding or mis-interpreting anything on GCC site. > > GCC 11 have better value range analysis, that give GCC more confidence > to perform more aggressive optimization, but it cause scalbn/scalbnf get > wrong result. C doesn't specify what happens when signed integer values overflow; compiler developers believe that gives them the license to do this kind of "optimization". This patch makes the code more compliant with the C spec. The only way to get known overflow behavior would be to use unsigned integers, but as this code depends on signed comparisons, that isn't practical here. I've added tests for this case to the picolibc test suite and verified that your patch corrects this issue on 32-bit ARM using GCC 11. =2D-=20 =2Dkeith --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAmD29fQACgkQ2yIaaQAA ABE+fBAAtrls+W0JHy/VF3DqU+quoJn0k4uYwE5eyKG3T8OEGFy+nqJVI3q/NUu9 Ezfe1eu0MSJKCeiDvxykNeOQwTGPmzHm0TTMRDmOYMP4gWk0/sBqvVDhGism+fVz U6cks3uRmox4UyX5nf2DOJKktwHfuEcKLCBPRBlGfMLtEAggaSTI1d6Hp4Iy2MIS fAjpea2J9/bubNxICHYxjB0xDpaNnOF2hLT9Wnn9Nz55zQNRvCEwUE7M07uqTM/y wz9b61jdt+xy/qMBhkCMW/T3BNTqG0MuA5hs5gRhsz9T+4y8fxwJIHv3uckHe9ru UTERYsLMIf7P/HtUyYQKidvf+OxzCup1sIkwwqJqjFgOI9QtG1ZqpdTUzuL2s3vi jE7PW64vel1eG2ykKxhBogeYr4H4p94cCmATUtuJZARv5ffF8Z4Q3hWiLc9tpZqt Jt7qORoo62gAyOFOdkcHJ82me4yx4HDb6SdONqIbliq8kulciqCzLQr5s3BHMreE l8H+W0s+wb809n3c6PIlbkyPwyt8ObhNI2XSEAOCu1bkhdxJPlgdmDSVmp4DOOoN QryktnMTkqUO/zngH8GndXaPu8cuDvRh0guTqWTCYGuuag/0b+hgi3tTbE2hS1zo a913rf9zsTYaecMqIh7Sm7NpLWVgTQ4ZEj9TkkIV+8ZVJK3CyZ4= =I0CJ -----END PGP SIGNATURE----- --=-=-=--