From patchwork Tue Oct 23 20:12:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Meissner X-Patchwork-Id: 988354 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-488162-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="besI9Fk7"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42fl1H1Ms6z9sMl for ; Wed, 24 Oct 2018 07:12:32 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:mime-version:content-type:message-id; q=dns; s= default; b=klFhFa0qgkigQp1oOpiwsSLHgdM++8ym60Qt8q5CXQ6s41TAyqQb/ 8mJZv//FttBG0fk8TpCpirTJM0bZX3hZLSNIcIm/HE6wz/LilNDUniFlG9X3lYId yVtVXtnaNGsWl4911yAkEy6TWkc5zrwAZUoV0Zw+BkMOOTd2fGM5kM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:mime-version:content-type:message-id; s= default; bh=ccW0jIxLId7JTUcGS71inQOiFgw=; b=besI9Fk7SEaA32hwkR87 TUTyZw9IoMu8kwNqud12gQ2zcup+qmLzM77iGcFL3F4/A1CvAJgoh70qg7ruH6Br /kByrS4x+00fDt5DRlkzW6p3gswF0RjLvNDjlUfT2dsQjyaeudmeiFHDDwcYAHFC BQ8qeLMKJ5iM9NoUtBm5/Zo= Received: (qmail 56737 invoked by alias); 23 Oct 2018 20:12:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 56710 invoked by uid 89); 23 Oct 2018 20:12:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KHOP_DYNAMIC, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=king, King, meissner, sk:meissne X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Oct 2018 20:12:20 +0000 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9NK45e1137398 for ; Tue, 23 Oct 2018 16:12:18 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2na94nuqmy-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 23 Oct 2018 16:12:18 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 23 Oct 2018 14:12:17 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 23 Oct 2018 14:12:14 -0600 Received: from b03ledav001.gho.boulder.ibm.com (b03ledav001.gho.boulder.ibm.com [9.17.130.232]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w9NKCDIR19202050 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 23 Oct 2018 13:12:14 -0700 Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE9616E04C; Tue, 23 Oct 2018 20:12:13 +0000 (GMT) Received: from b03ledav001.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5974E6E052; Tue, 23 Oct 2018 20:12:13 +0000 (GMT) Received: from ibm-toto.the-meissners.org (unknown [9.32.77.218]) by b03ledav001.gho.boulder.ibm.com (Postfix) with ESMTPS; Tue, 23 Oct 2018 20:12:13 +0000 (GMT) Date: Tue, 23 Oct 2018 16:12:11 -0400 From: Michael Meissner To: GCC Patches , Segher Boessenkool , David Edelsohn , Bill Schmidt , Michael Meissner Subject: [PATCH], PowerPC: Use f128 for long double built-ins if we have changed to use IEEE 128-bit floating point Mail-Followup-To: Michael Meissner , GCC Patches , Segher Boessenkool , David Edelsohn , Bill Schmidt MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) x-cbid: 18102320-0004-0000-0000-000014A35D98 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009922; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000268; SDB=6.01106960; UDB=6.00573287; IPR=6.00887044; MB=3.00023877; MTD=3.00000008; XFM=3.00000015; UTC=2018-10-23 20:12:16 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18102320-0005-0000-0000-000089428C90 Message-Id: <20181023201211.GA5010@ibm-toto.the-meissners.org> This patch changes the name used by the l built-in functions that return or are passed long double if the long double type is changed from the current IBM long double format to the IEEE 128-bit format. I have done a bootstrap and make check with no regressions on a little endian power8 system. Is it ok to check into the trunk? This will need to be back ported to the GCC 8.x branch. [gcc] 2018-10-23 Michael Meissner * config/rs6000/rs6000.c (TARGET_MANGLE_DECL_ASSEMBLER_NAME): Define as rs6000_mangle_decl_assembler_name. (rs6000_mangle_decl_assembler_name): If the user switched from IBM long double to IEEE long double, switch the names of the long double built-in functions to be f128 instead of l. [gcc/testsuite] 2018-10-23 Michael Meissner * gcc.target/powerpc/float128-math.c: New test to make sure the long double built-in function names use the f128 form if the user switched from IBM long double to IEEE long double. * gcc.target/powerpc/ppc-fortran/ieee128-math.f90: Likewise. Index: gcc/config/rs6000/rs6000.c =================================================================== --- gcc/config/rs6000/rs6000.c (revision 265400) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -1981,6 +1981,9 @@ static const struct attribute_spec rs600 #undef TARGET_SETJMP_PRESERVES_NONVOLATILE_REGS_P #define TARGET_SETJMP_PRESERVES_NONVOLATILE_REGS_P hook_bool_void_true + +#undef TARGET_MANGLE_DECL_ASSEMBLER_NAME +#define TARGET_MANGLE_DECL_ASSEMBLER_NAME rs6000_mangle_decl_assembler_name /* Processor table. */ @@ -38965,6 +38968,67 @@ rs6000_globalize_decl_name (FILE * strea #endif +/* On 64-bit Linux and Freebsd systems, possibly switch the long double library + function names from l to f128 if the default long double type is + IEEE 128-bit. Typically, with the C and C++ languages, the standard math.h + include file switches the names on systems that support long double as IEEE + 128-bit, but that doesn't work if the user uses __builtin_l directly or + if they use Fortran. Use the TARGET_MANGLE_DECL_ASSEMBLER_NAME hook to + change this name. We only do this if the default is long double is not IEEE + 128-bit, and the user asked for IEEE 128-bit. */ + +static tree +rs6000_mangle_decl_assembler_name (tree decl, tree id) +{ + if (!TARGET_IEEEQUAD_DEFAULT && TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128 + && TREE_CODE (decl) == FUNCTION_DECL && DECL_IS_BUILTIN (decl) ) + { + size_t len = IDENTIFIER_LENGTH (id); + const char *name = IDENTIFIER_POINTER (id); + + if (name[len-1] == 'l') + { + bool has_long_double_p = false; + tree type = TREE_TYPE (decl); + machine_mode ret_mode = TYPE_MODE (type); + + /* See if the function returns long double or long double + complex. */ + if (ret_mode == TFmode || ret_mode == TCmode) + has_long_double_p = true; + else + { + function_args_iterator args_iter; + tree arg; + + /* See if we have a long double or long double complex + argument. */ + FOREACH_FUNCTION_ARGS (type, arg, args_iter) + { + machine_mode arg_mode = TYPE_MODE (arg); + if (arg_mode == TFmode || arg_mode == TCmode) + { + has_long_double_p = true; + break; + } + } + } + + /* If we have long double, change the name. */ + if (has_long_double_p) + { + char *name2 = (char *) alloca (len + 4); + memcpy (name2, name, len-1); + strcpy (name2 + len - 1, "f128"); + id = get_identifier (name2); + } + } + } + + return id; +} + + struct gcc_target targetm = TARGET_INITIALIZER; #include "gt-rs6000.h" Index: gcc/testsuite/gcc.target/powerpc/float128-math.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/float128-math.c (revision 0) +++ gcc/testsuite/gcc.target/powerpc/float128-math.c (working copy) @@ -0,0 +1,20 @@ +/* { dg-do compile { target { powerpc*-*-linux* } } } */ +/* { dg-require-effective-target ppc_float128_sw } */ +/* { dg-require-effective-target vsx_hw } */ +/* { dg-options "-mvsx -O2 -mfloat128 -mabi=ieeelongdouble -Wno-psabi" } */ + +/* Test whether we convert __builtin_l to __builtin_f128 if the + default long double type is IEEE 128-bit. Also test that using the explicit + __builtin_f128 function does not interfere with the __builtin_l + function. */ + +extern __float128 sinf128 (__float128); + +void foo (__float128 *p, long double *q, long double *r) +{ + *p = sinf128 (*p); + *q = __builtin_sinl (*q); +} + +/* { dg-final { scan-assembler-times {\mbl sinf128\M} 2 } } */ +/* { dg-final { scan-assembler-not {\mbl sinl\M} } } */ Index: gcc/testsuite/gcc.target/powerpc/ppc-fortran/ieee128-math.f90 =================================================================== --- gcc/testsuite/gcc.target/powerpc/ppc-fortran/ieee128-math.f90 (revision 0) +++ gcc/testsuite/gcc.target/powerpc/ppc-fortran/ieee128-math.f90 (working copy) @@ -0,0 +1,20 @@ +! { dg-do compile { target { powerpc*-*-linux* } } } +! { dg-require-effective-target ppc_float128_sw } +! { dg-require-effective-target vsx_hw } +! { dg-options "-mvsx -mabi=ieeelongdouble -mfloat128" } +! { dg-excess-errors "expect error due to switching long double type" } +! Since the error message is not associated with a particular line +! number, we cannot use the dg-error directive and cannot specify a +! regexp to describe the expected error message. The expected warning +! message is: +! "Warning: Using IEEE extended precision long double [-Wpsabi]" + +program test_qp + implicit none + real(16), volatile :: fp1, fp2; + fp1 = 2.0 + fp2 = log (fp1) +end + +! { dg-final { scan-assembler-not {\mbl logl\M} } } +! { dg-final { scan-assembler {\mbl logf128\M} } }