x86/boot: Remove semicolon from "rep" prefixes
Subsystems (4)
PATCH v2 1/2 x86/boot: Remove semicolon from "rep" prefixes
Minimum version of binutils required to compile the kernel is 2.25. This version correctly handles the "rep" prefixes, so it is possible to remove the semicolon, which was used to support ancient versions of GNU as.
Due to the semicolon, the compiler considers "rep; insn" (or its alternate "rep\n\tinsn" form) as two separate instructions. Removing the semicolon makes asm length calculations more accurate, consequently making scheduling and inlining decisions of the compiler more accurate.
Removing the semicolon also enables assembler checks involving "rep" prefixes. Trying to assemble e.g. "rep addl %eax, %ebx" results in:
Error: invalid instruction add' after rep'
---
v2: Split the patch from the previous version.
--- arch/x86/boot/bioscall.S | 4 ++-- arch/x86/boot/boot.h | 4 ++-- arch/x86/boot/compressed/string.c | 8 ++++---- arch/x86/boot/copy.S | 8 ++++---- arch/x86/boot/header.S | 2 +- arch/x86/boot/string.c | 2 +- arch/x86/boot/video.c | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-)
arch/x86/boot/bioscall.S +2 -2
@@ -32,7 +32,7 @@ intcall: movw %dx, %si movw %sp, %di movw $11, %cx - rep; movsl + rep movsl /* Pop full state from the stack */ popal
@@ -67,7 +67,7 @@ intcall: jz 4f movw %sp, %si movw $11, %cx - rep; movsl + rep movsl 4: addw $44, %sp /* Restore state and return */
arch/x86/boot/boot.h +2 -2
@@ -155,14 +155,14 @@ static inline void wrgs32(u32 v, addr_t addr)static inline bool memcmp_fs (const void *s1,addr_t s2,size_t len) {bool diff; - asm volatile("fs; repe; cmpsb" CC_SET(nz) + asm volatile("fs repe cmpsb" CC_SET(nz) : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }static inline bool memcmp_gs (const void *s1,addr_t s2,size_t len) {bool diff; - asm volatile("gs; repe; cmpsb" CC_SET(nz) + asm volatile("gs repe cmpsb" CC_SET(nz) : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }
arch/x86/boot/compressed/string.c +4 -4
@@ -15,9 +15,9 @@ static void *____memcpy(void *dest, const void *src, size_t n) {int d0, d1, d2; asmvolatile ( -"rep ; movsl\n\t" +"rep movsl\n\t" "movl %4,%%ecx\n\t" -"rep ; movsb\n\t" +"rep movsb" :"=&c" (d0),"=&D" (d1),"=&S" (d2) :"0" (n >>2 ),"g" (n &3 ),"1" (dest),"2" (src) :"memory" );
@@ -29,9 +29,9 @@ static void *____memcpy(void *dest, const void *src, size_t n) {long d0, d1, d2; asmvolatile ( -"rep ; movsq\n\t" +"rep movsq\n\t" "movq %4,%%rcx\n\t" -"rep ; movsb\n\t" +"rep movsb" :"=&c" (d0),"=&D" (d1),"=&S" (d2) :"0" (n >>3 ),"g" (n &7 ),"1" (dest),"2" (src) :"memory" );
arch/x86/boot/copy.S +4 -4
@@ -22,10 +22,10 @@ SYM_FUNC_START_NOALIGN(memcpy) movw %dx, %si pushw %cx shrw $2, %cx - rep; movsl + rep movsl popw %cx andw $3, %cx - rep; movsb + rep movsb popw %di popw %si retl
@@ -38,10 +38,10 @@ SYM_FUNC_START_NOALIGN(memset) imull $0x01010101,%eax pushw %cx shrw $2, %cx - rep; stosl + rep stosl popw %cx andw $3, %cx - rep; stosb + rep stosb popw %di retl SYM_FUNC_END(memset)
arch/x86/boot/header.S +1 -1
@@ -585,7 +585,7 @@ start_of_setup: xorl %eax, %eax subw %di, %cx shrw $2, %cx - rep; stosl + rep stosl # Jump to C code (should not return) calll main
arch/x86/boot/string.c +1 -1
@@ -32,7 +32,7 @@int memcmp (const void *s1,const void *s2,size_t len) {bool diff; - asm("repe; cmpsb" CC_SET(nz) + asm("repe cmpsb" CC_SET(nz) : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }
arch/x86/boot/video.c +1 -1
@@ -292,7 +292,7 @@ static void restore_screen(void)"shrw %%cx ; " "jnc 1f ; " "stosw \n\t" -"1: rep;stosl ; " +"1: rep stosl ; " "popw %%es" : "+D" (dst), "+c" (npad) : "bdS" (video_segment),
Signature · 1 line
2.49.0
PATCH v2 2/2 x86/asm: Remove semicolon from "rep" prefixes
Minimum version of binutils required to compile the kernel is 2.25. This version correctly handles the "rep" prefixes, so it is possible to remove the semicolon, which was used to support ancient versions of GNU as.
Due to the semicolon, the compiler considers "rep; insn" (or its alternate "rep\n\tinsn" form) as two separate instructions. Removing the semicolon makes asm length calculations more accurate, consequently making scheduling and inlining decisions of the compiler more accurate.
Removing the semicolon also enables assembler checks involving "rep" prefixes. Trying to assemble e.g. "rep addl %eax, %ebx" results in:
Error: invalid instruction add' after rep'
---
v2: Split the patch from the previous version.
--- arch/x86/include/asm/io.h | 6 +++--- arch/x86/include/asm/string_32.h | 15 ++++++--------- arch/x86/kernel/head_32.S | 8 +++----- arch/x86/kernel/relocate_kernel_32.S | 6 +++--- arch/x86/kernel/relocate_kernel_64.S | 6 +++--- arch/x86/lib/iomem.c | 2 +- arch/x86/lib/string_32.c | 17 ++++++----------- arch/x86/lib/strstr_32.c | 6 ++---- arch/x86/lib/usercopy_32.c | 18 +++++++++--------- arch/x86/platform/pvh/head.S | 3 +-- arch/x86/power/hibernate_asm_32.S | 3 +-- arch/x86/power/hibernate_asm_64.S | 3 +-- 12 files changed, 39 insertions(+), 54 deletions(-)
arch/x86/include/asm/io.h +3 -3
@@ -217,7 +217,7 @@ void memset_io(volatile void __iomem *, int, size_t);static inline void __iowrite32_copy (void __iomem *to,const void *from,size_t count) { - asmvolatile ("rep ; movsl" + asmvolatile ("rep movsl" :"=&c" (count),"=&D" (to),"=&S" (from) :"0" (count),"1" (to),"2" (from) :"memory" );
@@ -282,7 +282,7 @@ static inline void outs##bwl(u16 port, const void *addr, unsigned long count) \ count--; \ } \ }else { \ - asm volatile("rep; outs" #bwl \ + asm volatile("rep outs" #bwl \ :"+S" (addr),"+c" (count) \ :"d" (port) :"memory" ); \ } \
@@ -298,7 +298,7 @@ static inline void ins##bwl(u16 port, void *addr, unsigned long count) \ count--; \ } \ }else { \ - asm volatile("rep; ins" #bwl \ + asm volatile("rep ins" #bwl \ :"+D" (addr),"+c" (count) \ :"d" (port) :"memory" ); \ } \
arch/x86/include/asm/string_32.h +6 -9
@@ -33,11 +33,11 @@ extern size_t strlen(const char *s); static __always_inline void *__memcpy(void *to, const void *from, size_t n) {int d0, d1, d2; - asmvolatile ("rep ; movsl\n\t" + asmvolatile ("rep movsl\n\t" "movl %4,%%ecx\n\t" "andl $3,%%ecx\n\t" "jz 1f\n\t" -"rep ; movsb\n\t" +"rep movsb\n\t" "1:" :"=&c" (d0),"=&D" (d1),"=&S" (d2) : "0" (n / 4), "g" (n), "1" ((long)to), "2" ((long)from)
@@ -89,7 +89,7 @@ static __always_inline void *__constant_memcpy(void *to, const void *from,if (n >=5 *4 ) {/* large block: use rep prefix */ int ecx; - asmvolatile ("rep ; movsl" + asmvolatile ("rep movsl" :"=&c" (ecx),"=&D" (edi),"=&S" (esi) :"0" (n /4 ),"1" (edi),"2" (esi) : "memory"
@@ -165,8 +165,7 @@ 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; - asmvolatile ("rep\n\t" -"stosb" + asmvolatile ("rep stosb" :"=&c" (d0),"=&D" (d1) :"a" (c),"1" (s),"0" (count) :"memory" );
@@ -199,8 +198,7 @@ extern void *memset(void *, int, size_t);static inline void *memset16 (uint16_t *s,uint16_t v,size_t n) {int d0, d1; - asmvolatile ("rep\n\t" -"stosw" + asmvolatile ("rep stosw" :"=&c" (d0),"=&D" (d1) :"a" (v),"1" (s),"0" (n) :"memory" );
@@ -211,8 +209,7 @@ static inline void *memset16(uint16_t *s, uint16_t v, size_t n)static inline void *memset32 (uint32_t *s,uint32_t v,size_t n) {int d0, d1; - asmvolatile ("rep\n\t" -"stosl" + asmvolatile ("rep stosl" :"=&c" (d0),"=&D" (d1) :"a" (v),"1" (s),"0" (n) :"memory" );
arch/x86/kernel/head_32.S +3 -5
@@ -86,7 +86,7 @@ SYM_CODE_START(startup_32) movl $pa(__bss_stop),%ecx subl %edi,%ecx shrl $2,%ecx - rep ; stosl + rep stosl /* * Copy bootup parameters out of the way. * Note: %esi still has the pointer to the real-mode data.
@@ -98,15 +98,13 @@ SYM_CODE_START(startup_32) movl $pa(boot_params),%edi movl $(PARAM_SIZE/4),%ecx cld - rep - movsl + rep movsl movl pa(boot_params) + NEW_CL_POINTER,%esi andl %esi,%esi jz 1f # No command line movl $pa(boot_command_line),%edi movl $(COMMAND_LINE_SIZE/4),%ecx - rep - movsl + rep movsl 1: #ifdef CONFIG_OLPC
arch/x86/kernel/relocate_kernel_32.S +3 -3
@@ -263,17 +263,17 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) movl %edx, %edi movl $1024, %ecx - rep ; movsl + rep movsl movl %ebp, %edi movl %eax, %esi movl $1024, %ecx - rep ; movsl + rep movsl movl %eax, %edi movl %edx, %esi movl $1024, %ecx - rep ; movsl + rep movsl lea PAGE_SIZE(%ebp), %esi jmp 0b
arch/x86/kernel/relocate_kernel_64.S +3 -3
@@ -363,20 +363,20 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) /* copy source page to swap page */ movq kexec_pa_swap_page(%rip), %rdi movl $512, %ecx - rep ; movsq + rep movsq /* copy destination page to source page */ movq %rax, %rdi movq %rdx, %rsi movl $512, %ecx - rep ; movsq + rep movsq /* copy swap page to destination page */ movq %rdx, %rdi movq kexec_pa_swap_page(%rip), %rsi .Lnoswap: movl $512, %ecx - rep ; movsq + rep movsq lea PAGE_SIZE(%rax), %rsi jmp .Lloop
arch/x86/lib/iomem.c +1 -1
@@ -10,7 +10,7 @@ static __always_inline void rep_movs(void *to, const void *from, size_t n) {unsigned long d0, d1, d2; - asmvolatile ("rep ; movsl\n\t" + asmvolatile ("rep movsl\n\t" "testb $2,%b4\n\t" "je 1f\n\t" "movsw\n"
arch/x86/lib/string_32.c +6 -11
@@ -40,8 +40,7 @@ char *strncpy(char *dest, const char *src, size_t count)"stosb\n\t" "testb %%al,%%al\n\t" "jne 1b\n\t" -"rep\n\t" -"stosb\n" +"rep stosb\n" "2:" : "=&S" (d0), "=&D" (d1), "=&c" (d2), "=&a" (d3) : "0" (src), "1" (dest), "2" (count) : "memory");
@@ -54,8 +53,7 @@ EXPORT_SYMBOL(strncpy);char *strcat (char *dest,const char *src) {int d0, d1, d2, d3; - asmvolatile ("repne\n\t" -"scasb\n\t" + asmvolatile ("repne scasb\n\t" "decl %1\n" "1:\tlodsb\n\t" "stosb\n\t"
@@ -72,8 +70,7 @@ EXPORT_SYMBOL(strcat);char *strncat (char *dest,const char *src,size_t count) {int d0, d1, d2, d3; - asmvolatile ("repne\n\t" -"scasb\n\t" + asmvolatile ("repne scasb\n\t" "decl %1\n\t" "movl %8,%3\n" "1:\tdecl %3\n\t"
@@ -167,8 +164,7 @@ size_t strlen(const char *s) {int d0;size_t res; - asmvolatile ("repne\n\t" -"scasb" + asmvolatile ("repne scasb" :"=c" (res),"=&D" (d0) :"1" (s),"a" (0 ),"0" (0xffffffffu ) :"memory" );
@@ -184,8 +180,7 @@ void *memchr(const void *cs, int c, size_t count)void *res;if (!count)return NULL ; - asmvolatile ("repne\n\t" -"scasb\n\t" + asmvolatile ("repne scasb\n\t" "je 1f\n\t" "movl $1,%0\n" "1:\tdecl %0"
@@ -202,7 +197,7 @@ void *memscan(void *addr, int c, size_t size) {if (!size)return addr; - asmvolatile ("repnz; scasb\n\t" + asmvolatile ("repnz scasb\n\t" "jnz 1f\n\t" "dec %%edi\n" "1:"
arch/x86/lib/strstr_32.c +2 -4
@@ -8,16 +8,14 @@ int d0, d1; registerchar *__res; __asm__ __volatile__("movl %6,%%edi\n\t" -"repne\n\t" -"scasb\n\t" +"repne scasb\n\t" "notl %%ecx\n\t" "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ "movl %%ecx,%%edx\n" "1:\tmovl %6,%%edi\n\t" "movl %%esi,%%eax\n\t" "movl %%edx,%%ecx\n\t" -"repe\n\t" -"cmpsb\n\t" +"repe cmpsb\n\t" "je 2f\n\t" /* also works for empty string, see above */ "xchgl %%eax,%%esi\n\t" "incl %%esi\n\t"
arch/x86/lib/usercopy_32.c +9 -9
@@ -38,9 +38,9 @@ do { \might_fault (); \ __asm__ __volatile__( \ASM_STAC "\n" \ -"0: rep; stosl\n" \ +"0: rep stosl\n" \" movl %2,%0\n" \ -"1: rep; stosb\n" \ +"1: rep stosb\n" \"2: " ASM_CLAC "\n" \ _ASM_EXTABLE_TYPE_REG(0b, 2b, EX_TYPE_UCOPY_LEN4, %2) \_ASM_EXTABLE_UA (1b ,2b ) \
@@ -140,9 +140,9 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)" shrl $2, %0\n" " andl $3, %%eax\n" " cld\n" -"99: rep; movsl\n" +"99: rep movsl\n" "36: movl %%eax, %0\n" -"37: rep; movsb\n" +"37: rep movsb\n" "100:\n" _ASM_EXTABLE_UA(1b, 100b)_ASM_EXTABLE_UA (2b ,100b )
@@ -242,9 +242,9 @@ static unsigned long __copy_user_intel_nocache(void *to," shrl $2, %0\n" " andl $3, %%eax\n" " cld\n" -"6: rep; movsl\n" +"6: rep movsl\n" " movl %%eax,%0\n" -"7: rep; movsb\n" +"7: rep movsb\n" "8:\n" _ASM_EXTABLE_UA(0b, 8b)_ASM_EXTABLE_UA (1b ,8b )
@@ -293,14 +293,14 @@ do { \" negl %0\n" \" andl $7,%0\n" \" subl %0,%3\n" \ -"4: rep; movsb\n" \ +"4: rep movsb\n" \" movl %3,%0\n" \" shrl $2,%0\n" \" andl $3,%3\n" \" .align 2,0x90\n" \ -"0: rep; movsl\n" \ +"0: rep movsl\n" \" movl %3,%0\n" \ -"1: rep; movsb\n" \ +"1: rep movsb\n" \"2:\n" \ _ASM_EXTABLE_TYPE_REG(4b, 2b, EX_TYPE_UCOPY_LEN1, %3) \ _ASM_EXTABLE_TYPE_REG(0b, 2b, EX_TYPE_UCOPY_LEN4, %3) \
arch/x86/platform/pvh/head.S +1 -2
@@ -87,8 +87,7 @@ SYM_CODE_START(pvh_start_xen) mov %ebx, %esi movl rva(pvh_start_info_sz)(%ebp), %ecx shr $2,%ecx - rep - movsl + rep movsl leal rva(early_stack_end)(%ebp), %esp
arch/x86/power/hibernate_asm_32.S +1 -2
@@ -69,8 +69,7 @@ copy_loop: movl pbe_orig_address(%edx), %edi movl $(PAGE_SIZE >> 2), %ecx - rep - movsl + rep movsl movl pbe_next(%edx), %edx jmp copy_loop
arch/x86/power/hibernate_asm_64.S +1 -2
@@ -138,8 +138,7 @@ SYM_FUNC_START(core_restore_code) movq pbe_address(%rdx), %rsi movq pbe_orig_address(%rdx), %rdi movq $(PAGE_SIZE >> 3), %rcx - rep - movsq + rep movsq /* progress to the next pbe */ movq pbe_next(%rdx), %rdx
Signature · 1 line
2.49.0
[tip: x86/asm] x86/asm: Remove semicolon from "rep" prefixes
The following commit has been merged into the x86/asm branch of tip:
The following commit has been merged into the x86/asm branch of tip:
Commit-ID: 42c782fae38f0559e6355707ee0afde9ac16dcc3 Gitweb: https://git.kernel.org/tip/42c782fae38f0559e6355707ee0afde9ac16dcc3 Author: Uros Bizjak <[email protected]> AuthorDate: Fri, 18 Apr 2025 09:13:51 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 18 Apr 2025 09:33:33 +02:00
x86/asm: Remove semicolon from "rep" prefixes
Minimum version of binutils required to compile the kernel is 2.25. This version correctly handles the "rep" prefixes, so it is possible to remove the semicolon, which was used to support ancient versions of GNU as.
Due to the semicolon, the compiler considers "rep; insn" (or its alternate "rep\n\tinsn" form) as two separate instructions. Removing the semicolon makes asm length calculations more accurate, consequently making scheduling and inlining decisions of the compiler more accurate.
Removing the semicolon also enables assembler checks involving "rep" prefixes. Trying to assemble e.g. "rep addl %eax, %ebx" results in:
Error: invalid instruction add' after rep'
--- arch/x86/include/asm/io.h | 6 +++--- arch/x86/include/asm/string_32.h | 15 ++++++--------- arch/x86/kernel/head_32.S | 8 +++----- arch/x86/kernel/relocate_kernel_32.S | 6 +++--- arch/x86/kernel/relocate_kernel_64.S | 6 +++--- arch/x86/lib/iomem.c | 2 +- arch/x86/lib/string_32.c | 17 ++++++----------- arch/x86/lib/strstr_32.c | 6 ++---- arch/x86/lib/usercopy_32.c | 18 +++++++++--------- arch/x86/platform/pvh/head.S | 3 +-- arch/x86/power/hibernate_asm_32.S | 3 +-- arch/x86/power/hibernate_asm_64.S | 3 +-- 12 files changed, 39 insertions(+), 54 deletions(-)
arch/x86/include/asm/io.h +3 -3
@@ -217,7 +217,7 @@ void memset_io(volatile void __iomem *, int, size_t);static inline void __iowrite32_copy (void __iomem *to,const void *from,size_t count) { - asmvolatile ("rep ; movsl" + asmvolatile ("rep movsl" :"=&c" (count),"=&D" (to),"=&S" (from) :"0" (count),"1" (to),"2" (from) :"memory" );
@@ -282,7 +282,7 @@ static inline void outs##bwl(u16 port, const void *addr, unsigned long count) \ count--; \ } \ }else { \ - asm volatile("rep; outs" #bwl \ + asm volatile("rep outs" #bwl \ :"+S" (addr),"+c" (count) \ :"d" (port) :"memory" ); \ } \
@@ -298,7 +298,7 @@ static inline void ins##bwl(u16 port, void *addr, unsigned long count) \ count--; \ } \ }else { \ - asm volatile("rep; ins" #bwl \ + asm volatile("rep ins" #bwl \ :"+D" (addr),"+c" (count) \ :"d" (port) :"memory" ); \ } \
arch/x86/include/asm/string_32.h +6 -9
@@ -33,11 +33,11 @@ extern size_t strlen(const char *s); static __always_inline void *__memcpy(void *to, const void *from, size_t n) {int d0, d1, d2; - asmvolatile ("rep ; movsl\n\t" + asmvolatile ("rep movsl\n\t" "movl %4,%%ecx\n\t" "andl $3,%%ecx\n\t" "jz 1f\n\t" -"rep ; movsb\n\t" +"rep movsb\n\t" "1:" :"=&c" (d0),"=&D" (d1),"=&S" (d2) : "0" (n / 4), "g" (n), "1" ((long)to), "2" ((long)from)
@@ -89,7 +89,7 @@ static __always_inline void *__constant_memcpy(void *to, const void *from,if (n >=5 *4 ) {/* large block: use rep prefix */ int ecx; - asmvolatile ("rep ; movsl" + asmvolatile ("rep movsl" :"=&c" (ecx),"=&D" (edi),"=&S" (esi) :"0" (n /4 ),"1" (edi),"2" (esi) : "memory"
@@ -165,8 +165,7 @@ 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; - asmvolatile ("rep\n\t" -"stosb" + asmvolatile ("rep stosb" :"=&c" (d0),"=&D" (d1) :"a" (c),"1" (s),"0" (count) :"memory" );
@@ -199,8 +198,7 @@ extern void *memset(void *, int, size_t);static inline void *memset16 (uint16_t *s,uint16_t v,size_t n) {int d0, d1; - asmvolatile ("rep\n\t" -"stosw" + asmvolatile ("rep stosw" :"=&c" (d0),"=&D" (d1) :"a" (v),"1" (s),"0" (n) :"memory" );
@@ -211,8 +209,7 @@ static inline void *memset16(uint16_t *s, uint16_t v, size_t n)static inline void *memset32 (uint32_t *s,uint32_t v,size_t n) {int d0, d1; - asmvolatile ("rep\n\t" -"stosl" + asmvolatile ("rep stosl" :"=&c" (d0),"=&D" (d1) :"a" (v),"1" (s),"0" (n) :"memory" );
arch/x86/kernel/head_32.S +3 -5
@@ -86,7 +86,7 @@ SYM_CODE_START(startup_32) movl $pa(__bss_stop),%ecx subl %edi,%ecx shrl $2,%ecx - rep ; stosl + rep stosl /* * Copy bootup parameters out of the way. * Note: %esi still has the pointer to the real-mode data.
@@ -98,15 +98,13 @@ SYM_CODE_START(startup_32) movl $pa(boot_params),%edi movl $(PARAM_SIZE/4),%ecx cld - rep - movsl + rep movsl movl pa(boot_params) + NEW_CL_POINTER,%esi andl %esi,%esi jz 1f # No command line movl $pa(boot_command_line),%edi movl $(COMMAND_LINE_SIZE/4),%ecx - rep - movsl + rep movsl 1: #ifdef CONFIG_OLPC
arch/x86/kernel/relocate_kernel_32.S +3 -3
@@ -263,17 +263,17 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) movl %edx, %edi movl $1024, %ecx - rep ; movsl + rep movsl movl %ebp, %edi movl %eax, %esi movl $1024, %ecx - rep ; movsl + rep movsl movl %eax, %edi movl %edx, %esi movl $1024, %ecx - rep ; movsl + rep movsl lea PAGE_SIZE(%ebp), %esi jmp 0b
arch/x86/kernel/relocate_kernel_64.S +3 -3
@@ -363,20 +363,20 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) /* copy source page to swap page */ movq kexec_pa_swap_page(%rip), %rdi movl $512, %ecx - rep ; movsq + rep movsq /* copy destination page to source page */ movq %rax, %rdi movq %rdx, %rsi movl $512, %ecx - rep ; movsq + rep movsq /* copy swap page to destination page */ movq %rdx, %rdi movq kexec_pa_swap_page(%rip), %rsi .Lnoswap: movl $512, %ecx - rep ; movsq + rep movsq lea PAGE_SIZE(%rax), %rsi jmp .Lloop
arch/x86/lib/iomem.c +1 -1
@@ -10,7 +10,7 @@ static __always_inline void rep_movs(void *to, const void *from, size_t n) {unsigned long d0, d1, d2; - asmvolatile ("rep ; movsl\n\t" + asmvolatile ("rep movsl\n\t" "testb $2,%b4\n\t" "je 1f\n\t" "movsw\n"
arch/x86/lib/string_32.c +6 -11
@@ -40,8 +40,7 @@ char *strncpy(char *dest, const char *src, size_t count)"stosb\n\t" "testb %%al,%%al\n\t" "jne 1b\n\t" -"rep\n\t" -"stosb\n" +"rep stosb\n" "2:" : "=&S" (d0), "=&D" (d1), "=&c" (d2), "=&a" (d3) : "0" (src), "1" (dest), "2" (count) : "memory");
@@ -54,8 +53,7 @@ EXPORT_SYMBOL(strncpy);char *strcat (char *dest,const char *src) {int d0, d1, d2, d3; - asmvolatile ("repne\n\t" -"scasb\n\t" + asmvolatile ("repne scasb\n\t" "decl %1\n" "1:\tlodsb\n\t" "stosb\n\t"
@@ -72,8 +70,7 @@ EXPORT_SYMBOL(strcat);char *strncat (char *dest,const char *src,size_t count) {int d0, d1, d2, d3; - asmvolatile ("repne\n\t" -"scasb\n\t" + asmvolatile ("repne scasb\n\t" "decl %1\n\t" "movl %8,%3\n" "1:\tdecl %3\n\t"
@@ -167,8 +164,7 @@ size_t strlen(const char *s) {int d0;size_t res; - asmvolatile ("repne\n\t" -"scasb" + asmvolatile ("repne scasb" :"=c" (res),"=&D" (d0) :"1" (s),"a" (0 ),"0" (0xffffffffu ) :"memory" );
@@ -184,8 +180,7 @@ void *memchr(const void *cs, int c, size_t count)void *res;if (!count)return NULL ; - asmvolatile ("repne\n\t" -"scasb\n\t" + asmvolatile ("repne scasb\n\t" "je 1f\n\t" "movl $1,%0\n" "1:\tdecl %0"
@@ -202,7 +197,7 @@ void *memscan(void *addr, int c, size_t size) {if (!size)return addr; - asmvolatile ("repnz; scasb\n\t" + asmvolatile ("repnz scasb\n\t" "jnz 1f\n\t" "dec %%edi\n" "1:"
arch/x86/lib/strstr_32.c +2 -4
@@ -8,16 +8,14 @@ int d0, d1; registerchar *__res; __asm__ __volatile__("movl %6,%%edi\n\t" -"repne\n\t" -"scasb\n\t" +"repne scasb\n\t" "notl %%ecx\n\t" "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */ "movl %%ecx,%%edx\n" "1:\tmovl %6,%%edi\n\t" "movl %%esi,%%eax\n\t" "movl %%edx,%%ecx\n\t" -"repe\n\t" -"cmpsb\n\t" +"repe cmpsb\n\t" "je 2f\n\t" /* also works for empty string, see above */ "xchgl %%eax,%%esi\n\t" "incl %%esi\n\t"
arch/x86/lib/usercopy_32.c +9 -9
@@ -38,9 +38,9 @@ do { \might_fault (); \ __asm__ __volatile__( \ASM_STAC "\n" \ -"0: rep; stosl\n" \ +"0: rep stosl\n" \" movl %2,%0\n" \ -"1: rep; stosb\n" \ +"1: rep stosb\n" \"2: " ASM_CLAC "\n" \ _ASM_EXTABLE_TYPE_REG(0b, 2b, EX_TYPE_UCOPY_LEN4, %2) \_ASM_EXTABLE_UA (1b ,2b ) \
@@ -140,9 +140,9 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)" shrl $2, %0\n" " andl $3, %%eax\n" " cld\n" -"99: rep; movsl\n" +"99: rep movsl\n" "36: movl %%eax, %0\n" -"37: rep; movsb\n" +"37: rep movsb\n" "100:\n" _ASM_EXTABLE_UA(1b, 100b)_ASM_EXTABLE_UA (2b ,100b )
@@ -242,9 +242,9 @@ static unsigned long __copy_user_intel_nocache(void *to," shrl $2, %0\n" " andl $3, %%eax\n" " cld\n" -"6: rep; movsl\n" +"6: rep movsl\n" " movl %%eax,%0\n" -"7: rep; movsb\n" +"7: rep movsb\n" "8:\n" _ASM_EXTABLE_UA(0b, 8b)_ASM_EXTABLE_UA (1b ,8b )
@@ -293,14 +293,14 @@ do { \" negl %0\n" \" andl $7,%0\n" \" subl %0,%3\n" \ -"4: rep; movsb\n" \ +"4: rep movsb\n" \" movl %3,%0\n" \" shrl $2,%0\n" \" andl $3,%3\n" \" .align 2,0x90\n" \ -"0: rep; movsl\n" \ +"0: rep movsl\n" \" movl %3,%0\n" \ -"1: rep; movsb\n" \ +"1: rep movsb\n" \"2:\n" \ _ASM_EXTABLE_TYPE_REG(4b, 2b, EX_TYPE_UCOPY_LEN1, %3) \ _ASM_EXTABLE_TYPE_REG(0b, 2b, EX_TYPE_UCOPY_LEN4, %3) \
arch/x86/platform/pvh/head.S +1 -2
@@ -87,8 +87,7 @@ SYM_CODE_START(pvh_start_xen) mov %ebx, %esi movl rva(pvh_start_info_sz)(%ebp), %ecx shr $2,%ecx - rep - movsl + rep movsl leal rva(early_stack_end)(%ebp), %esp
arch/x86/power/hibernate_asm_32.S +1 -2
@@ -69,8 +69,7 @@ copy_loop: movl pbe_orig_address(%edx), %edi movl $(PAGE_SIZE >> 2), %ecx - rep - movsl + rep movsl movl pbe_next(%edx), %edx jmp copy_loop
arch/x86/power/hibernate_asm_64.S +1 -2
@@ -138,8 +138,7 @@ SYM_FUNC_START(core_restore_code) movq pbe_address(%rdx), %rsi movq pbe_orig_address(%rdx), %rdi movq $(PAGE_SIZE >> 3), %rcx - rep - movsq + rep movsq /* progress to the next pbe */ movq pbe_next(%rdx), %rdx
The following commit has been merged into the x86/boot branch of tip:
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 0dcc51477b94d87f23aeb400b78fbdfb09363000 Gitweb: https://git.kernel.org/tip/0dcc51477b94d87f23aeb400b78fbdfb09363000 Author: Uros Bizjak <[email protected]> AuthorDate: Fri, 18 Apr 2025 09:13:50 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 18 Apr 2025 09:32:57 +02:00
x86/boot: Remove semicolon from "rep" prefixes
Minimum version of binutils required to compile the kernel is 2.25. This version correctly handles the "rep" prefixes, so it is possible to remove the semicolon, which was used to support ancient versions of GNU as.
Due to the semicolon, the compiler considers "rep; insn" (or its alternate "rep\n\tinsn" form) as two separate instructions. Removing the semicolon makes asm length calculations more accurate, consequently making scheduling and inlining decisions of the compiler more accurate.
Removing the semicolon also enables assembler checks involving "rep" prefixes. Trying to assemble e.g. "rep addl %eax, %ebx" results in:
Error: invalid instruction add' after rep'
--- arch/x86/boot/bioscall.S | 4 ++-- arch/x86/boot/boot.h | 4 ++-- arch/x86/boot/compressed/string.c | 8 ++++---- arch/x86/boot/copy.S | 8 ++++---- arch/x86/boot/header.S | 2 +- arch/x86/boot/string.c | 2 +- arch/x86/boot/video.c | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-)
arch/x86/boot/bioscall.S +2 -2
@@ -32,7 +32,7 @@ intcall: movw %dx, %si movw %sp, %di movw $11, %cx - rep; movsl + rep movsl /* Pop full state from the stack */ popal
@@ -67,7 +67,7 @@ intcall: jz 4f movw %sp, %si movw $11, %cx - rep; movsl + rep movsl 4: addw $44, %sp /* Restore state and return */
arch/x86/boot/boot.h +2 -2
@@ -155,14 +155,14 @@ static inline void wrgs32(u32 v, addr_t addr)static inline bool memcmp_fs (const void *s1,addr_t s2,size_t len) {bool diff; - asm volatile("fs; repe; cmpsb" CC_SET(nz) + asm volatile("fs repe cmpsb" CC_SET(nz) : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }static inline bool memcmp_gs (const void *s1,addr_t s2,size_t len) {bool diff; - asm volatile("gs; repe; cmpsb" CC_SET(nz) + asm volatile("gs repe cmpsb" CC_SET(nz) : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }
arch/x86/boot/compressed/string.c +4 -4
@@ -15,9 +15,9 @@ static void *____memcpy(void *dest, const void *src, size_t n) {int d0, d1, d2; asmvolatile ( -"rep ; movsl\n\t" +"rep movsl\n\t" "movl %4,%%ecx\n\t" -"rep ; movsb\n\t" +"rep movsb" :"=&c" (d0),"=&D" (d1),"=&S" (d2) :"0" (n >>2 ),"g" (n &3 ),"1" (dest),"2" (src) :"memory" );
@@ -29,9 +29,9 @@ static void *____memcpy(void *dest, const void *src, size_t n) {long d0, d1, d2; asmvolatile ( -"rep ; movsq\n\t" +"rep movsq\n\t" "movq %4,%%rcx\n\t" -"rep ; movsb\n\t" +"rep movsb" :"=&c" (d0),"=&D" (d1),"=&S" (d2) :"0" (n >>3 ),"g" (n &7 ),"1" (dest),"2" (src) :"memory" );
arch/x86/boot/copy.S +4 -4
@@ -22,10 +22,10 @@ SYM_FUNC_START_NOALIGN(memcpy) movw %dx, %si pushw %cx shrw $2, %cx - rep; movsl + rep movsl popw %cx andw $3, %cx - rep; movsb + rep movsb popw %di popw %si retl
@@ -38,10 +38,10 @@ SYM_FUNC_START_NOALIGN(memset) imull $0x01010101,%eax pushw %cx shrw $2, %cx - rep; stosl + rep stosl popw %cx andw $3, %cx - rep; stosb + rep stosb popw %di retl SYM_FUNC_END(memset)
arch/x86/boot/header.S +1 -1
@@ -585,7 +585,7 @@ start_of_setup: xorl %eax, %eax subw %di, %cx shrw $2, %cx - rep; stosl + rep stosl # Jump to C code (should not return) calll main
arch/x86/boot/string.c +1 -1
@@ -32,7 +32,7 @@int memcmp (const void *s1,const void *s2,size_t len) {bool diff; - asm("repe; cmpsb" CC_SET(nz) + asm("repe cmpsb" CC_SET(nz) : CC_OUT(nz) (diff), "+D" (s1), "+S" (s2), "+c" (len));return diff; }
arch/x86/boot/video.c +1 -1
@@ -292,7 +292,7 @@ static void restore_screen(void)"shrw %%cx ; " "jnc 1f ; " "stosw \n\t" -"1: rep;stosl ; " +"1: rep stosl ; " "popw %%es" : "+D" (dst), "+c" (npad) : "bdS" (video_segment),
arch/x86/boot/video.c static void restore_screen(void) · line 296
Quoted 11 lines · Uros Bizjak
arch/x86/boot/video.c +1
-1@@ -292,7 +292,7 @@ static void restore_screen(void)"shrw %%cx ; " "jnc 1f ; " "stosw \n\t" -"1: rep;stosl ; " +"1: rep stosl ; " "popw %%es"
Doesn't this one still need a separator between STOSL and POPW ?
~Andrew
Quoted 15 lines · Andrew Cooper
arch/x86/boot/video.c static void restore_screen(void) · line 296
Quoted 11 lines · Uros Bizjak
arch/x86/boot/video.c +1
-1@@ -292,7 +292,7 @@ static void restore_screen(void)"shrw %%cx ; " "jnc 1f ; " "stosw \n\t" -"1: rep;stosl ; " +"1: rep stosl ; " "popw %%es" Doesn't this one still need a separator between STOSL and POPW ?
";" is a separator as well.
Uros.
Quoted 15 lines · Uros Bizjak
Quoted 13 lines · Andrew Cooper
arch/x86/boot/video.c static void restore_screen(void) · line 296
Quoted 11 lines · Uros Bizjak
arch/x86/boot/video.c +1
-1@@ -292,7 +292,7 @@ static void restore_screen(void)"shrw %%cx ; " "jnc 1f ; " "stosw \n\t" -"1: rep;stosl ; " +"1: rep stosl ; " "popw %%es" Doesn't this one still need a separator between STOSL and POPW ?
Quoted 1 line
";" is a separator as well.
Yes, it is. I've clearly not had enough coffee yet. Sorry for the noise.
~Andrew