]> Git Repo - linux.git/commitdiff
x86/asm/64: Clean up memset16(), memset32(), memset64() assembly constraints in ...
authorAlexey Dobriyan <[email protected]>
Thu, 14 Mar 2024 16:57:15 +0000 (19:57 +0300)
committerIngo Molnar <[email protected]>
Fri, 22 Mar 2024 10:47:34 +0000 (11:47 +0100)
- Use "+" constraint modifier,
  simplify inputs and output lists,
  delete dummy variables with meaningless names,

  "&" only makes sense in complex assembly creating constraints on
  intermediate registers. But 1 instruction assemblies don't have
  inner body so to speak.

- Write "rep stos*" on one line:
  Rep prefix is integral part of x86 instruction.  I'm not sure why
  people separate "rep" with newline.

  Uros Bizjak adds context: "some archaic assemblers rejected 'rep
  insn' on one line. I have checked that the minimum required
  binutils-2.25 assembles this without problems."

- Use __auto_type for maximum copy pasta experience,

- Reformat a bit to make everything looks nicer.

Note that "memory" clobber is too much if "n" is known at compile time.
However,

"=m" (*(T(*)[n])s)

doesn't work because -Wvla even if "n" is compile time constant:

if (BCP(n)) {
rep stos
: "=m" (*(T(*)[n])s)
} else {
rep stosw
: "memory"
}

The above doesn't work.

Signed-off-by: Alexey Dobriyan <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Reviewed-by: Uros Bizjak <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
arch/x86/include/asm/string_64.h

index 857d364b98888a61aa18d375d7796eab77293e9d..9d0b324eab213a5bac319a3be854daeb0d2f15ba 100644 (file)
@@ -30,37 +30,40 @@ void *__memset(void *s, int c, size_t n);
 #define __HAVE_ARCH_MEMSET16
 static inline void *memset16(uint16_t *s, uint16_t v, size_t n)
 {
-       long d0, d1;
-       asm volatile("rep\n\t"
-                    "stosw"
-                    : "=&c" (d0), "=&D" (d1)
-                    : "a" (v), "1" (s), "0" (n)
-                    : "memory");
-       return s;
+       const __auto_type s0 = s;
+       asm volatile (
+               "rep stosw"
+               : "+D" (s), "+c" (n)
+               : "a" (v)
+               : "memory"
+       );
+       return s0;
 }
 
 #define __HAVE_ARCH_MEMSET32
 static inline void *memset32(uint32_t *s, uint32_t v, size_t n)
 {
-       long d0, d1;
-       asm volatile("rep\n\t"
-                    "stosl"
-                    : "=&c" (d0), "=&D" (d1)
-                    : "a" (v), "1" (s), "0" (n)
-                    : "memory");
-       return s;
+       const __auto_type s0 = s;
+       asm volatile (
+               "rep stosl"
+               : "+D" (s), "+c" (n)
+               : "a" (v)
+               : "memory"
+       );
+       return s0;
 }
 
 #define __HAVE_ARCH_MEMSET64
 static inline void *memset64(uint64_t *s, uint64_t v, size_t n)
 {
-       long d0, d1;
-       asm volatile("rep\n\t"
-                    "stosq"
-                    : "=&c" (d0), "=&D" (d1)
-                    : "a" (v), "1" (s), "0" (n)
-                    : "memory");
-       return s;
+       const __auto_type s0 = s;
+       asm volatile (
+               "rep stosq"
+               : "+D" (s), "+c" (n)
+               : "a" (v)
+               : "memory"
+       );
+       return s0;
 }
 #endif
 
This page took 0.062209 seconds and 4 git commands to generate.