Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4029639ybv; Tue, 25 Feb 2020 11:46:33 -0800 (PST) X-Google-Smtp-Source: APXvYqx6O75vbc4OHKJ+IHjYf5Qap+q0esgbAFyOt9M3fNZ59HJZdfiqhNYm1uU6D+tLuye2Wgvh X-Received: by 2002:a9d:dc1:: with SMTP id 59mr179454ots.250.1582659992854; Tue, 25 Feb 2020 11:46:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582659992; cv=none; d=google.com; s=arc-20160816; b=xyzmt6/CorNvwYFJsnrQqf3AnRhMSVQjb9Pcw7Xa1PNeTfdLjptOvKYMkUnSbO/3xF tGMUFAE1CXUIPYJODC00TpPrHpuV9QVDXd666G1hxL9+awDmrOyZXxSkQhtxo3Cn2eJ6 r9KVO8n5aiugnO1IvU/Nv5Bv4jBYjPqAtWcDhVvcKDZnzJnOvATX4fRhmsFgvinZ5UYa mMz0Ugl4Of20zRmXkH7RQxYygaT14Qs0wEk4WYalmiv1ECbGEsh3xw+itfLiT4yvgXan sGrteO+ppyiJdIl0G8ykN1zSNfVJoAr4Gb6gfv09uANXb6JcLPEjn/SkhhZnoAEjY1P1 rNyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=fTg52wHdPY7uW1HKOf1Xj2//s3wUIhQezj76A9X1P3A=; b=zHNGGjlCX+fQZUXnOE5nG/KbCkTcSNbnD+Z45gsX/Ts592af2x9+/an02xBIQAstjM I2B5tynIBuuGIaS2LMPYuDrzu2ApzExcua+r7CGW3PxGA/JxCd3b2bEbQBw5rBYZDm6E HKYQ9GxrNM3jDxh5g1S7A250u7Z4EfdIYWVwOXpgz65tETtBYfBVcgWUss7vy+oUNPzk aWODgBlOEMnOUfBT6idnAkQv+WXxKK72G4qxZVMLhgAftLDdiCm6R6S3CnefEuFR09cu Cyk+QscP6nhQ4KHsOJzCredeZVxfMQjXrxiHSrc+PZVmsnWeIvqYeMZNF+Je2ZfTLzng XvbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l20si107723otr.202.2020.02.25.11.46.20; Tue, 25 Feb 2020 11:46:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731550AbgBYTpc (ORCPT + 99 others); Tue, 25 Feb 2020 14:45:32 -0500 Received: from foss.arm.com ([217.140.110.172]:55106 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731029AbgBYTpb (ORCPT ); Tue, 25 Feb 2020 14:45:31 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 714AE31B; Tue, 25 Feb 2020 11:45:30 -0800 (PST) Received: from [192.168.1.123] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A62DC3FA00; Tue, 25 Feb 2020 11:45:28 -0800 (PST) Subject: Re: [PATCH] ARM: use assembly mnemonics for VFP register access To: Ard Biesheuvel , Nick Desaulniers Cc: Arnd Bergmann , LKML , Stefan Agner , Jian Cai , clang-built-linux , Manoj Gupta , Russell King , Linux ARM References: <8bb16ac4b15a7e28a8e819ef9aae20bfc3f75fbc.1582266841.git.stefan@agner.ch> From: Robin Murphy Message-ID: Date: Tue, 25 Feb 2020 19:45:14 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-02-25 7:33 pm, Ard Biesheuvel wrote: > On Tue, 25 Feb 2020 at 20:10, Nick Desaulniers wrote: >> >> On Mon, Feb 24, 2020 at 9:22 PM Stefan Agner wrote: >>> >>> Clang's integrated assembler does not allow to to use the mcr >>> instruction to access floating point co-processor registers: >>> arch/arm/vfp/vfpmodule.c:342:2: error: invalid operand for instruction >>> fmxr(FPEXC, fpexc & ~(FPEXC_EX|FPEXC_DEX|FPEXC_FP2V|FPEXC_VV|FPEXC_TRAP_MASK)); >>> ^ >>> arch/arm/vfp/vfpinstr.h:79:6: note: expanded from macro 'fmxr' >>> asm("mcr p10, 7, %0, " vfpreg(_vfp_) ", cr0, 0 @ fmxr " #_vfp_ ", %0" \ >>> ^ >>> :1:6: note: instantiated into assembly here >>> mcr p10, 7, r0, cr8, cr0, 0 @ fmxr FPEXC, r0 >>> ^ >>> >>> The GNU assembler supports the .fpu directive at least since 2.17 (when >>> documentation has been added). Since Linux requires binutils 2.21 it is >>> safe to use .fpu directive. Use the .fpu directive and mnemonics for VFP >>> register access. >>> >>> This allows to build vfpmodule.c with Clang and its integrated assembler. >>> >>> Link: https://github.com/ClangBuiltLinux/linux/issues/905 >>> Signed-off-by: Stefan Agner >>> --- >>> arch/arm/vfp/vfpinstr.h | 12 ++++-------- >>> 1 file changed, 4 insertions(+), 8 deletions(-) >>> >>> diff --git a/arch/arm/vfp/vfpinstr.h b/arch/arm/vfp/vfpinstr.h >>> index 38dc154e39ff..799ccf065406 100644 >>> --- a/arch/arm/vfp/vfpinstr.h >>> +++ b/arch/arm/vfp/vfpinstr.h >>> @@ -62,21 +62,17 @@ >>> #define FPSCR_C (1 << 29) >>> #define FPSCR_V (1 << 28) >>> >>> -/* >>> - * Since we aren't building with -mfpu=vfp, we need to code >>> - * these instructions using their MRC/MCR equivalents. >>> - */ >>> -#define vfpreg(_vfp_) #_vfp_ >>> - >>> #define fmrx(_vfp_) ({ \ >>> u32 __v; \ >>> - asm("mrc p10, 7, %0, " vfpreg(_vfp_) ", cr0, 0 @ fmrx %0, " #_vfp_ \ >>> + asm(".fpu vfpv2\n" \ >>> + "vmrs %0, " #_vfp_ \ >>> : "=r" (__v) : : "cc"); \ >>> __v; \ >>> }) >>> >>> #define fmxr(_vfp_,_var_) \ >>> - asm("mcr p10, 7, %0, " vfpreg(_vfp_) ", cr0, 0 @ fmxr " #_vfp_ ", %0" \ >>> + asm(".fpu vfpv2\n" \ >>> + "vmsr " #_vfp_ ", %0" \ >>> : : "r" (_var_) : "cc") >>> >>> u32 vfp_single_cpdo(u32 inst, u32 fpscr); >>> -- >> >> Hi Stefan, >> Thanks for the patch. Reading through: >> - FMRX, FMXR, and FMSTAT: >> http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0068b/Bcfbdihi.html >> - VMRS and VMSR: >> http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204h/Bcfbdihi.html >> >> Should a macro called `fmrx` that had a comment about `fmrx` be using >> `vmrs` in place of `fmrx`? >> >> It looks like Clang treats them the same, but GCC keeps them separate: >> https://godbolt.org/z/YKmSAs >> Ah, this is only when streaming to assembly. Looks like they have the >> same encoding, and produce the same disassembly. (Godbolt emits >> assembly by default, and has the option to compile, then disassemble). >> If I take my case from godbolt above: >> >> ➜ /tmp arm-linux-gnueabihf-gcc -O2 -c x.c >> ➜ /tmp llvm-objdump -dr x.o >> >> x.o: file format elf32-arm-little >> >> >> Disassembly of section .text: >> >> 00000000 bar: >> 0: f1 ee 10 0a vmrs r0, fpscr >> 4: 70 47 bx lr >> 6: 00 bf nop >> >> 00000008 baz: >> 8: f1 ee 10 0a vmrs r0, fpscr >> c: 70 47 bx lr >> e: 00 bf nop >> >> So indeed a similar encoding exists for the two different assembler >> instructions. > > Does that hold for ARM (A32) instructions as well? It should do - they're all the same thing underneath. The UAL syntax just renamed all the legacy VFP mnemonics from Fxxx to Vxxx form, apart from a couple of things that were already deprecated. GAS still accepts both regardless of ".syntax unified", and as a result GCC never saw a reason to stop emitting the old mnemonics. Robin.