Skip to content

Commit 4c9a938

Browse files
Alexey DobriyanIngo Molnar
authored andcommitted
x86/asm/64: Clean up memset16(), memset32(), memset64() assembly constraints in <asm/string_64.h>
- 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]
1 parent 6483371 commit 4c9a938

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

arch/x86/include/asm/string_64.h

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,40 @@ void *__memset(void *s, int c, size_t n);
3030
#define __HAVE_ARCH_MEMSET16
3131
static inline void *memset16(uint16_t *s, uint16_t v, size_t n)
3232
{
33-
long d0, d1;
34-
asm volatile("rep\n\t"
35-
"stosw"
36-
: "=&c" (d0), "=&D" (d1)
37-
: "a" (v), "1" (s), "0" (n)
38-
: "memory");
39-
return s;
33+
const __auto_type s0 = s;
34+
asm volatile (
35+
"rep stosw"
36+
: "+D" (s), "+c" (n)
37+
: "a" (v)
38+
: "memory"
39+
);
40+
return s0;
4041
}
4142

4243
#define __HAVE_ARCH_MEMSET32
4344
static inline void *memset32(uint32_t *s, uint32_t v, size_t n)
4445
{
45-
long d0, d1;
46-
asm volatile("rep\n\t"
47-
"stosl"
48-
: "=&c" (d0), "=&D" (d1)
49-
: "a" (v), "1" (s), "0" (n)
50-
: "memory");
51-
return s;
46+
const __auto_type s0 = s;
47+
asm volatile (
48+
"rep stosl"
49+
: "+D" (s), "+c" (n)
50+
: "a" (v)
51+
: "memory"
52+
);
53+
return s0;
5254
}
5355

5456
#define __HAVE_ARCH_MEMSET64
5557
static inline void *memset64(uint64_t *s, uint64_t v, size_t n)
5658
{
57-
long d0, d1;
58-
asm volatile("rep\n\t"
59-
"stosq"
60-
: "=&c" (d0), "=&D" (d1)
61-
: "a" (v), "1" (s), "0" (n)
62-
: "memory");
63-
return s;
59+
const __auto_type s0 = s;
60+
asm volatile (
61+
"rep stosq"
62+
: "+D" (s), "+c" (n)
63+
: "a" (v)
64+
: "memory"
65+
);
66+
return s0;
6467
}
6568
#endif
6669

0 commit comments

Comments
 (0)