From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70040.outbound.protection.outlook.com [40.107.7.40]) by sourceware.org (Postfix) with ESMTPS id A605D3857C50 for ; Mon, 3 Aug 2020 21:35:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A605D3857C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R8yQuwqeu98imy6vLZN/r54Vpn94ET/qA768VGfKfyE=; b=Vib646PDOGW2+YbkHvrrLucjJWOMjn2JdbuxXFBsIobGVo4P6ZbXY3ckDUxPIwwcLe0tjzmTE+RCTFGhj9aHD36PtUP91x9hAlNn+J+uWkMzbqi7W1/uRSOosUzXLtMTeZvlPHHqldtgYqvJyoTr2yxJ1ga774HkmHgsKmQjQ5M= Received: from AM5PR0502CA0005.eurprd05.prod.outlook.com (2603:10a6:203:91::15) by DB6PR08MB2822.eurprd08.prod.outlook.com (2603:10a6:6:1d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Mon, 3 Aug 2020 21:35:50 +0000 Received: from AM5EUR03FT020.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:91:cafe::d0) by AM5PR0502CA0005.outlook.office365.com (2603:10a6:203:91::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Mon, 3 Aug 2020 21:35:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT020.mail.protection.outlook.com (10.152.16.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Mon, 3 Aug 2020 21:35:49 +0000 Received: ("Tessian outbound d7d79595a1cb:v63"); Mon, 03 Aug 2020 21:35:49 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 73507c2be1a1da71 X-CR-MTA-TID: 64aa7808 Received: from a6dd76792d23.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 13FCD51D-9368-4C68-8A82-DF2A41018B5D.1; Mon, 03 Aug 2020 21:35:42 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a6dd76792d23.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 03 Aug 2020 21:35:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FXuxjEkrFFQKyf315FgdrE0YgjrFlCofrbhVlGRJ2o7RjclltWh0Wjd0s64CljRf7OVbkjOKr/QPDPO8xeZdxJzmIq3t9xuLbnbB0GD5szxyx1iuW7FHX9b3xbpkIUosR9WWn2o+Db+WkbNqO2eQMJ53UHc1pqCVD6tniqNQy00XhUKrepWBsaGdd6uzXX/udICm9X4iAr6SA6AeA8agRy6QvPdqAebu3laL1Gj29I985CtPiCI45Et5fQzwvZOerArndL0VDmhCXjQVdlAPdK9XXQlvhYFZ81Vb9xMz6hfqGBLNxXVlFIvO6ZobKKlctYigd9KIIEXOamnFFKM/Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R8yQuwqeu98imy6vLZN/r54Vpn94ET/qA768VGfKfyE=; b=CfGHEhr/WH7IXq6xsEAnF1gcLxDFgT4WXpBNlc22gvDNrUXkJMC1UAXCaS4QXPBqKQwbcoXeHy6NyodvGfV3n5Kl12hknERvu6JIB7r3oDOgrA6hUCAr/0+BI0Qi371SlIBiaGrCe21jbX+w1OSsSbrj30F+LhNvg8/1O5JB47giUd6BSgPtdl24Qh1mh8cknel45VT73Bg/jG/sNwQIyue6KU5azN1fXzebkIIj1NIBVzwytxoRwlBTB7ULrJA/OUAev2jVEFXfr4U2zKv//lxw06l+gl2HpCITgVDxPu6oj+e+Q7OGKByF3lL78d4cagobXOM5cQ5+fLoIO1ikyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R8yQuwqeu98imy6vLZN/r54Vpn94ET/qA768VGfKfyE=; b=Vib646PDOGW2+YbkHvrrLucjJWOMjn2JdbuxXFBsIobGVo4P6ZbXY3ckDUxPIwwcLe0tjzmTE+RCTFGhj9aHD36PtUP91x9hAlNn+J+uWkMzbqi7W1/uRSOosUzXLtMTeZvlPHHqldtgYqvJyoTr2yxJ1ga774HkmHgsKmQjQ5M= Authentication-Results-Original: keithp.com; dkim=none (message not signed) header.d=none;keithp.com; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM5PR0801MB1748.eurprd08.prod.outlook.com (2603:10a6:203:3c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17; Mon, 3 Aug 2020 21:35:41 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c%6]) with mapi id 15.20.3239.021; Mon, 3 Aug 2020 21:35:41 +0000 Date: Mon, 3 Aug 2020 22:35:34 +0100 From: Szabolcs Nagy To: Keith Packard Cc: newlib@sourceware.org Subject: Re: [PATCH] libm/math: Use __math_xflow in obsolete math code Message-ID: <20200803213534.GH14398@arm.com> References: <20200730234236.1282460-1-keithp@keithp.com> <20200731151941.GC5387@arm.com> <87eeonhac3.fsf@keithp.com> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <87eeonhac3.fsf@keithp.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-ClientProxiedBy: SN6PR08CA0005.namprd08.prod.outlook.com (2603:10b6:805:66::18) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.55) by SN6PR08CA0005.namprd08.prod.outlook.com (2603:10b6:805:66::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Mon, 3 Aug 2020 21:35:40 +0000 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 16d2396a-21f9-453c-c597-08d837f53092 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1748:|DB6PR08MB2822: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 6e/1chOPHIcwx6UzvM685t2OtaRpiG/b+spfWg/MkNk8z3pyLuLBn2dGPTAlxHKwRjuZfq5coirPwaIxaaODZUTxPBQeiefuTP7TW8vJVnkMerKqtHz0NS3qC/Vj5NVEsiGXRLHo0OhYaNUaTDCn8nQUgM331hUa7OIlzh7i4mFfBCVGCSxDCZtAa0oRTqRDTfRO9UuFnx9n5w1OTZRaVebvzckXZhrTWzFVmApHeRKxzyuJaWca319+914i3B/wUOTshn+dNtM+JctrYbz+932bq0pltbJy+CaLkBaUK9Key9p4xh7y/lKPO+tFVpKtBWVGA9aO7U1NBLcYjSEYiw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(39860400002)(396003)(376002)(346002)(366004)(83380400001)(52116002)(6916009)(6666004)(316002)(86362001)(8936002)(956004)(8676002)(36756003)(4326008)(478600001)(2906002)(2616005)(26005)(66946007)(44832011)(55016002)(1076003)(5660300002)(7696005)(8886007)(66476007)(66556008)(186003)(16526019)(33656002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: j4+VeQVWSYCdpXMZUCYqTT1ULf4/TR7BF2Yf/X9cjDeCca/X51gcE1Z8hcCVcWIR4RqV0OCTx9Yoy0H8cMyefNBp1UwCilzUC9eZkA6pHv+lfXdOtQELo8kBKQWbUnGGYetvUu/XG/8F9YRIjgdTQbOGaZ0pGRwyoYQ9M00lBDzAi3xUAibggPeHDB8/gXYGF621HufRZfEfCmcSS5b3QoNuk/eJ4htcCJPquv9ncS57kspF9bX8c8Z3auvu1R8MpZqrDuIVgZzxXJwvMrShB2bU+Jy3yyHms/gLK4Df/dOvXxL6LFiFE14piVb4RamNPK8lKRRjJsXUpowTMLu69FdeBJaYqv1DYdnrwEMHhuaWZSz7Ef+n35z5aGniP4vOW1lhdA9TwhNJZ1K5Aooxj5tNV409hpK8yvGfdQ7XYWqMDU8boGcl/DA4wVkXqY3HaQwl2pkKe1ONqLaca73+RlTBhMol81emZR6XLt+WWUVuqRXmz4aWr5sgaRiGzU+MlbY/Eh8R6xSsw4YF6esGdtLkJZYIFTlyQU1YN2cArEw1JOK8AnfscrzG4K7lRUl0k4Txehu/XuCsoFDb3mG7kaabJHS79sr6FS2E9ULaPMwPZOGbt+RMpwTY+pSznpncpNo80P5kQisr6MpNLpX8YQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1748 Original-Authentication-Results: keithp.com; dkim=none (message not signed) header.d=none;keithp.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT020.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 8c608c50-4934-4367-2925-08d837f52ba0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JUzI0JQVxJTD+oUmGlK3cWzcYqzr6nW3/nPX35EPLiGm4YqlDC1OEua/mzqueTYBi+zFj2VNzWorzRo3AhHGXO7EyXUFsN5LZydETVxarBK4JgsjHQmFDueN8o8yDRF1zWydRJrRdgTSO9evcleTpb1M79GPyT2rjp39hYR7rTCkOaDP0iyA3KVZ4pkiDKVNJFmbHmoT4hEkMXkgP9PqsXqGVPZj09v2G08t7cONs0kccgDeExeH/2XXsUjfY0YuLtOmkvlBzeS8BWBT1NKrDFZcP1vI+N7B/8kih2AGDzGxXL8MJ/osAqroCR/jsm6KOcxzfm5q9PL5uLl9KC/zesqtngz+XsRepW3B9T2QyGB1Enax1Mv7zVR6HlanF86jSNwFkeV8OIFRZCaYQRGgSw== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(376002)(346002)(136003)(396003)(39860400002)(46966005)(1076003)(81166007)(336012)(8886007)(70586007)(6862004)(356005)(86362001)(8676002)(82310400002)(83380400001)(7696005)(82740400003)(70206006)(478600001)(5660300002)(47076004)(33656002)(2906002)(8936002)(44832011)(36756003)(16526019)(2616005)(956004)(6666004)(55016002)(316002)(186003)(26005)(4326008)(36906005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2020 21:35:49.3825 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 16d2396a-21f9-453c-c597-08d837f53092 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT020.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2822 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 03 Aug 2020 21:35:55 -0000 The 08/03/2020 11:07, Keith Packard wrote: > Szabolcs Nagy writes: > > > note1: i used c99 code when i wrote the > > new math code and currently the old math > > code can be compiled with older compilers, > > this change might prevent that. > > Hrm. I just learned about "#pragma STDC FENV_ACCESS on" this morning and > am wondering if we shouldn't just patch the old math library to use that > instead of calling the __math_xflow functions. Would be a simpler patch > and provide precise compatibility with the previous version. i don't know of any c compiler that correctly implements that pragma and some compilers (clang) warn about it so i don't use it myself. but the correct iso c way is to use it on every code that may run in non-default fenv (non-nearest rounding mode) or may run between exception setting and getting operations. (i.e. not just for math code that has fenv functions in it). the drawback is that it means that any call may access the fenv (i.e. if you mark a function implementation with the pragma then any call within that function may change the rounding mode unless the compiler can prove otherwise), so all extern calls become floating-point barriers which prevents some useful optimizations (most calls don't change the rounding mode). and this still does not give complete fenv safety, because it's not clear if inline asm or other language extensions may access fenv or not and how compilers will deal with that: currently float operations are reordered across inline asm. > > Here's an example of how that works: > > #include > #include > > #pragma STDC FENV_ACCESS on > > int main(void) > { > double x; > int e; > feclearexcept(FE_ALL_EXCEPT); > x = 0.0 / 0.0; > e = fetestexcept(FE_ALL_EXCEPT); > printf("x %g e %x\n", x, e); > return 0; > } > > $ cc except.c -lm > $ ./a.out > x -nan e 1 > $ > > As you can see, even using constants still raise the appropriate > exception. either you got lucky or you use another compiler than i do. (gcc gets close to exception safe operation if you use -frounding-math: then it assumes the compiled code itself does not change the rounding mode, but its caller might, which e.g. means that constant folding is not allowed: inexact arithmetic operations are rounding mode dependent. so the generated code mostly preserves fenv exceptions, but this can break if the result does not depend on rounding: nextafter(DBL_MIN,0) should raise underflow but it may be const folded, or relational operations may not preserve exceptions)