Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48C22C6FD1D for ; Tue, 21 Mar 2023 06:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230357AbjCUGgo (ORCPT ); Tue, 21 Mar 2023 02:36:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjCUGgi (ORCPT ); Tue, 21 Mar 2023 02:36:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11EAA3B85C for ; Mon, 20 Mar 2023 23:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679380528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tlcmKFBm9EfeLOX/A4Ek+TTZZd7OjXZ+kA7z9b9Tay8=; b=Xyg1avX62sTLnt4ZtsX27ok177kZnMQPdX1tMbow9isdbLzRdw71rZoS2x2/ASfImrqxrN 4OBh5AFblJqRn1d9Go5Kqsqkq58AhrwB2dIyBrwGPQi/EJRQZ3HTgS1uQC5DKVPTt4Khbn FHIgb5QrKR3ZG9zvDSJ79U4I/GW4vbw= Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665--RKgjSXMNWq3KZ8UyX6bRw-1; Tue, 21 Mar 2023 02:35:27 -0400 X-MC-Unique: -RKgjSXMNWq3KZ8UyX6bRw-1 Received: by mail-ot1-f70.google.com with SMTP id p28-20020a0568301d5c00b0069f851af0aaso466901oth.22 for ; Mon, 20 Mar 2023 23:35:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679380526; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tlcmKFBm9EfeLOX/A4Ek+TTZZd7OjXZ+kA7z9b9Tay8=; b=HA2wkDpmYfAqNiDYAEdpfZcva/Uxdsno6sRtdNlCZc541VGlilOaiQt2Le56VaWCkY v7iABDOncRlFSuz5embpQXqQu73zqByK1ZU3Ey3066/N0fPqXeJRYYkfF/CdDJmNXpmp q1OTDqeJJB3h6JyPxxNWxJpM9ri7A/wSIYjps/tjlphKadWvEjQkazxrSZpJgzidldjK r/PhPEMbPig9m8gzSwI2f+zbTo5OS3tX+fSHlf64aGOuOgdP7cW+mDDs6R/YCou8QGZu vNdhikBQBZPyVxknFXAmLj0kecgpdOUrPqYFgsPUGrTaxGrq3J+fFT0xjmGq9TdPvbEe kLIg== X-Gm-Message-State: AO0yUKXCqf72vq4ePYZWCL8FvmcxQfT/RUFYx+rrfONWbUnd2JuinJsj SBUtwn6iR5V4fnOIRIXTu2UbrasHpgPWcrdw2L8j1R8OvqH6/3SFKdrAj2YLP5RNDO2NxK8WnMa tsNIBTySw9fjc9CG/3k+SZvTb8t7HqMJBL6Y= X-Received: by 2002:a9d:6ad0:0:b0:69f:d2:4ff9 with SMTP id m16-20020a9d6ad0000000b0069f00d24ff9mr658172otq.34.1679380525851; Mon, 20 Mar 2023 23:35:25 -0700 (PDT) X-Google-Smtp-Source: AK7set8BL8xxcS2gihrUiVrow++wCxZdFOVZ6MdUs+6m2NdC+EoSp3K2yAnigR0ShdhdoBiekQPvMA== X-Received: by 2002:a9d:6ad0:0:b0:69f:d2:4ff9 with SMTP id m16-20020a9d6ad0000000b0069f00d24ff9mr658162otq.34.1679380525642; Mon, 20 Mar 2023 23:35:25 -0700 (PDT) Received: from localhost.localdomain ([2804:1b3:a801:b074:274d:d04e:badc:c89f]) by smtp.gmail.com with ESMTPSA id y75-20020a4a454e000000b005293e9a12f5sm4545147ooa.45.2023.03.20.23.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 23:35:25 -0700 (PDT) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Leonardo Bras , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 5/6] riscv/cmpxchg: Deduplicate xchg() macros Date: Tue, 21 Mar 2023 03:34:31 -0300 Message-Id: <20230321063430.2218795-6-leobras@redhat.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230321063430.2218795-1-leobras@redhat.com> References: <20230321063430.2218795-1-leobras@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Every xchg define (_relaxed, _acquire, _release, vanilla) contain it's own define for creating tmp variables and selecting the correct asm code for given variable size. All those defines are mostly the same code (other than specific barriers), so there is no need to keep the 4 copies. Unify those under a more general define, that can reproduce the previous 4 versions. (This did not cause any change in generated asm) Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/cmpxchg.h | 62 ++++++-------------------------- 1 file changed, 10 insertions(+), 52 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 715bf61e72c82..23da4d8e6f0c8 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -11,7 +11,7 @@ #include #include -#define ___xchg(sfx, prepend, append) \ +#define ____xchg(sfx, prepend, append) \ ({ \ __asm__ __volatile__ ( \ prepend \ @@ -22,17 +22,17 @@ : "memory"); \ }) -#define __xchg_relaxed(ptr, new, size) \ +#define ___xchg(ptr, new, size, sfx, prepend, append) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ __typeof__(new) __new = (new); \ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - ___xchg(".w", "", ""); \ + ____xchg(".w" sfx, prepend, append); \ break; \ case 8: \ - ___xchg(".d", "", ""); \ + ____xchg(".d" sfx, prepend, append); \ break; \ default: \ BUILD_BUG(); \ @@ -40,6 +40,9 @@ __ret; \ }) +#define __xchg_relaxed(ptr, new, size) \ + ___xchg(ptr, new, size, "", "", "") + #define arch_xchg_relaxed(ptr, x) \ ({ \ __typeof__(*(ptr)) _x_ = (x); \ @@ -48,22 +51,7 @@ }) #define __xchg_acquire(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - switch (size) { \ - case 4: \ - ___xchg(".w", "", RISCV_ACQUIRE_BARRIER); \ - break; \ - case 8: \ - ___xchg(".d", "", RISCV_ACQUIRE_BARRIER); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___xchg(ptr, new, size, "", "", RISCV_ACQUIRE_BARRIER) #define arch_xchg_acquire(ptr, x) \ ({ \ @@ -73,22 +61,7 @@ }) #define __xchg_release(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - switch (size) { \ - case 4: \ - ___xchg(".w", RISCV_RELEASE_BARRIER, ""); \ - break; \ - case 8: \ - ___xchg(".d", RISCV_RELEASE_BARRIER, ""); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___xchg(ptr, new, size, "", RISCV_RELEASE_BARRIER, "") #define arch_xchg_release(ptr, x) \ ({ \ @@ -98,22 +71,7 @@ }) #define __xchg(ptr, new, size) \ -({ \ - __typeof__(ptr) __ptr = (ptr); \ - __typeof__(new) __new = (new); \ - __typeof__(*(ptr)) __ret; \ - switch (size) { \ - case 4: \ - ___xchg(".w.aqrl", "", ""); \ - break; \ - case 8: \ - ___xchg(".d.aqrl", "", ""); \ - break; \ - default: \ - BUILD_BUG(); \ - } \ - __ret; \ -}) + ___xchg(ptr, new, size, ".aqrl", "", "") #define arch_xchg(ptr, x) \ ({ \ -- 2.40.0