Message ID | 20240118-csum_remove_output_operands_asm_goto-v1-1-47c672bb9d4b@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-30587-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp644532dyb; Thu, 18 Jan 2024 13:54:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjENShF0RvABnDMuYhqSYfqdK3LcbX9hGSXcGsE0WbPRQGB9+vP3vZHxA9ZSTcsSNMWmCV X-Received: by 2002:a05:6214:29cf:b0:681:5953:50d5 with SMTP id gh15-20020a05621429cf00b00681595350d5mr7829qvb.10.1705614859844; Thu, 18 Jan 2024 13:54:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705614859; cv=pass; d=google.com; s=arc-20160816; b=nFXXS/v+odZZKSjbURgotBojPIuN8oS9jKF82xXTNs1hrFan+gNxRCbt5tdSDQZ6qZ Dik4vPQADG8fvYg0PWEYg2F00g8/2oVNtL12a2OfWrkdZb3Qhj6XyNxZaF5j9i/nNP4L zfTS45q+vwh5PwMZZ/8UR00y0bSxPvTgd+Q16PYqeqYYZrJTarn5bGdW7uSeQo5wp3hk 1YrvvLwo++ivY369MMvNIfeF1xMQC5GB1WjrMhlB2XzrWBhu5m71BHlhrh9ZaTDafbbB hN9wbbger83z1FoY3aImw3cryeNWAtlwZWXH10UtjM/HoNxws4ezKKnNDmhBRlJ+PHRv wbKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=1ykJGA57/c6XjRX+/wiozqy8iJ6Vsrt2RLKtiLpKiLM=; fh=Q3S7ZgH7Zm5APQA66CHOxj7VLxBfQoZXcjv40qXT1hk=; b=OhgPhwbZUO5297KEYTfBGEORXus0EOYi2jf6e4f/MLKMRvmYYzOoieNfAVo9fBZH2q kkhRBdQ8u3kZIi0Sfe8PF68VXOQXs9jJDnsgNP9m2M/+fYlcZvOtQsy5Jbq7B1xHd0Zd nFnfB5lkDYFvYolRtnwPZ2anIgh0xL2sT7YqUZusTAHfvG+pcwcZvr5cWrvYeXrueYry K9MSklf85y+DPrchZnrN1FQL57pf7ygblcMgt2fmPwLhBB5ao4ZFRyUD34nlBv/sNFg7 OWAPsgBJg9KI+7dgoD+lWwfBo5lrCqmMLG+L83MgT5J+pwey8PCy8PhPifAOVk5rV80T hCXg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=C8u3bvO7; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-30587-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30587-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v8-20020a0cdd88000000b006819bda6ad3si547625qvk.453.2024.01.18.13.54.19 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 13:54:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30587-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=C8u3bvO7; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-30587-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30587-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 931491C24B0A for <ouuuleilei@gmail.com>; Thu, 18 Jan 2024 21:54:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 402B531A7E; Thu, 18 Jan 2024 21:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="C8u3bvO7" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A8692EAF9 for <linux-kernel@vger.kernel.org>; Thu, 18 Jan 2024 21:54:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705614844; cv=none; b=ULR8wSQ+Ktoa3AcavWe/AcqUgC/wVYhIS15J5Vp8hfjfCBQAHS4eiLHDLwM/TPsya4NmEj50i+8CxoSQE11wWKSxjrPBgkCKRyIA3d9HHXimufvtwouiWz9soWsWOOSCqEXwDkcl1KnGdut6qFkyYFJVc53pqcKI6qMjSSej4E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705614844; c=relaxed/simple; bh=0OLoge7JRZVK/JTs8M53rSZCOS6zKNIvbnryNlKfkNs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=fNUlYKFjQibfXmAYTXPDe6M9KCpz7kVIhnIXdBjTl+5sieQ+cgsO+66lMwG06lEtOJ8YCCIWUCWoJhikirZVUHCQBstVDD1RuAlraX6rBVpGTMRQTcHZbcV2VGJbf+YpedlxAlAacPs2p0xmQRFJTq9hgSaa2U3wQWLhpA6PJdU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=C8u3bvO7; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6d9b37f4804so828399b3a.1 for <linux-kernel@vger.kernel.org>; Thu, 18 Jan 2024 13:54:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1705614841; x=1706219641; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=1ykJGA57/c6XjRX+/wiozqy8iJ6Vsrt2RLKtiLpKiLM=; b=C8u3bvO7oxhgginUEjQzW+277qLH3R4XqiYXdi4z+KsPPXPEq7lceJzx1p1os6UKFt zUaGS53pZUomjlGD4JAUIcV4DQH/KW5XaF6cSOqqzxVqgTk8r09FDyKi3nE+NSCllQw7 wueWI6E42J/rwk4Ca07/cZm7rVJ7p5NLjQxtfJOKk8dWYSPIIxGOMsbbzb2+MUru5asx OMq1/yJvjyHwxWe1JS80uDYOJPBckJcphpEJj5z6QLVcCKOxkyOtVbK5F/er37Rs2GaF TW9wNwZtHum51NvCM7HvkDUFNtPLFuuasFs4kckwwtkguU6ibJFZxpMy5Ml7ql3Zy6Oe NXUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705614841; x=1706219641; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1ykJGA57/c6XjRX+/wiozqy8iJ6Vsrt2RLKtiLpKiLM=; b=ewXDKk4E/eIRlFrMyOqomaUfz/6w1SNTfVEbo8odr4SIXpY9DPai1bSHeLWt9XZea2 HNK/noHBNyUvKPRfV3f5G1SCGim1Aa+/OC3Qd/HDiUgb/sSAAMRKBLG23zOazuzrNAAd R56G5S1qejRLyw5R+MnsPTmhO9akvgK1wdAV1sCgu378B+Zs21GIzsA7DuLjz4pB+vE/ KV7oHnPiUPrIF+pNG7w6wlh/Z/m9xK9odjmLYxPo7uSVoGsX5TRXbFLGfbNLsKgGrpKA DVYL+paZdaycHmjVlwSHGFBRR5sIpDZTN0QgJGi/uxw+/HM+X3vOkjwkKVmOo5ebv0hT TM+Q== X-Gm-Message-State: AOJu0Yz1mHcuGolKCQDltshopWMSsiIbkHakrcLIGFYAGqnX1wG27B/m jV17qEjOdaQ3x7YAgdGEEUMQgNoOghFhz8lWcm4ESE6Hylh26dq4YwIknxwMG92QahwLedICtFT j X-Received: by 2002:a05:6a20:2dc:b0:19b:1da4:8dc with SMTP id 28-20020a056a2002dc00b0019b1da408dcmr18728pzb.34.1705614841620; Thu, 18 Jan 2024 13:54:01 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id j15-20020aa78d0f000000b006d9c7f2840bsm3771459pfe.57.2024.01.18.13.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 13:54:01 -0800 (PST) From: Charlie Jenkins <charlie@rivosinc.com> Date: Thu, 18 Jan 2024 13:53:59 -0800 Subject: [PATCH] riscv: lib: Support csum on GCC <11 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240118-csum_remove_output_operands_asm_goto-v1-1-47c672bb9d4b@rivosinc.com> X-B4-Tracking: v=1; b=H4sIAPadqWUC/x3NQQrDIBBA0auEWVfIiNCmVylFxEzTWeiIoyEQc vdKl2/z/wlKlUnhOZ1QaWdlyQN4myB+Q97I8DoMdrZuRnyYqD35Skl28tJb6c1LoRryqj5o8ps 0MW5ZrI3oMNIdRqpU+vDx37ze1/UDe5WzqHYAAAA= To: Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu> Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins <charlie@rivosinc.com> X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1705614840; l=2787; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=0OLoge7JRZVK/JTs8M53rSZCOS6zKNIvbnryNlKfkNs=; b=dJpuJl1dFpZjTsUOyTWIxBNNNkZvncdUMycB4TzPg8EkchYbaXeZWzM0gJrYusU4KUPaoHcVO XLWURTe24UwBbkRTIcQdUzshBpJFlZdeoMxWOC8rVKRzmO3g1hoiBq2 X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788466807578966483 X-GMAIL-MSGID: 1788466807578966483 |
Series |
riscv: lib: Support csum on GCC <11
|
|
Commit Message
Charlie Jenkins
Jan. 18, 2024, 9:53 p.m. UTC
The OutputOperands field for asm goto statements is only supported
starting from GCC 11. Split the asm goto to remove the use of this
feature.
Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
Fixes: a04c192eabfb ("riscv: Add checksum library")
---
The OutputOperands field for asm goto statements is only supported
starting from GCC 11. Split the asm goto to remove the use of this
feature.
---
arch/riscv/lib/csum.c | 42 ++++++++++++++++++++++++++++++------------
1 file changed, 30 insertions(+), 12 deletions(-)
---
base-commit: 080c4324fa5e81ff3780206a138223abfb57a68e
change-id: 20240118-csum_remove_output_operands_asm_goto-49922c141ce7
Comments
On Thu, Jan 18, 2024 at 01:53:59PM -0800, Charlie Jenkins wrote: > The OutputOperands field for asm goto statements is only supported > starting from GCC 11. Split the asm goto to remove the use of this > feature. > > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> > Fixes: a04c192eabfb ("riscv: Add checksum library") > --- > The OutputOperands field for asm goto statements is only supported > starting from GCC 11. Split the asm goto to remove the use of this > feature. Maybe this is a super naive question, but is it possible to just not use the custom csum code for gcc older than 11? > --- > arch/riscv/lib/csum.c | 42 ++++++++++++++++++++++++++++++------------ > 1 file changed, 30 insertions(+), 12 deletions(-) > > diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c > index 06ce8e7250d9..23be289f52b6 100644 > --- a/arch/riscv/lib/csum.c > +++ b/arch/riscv/lib/csum.c > @@ -177,22 +177,35 @@ do_csum_with_alignment(const unsigned char *buff, int len) > : no_zbb); > > #ifdef CONFIG_32BIT > - asm_volatile_goto(".option push \n\ > + /* > + * OutputOperands in asm goto is not supported until GCC 11, so > + * this asm has to be split to be compatible. > + */ > + asm (".option push \n\ > .option arch,+zbb \n\ > rori %[fold_temp], %[csum], 16 \n\ > andi %[offset], %[offset], 1 \n\ > add %[csum], %[fold_temp], %[csum] \n\ > - beq %[offset], zero, %l[end] \n\ > - rev8 %[csum], %[csum] \n\ > .option pop" > : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp) > - : [offset] "r" (offset) > - : > - : end); > + : [offset] "r" (offset)); > + > + if (offset == 0) > + goto end; > + > + asm (".option push \n\ > + .option arch, +zbb \n\ > + rev8 %[csum], %[csum] \n\ > + .option pop" > + : [csum] "+r" (csum)); > > return (unsigned short)csum; > #else /* !CONFIG_32BIT */ > - asm_volatile_goto(".option push \n\ > + /* > + * OutputOperands in asm goto is not supported until GCC 11, so > + * this asm has to be split to be compatible. > + */ > + asm (".option push \n\ > .option arch,+zbb \n\ > rori %[fold_temp], %[csum], 32 \n\ > add %[csum], %[fold_temp], %[csum] \n\ > @@ -200,13 +213,18 @@ do_csum_with_alignment(const unsigned char *buff, int len) > roriw %[fold_temp], %[csum], 16 \n\ > addw %[csum], %[fold_temp], %[csum] \n\ > andi %[offset], %[offset], 1 \n\ > - beq %[offset], zero, %l[end] \n\ > - rev8 %[csum], %[csum] \n\ > .option pop" > : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp) > - : [offset] "r" (offset) > - : > - : end); > + : [offset] "r" (offset)); > + > + if (offset == 0) > + goto end; > + > + asm (".option push \n\ > + .option arch, +zbb \n\ > + rev8 %[csum], %[csum] \n\ > + .option pop" > + : [csum] "+r" (csum)); > > return (csum << 16) >> 48; > #endif /* !CONFIG_32BIT */ > > --- > base-commit: 080c4324fa5e81ff3780206a138223abfb57a68e > change-id: 20240118-csum_remove_output_operands_asm_goto-49922c141ce7 > -- > - Charlie > >
On Thu, 18 Jan 2024 14:05:44 PST (-0800), Conor Dooley wrote: > On Thu, Jan 18, 2024 at 01:53:59PM -0800, Charlie Jenkins wrote: >> The OutputOperands field for asm goto statements is only supported >> starting from GCC 11. Split the asm goto to remove the use of this >> feature. >> >> Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> >> Fixes: a04c192eabfb ("riscv: Add checksum library") >> --- >> The OutputOperands field for asm goto statements is only supported >> starting from GCC 11. Split the asm goto to remove the use of this >> feature. > > Maybe this is a super naive question, but is it possible to just not > use the custom csum code for gcc older than 11? Charlie and I were talking, these old GCC versions also don't support ZBB. So I think we can get away with something like diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c index 06ce8e7250d9..17f883b612c9 100644 --- a/arch/riscv/lib/csum.c +++ b/arch/riscv/lib/csum.c @@ -158,10 +158,16 @@ do_csum_with_alignment(const unsigned char *buff, int len) /* * Zbb support saves 6 instructions, so not worth checking without - * alternatives if supported + * alternatives if supported. + * + * Note that we pull the check for ZBB into the preprocessor proper + * here, as otherwise GCC will attempt to compile the code inside the + * "if (IS_ENABLED(ZBB)" block which fails because GCC10 doesn't + * support ASM goto output operands. GCC 10 also doesn't support ZBB, + * so we're safe with that check here. */ - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { +#if defined(CONFIG_RISCV_ISA_ZBB) + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { unsigned long fold_temp; /* @@ -213,6 +219,7 @@ do_csum_with_alignment(const unsigned char *buff, int len) end: return csum >> 16; } +#endif /*CONFIG_RISCV_ISA_ZBB*/ no_zbb: #ifndef CONFIG_32BIT csum += ror64(csum, 32); @@ -244,10 +251,11 @@ do_csum_no_alignment(const unsigned char *buff, int len) /* * Zbb support saves 6 instructions, so not worth checking without - * alternatives if supported + * alternatives if supported. See above for the ZBB preprocessor + * check. */ - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { +#if defined(CONFIG_RISCV_ISA_ZBB) + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { unsigned long fold_temp; /* @@ -287,6 +295,7 @@ do_csum_no_alignment(const unsigned char *buff, int len) #endif /* !CONFIG_32BIT */ return csum >> 16; } +#endif /*CONFIG_RISCV_ISA_ZBB*/ no_zbb: #ifndef CONFIG_32BIT csum += ror64(csum, 32); which is building for me on GCC-10/defconfig. > >> --- >> arch/riscv/lib/csum.c | 42 ++++++++++++++++++++++++++++++------------ >> 1 file changed, 30 insertions(+), 12 deletions(-) >> >> diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c >> index 06ce8e7250d9..23be289f52b6 100644 >> --- a/arch/riscv/lib/csum.c >> +++ b/arch/riscv/lib/csum.c >> @@ -177,22 +177,35 @@ do_csum_with_alignment(const unsigned char *buff, int len) >> : no_zbb); >> >> #ifdef CONFIG_32BIT >> - asm_volatile_goto(".option push \n\ >> + /* >> + * OutputOperands in asm goto is not supported until GCC 11, so >> + * this asm has to be split to be compatible. >> + */ >> + asm (".option push \n\ >> .option arch,+zbb \n\ >> rori %[fold_temp], %[csum], 16 \n\ >> andi %[offset], %[offset], 1 \n\ >> add %[csum], %[fold_temp], %[csum] \n\ >> - beq %[offset], zero, %l[end] \n\ >> - rev8 %[csum], %[csum] \n\ >> .option pop" >> : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp) >> - : [offset] "r" (offset) >> - : >> - : end); >> + : [offset] "r" (offset)); >> + >> + if (offset == 0) >> + goto end; >> + >> + asm (".option push \n\ >> + .option arch, +zbb \n\ >> + rev8 %[csum], %[csum] \n\ >> + .option pop" >> + : [csum] "+r" (csum)); >> >> return (unsigned short)csum; >> #else /* !CONFIG_32BIT */ >> - asm_volatile_goto(".option push \n\ >> + /* >> + * OutputOperands in asm goto is not supported until GCC 11, so >> + * this asm has to be split to be compatible. >> + */ >> + asm (".option push \n\ >> .option arch,+zbb \n\ >> rori %[fold_temp], %[csum], 32 \n\ >> add %[csum], %[fold_temp], %[csum] \n\ >> @@ -200,13 +213,18 @@ do_csum_with_alignment(const unsigned char *buff, int len) >> roriw %[fold_temp], %[csum], 16 \n\ >> addw %[csum], %[fold_temp], %[csum] \n\ >> andi %[offset], %[offset], 1 \n\ >> - beq %[offset], zero, %l[end] \n\ >> - rev8 %[csum], %[csum] \n\ >> .option pop" >> : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp) >> - : [offset] "r" (offset) >> - : >> - : end); >> + : [offset] "r" (offset)); >> + >> + if (offset == 0) >> + goto end; >> + >> + asm (".option push \n\ >> + .option arch, +zbb \n\ >> + rev8 %[csum], %[csum] \n\ >> + .option pop" >> + : [csum] "+r" (csum)); >> >> return (csum << 16) >> 48; >> #endif /* !CONFIG_32BIT */ >> >> --- >> base-commit: 080c4324fa5e81ff3780206a138223abfb57a68e >> change-id: 20240118-csum_remove_output_operands_asm_goto-49922c141ce7 >> -- >> - Charlie >> >>
On Thu, Jan 18, 2024 at 02:20:42PM -0800, Palmer Dabbelt wrote: > On Thu, 18 Jan 2024 14:05:44 PST (-0800), Conor Dooley wrote: > > On Thu, Jan 18, 2024 at 01:53:59PM -0800, Charlie Jenkins wrote: > > > The OutputOperands field for asm goto statements is only supported > > > starting from GCC 11. Split the asm goto to remove the use of this > > > feature. > > > > > > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> > > > Fixes: a04c192eabfb ("riscv: Add checksum library") > > > --- > > > The OutputOperands field for asm goto statements is only supported > > > starting from GCC 11. Split the asm goto to remove the use of this > > > feature. > > > > Maybe this is a super naive question, but is it possible to just not > > use the custom csum code for gcc older than 11? > > Charlie and I were talking, these old GCC versions also don't support ZBB. > So I think we can get away with something like I sent an updated version that uses CC_HAS_ASM_GOTO_TIED_OUTPUT since there may exist a compiler that supports ZBB but doesn't support output in asm goto. - Charlie > > diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c > index 06ce8e7250d9..17f883b612c9 100644 > --- a/arch/riscv/lib/csum.c > +++ b/arch/riscv/lib/csum.c > @@ -158,10 +158,16 @@ do_csum_with_alignment(const unsigned char *buff, int len) > > /* > * Zbb support saves 6 instructions, so not worth checking without > - * alternatives if supported > + * alternatives if supported. > + * > + * Note that we pull the check for ZBB into the preprocessor proper > + * here, as otherwise GCC will attempt to compile the code inside the > + * "if (IS_ENABLED(ZBB)" block which fails because GCC10 doesn't > + * support ASM goto output operands. GCC 10 also doesn't support ZBB, > + * so we're safe with that check here. > */ > - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && > - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { > +#if defined(CONFIG_RISCV_ISA_ZBB) > + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { > unsigned long fold_temp; > > /* > @@ -213,6 +219,7 @@ do_csum_with_alignment(const unsigned char *buff, int len) > end: > return csum >> 16; > } > +#endif /*CONFIG_RISCV_ISA_ZBB*/ > no_zbb: > #ifndef CONFIG_32BIT > csum += ror64(csum, 32); > @@ -244,10 +251,11 @@ do_csum_no_alignment(const unsigned char *buff, int len) > > /* > * Zbb support saves 6 instructions, so not worth checking without > - * alternatives if supported > + * alternatives if supported. See above for the ZBB preprocessor > + * check. > */ > - if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && > - IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { > +#if defined(CONFIG_RISCV_ISA_ZBB) > + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { > unsigned long fold_temp; > > /* > @@ -287,6 +295,7 @@ do_csum_no_alignment(const unsigned char *buff, int len) > #endif /* !CONFIG_32BIT */ > return csum >> 16; > } > +#endif /*CONFIG_RISCV_ISA_ZBB*/ > no_zbb: > #ifndef CONFIG_32BIT > csum += ror64(csum, 32); > > which is building for me on GCC-10/defconfig. > > > > > > --- > > > arch/riscv/lib/csum.c | 42 ++++++++++++++++++++++++++++++------------ > > > 1 file changed, 30 insertions(+), 12 deletions(-) > > > > > > diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c > > > index 06ce8e7250d9..23be289f52b6 100644 > > > --- a/arch/riscv/lib/csum.c > > > +++ b/arch/riscv/lib/csum.c > > > @@ -177,22 +177,35 @@ do_csum_with_alignment(const unsigned char *buff, int len) > > > : no_zbb); > > > #ifdef CONFIG_32BIT > > > - asm_volatile_goto(".option push \n\ > > > + /* > > > + * OutputOperands in asm goto is not supported until GCC 11, so > > > + * this asm has to be split to be compatible. > > > + */ > > > + asm (".option push \n\ > > > .option arch,+zbb \n\ > > > rori %[fold_temp], %[csum], 16 \n\ > > > andi %[offset], %[offset], 1 \n\ > > > add %[csum], %[fold_temp], %[csum] \n\ > > > - beq %[offset], zero, %l[end] \n\ > > > - rev8 %[csum], %[csum] \n\ > > > .option pop" > > > : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp) > > > - : [offset] "r" (offset) > > > - : > > > - : end); > > > + : [offset] "r" (offset)); > > > + > > > + if (offset == 0) > > > + goto end; > > > + > > > + asm (".option push \n\ > > > + .option arch, +zbb \n\ > > > + rev8 %[csum], %[csum] \n\ > > > + .option pop" > > > + : [csum] "+r" (csum)); > > > return (unsigned short)csum; > > > #else /* !CONFIG_32BIT */ > > > - asm_volatile_goto(".option push \n\ > > > + /* > > > + * OutputOperands in asm goto is not supported until GCC 11, so > > > + * this asm has to be split to be compatible. > > > + */ > > > + asm (".option push \n\ > > > .option arch,+zbb \n\ > > > rori %[fold_temp], %[csum], 32 \n\ > > > add %[csum], %[fold_temp], %[csum] \n\ > > > @@ -200,13 +213,18 @@ do_csum_with_alignment(const unsigned char *buff, int len) > > > roriw %[fold_temp], %[csum], 16 \n\ > > > addw %[csum], %[fold_temp], %[csum] \n\ > > > andi %[offset], %[offset], 1 \n\ > > > - beq %[offset], zero, %l[end] \n\ > > > - rev8 %[csum], %[csum] \n\ > > > .option pop" > > > : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp) > > > - : [offset] "r" (offset) > > > - : > > > - : end); > > > + : [offset] "r" (offset)); > > > + > > > + if (offset == 0) > > > + goto end; > > > + > > > + asm (".option push \n\ > > > + .option arch, +zbb \n\ > > > + rev8 %[csum], %[csum] \n\ > > > + .option pop" > > > + : [csum] "+r" (csum)); > > > return (csum << 16) >> 48; > > > #endif /* !CONFIG_32BIT */ > > > > > > --- > > > base-commit: 080c4324fa5e81ff3780206a138223abfb57a68e > > > change-id: 20240118-csum_remove_output_operands_asm_goto-49922c141ce7 > > > -- > > > - Charlie > > > > > >
diff --git a/arch/riscv/lib/csum.c b/arch/riscv/lib/csum.c index 06ce8e7250d9..23be289f52b6 100644 --- a/arch/riscv/lib/csum.c +++ b/arch/riscv/lib/csum.c @@ -177,22 +177,35 @@ do_csum_with_alignment(const unsigned char *buff, int len) : no_zbb); #ifdef CONFIG_32BIT - asm_volatile_goto(".option push \n\ + /* + * OutputOperands in asm goto is not supported until GCC 11, so + * this asm has to be split to be compatible. + */ + asm (".option push \n\ .option arch,+zbb \n\ rori %[fold_temp], %[csum], 16 \n\ andi %[offset], %[offset], 1 \n\ add %[csum], %[fold_temp], %[csum] \n\ - beq %[offset], zero, %l[end] \n\ - rev8 %[csum], %[csum] \n\ .option pop" : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp) - : [offset] "r" (offset) - : - : end); + : [offset] "r" (offset)); + + if (offset == 0) + goto end; + + asm (".option push \n\ + .option arch, +zbb \n\ + rev8 %[csum], %[csum] \n\ + .option pop" + : [csum] "+r" (csum)); return (unsigned short)csum; #else /* !CONFIG_32BIT */ - asm_volatile_goto(".option push \n\ + /* + * OutputOperands in asm goto is not supported until GCC 11, so + * this asm has to be split to be compatible. + */ + asm (".option push \n\ .option arch,+zbb \n\ rori %[fold_temp], %[csum], 32 \n\ add %[csum], %[fold_temp], %[csum] \n\ @@ -200,13 +213,18 @@ do_csum_with_alignment(const unsigned char *buff, int len) roriw %[fold_temp], %[csum], 16 \n\ addw %[csum], %[fold_temp], %[csum] \n\ andi %[offset], %[offset], 1 \n\ - beq %[offset], zero, %l[end] \n\ - rev8 %[csum], %[csum] \n\ .option pop" : [csum] "+r" (csum), [fold_temp] "=&r" (fold_temp) - : [offset] "r" (offset) - : - : end); + : [offset] "r" (offset)); + + if (offset == 0) + goto end; + + asm (".option push \n\ + .option arch, +zbb \n\ + rev8 %[csum], %[csum] \n\ + .option pop" + : [csum] "+r" (csum)); return (csum << 16) >> 48; #endif /* !CONFIG_32BIT */