From patchwork Fri Oct 1 21:36:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick McGehearty X-Patchwork-Id: 1535555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=m3cK6GAd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HLk3q0j3lz9t10 for ; Sat, 2 Oct 2021 07:37:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C58F1385742E for ; Fri, 1 Oct 2021 21:37:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C58F1385742E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633124258; bh=jNrAhxKHF1GZ2L1zUUZ7GaR+fcLLJBfUbA0OJufysIU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=m3cK6GAdwjGSVHbHRnrxfg7l6AwP6UVWNE8UtUPMbhfdOGRLR026j7AU33Tbf0mHl 8kE+4LNdpmOKbgQk6KgB/f79qog5JOUZPm6EPgAOw/T1RkVGu2LIpyUGnI09KSE782 j/Gh71VPc1cUVMSJCKIMQ7g3SJ7AOkSGbMOsEJUI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id B2CA13858410 for ; Fri, 1 Oct 2021 21:36:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B2CA13858410 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 191KOoNI012501; Fri, 1 Oct 2021 21:36:52 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3bdevvhb5x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Oct 2021 21:36:45 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 191LaOCw022227; Fri, 1 Oct 2021 21:36:26 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by userp3020.oracle.com with ESMTP id 3bc3cj3wn8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 01 Oct 2021 21:36:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IIfhMrzXKqUxj7C2UzRgeaKHoJ5RNK4NIdFviB3KlnINVwYi6jV8RSE1U1qm5tWkmQ7td4glRswB0eK2ByaT0vfbmJHXlWfmCfd54hoh7Ru6zR/jSbtnoMruOhwytlBJR4ALDHEKepz0066i0o5UvA0Hp8NQtiJs4rC+qwWQVWpfljAxqtuWouKBgGFpgyqvhIvKhPIav5GlLtxnYsjtBnwQvDv2BOIiOtV+rdRccW3AIdzGTwDBr6pDlSskuQGC0rGsUO5JW3jo11TpibbRhyVGa7Iln5+vZXTzvvx4ysdmfdwrZXDpd+S1Yh7cNu81khULcQa1m9AawWeVndTJ9Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jNrAhxKHF1GZ2L1zUUZ7GaR+fcLLJBfUbA0OJufysIU=; b=DkbdOYtOvwAhrSCKevuJjWFX6w/Pdyy2ZgBzlAZ6rNx43crbGiJKj9nrAutXKctBcKwtc0tDZlHBi/mtdkF2y1lCpV9o8x4wzm13NUmvNgJAqjmQFvrdUd1E/FUU0TCahrtBKhW1VYCpwqIMWa4ozRpvdpTLQoPuTZL2QcEADavyG5KJsJ/zMrsSpev4edjMm0+9RZ5IIaJZ0aL0v4EBRreqW0VR9ZjXHWrEHhoI7PgjJ9Yz+fmMIhmZsrxAGsGPUeAcZAHOrj8AeW/98eG/5I7P1Dz0W4Gm8m48bNSPRhNSRBv8MkdpoduP4pKuMOkzODloYbxpbC5cXIW0fcJrkQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BYAPR10MB3208.namprd10.prod.outlook.com (2603:10b6:a03:159::10) by BYAPR10MB3493.namprd10.prod.outlook.com (2603:10b6:a03:123::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14; Fri, 1 Oct 2021 21:36:22 +0000 Received: from BYAPR10MB3208.namprd10.prod.outlook.com ([fe80::7c09:ef39:34f2:e79c]) by BYAPR10MB3208.namprd10.prod.outlook.com ([fe80::7c09:ef39:34f2:e79c%4]) with mapi id 15.20.4566.019; Fri, 1 Oct 2021 21:36:22 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH v6] Fix for powerpc64 long double complex divide failure Date: Fri, 1 Oct 2021 21:36:14 +0000 Message-Id: <1633124174-2825-1-git-send-email-patrick.mcgehearty@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-ClientProxiedBy: BYAPR21CA0022.namprd21.prod.outlook.com (2603:10b6:a03:114::32) To BYAPR10MB3208.namprd10.prod.outlook.com (2603:10b6:a03:159::10) MIME-Version: 1.0 Received: from localhost.us.oracle.com (148.87.23.4) by BYAPR21CA0022.namprd21.prod.outlook.com (2603:10b6:a03:114::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.13 via Frontend Transport; Fri, 1 Oct 2021 21:36:22 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b7e8870d-2dde-47dd-73a1-08d985238351 X-MS-TrafficTypeDiagnostic: BYAPR10MB3493: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: prTtywg80/UrWdw2Jsp3bElt/Q228Zcyn81YsMPAjduKOkYKIhLmz/8yC0rmNasmhqmGFajqeAWObv9M+xrHPkuTcE+o5gkBDDSzkAYVqm9jnfMj2v5MlzcgjpxQ/j1WCdfNWfVDBEMpTjf+dNiuF2GpMlw7PmD+dZ+ej4bSEGttmg/f7ZwHpVQxbQG3vePtn9Mo7bbmuN26M0oSYUBrHuGCAhOrxM00OysUvO4M8vYdcztxAz++53Q4ZoGiq4rxHp994kbQbslERI5osuM3hBVV8l3dSHNgx+oi0d+RzL/FEDhXuint4eKpzY+/kh8AscJLppLw/tmA0JhlzoMLJ9bRkXDCI1IPMSYeGYcUQVGiZTkGfJg7JsbugVlM+8Op728BlUtdKG6c/q/wQmn5UgpXIBKUbEF4FM0Wzy5pkKYDKcoVaFzF4ny33T/xrbZYC09UXlye3IgvC+y/IUmfPHwkkOUVen+j3ceM5LOpg/fhoV5hJ+OgHtByCLRqneUY+xgySh05B0EqZkgk2n/Ru7DK8Oh0CaWRR2IoNYvMbeQ5B/01+OXz/iSGoz8B6AvE/CEcW+0xOyWAo/Q5k4ko/F6lRuBnkA/M2eGEXfWc3NptVB1tfXX3+1btztAyKJs7iOsnH6XG2efH+cxXdtOgwYCZFsCS0A8HSTrGOAg/FdhCzbshgxrlmELELNIO2htqSHi0HlQN5IgNcCTG7TOQscTO/crULmcwbgHX+rULZtIYqDetzwVis31NTnvrFpauJn8pJBed77LKv4oASOAPAOJBZV1Omy2GmtBAQB39xAI= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3208.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(52116002)(2906002)(83380400001)(7696005)(966005)(5660300002)(316002)(86362001)(38350700002)(4326008)(66556008)(6486002)(26005)(36756003)(66476007)(6916009)(8676002)(186003)(8936002)(6666004)(38100700002)(956004)(508600001)(2616005)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ypyu7jswfV7QsSgPd0+pPpSzaxcFezwh+qszdBHMYB0tE8xTCYFpYG40xy/iQR3fe78Q9KjvPcbdExPE4EEAqF9TQKAjanP5rULe+njMif4FsV1tBU3o3cSeoa62h2JlzguUu5x12EUSrAwYTi6L4KBNHFGprhMR7wksTMnVQh59CjB+qADffdxDJawT3DF2i9yYX2hGzYMxoWb2cHeIxBDnm8SM0My26e0g4ceXs7sMU7MOrclA0wyLiylx3708G/FcaMc2eGeZB6OZS9plk2OTghxShfkysNeobrMtOtm4Zzlbpywa2xFdDY6xj98fCEg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47dd-73a1-08d985238351 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3208.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 21:36:22.5317 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: M0jrf4Bvs+VVJQKUb+WGhaCdoXUTvCFQyZO9yD7P2I7IZebM+M6IsNXyrHE4BMzVTrZOu971BpUao9uu2d/t1nIIfTiCZqpJDkMMxJJTslw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB3493 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10124 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110010150 X-Proofpoint-ORIG-GUID: 7iQOcQLD7hnyvCemUwvfZ97mOWX7YcD2 X-Proofpoint-GUID: 7iQOcQLD7hnyvCemUwvfZ97mOWX7YcD2 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick McGehearty via Gcc-patches From: Patrick McGehearty Reply-To: Patrick McGehearty Cc: joseph@codesourcery.com, segher@kernel.crashing.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" - - - - New in version 6: Due to an oversight (i.e. coding error), version 5 changed the use of __LIBGCC_TF_EPSILON__ to __LIBGCC_DF_EPSILON__ but not the other LIBGCC_TF values. For correct execution of the long double test case it is necessary to also switch to using __LIBGCC_DF_MIN__. For consistency we also switch to using __LIBGCC_DF_MAX__. LDBL_MIN is 2**53 times as larger than DBL_MIN. The larger value causes the code to switch the order of computation when it is not optimal, resulting in failure for one of the values in the cdivchk_ld.c test. Using DBL_MIN does not cause that failure.. There may be opportunity for further refinement of IBM128 format Long Double complex divide, but that's beyond the scope of this patch. - - - - This revision adds a test in libgcc/libgcc2.c for when "__LIBGCC_TF_MANT_DIG__ == 106" to use __LIBGCC_DF_EPSILON__ instead of __LIBGCC_TF_EPSILON__. That is specific to IBM 128-bit format long doubles where EPSILON is very, very small and 1/EPSILON oveflows to infinity. This change avoids the overflow without affecting any other platform. Discussion in the patch is adjusted to reflect this limitation. It does not make any changes to .../rs6000/_divkc3.c, leaving it to use __LIBGCC_KF__*. That means the upstream gcc will not build in older IBM environments that do not recognize the KF floating point mode properly. Environments that do not need IBM longdouble support do build cleanly. - - - - This patch addresses the failure of powerpc64 long double complex divide in native ibm long double format after the patch "Practical improvement to libgcc complex divide". The new code uses the following macros which are intended to be mapped to appropriate values according to the underlying hardware representation. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101104 RBIG a value near the maximum representation RMIN a value near the minimum representation (but not in the subnormal range) RMIN2 a value moderately less than 1 RMINSCAL the inverse of RMIN2 RMAX2 RBIG * RMIN2 - a value to limit scaling to not overflow When "long double" values were not using the IEEE 128-bit format but the traditional IBM 128-bit, the previous code used the LDBL values which caused overflow for RMINSCAL. The new code uses the DBL values. RBIG LDBL_MAX = 0x1.fffffffffffff800p+1022 DBL_MAX = 0x1.fffffffffffff000p+1022 RMIN LDBL_MIN = 0x1.0000000000000000p-969 RMIN DBL_MIN = 0x1.0000000000000000p-1022 RMIN2 LDBL_EPSILON = 0x0.0000000000001000p-1022 = 0x1.0p-1074 RMIN2 DBL_EPSILON = 0x1.0000000000000000p-52 RMINSCAL 1/LDBL_EPSILON = inf (1.0p+1074 does not fit in IBM 128-bit). 1/DBL_EPSILON = 0x1.0000000000000000p+52 RMAX2 = RBIG * RMIN2 = 0x1.fffffffffffff800p-52 RBIG * RMIN2 = 0x1.fffffffffffff000p+970 The MAX and MIN values have only modest changes since the maximum and minimum values are about the same as for double precision. The EPSILON field is considerably different. Due to how very small values can be represented in the lower 64 bits of the IBM 128-bit floating point, EPSILON is extremely small, so far beyond the desired value that inversion of the value overflows and even without the overflow, the RMAX2 is so small as to eliminate most usage of the test. The change has been tested on gcc135.fsffrance.org and gains the expected improvements in accuracy for long double complex divide. libgcc/ PR target/101104 * libgcc2.c (RMIN2, RMINSCAL, RMAX2): Use more correct values for native IBM 128-bit. --- libgcc/libgcc2.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c index 38f935e..e66e6f0 100644 --- a/libgcc/libgcc2.c +++ b/libgcc/libgcc2.c @@ -1904,10 +1904,17 @@ NAME (TYPE x, int m) # define MODE tc # define CEXT __LIBGCC_TF_FUNC_EXT__ # define NOTRUNC (!__LIBGCC_TF_EXCESS_PRECISION__) -# define RBIG (__LIBGCC_TF_MAX__ / 2) -# define RMIN (__LIBGCC_TF_MIN__) -# define RMIN2 (__LIBGCC_TF_EPSILON__) -# define RMINSCAL (1 / __LIBGCC_TF_EPSILON__) +# if __LIBGCC_TF_MANT_DIG__ == 106 +# define RBIG (__LIBGCC_DF_MAX__ / 2) +# define RMIN (__LIBGCC_DF_MIN__) +# define RMIN2 (__LIBGCC_DF_EPSILON__) +# define RMINSCAL (1 / __LIBGCC_DF_EPSILON__) +# else +# define RBIG (__LIBGCC_TF_MAX__ / 2) +# define RMIN (__LIBGCC_TF_MIN__) +# define RMIN2 (__LIBGCC_TF_EPSILON__) +# define RMINSCAL (1 / __LIBGCC_TF_EPSILON__) +# endif # define RMAX2 (RBIG * RMIN2) #else # error