[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <F66E73EB-7237-439F-8408-C0C39B1CE2D2@zytor.com>
Date: Tue, 06 May 2025 10:54:35 -0700
From: "H. Peter Anvin" <hpa@...or.com>
To: Uros Bizjak <ubizjak@...il.com>, x86@...nel.org,
linux-kernel@...r.kernel.org
CC: Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...nel.org>,
Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
torvalds@...ux-foundation.org
Subject: Re: [PATCH -tip 1/3] x86/asm/32: Modernize memset() functions
On May 6, 2025 9:52:06 AM PDT, Uros Bizjak <ubizjak@...il.com> wrote:
>Use inout "+" constraint modifier where appropriate and declare
>temporary variable using __auto_type, similar to what x86_64 does.
>
>No functional changes intended.
>
>Signed-off-by: Uros Bizjak <ubizjak@...il.com>
>Cc: Thomas Gleixner <tglx@...utronix.de>
>Cc: Ingo Molnar <mingo@...nel.org>
>Cc: Borislav Petkov <bp@...en8.de>
>Cc: Dave Hansen <dave.hansen@...ux.intel.com>
>Cc: "H. Peter Anvin" <hpa@...or.com>
>---
> arch/x86/include/asm/string_32.h | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
>diff --git a/arch/x86/include/asm/string_32.h b/arch/x86/include/asm/string_32.h
>index e9cce169bb4c..9152d2c0f60e 100644
>--- a/arch/x86/include/asm/string_32.h
>+++ b/arch/x86/include/asm/string_32.h
>@@ -164,12 +164,12 @@ extern void *memchr(const void *cs, int c, size_t count);
>
> static inline void *__memset_generic(void *s, char c, size_t count)
> {
>- int d0, d1;
>+ const __auto_type s0 = s;
> asm volatile("rep stosb"
>- : "=&c" (d0), "=&D" (d1)
>- : "a" (c), "1" (s), "0" (count)
>+ : "+D" (s), "+c" (count)
>+ : "a" (c)
> : "memory");
>- return s;
>+ return s0;
> }
>
> /* we might want to write optimized versions of these later */
>@@ -197,23 +197,23 @@ extern void *memset(void *, int, size_t);
> #define __HAVE_ARCH_MEMSET16
> static inline void *memset16(uint16_t *s, uint16_t v, size_t n)
> {
>- int d0, d1;
>+ const __auto_type s0 = s;
> asm volatile("rep stosw"
>- : "=&c" (d0), "=&D" (d1)
>- : "a" (v), "1" (s), "0" (n)
>+ : "+D" (s), "+c" (n)
>+ : "a" (v)
> : "memory");
>- return s;
>+ return s0;
> }
>
> #define __HAVE_ARCH_MEMSET32
> static inline void *memset32(uint32_t *s, uint32_t v, size_t n)
> {
>- int d0, d1;
>+ const __auto_type s0 = s;
> asm volatile("rep stosl"
>- : "=&c" (d0), "=&D" (d1)
>- : "a" (v), "1" (s), "0" (n)
>+ : "+D" (s), "+c" (n)
>+ : "a" (v)
> : "memory");
>- return s;
>+ return s0;
> }
>
> /*
So __auto_type is spelled "auto" in newer C versions, but "auto" was a (completely useless!) keyword going all the way back to K&R C. Can anyone think of a reason why we don't do:
#define auto __auto_type
... and just start using the modern keyword right away?
-hpa
Powered by blists - more mailing lists