From patchwork Mon May 9 14:35:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 53660 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 84DE53949084 for ; Mon, 9 May 2022 14:40:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84DE53949084 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652107224; bh=GagFlId21QCPGcisWW+wABcUktXNJketdNXT2Ks9td0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UPvhxLtsfeuUqG7+yYTZ6KNpWanTi3DugPszyoz6Rc4Pah2v4TKbNQSbCosCZEmds AH9dhACpi5ZjCEU7JEEWybuOY3XSHdyeXxdgWwZ1gdf377tE2vtOWp67CXy9iT6+Uj XenCQ7W/ijMhrrAfJH3uv/3J2pK4uNv4iRGleNq8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70044.outbound.protection.outlook.com [40.107.7.44]) by sourceware.org (Postfix) with ESMTPS id A38DF3948A40 for ; Mon, 9 May 2022 14:35:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A38DF3948A40 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=au521OiWMxbzS7YCPEK7hYHnu/swBXh9x6z9+KYccnrDFseac1iVxfTZ97gHHzME09GGp0YmoBP0ajmzC2SGu+N7L4G4+7bfBUqBg9MhgKMJG1fGnmpcsiBUNrpamPnoFcIynFbYnpuSGUqwCs+d5rnWmJRXm8chiXlng8ocpGeQdc/cGl5YM2PYioq/zLVLyumPovuVx7LxWIVGNB3pIHLtxPcVErTjP390Mk6msJK0CZ9NLIS5s+BlYMaQbsA/BQnKnriEvig+2Jmr5BQYiikUsonz4bZUQCnNuMvJDbO/Ge3hYjb/V652Mu1Lk0mscwfTBlfzUhyz5OhNQIQ2Wg== ARC-Message-Signature: i=2; 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=GagFlId21QCPGcisWW+wABcUktXNJketdNXT2Ks9td0=; b=XAhfGI+Fn8k20n5YltqgdRES1Dxoh1w3oHAYwnJShZS/zdp6JueASZF598GTUcOJyHT7cZ70ThlvLN7OoyHOxZivkjKaIc/D7vWE9funje0U45/VXgED3Le3/RPJBzAOOesYGStE2Hg/3cZBh2nrfjkDCKgg+kAxDfQQSYRiQtKIihOue4Q8K3uI8tB50BY8PxyNWAsGbHLjYzysP7UNCE+FPpAoq/h2USInLlvviUeq1tD0aW+LGj0Oj0G2EWc2JScLFG7cBVS0+Ml9W4BMsa5FrbYsgPNDGJ0HUHQfwntOD9YmgGtH217o2wAqSvbrKIOpWdwppRmZY7Te9KQWpw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AS8PR04CA0027.eurprd04.prod.outlook.com (2603:10a6:20b:310::32) by AS8PR08MB6855.eurprd08.prod.outlook.com (2603:10a6:20b:398::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Mon, 9 May 2022 14:35:42 +0000 Received: from VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:310:cafe::6) by AS8PR04CA0027.outlook.office365.com (2603:10a6:20b:310::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.23 via Frontend Transport; Mon, 9 May 2022 14:35:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass 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 VE1EUR03FT053.mail.protection.outlook.com (10.152.19.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Mon, 9 May 2022 14:35:42 +0000 Received: ("Tessian outbound 62985e3c34b6:v118"); Mon, 09 May 2022 14:35:42 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 684d262fcdffafee X-CR-MTA-TID: 64aa7808 Received: from bf5a6e6c82cb.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 808064C1-9066-4E7F-A25C-50D839BF9CA4.1; Mon, 09 May 2022 14:35:36 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id bf5a6e6c82cb.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 09 May 2022 14:35:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IFExD3k0kp64WPZHoAm/0roXZfrbp8KM6TG1/QYJsr4er64BMS5c6z8M2XLpVl2TGkmg/eJnuePnAuN5rvqNYd4bw7FLYOz+Vng4KLiFuXz5xe/juHc9kb7xJBLSc7tnBQspaIWjIcYXr1MA0z6MhjKAvYiD0kNBmGNNQQyzgOaD+g/1N0oq7eHeWePqmkx8639THhd7W4KQq2gcPzN7m6DL7s/hGuY49be1yVUzUcllwwcYKSOaeuz7725JhfjTGQkXO+9SlM9Azw3g9pAswnvPw1PtGpb5SS3fRie2T3EoWpAb4W/eWRfs+BI/xDGIul9th9LkuLAMJVLXr0nPoA== 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=GagFlId21QCPGcisWW+wABcUktXNJketdNXT2Ks9td0=; b=DF2hEluGVwFjX7O9hMlrzjZ80XN0oW6cX9H+9+WOeumTu6ucL9RwhIcxJjXLkjSsRCBnea+DGSGmt5Gdb/Cz1epd+7FHy7JGoVTzsn+1dGAdccp1a9Ps3P5RHcuwxEjpYlSIOHYT6PgEDQhXtpDXW63aVUFukbTZ0P4YnZuKoWsONaHI2lbXPFxP/v8wH7VsWUEu/AiP5QhtuSoTAyXTFzfLWUH/GG5ugz8/50hB70j07UwiOc10fYZhLrr5KTMFKd/07n78RPub4V1IXb5NR6GF7CEQ2vHWUM2KTNE2d6LL51BEh/qepkdsA9n7U2vsEOvAAzPzwM6FEo4bOhgZpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=gcc.gnu.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from AM6P192CA0074.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::15) by DU0PR08MB7663.eurprd08.prod.outlook.com (2603:10a6:10:319::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.20; Mon, 9 May 2022 14:35:33 +0000 Received: from AM5EUR03FT042.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8d:cafe::de) by AM6P192CA0074.outlook.office365.com (2603:10a6:209:8d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.20 via Frontend Transport; Mon, 9 May 2022 14:35:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT042.mail.protection.outlook.com (10.152.17.168) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Mon, 9 May 2022 14:35:33 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Mon, 9 May 2022 14:35:36 +0000 Received: from e129018.arm.com (10.57.34.214) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Mon, 9 May 2022 14:35:36 +0000 To: Subject: [PATCH 09/10] libgcc: Add support for HF mode (aka __fp16) in libbid Date: Mon, 9 May 2022 16:35:06 +0200 Message-ID: <20220509143507.239804-10-christophe.lyon@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220509143507.239804-1-christophe.lyon@arm.com> References: <20220509143507.239804-1-christophe.lyon@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 44562d7d-e9b1-47f6-6766-08da31c931f7 X-MS-TrafficTypeDiagnostic: DU0PR08MB7663:EE_|VE1EUR03FT053:EE_|AS8PR08MB6855:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: QlYJRVI7TIbWyzMQdUug5u0DjDxS05rvapV6lgLdehRhqIKsU1ZoBjx6MVn6fBoNZdMdMXSPcQPucE8Pkr5iLyDwe7MFAxXIuGIqYRsIIMfj/eo3Hypem0fY6QY7L7LBXvMvAE1yK4ehyy5Dlo/Qs5eskHVy0jJNLALlwaJHPaF+dJVDvm/I5rzSzN+eZU++6WJP15NMMAOlMw3/Q42jLnXgV+5GkFJhr+HJ7Aj440S2pXR8AnI5JWuaoT/juxGmqsA6zJFpEpneuyMpU7ggJv8f2o/E0VYRfcrnRZi2o4gU0FPoTmZGbCPX7RLKjRphB5ZmofBSqY64T3H2XDL9mRx1Zb40P6xQOEuuEf842gnrUCTuHozyU8zXU1X0aEiGS4d+EPOde27bgxVQ53IjbvW+AAVmtcoqF1ri1oBKj7k7/ynnvYaddqt9fHFNUg0W6BkIvAweJS7mKKNx2W+raKHgemyhdytfQax3ktSUlDIQppsDmwk0UimHxE+pKmIkROioqkX9v/+BlSwf/SItuqJMvar3I30IxjQs3R4SG4gtyrbrv1II/ush5mdPvxAbfZapQpMD3V1A88XcG5bUrhvOvZyIXtzctzC3ZE7c8lj1IUAXmfgzU4mTzTA+YwGUTrWa1AgpDEL7sinYhhzwruiC+VucMhEjR/TL5YMM88X3EWckpEHfOrMw7ja8iQ7jdLQjZhqfBvLaI8RIxu2hseR/nTi+xRjiUfWPSvTiqGrCnBNH/m7WbcG+nYGY5dfuhxSiwK/keummRXrJhZR4p+55rKseuYqApYWFfuvwYrht+KLtMehabZPFQL2xK00gYCfer8DExQFJGKqc3uPeQ9N6h+dYsnoSBGTuvxu2upk= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(7696005)(8676002)(40460700003)(26005)(6666004)(4326008)(70206006)(82310400005)(316002)(44832011)(6916009)(70586007)(36860700001)(86362001)(356005)(2616005)(1076003)(81166007)(426003)(186003)(47076005)(5660300002)(36756003)(336012)(8936002)(2906002)(30864003)(84970400001)(83380400001)(508600001)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB7663 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 048c97d6-00ad-4f16-320b-08da31c92cb6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BB6WwwpolXX4Svy+hvZcxh4eopcrZCkcQXThhHZF4cZ6TValcMyTsa3nEEewHMacUgkzh4wTdsgNtnl23FuV2Cbyz0OdHfXvsf4jNNzorXpAF1iTZht6CPZB4kau9IQzWn0XDMFVoomWQEBoHcasNUSqeiRU///JdDqckvM3mI6wQinkrMnJ1bSssHSK333MS/FnW94FTKXpaQ1VnMbFuofGxWeTHFfqFYf1FG+SSQh7whZE5uu5HGQxWK4H1f/JTMpDYH/kddiJzp2y4VFKj04/8hjqss0jaN7RYQ3VWQ36R2k0NMJdSCipmMr8Ciro5PrgKA8k401wgWQj1BA+9gg868l764LQsmXaqcBbe702cNntA5HryXbqBTDXwyFMCPjTvvTH2/09Zxyr5G4cwS7kh4dvsrPUlWdQrE/Af4/+bCsi9zLIoL4eMJ6FxjEJ8PsYR2Cv2Uup6kFzr5RfgOa9PLMowdyiwPI1oz8urObT8fjejsyEwfvcWTqLEZwmla0mWC6c1McGtX9QMskM2211Td5XDaAM9nwpWMorgXjgFksGy72xudF+yOjW5DW0qNvdKP/5oElAYFIudtGmRCsBlfQoyIntNIWJY8RxcSmzm6PEKafAzgeYnLBVd47cV8U59nfHMFUe+7lNrpdmYOApyvESWGlA16Jsbv82AFBfzZHExRhqorFnyGyQ2BdjctZCZ9OpkYvoKCp8S6wmGaZfqdmhLeoAOs037yPu1IyArAcHYVMQ/eQCKBhx8hn+dJlaInZfpnmpYIDl/ePNlQ9JQeFOepFcGAAOFu1GWlL3dOJiurwVxI+F6erSe+SF 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; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(2616005)(40460700003)(1076003)(26005)(36860700001)(2906002)(70586007)(70206006)(4326008)(8676002)(47076005)(336012)(186003)(426003)(82310400005)(36756003)(316002)(6916009)(44832011)(7696005)(30864003)(6666004)(84970400001)(86362001)(81166007)(83380400001)(5660300002)(8936002)(508600001)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2022 14:35:42.1425 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44562d7d-e9b1-47f6-6766-08da31c931f7 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: VE1EUR03FT053.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6855 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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: Christophe Lyon via Gcc-patches From: Christophe Lyon Reply-To: Christophe Lyon Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch adds support for trunc and extend operations between HF mode (__fp16) and Decimal Floating Point formats (_Decimal32, _Decimal64 and _Decimal128). For simplicity we rely on the implicit conversions inserted by the compiler between HF and SD/DF/TF modes. The existing bid*_to_binary* and binary*_to_bid* functions are non-trivial and at this stage it is not clear if there is a performance-critical use case involving __fp16 and _Decimal* formats. The patch also adds two executable tests for AArch64, to make sure the right functions are used, available (link phase) and functional. 2022-05-04 Christophe Lyon libgcc/ChangeLog: * Makefile.in (D32PBIT_FUNCS): Add _hf_to_sd and _sd_to_hf. (D64PBIT_FUNCS): Add _hf_to_dd and _dd_to_hf. (D128PBIT_FUNCS): Add _hf_to_td _td_to_hf. libgcc/config/libbid/ChangeLog: * bid_gcc_intrinsics.h (LIBGCC2_HAS_HF_MODE): Define according to __LIBGCC_HAS_HF_MODE__. (BID_HAS_HF_MODE): Define. (HFtype): Define. (__bid_extendhfsd): New prototype. (__bid_extendhfdd): Likewise. (__bid_extendhftd): Likewise. (__bid_truncsdhf): Likewise. (__bid_truncddhf): Likewise. (__bid_trunctdhf): Likewise. * _dd_to_hf.c: New file. * _hf_to_dd.c: New file. * _hf_to_sd.c: New file. * _hf_to_td.c: New file. * _sd_to_hf.c: New file. * _td_to_hf.c: New file. gcc/testsuite/ChangeLog: * gcc.target/aarch64/convert-dfp-2.c: New test. * gcc.target/aarch64/convert-dfp.c: New test. --- .../gcc.target/aarch64/convert-dfp-2.c | 42 +++++++++++++ .../gcc.target/aarch64/convert-dfp.c | 60 +++++++++++++++++++ libgcc/Makefile.in | 9 ++- libgcc/config/libbid/_dd_to_hf.c | 36 +++++++++++ libgcc/config/libbid/_hf_to_dd.c | 36 +++++++++++ libgcc/config/libbid/_hf_to_sd.c | 36 +++++++++++ libgcc/config/libbid/_hf_to_td.c | 36 +++++++++++ libgcc/config/libbid/_sd_to_hf.c | 36 +++++++++++ libgcc/config/libbid/_td_to_hf.c | 36 +++++++++++ libgcc/config/libbid/bid_gcc_intrinsics.h | 30 +++++++++- 10 files changed, 352 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/convert-dfp-2.c create mode 100644 gcc/testsuite/gcc.target/aarch64/convert-dfp.c create mode 100644 libgcc/config/libbid/_dd_to_hf.c create mode 100644 libgcc/config/libbid/_hf_to_dd.c create mode 100644 libgcc/config/libbid/_hf_to_sd.c create mode 100644 libgcc/config/libbid/_hf_to_td.c create mode 100644 libgcc/config/libbid/_sd_to_hf.c create mode 100644 libgcc/config/libbid/_td_to_hf.c diff --git a/gcc/testsuite/gcc.target/aarch64/convert-dfp-2.c b/gcc/testsuite/gcc.target/aarch64/convert-dfp-2.c new file mode 100644 index 00000000000..ebbbc649455 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/convert-dfp-2.c @@ -0,0 +1,42 @@ +/* { dg-do run } */ +/* { dg-options "-save-temps" } */ + +/* Test conversions from DFP to smaller types. */ + +_Decimal32 var32; +_Decimal64 var64; +_Decimal128 var128; +__fp16 var16; + +void foo32 (_Decimal32 param32) +{ + var16 = param32; +} + +void foo64 (_Decimal64 param64) +{ + var16 = param64; + var32 = param64; +} + +void foo128 (_Decimal128 param128) +{ + var16 = param128; + var32 = param128; + var64 = param128; +} + +int main () +{ + foo32 (var32); + foo64 (var64); + foo128 (var128); + return 0; +} + +/* { dg-final { scan-assembler-times {\tbl\t__bid_truncsdhf} 1 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_truncddhf} 1 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_truncddsd2} 1 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_trunctdhf} 1 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_trunctdsd2} 1 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_trunctddd2} 1 } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/convert-dfp.c b/gcc/testsuite/gcc.target/aarch64/convert-dfp.c new file mode 100644 index 00000000000..cd5ada46e3d --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/convert-dfp.c @@ -0,0 +1,60 @@ +/* { dg-do run } */ +/* { dg-options "-save-temps" } */ + +/* Test conversions to/from DFP values. */ + +extern void abort (); + +_Decimal32 var32 = 1.2df; + +int foo32 (_Decimal32 param32, _Decimal64 param64, _Decimal128 param128, __fp16 param16) +{ + return (param32 == var32) + + (param64 == var32) + + (param128 == var32) + /* Small enough relative difference? */ + + ((((_Decimal32)param16 - var32) / var32) < 0.002df); +} + +_Decimal64 var64 = 1.2dd; + +int foo64 (_Decimal32 param32, _Decimal64 param64, _Decimal128 param128, __fp16 param16) +{ + return (param32 == var64) + + (param64 == var64) + + (param128 == var64) + /* Small enough relative difference? */ + + ((((_Decimal64)param16 - var64) / var64) < 0.002dd); +} + +_Decimal128 var128 = 1.2dl; + +int foo128 (_Decimal32 param32, _Decimal64 param64, _Decimal128 param128, __fp16 param16) +{ + return (param32 == var128) + + (param64 == var128) + + (param128 == var128) + /* Small enough relative difference? */ + + ((((_Decimal128)param16 - var128) / var128) < 0.002dl); +} + +int main() +{ + if (foo32 (1.2df, 1.2dd, 1.2dl, (__fp16)1.2) != 4) + abort (); + + if (foo64 (1.2df, 1.2dd, 1.2dl, (__fp16)1.2) != 4) + abort (); + + if (foo128 (1.2df, 1.2dd, 1.2dl, (__fp16)1.2) != 4) + abort (); + + return 0; +} + +/* { dg-final { scan-assembler-times {\tbl\t__bid_extendsddd2} 2 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_extendsdtd2} 2 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_extendddtd2} 2 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_extendhfsd} 1 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_extendhfdd} 1 } } */ +/* { dg-final { scan-assembler-times {\tbl\t__bid_extendhftd} 1 } } */ diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 09b3ec8bc2e..1fe708a93f7 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -677,7 +677,8 @@ D32PBIT_FUNCS = _addsub_sd _div_sd _mul_sd _plus_sd _minus_sd \ _si_to_sd _di_to_sd _usi_to_sd _udi_to_sd \ _sd_to_sf _sd_to_df _sd_to_xf _sd_to_tf \ _sf_to_sd _df_to_sd _xf_to_sd _tf_to_sd \ - _sd_to_dd _sd_to_td _unord_sd _conv_sd + _sd_to_dd _sd_to_td _unord_sd _conv_sd \ + _hf_to_sd _sd_to_hf D64PBIT_FUNCS = _addsub_dd _div_dd _mul_dd _plus_dd _minus_dd \ _eq_dd _ne_dd _lt_dd _gt_dd _le_dd _ge_dd \ @@ -685,7 +686,8 @@ D64PBIT_FUNCS = _addsub_dd _div_dd _mul_dd _plus_dd _minus_dd \ _si_to_dd _di_to_dd _usi_to_dd _udi_to_dd \ _dd_to_sf _dd_to_df _dd_to_xf _dd_to_tf \ _sf_to_dd _df_to_dd _xf_to_dd _tf_to_dd \ - _dd_to_sd _dd_to_td _unord_dd _conv_dd + _dd_to_sd _dd_to_td _unord_dd _conv_dd \ + _hf_to_dd _dd_to_hf D128PBIT_FUNCS = _addsub_td _div_td _mul_td _plus_td _minus_td \ _eq_td _ne_td _lt_td _gt_td _le_td _ge_td \ @@ -693,7 +695,8 @@ D128PBIT_FUNCS = _addsub_td _div_td _mul_td _plus_td _minus_td \ _si_to_td _di_to_td _usi_to_td _udi_to_td \ _td_to_sf _td_to_df _td_to_xf _td_to_tf \ _sf_to_td _df_to_td _xf_to_td _tf_to_td \ - _td_to_sd _td_to_dd _unord_td _conv_td + _td_to_sd _td_to_dd _unord_td _conv_td \ + _hf_to_td _td_to_hf ifeq ($(enable_decimal_float),bid) ifneq ($(D32PBIT),) diff --git a/libgcc/config/libbid/_dd_to_hf.c b/libgcc/config/libbid/_dd_to_hf.c new file mode 100644 index 00000000000..c69af77a703 --- /dev/null +++ b/libgcc/config/libbid/_dd_to_hf.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "bid_conf.h" +#include "bid_functions.h" +#include "bid_gcc_intrinsics.h" + +HFtype +__bid_truncddhf (_Decimal64 x) { + HFtype res; + union decimal64 ux; + + ux.d = x; + res = __bid64_to_binary32 (ux.i); + return (res); +} diff --git a/libgcc/config/libbid/_hf_to_dd.c b/libgcc/config/libbid/_hf_to_dd.c new file mode 100644 index 00000000000..f85100e24f8 --- /dev/null +++ b/libgcc/config/libbid/_hf_to_dd.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "bid_conf.h" +#include "bid_functions.h" +#include "bid_gcc_intrinsics.h" + +#if LIBGCC2_HAS_HF_MODE || BID_HAS_HF_MODE +_Decimal64 +__bid_extendhfdd (HFtype x) { + union decimal64 res; + SFtype xsf = x; + res.i = __binary32_to_bid64 (xsf); + return (res.d); +} +#endif diff --git a/libgcc/config/libbid/_hf_to_sd.c b/libgcc/config/libbid/_hf_to_sd.c new file mode 100644 index 00000000000..285b80c6e05 --- /dev/null +++ b/libgcc/config/libbid/_hf_to_sd.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "bid_conf.h" +#include "bid_functions.h" +#include "bid_gcc_intrinsics.h" + +#if LIBGCC2_HAS_HF_MODE || BID_HAS_HF_MODE +_Decimal32 +__bid_extendhfsd (HFtype x) { + union decimal32 res; + SFtype xsf = x; + res.i = __binary32_to_bid32 (xsf); + return (res.d); +} +#endif diff --git a/libgcc/config/libbid/_hf_to_td.c b/libgcc/config/libbid/_hf_to_td.c new file mode 100644 index 00000000000..99b661ec727 --- /dev/null +++ b/libgcc/config/libbid/_hf_to_td.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "bid_conf.h" +#include "bid_functions.h" +#include "bid_gcc_intrinsics.h" + +#if LIBGCC2_HAS_HF_MODE || BID_HAS_HF_MODE +_Decimal128 +__bid_extendhftd (HFtype x) { + union decimal128 res; + SFtype xsf = x; + res.i = __binary32_to_bid128 (xsf); + return (res.d); +} +#endif diff --git a/libgcc/config/libbid/_sd_to_hf.c b/libgcc/config/libbid/_sd_to_hf.c new file mode 100644 index 00000000000..5e5b1e303e6 --- /dev/null +++ b/libgcc/config/libbid/_sd_to_hf.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "bid_conf.h" +#include "bid_functions.h" +#include "bid_gcc_intrinsics.h" + +HFtype +__bid_truncsdhf (_Decimal32 x) { + HFtype res; + union decimal32 ux; + + ux.d = x; + res = __bid32_to_binary32 (ux.i); + return (res); +} diff --git a/libgcc/config/libbid/_td_to_hf.c b/libgcc/config/libbid/_td_to_hf.c new file mode 100644 index 00000000000..a71d278b3c7 --- /dev/null +++ b/libgcc/config/libbid/_td_to_hf.c @@ -0,0 +1,36 @@ +/* Copyright (C) 2022 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#include "bid_conf.h" +#include "bid_functions.h" +#include "bid_gcc_intrinsics.h" + +HFtype +__bid_trunctdhf (_Decimal128 x) { + HFtype res; + union decimal128 ux; + + ux.d = x; + res = __bid128_to_binary32 (ux.i); + return (res); +} diff --git a/libgcc/config/libbid/bid_gcc_intrinsics.h b/libgcc/config/libbid/bid_gcc_intrinsics.h index b0a23debc15..feeb7ce9fc9 100644 --- a/libgcc/config/libbid/bid_gcc_intrinsics.h +++ b/libgcc/config/libbid/bid_gcc_intrinsics.h @@ -31,6 +31,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #include "tm.h" #include "libgcc_tm.h" +#ifdef __LIBGCC_HAS_HF_MODE__ +#define LIBGCC2_HAS_HF_MODE 1 +#else +#define LIBGCC2_HAS_HF_MODE 0 +#endif + #ifdef __LIBGCC_HAS_XF_MODE__ #define LIBGCC2_HAS_XF_MODE 1 #else @@ -43,6 +49,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #define LIBGCC2_HAS_TF_MODE 0 #endif +#ifndef BID_HAS_HF_MODE +#define BID_HAS_HF_MODE LIBGCC2_HAS_HF_MODE +#endif + #ifndef BID_HAS_XF_MODE #define BID_HAS_XF_MODE LIBGCC2_HAS_XF_MODE #endif @@ -53,6 +63,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* Some handy typedefs. */ +#if LIBGCC2_HAS_HF_MODE +typedef float HFtype __attribute__ ((mode (HF))); +#endif /* LIBGCC2_HAS_HF_MODE */ typedef float SFtype __attribute__ ((mode (SF))); typedef float DFtype __attribute__ ((mode (DF))); #if LIBGCC2_HAS_XF_MODE @@ -98,6 +111,12 @@ typedef __attribute__ ((aligned(16))) struct #endif #endif +#if BID_HAS_HF_MODE +#ifndef HFtype +#define HFtype __fp16 +#endif +#endif + #ifndef SFtype #define SFtype float #endif @@ -110,8 +129,7 @@ typedef __attribute__ ((aligned(16))) struct #ifndef XFtype #define XFtype long double #endif - -#endif /* IN_LIBGCC2 */ +#endif #if BID_HAS_TF_MODE #ifndef TFtype @@ -249,6 +267,14 @@ extern _Decimal128 __bid_extendxftd (XFtype); extern int isinfd32 (_Decimal32); extern int isinfd64 (_Decimal64); extern int isinfd128 (_Decimal128); +#if BID_HAS_HF_MODE +extern _Decimal32 __bid_extendhfsd (HFtype); +extern _Decimal64 __bid_extendhfdd (HFtype); +extern _Decimal128 __bid_extendhftd (HFtype); +extern HFtype __bid_truncsdhf (_Decimal32); +extern HFtype __bid_truncddhf (_Decimal64); +extern HFtype __bid_trunctdhf (_Decimal128); +#endif #endif /* BID_HAS_GCC_DECIMAL_INTRINSICS */ extern void __dfp_set_round (int);