Message ID | 20230503201324.1587003-1-mathieu.desnoyers@efficios.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1597779vqo; Wed, 3 May 2023 13:43:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5TZqbbGStnv9Ls4SdCjfVFBOzNPBI2doLnIUU510LBDnQXq3IAgdhAefYDknEcxzXI5Yrh X-Received: by 2002:a05:6a00:3496:b0:63b:6d4d:4c9 with SMTP id cp22-20020a056a00349600b0063b6d4d04c9mr3855572pfb.9.1683146594021; Wed, 03 May 2023 13:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683146594; cv=none; d=google.com; s=arc-20160816; b=GFM1ekrKQn6ow63JjPJrswUX0RIlCz1ETRuo6TvixK+dV1dmMpy+Y+VQEi3/mxj2uJ /wmVYco7i/VpHmnP3oidXX2yDEcP5kOe/3hRB0RNdqUayy03jmv/bFqw0CWkMbiak+jE ZBXX/0TWEOcLUNf2KnVJENsUycKTTUJd8hmId65FOoj0lTrsC/qWnVngBybDVN67wtVS doD3SzKphFEHs42z3VProRRiOFV68HbJJ3h1jc4JIMXQhU2lcufTz+41DLdkR4SEz937 XbyDWNidYqjDaolE2bZYlonD3uARs7gu4TSt7OzVE5pM7A5hNIxEb0HETBuitOTtTgwW ypsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=GMWdqSjVCBGTLqvsl1GuDgQBpGYGY548bbp3vb2dCMU=; b=kExo1Z6eL3cPlf9V+M87ugy8SVfmIQoE0t7GleiKUh+pPvAAfc3fix4mCA6GkfJWZW 3/G/yWqyiP619gfq1bgOEWEWeLRPYvs793yI4vU6Bv/UpofyIeLCibein+Ogm2Ru3KyI 2ccLcZ52T+qJjIADrTZop9+bsmL4/veINhooboxwDajPnlHDp03rIujKZXxoSgTD5OLk oymC1bgfZOl25miPhibPOYAp4jbVmiUCbGQlie2faIL9FxKccah0H/hyD7cxQlnyHorj HFqjnIt8T1fI3+fuacA3xD0c3Y8cPEKqYYP8dYHjhbot+kOKLOiMkv2HUwpG4qqH8dJt 65TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=iWQhduDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g64-20020a636b43000000b00513128cd495si33168436pgc.730.2023.05.03.13.42.38; Wed, 03 May 2023 13:43:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=iWQhduDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbjECUOo (ORCPT <rfc822;lhua1029@gmail.com> + 99 others); Wed, 3 May 2023 16:14:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230156AbjECUOg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 3 May 2023 16:14:36 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 846B58A62 for <linux-kernel@vger.kernel.org>; Wed, 3 May 2023 13:13:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1683144808; bh=40ZXckww7AYtcV479k70ydFlE0zo0yVWPM2kmuXq4GE=; h=From:To:Cc:Subject:Date:From; b=iWQhduDV2eR1p8Thl+BMwPzCkIwdsiO/5RLyy8ywDEU3r6f16RUbK/SQUaD/8xsdL 3OVqXh1KHJm0i2fCxTimnKBAcpcDrQMNByvpRV7eOP5l2Yybwd6Xia/HGrnYGDl3L0 iMmMYtqenUAKxh8LeUqDRp7spzSOT+ONHMNuRvtTuVRX9ucQ40zsQcK/p2lkKqq2h7 /iW+zAJ4wDCOG/bEKoPymILTMcMYk+x06S+cB1qPjcG/lUAzOw0nLM/5wMfLsDX+ZM w6co6Xh+3+g1i784LVhFGB7QlwV/xHSl2imfTDobzxaEN3RqOmVVCJ8KXsPyxWUflS XdCyV2qe+sO9w== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4QBSnN4dzBz11hs; Wed, 3 May 2023 16:13:28 -0400 (EDT) From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> To: Peter Zijlstra <peterz@infradead.org> Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Subject: [RFC PATCH 1/3] selftests/rseq: Implement rseq_unqual_scalar_typeof Date: Wed, 3 May 2023 16:13:22 -0400 Message-Id: <20230503201324.1587003-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764907123204463336?= X-GMAIL-MSGID: =?utf-8?q?1764907123204463336?= |
Series |
[RFC,1/3] selftests/rseq: Implement rseq_unqual_scalar_typeof
|
|
Commit Message
Mathieu Desnoyers
May 3, 2023, 8:13 p.m. UTC
Allow defining variables and perform cast with a typeof which removes
the volatile and const qualifiers.
This prevents declaring a stack variable with a volatile qualifier
within a macro, which would generate sub-optimal assembler.
This is imported from the "librseq" project.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
---
tools/testing/selftests/rseq/compiler.h | 27 +++++++++++++++++++++++++
1 file changed, 27 insertions(+)
Comments
On Wed, May 03, 2023 at 04:13:22PM -0400, Mathieu Desnoyers wrote: > Allow defining variables and perform cast with a typeof which removes > the volatile and const qualifiers. > > This prevents declaring a stack variable with a volatile qualifier > within a macro, which would generate sub-optimal assembler. > > This is imported from the "librseq" project. > > Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> > --- > tools/testing/selftests/rseq/compiler.h | 27 +++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/tools/testing/selftests/rseq/compiler.h b/tools/testing/selftests/rseq/compiler.h > index f47092bddeba..8dc7f881e253 100644 > --- a/tools/testing/selftests/rseq/compiler.h > +++ b/tools/testing/selftests/rseq/compiler.h > @@ -33,4 +33,31 @@ > #define RSEQ_COMBINE_TOKENS(_tokena, _tokenb) \ > RSEQ__COMBINE_TOKENS(_tokena, _tokenb) > > +#ifdef __cplusplus > +#define rseq_unqual_scalar_typeof(x) \ > + std::remove_cv<std::remove_reference<decltype(x)>::type>::type > +#else > +/* > + * Use C11 _Generic to express unqualified type from expression. This removes > + * volatile qualifier from expression type. > + */ > +#define rseq_unqual_scalar_typeof(x) \ > + __typeof__( \ > + _Generic((x), \ > + char: (char)0, \ > + unsigned char: (unsigned char)0, \ > + signed char: (signed char)0, \ > + unsigned short: (unsigned short)0, \ > + signed short: (signed short)0, \ > + unsigned int: (unsigned int)0, \ > + signed int: (signed int)0, \ > + unsigned long: (unsigned long)0, \ > + signed long: (signed long)0, \ > + unsigned long long: (unsigned long long)0, \ > + signed long long: (signed long long)0, \ > + default: (x) \ > + ) \ > + ) FWIW, I like how the kernel version uses a little helper for the signed/unsigned pairs. Makes it a little more readable. > +#endif > + > #endif /* RSEQ_COMPILER_H_ */ > -- > 2.25.1 >
On 2023-05-04 02:09, Peter Zijlstra wrote: > On Wed, May 03, 2023 at 04:13:22PM -0400, Mathieu Desnoyers wrote: >> Allow defining variables and perform cast with a typeof which removes >> the volatile and const qualifiers. >> >> This prevents declaring a stack variable with a volatile qualifier >> within a macro, which would generate sub-optimal assembler. >> >> This is imported from the "librseq" project. >> >> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> >> --- >> tools/testing/selftests/rseq/compiler.h | 27 +++++++++++++++++++++++++ >> 1 file changed, 27 insertions(+) >> >> diff --git a/tools/testing/selftests/rseq/compiler.h b/tools/testing/selftests/rseq/compiler.h >> index f47092bddeba..8dc7f881e253 100644 >> --- a/tools/testing/selftests/rseq/compiler.h >> +++ b/tools/testing/selftests/rseq/compiler.h >> @@ -33,4 +33,31 @@ >> #define RSEQ_COMBINE_TOKENS(_tokena, _tokenb) \ >> RSEQ__COMBINE_TOKENS(_tokena, _tokenb) >> >> +#ifdef __cplusplus >> +#define rseq_unqual_scalar_typeof(x) \ >> + std::remove_cv<std::remove_reference<decltype(x)>::type>::type >> +#else >> +/* >> + * Use C11 _Generic to express unqualified type from expression. This removes >> + * volatile qualifier from expression type. >> + */ >> +#define rseq_unqual_scalar_typeof(x) \ >> + __typeof__( \ >> + _Generic((x), \ >> + char: (char)0, \ >> + unsigned char: (unsigned char)0, \ >> + signed char: (signed char)0, \ >> + unsigned short: (unsigned short)0, \ >> + signed short: (signed short)0, \ >> + unsigned int: (unsigned int)0, \ >> + signed int: (signed int)0, \ >> + unsigned long: (unsigned long)0, \ >> + signed long: (signed long)0, \ >> + unsigned long long: (unsigned long long)0, \ >> + signed long long: (signed long long)0, \ >> + default: (x) \ >> + ) \ >> + ) > > FWIW, I like how the kernel version uses a little helper for the > signed/unsigned pairs. Makes it a little more readable. OK, will update for next round: #define rseq_scalar_type_to_expr(type) \ unsigned type: (unsigned type)0, \ signed type: (signed type)0 /* * Use C11 _Generic to express unqualified type from expression. This removes * volatile qualifier from expression type. */ #define rseq_unqual_scalar_typeof(x) \ __typeof__( \ _Generic((x), \ char: (char)0, \ rseq_scalar_type_to_expr(char), \ rseq_scalar_type_to_expr(short), \ rseq_scalar_type_to_expr(int), \ rseq_scalar_type_to_expr(long), \ rseq_scalar_type_to_expr(long long), \ default: (x) \ ) \ ) Thanks, Mathieu > >> +#endif >> + >> #endif /* RSEQ_COMPILER_H_ */ >> -- >> 2.25.1 >>
diff --git a/tools/testing/selftests/rseq/compiler.h b/tools/testing/selftests/rseq/compiler.h index f47092bddeba..8dc7f881e253 100644 --- a/tools/testing/selftests/rseq/compiler.h +++ b/tools/testing/selftests/rseq/compiler.h @@ -33,4 +33,31 @@ #define RSEQ_COMBINE_TOKENS(_tokena, _tokenb) \ RSEQ__COMBINE_TOKENS(_tokena, _tokenb) +#ifdef __cplusplus +#define rseq_unqual_scalar_typeof(x) \ + std::remove_cv<std::remove_reference<decltype(x)>::type>::type +#else +/* + * Use C11 _Generic to express unqualified type from expression. This removes + * volatile qualifier from expression type. + */ +#define rseq_unqual_scalar_typeof(x) \ + __typeof__( \ + _Generic((x), \ + char: (char)0, \ + unsigned char: (unsigned char)0, \ + signed char: (signed char)0, \ + unsigned short: (unsigned short)0, \ + signed short: (signed short)0, \ + unsigned int: (unsigned int)0, \ + signed int: (signed int)0, \ + unsigned long: (unsigned long)0, \ + signed long: (signed long)0, \ + unsigned long long: (unsigned long long)0, \ + signed long long: (signed long long)0, \ + default: (x) \ + ) \ + ) +#endif + #endif /* RSEQ_COMPILER_H_ */