From patchwork Thu May 2 01:14:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1093974 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-499965-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="L6W0Pbl9"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.b="f65c4+Om"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.b="UMbgVLRo"; 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 44vckb4bXXz9s9N for ; Thu, 2 May 2019 11:15:01 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:content-id :content-transfer-encoding:mime-version; q=dns; s=default; b=jqy 6/hYXZtX0aZ+6BwtXaMcuWy7jrgbWhNo5hZMGxdbZiBuCbwgrhqAtgvCwEt8c7SY GqDESpd5NW8ttJW7YBmIpyZ+WBXJ0EBLg6HXDq19wPp+JudUQyyXykYCtqzKMxG3 tuVUXdQbik9JrdtQVAhS4JxXB9Hq+bEN0YXl1uAw= 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:from :to:cc:subject:date:message-id:content-type:content-id :content-transfer-encoding:mime-version; s=default; bh=u4uY45cZV 2cF2zDGEXXjXdGK5sc=; b=L6W0Pbl9gvz1vidadQW7hm33aSi8l8cu85+TG5VYR SQyC2lrFr3hrk8ZDPSJWvKz2fDKSzVtdwvxSHOOewohAao6fWfuVKjA61h042/t9 7w6KwOnNsZ1Kn38lG+T9YpbHTLUpG7SuQObsB3/BGblVuImczEVINmvKZ/nthw3k EE= Received: (qmail 120934 invoked by alias); 2 May 2019 01:14:51 -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 120909 invoked by uid 89); 2 May 2019 01:14:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT autolearn=ham version=3.3.1 spammy=sk:riscv64, ASAP, Maciej, rozycki X-HELO: esa2.hgst.iphmx.com Received: from esa2.hgst.iphmx.com (HELO esa2.hgst.iphmx.com) (68.232.143.124) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 May 2019 01:14:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1556759690; x=1588295690; h=from:to:cc:subject:date:message-id:content-id: content-transfer-encoding:mime-version; bh=q5TPYiMV8rf2RV2LwPObmxqJG46mICnPT7dz1IS7wLo=; b=f65c4+OmrNBSCRmDDWGd7l8yjbyh9npFUGYR8oAyUgearvukcineVuMq HPemJrBMulu8mIo7oFffXqi3/TfA1dmyG+2o/408Fzq5MccZ5VF2CwPXz Kg9G+gsnZpqYfv3+LviY9Q5CIHDnd5lvQLoMpekl994+QTsiOR2WX9Y7c F3qeWuiEdCcb6SDFIY4bF7blsHvIkziV1G7eObS79Mn9oX36Hgwz1dAT9 rTjuJ5wyv5eDwiYhzpZkB6on8Awr9Pqlw7lSxfHx/3o9/2cfJZVK48XVz 5gik2UrmMmzAACTLxTv5U35/LhzC/fF41SG4tC1XN/TeM1uxH5QbcVhVP Q==; Received: from mail-co1nam04lp2051.outbound.protection.outlook.com (HELO NAM04-CO1-obe.outbound.protection.outlook.com) ([104.47.45.51]) by ob1.hgst.iphmx.com with ESMTP; 02 May 2019 09:14:48 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ptmg6IUlBTqWpuwi/IWetrPI0NdSczUSubPbPkg58Rs=; b=UMbgVLRosNHgc8Q32omwopoMC/YoFeBaNS4jr4QZ8bZ1W+aJMTnK8sGHUBwBYVt56onsMExlkK08E8AJud+hLom4NJuHXxHVmQy2tJtdt5pCtFigckgrs5VyvMZNvgEl0rMBO4Gn+gElhwCauFZVr6W3rhk6rLac91uPKg/Fz3Y= Received: from BYAPR04MB6262.namprd04.prod.outlook.com (20.178.235.160) by BYAPR04MB4054.namprd04.prod.outlook.com (52.135.215.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1835.14; Thu, 2 May 2019 01:14:43 +0000 Received: from BYAPR04MB6262.namprd04.prod.outlook.com ([fe80::19cf:df1e:ae74:1b99]) by BYAPR04MB6262.namprd04.prod.outlook.com ([fe80::19cf:df1e:ae74:1b99%3]) with mapi id 15.20.1856.008; Thu, 2 May 2019 01:14:43 +0000 From: Maciej Rozycki To: "gcc-patches@gcc.gnu.org" CC: Iain Buclaw , David Abdurachmanov , Kito Cheng , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Jakub Jelinek Subject: [PATCH] libphobos: RISC-V: Fix soft-float build errors with IEEE exception flags Date: Thu, 2 May 2019 01:14:43 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=macro@wdc.com; x-ms-exchange-purlcount: 1 wdcipoutbound: EOP-TRUE x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 Content-ID: MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED From: Maciej W. Rozycki Fix assembly errors: .../libphobos/src/std/math.d: Assembler messages:.../libphobos/src/std/math.d:4773: Error: unrecognized opcode `frflags a0' .../libphobos/src/std/math.d:4856: Error: unrecognized opcode `fsflags a5' .../libphobos/src/std/math.d:4856: Error: unrecognized opcode `fsflags a5' .../libphobos/src/std/math.d:4773: Error: unrecognized opcode `frflags a0' .../libphobos/src/std/math.d:5549: Error: unrecognized opcode `fscsr a5' .../libphobos/src/std/math.d:5456: Error: unrecognized opcode `frcsr a5' .../libphobos/src/std/math.d:5456: Error: unrecognized opcode `frcsr a5' .../libphobos/src/std/math.d:5549: Error: unrecognized opcode `fscsr a5' .../libphobos/src/std/math.d:5456: Error: unrecognized opcode `frcsr a5' .../libphobos/src/std/math.d:5549: Error: unrecognized opcode `fscsr a0' .../libphobos/src/std/math.d:5456: Error: unrecognized opcode `frcsr a0' .../libphobos/src/std/math.d:5456: Error: unrecognized opcode `frcsr a0' .../libphobos/src/std/math.d:5549: Error: unrecognized opcode `fscsr s2' make[8]: *** [Makefile:1119: std/math.lo] Error 1 triggered with the RISC-V lp64 multilib in a GCC build configured with `--enable-multilib --enable-languages=all --target=riscv64-linux-gnu'. This is due to unconditional explicit use of F extension instructions within inline assembly, to access IEEE exception flags. The use of these instructions is not allowed when building for a soft-float ABI. Correct the problem by wrapping said inline assembly into a conditional such that if `D_SoftFloat' is true, then reads from IEEE exception flags return 0 and writes are ignored instead, complementing r270522 ("libphobos: Add D support for RISC-V Linux"), which is an updated version of , where the problematic code has originated from. libphobos/ * std/math.d (IeeeFlags.getIeeeFlags): Handle RISC-V soft-float ABI. (IeeeFlags.resetIeeeFlags): Likewise. (FloatingPointControl.getControlState): Likewise. (FloatingPointControl.setControlState): Likewise. --- Hi, I believe this change is obviously correct, and I also verified generated code using `objdump -d'. I have no way to regression-test it right now. Please confirm if I correctly referred to identifiers in the ChangeLog entry though, as my experience WRT the D programming language and its syntax in particular is nil. My understanding is changes to `libphobos' are supposed to go upstream first, but r270522 is a local change anyway AFAICT, and technically a `--enable-languages=all' build regression, so we better fix it ASAP. Finally my WDC copyright assignment with FSF is still in the works, but I believe this change can be considered legally insignificant for copyright purposes, i.e. having at most 15 lines or so, unless adding white space for indentation counts against that limit as well (which I doubt). With all of the above in mind, OK to apply to trunk and to GCC 9? Maciej --- libphobos/src/std/math.d | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) gcc-riscv-libphobos-soft-float.diff Index: gcc/libphobos/src/std/math.d =================================================================== --- gcc.orig/libphobos/src/std/math.d +++ gcc/libphobos/src/std/math.d @@ -4767,12 +4767,17 @@ struct IeeeFlags } else version (RISCV_Any) { - uint result = void; - asm pure nothrow @nogc + version (D_SoftFloat) + return 0; + else { - "frflags %0" : "=r" result; + uint result = void; + asm pure nothrow @nogc + { + "frflags %0" : "=r" result; + } + return result; } - return result; } else assert(0, "Not yet supported"); @@ -4850,10 +4855,15 @@ struct IeeeFlags } else version (RISCV_Any) { - uint newValues = 0x0; - asm pure nothrow @nogc + version (D_SoftFloat) + return; + else { - "fsflags %0" : : "r" newValues; + uint newValues = 0x0; + asm pure nothrow @nogc + { + "fsflags %0" : : "r" newValues; + } } } else @@ -5450,12 +5460,17 @@ struct FloatingPointControl } else version (RISCV_Any) { - ControlState cont; - asm pure nothrow @nogc + version (D_SoftFloat) + return 0; + else { - "frcsr %0" : "=r" cont; + ControlState cont; + asm pure nothrow @nogc + { + "frcsr %0" : "=r" cont; + } + return cont; } - return cont; } else assert(0, "Not yet supported"); @@ -5544,9 +5559,14 @@ struct FloatingPointControl } else version (RISCV_Any) { - asm pure nothrow @nogc + version (D_SoftFloat) + return; + else { - "fscsr %0" : : "r" (newState); + asm pure nothrow @nogc + { + "fscsr %0" : : "r" (newState); + } } } else