On Tue, Jun 23, 2015 at 09:49:26AM +0300, Alexey Dobriyan wrote:
> Clearing 32-bit register clears whole register, save REX prefix.

I see nothing documented in the Intel SDM that says this. Can you cite
a reference to support this claim?

An aside - even if this were true, I still prefer xorq and the extra
rex prefix byte because it more correctly conveys the intent of the
programmer.

-ml

> 
> Index: arch/amd64/amd64/acpi_wakecode.S
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/amd64/acpi_wakecode.S,v
> retrieving revision 1.35
> diff -u -p -u -r1.35 acpi_wakecode.S
> --- arch/amd64/amd64/acpi_wakecode.S  8 Dec 2014 07:12:37 -0000       1.35
> +++ arch/amd64/amd64/acpi_wakecode.S  20 Jun 2015 17:56:47 -0000
> @@ -307,7 +307,7 @@ _C_LABEL(acpi_long_mode_resume):
>       lidt    acpi_saved_idt
>  
>       /* Restore the saved task register */
> -     xorq    %rcx, %rcx
> +     xorl    %ecx, %ecx
>       movw    acpi_saved_tr, %cx
>       movq    acpi_saved_gdt+2, %rax
>       andb    $0xF9, 5(%rax,%rcx)
> @@ -337,7 +337,7 @@ _C_LABEL(acpi_long_mode_resume):
>       movq    acpi_saved_cr3, %rax
>       movq    %rax, %cr3
>  
> -     xorq    %rax, %rax      
> +     xorl    %eax, %eax
>       jmp     *acpi_saved_ret
>  
>  #ifdef HIBERNATE
> Index: arch/amd64/amd64/copy.S
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/amd64/copy.S,v
> retrieving revision 1.6
> diff -u -p -u -r1.6 copy.S
> --- arch/amd64/amd64/copy.S   16 Jan 2015 10:17:51 -0000      1.6
> +++ arch/amd64/amd64/copy.S   20 Jun 2015 17:56:47 -0000
> @@ -93,7 +93,7 @@ ENTRY(kcopy)
>  
>       movq    CPUVAR(CURPCB),%rdx
>       popq    PCB_ONFAULT(%rdx)
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>       ret
>  
>  1:   addq    %rcx,%rdi               # copy backward
> @@ -114,7 +114,7 @@ ENTRY(kcopy)
>  
>       movq    CPUVAR(CURPCB),%rdx
>       popq    PCB_ONFAULT(%rdx)
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>       ret
>  
>  ENTRY(copyout)
> @@ -222,7 +222,7 @@ ENTRY(copyoutstr)
>  
>       /* Success -- 0 byte reached. */
>       decq    %rdx
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>       jmp     copystr_return
>  
>  2:   /* rdx is zero -- return EFAULT or ENAMETOOLONG. */
> @@ -265,7 +265,7 @@ ENTRY(copyinstr)
>  
>       /* Success -- 0 byte reached. */
>       decq    %rdx
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>       jmp     copystr_return
>  
>  2:   /* edx is zero -- return EFAULT or ENAMETOOLONG. */
> Index: arch/amd64/amd64/locore.S
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/amd64/locore.S,v
> retrieving revision 1.62
> diff -u -p -u -r1.62 locore.S
> --- arch/amd64/amd64/locore.S 16 Jan 2015 10:17:51 -0000      1.62
> +++ arch/amd64/amd64/locore.S 20 Jun 2015 17:56:47 -0000
> @@ -732,7 +732,7 @@ longmode_hi:
>       movq    %rax,_C_LABEL(proc0paddr)(%rip)
>       leaq    (USPACE-FRAMESIZE)(%rax),%rsp
>       movq    %rsi,PCB_CR3(%rax)      # pcb->pcb_cr3
> -     xorq    %rbp,%rbp               # mark end of frames
> +     xorl    %ebp,%ebp               # mark end of frames
>  
>       xorw    %ax,%ax
>       movw    %ax,%gs
> @@ -1071,7 +1071,7 @@ syscall_return:
>       movl    TF_RDI(%rsp),%edx
>       movl    %ebx,%ecx
>       movl    CPUVAR(ILEVEL),%r8d
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>       call    _C_LABEL(printf)
>  #ifdef DDB
>       int     $3
> @@ -1143,7 +1143,7 @@ _C_LABEL(doreti_iret):
>  #ifdef DIAGNOSTIC
>  3:   sti
>       movabsq $4f, %rdi
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>       call    _C_LABEL(printf)
>  #ifdef DDB
>       int     $3
> @@ -1157,7 +1157,7 @@ _C_LABEL(doreti_iret):
>  ENTRY(pagezero)
>       movq    $-PAGE_SIZE,%rdx
>       subq    %rdx,%rdi
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>  1:
>       movnti  %rax,(%rdi,%rdx)
>       movnti  %rax,8(%rdi,%rdx)
> Index: arch/amd64/amd64/mptramp.S
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/amd64/mptramp.S,v
> retrieving revision 1.11
> diff -u -p -u -r1.11 mptramp.S
> --- arch/amd64/amd64/mptramp.S        8 Dec 2014 07:49:17 -0000       1.11
> +++ arch/amd64/amd64/mptramp.S        20 Jun 2015 17:56:47 -0000
> @@ -189,7 +189,7 @@ _TRMP_LABEL(mptramp_longmode)
>  _C_LABEL(cpu_spinup_trampoline_end): #end of code copied to MP_TRAMPOLINE
>       movl    _C_LABEL(local_apic)+LAPIC_ID,%eax
>       shrl    $LAPIC_ID_SHIFT,%eax
> -     xorq    %rcx,%rcx
> +     xorl    %ecx,%ecx
>  1:
>       movq    _C_LABEL(cpu_info)(,%rcx,8),%rdi
>       incq    %rcx
> Index: arch/amd64/amd64/mutex.S
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/amd64/mutex.S,v
> retrieving revision 1.9
> diff -u -p -u -r1.9 mutex.S
> --- arch/amd64/amd64/mutex.S  2 Jun 2013 01:55:52 -0000       1.9
> +++ arch/amd64/amd64/mutex.S  20 Jun 2015 17:56:52 -0000
> @@ -55,7 +55,7 @@ ENTRY(mtx_enter)
>        * %edx - the old ipl
>        * %rcx - curcpu()
>        */
> -     xorq    %rax, %rax
> +     xorl    %eax, %eax
>  #ifdef MULTIPROCESSOR
>       lock
>  #endif
> @@ -99,7 +99,7 @@ ENTRY(mtx_enter_try)
>        * %edx - the old ipl
>        * %rcx - curcpu()
>        */
> -     xorq    %rax, %rax
> +     xorl    %eax, %eax
>  #ifdef MULTIPROCESSOR
>       lock
>  #endif
> @@ -122,7 +122,7 @@ ENTRY(mtx_enter_try)
>       cmpq    MTX_OWNER(%rdi), %rcx
>       je      3f
>  #endif
> -     xorq    %rax, %rax
> +     xorl    %eax, %eax
>       ret
>  
>  #ifdef DIAGNOSTIC
> @@ -140,7 +140,7 @@ ENTRY(mtx_leave)
>       jne     2f
>       decl    CPU_INFO_MUTEX_LEVEL(%rcx)
>  #endif
> -     xorq    %rcx, %rcx
> +     xorl    %ecx, %ecx
>       movl    MTX_OLDIPL(%rax), %edi
>       movl    %ecx, MTX_OLDIPL(%rax)
>       movq    %rcx, MTX_OWNER(%rax)
> Index: arch/amd64/amd64/vector.S
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/amd64/vector.S,v
> retrieving revision 1.36
> diff -u -p -u -r1.36 vector.S
> --- arch/amd64/amd64/vector.S 7 Feb 2015 00:26:37 -0000       1.36
> +++ arch/amd64/amd64/vector.S 20 Jun 2015 17:56:52 -0000
> @@ -276,7 +276,7 @@ calltrap:
>       movabsq $4f,%rdi
>       movl    CPUVAR(ILEVEL),%esi
>       movl    %ebx,%edx
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>       call    _C_LABEL(printf)
>  #ifdef DDB
>       int     $3
> @@ -414,7 +414,7 @@ IDTVEC(resume_lapic_ltimer)
>       sti
>       cld
>       pushq   %rbx
> -     xorq    %rdi,%rdi
> +     xorl    %edi,%edi
>       call    _C_LABEL(lapic_clockintr)
>       jmp     _C_LABEL(Xdoreti)
>  2:
> Index: lib/libkern/arch/amd64/bzero.S
> ===================================================================
> RCS file: /cvs/src/sys/lib/libkern/arch/amd64/bzero.S,v
> retrieving revision 1.4
> diff -u -p -u -r1.4 bzero.S
> --- lib/libkern/arch/amd64/bzero.S    29 Nov 2014 18:51:23 -0000      1.4
> +++ lib/libkern/arch/amd64/bzero.S    20 Jun 2015 17:56:52 -0000
> @@ -9,7 +9,7 @@
>  ENTRY(bzero)
>       movq    %rsi,%rdx
>  
> -     xorq    %rax,%rax               /* set fill data to 0 */
> +     xorl    %eax,%eax               /* set fill data to 0 */
>  
>       /*
>        * if the string is too short, it's really not worth the overhead
> Index: lib/libkern/arch/amd64/memchr.S
> ===================================================================
> RCS file: /cvs/src/sys/lib/libkern/arch/amd64/memchr.S,v
> retrieving revision 1.3
> diff -u -p -u -r1.3 memchr.S
> --- lib/libkern/arch/amd64/memchr.S   29 Nov 2014 18:51:23 -0000      1.3
> +++ lib/libkern/arch/amd64/memchr.S   20 Jun 2015 17:56:52 -0000
> @@ -16,5 +16,5 @@ ENTRY(memchr)
>       jne     L1                      /* scan failed, return null */
>       leaq    -1(%rdi),%rax           /* adjust result of scan */
>       ret
> -L1:  xorq    %rax,%rax
> +L1:  xorl    %eax,%eax
>       ret
> Index: lib/libkern/arch/amd64/scanc.S
> ===================================================================
> RCS file: /cvs/src/sys/lib/libkern/arch/amd64/scanc.S,v
> retrieving revision 1.3
> diff -u -p -u -r1.3 scanc.S
> --- lib/libkern/arch/amd64/scanc.S    29 Nov 2014 18:51:23 -0000      1.3
> +++ lib/libkern/arch/amd64/scanc.S    20 Jun 2015 17:56:52 -0000
> @@ -42,7 +42,7 @@ ENTRY(scanc)
>       testl   %ecx,%ecx
>       jz      2f
>       movq    %r11,%rdi
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>  1:
>       lodsb
>       testb   %dl,(%rax,%rdi)
> Index: lib/libkern/arch/amd64/strchr.S
> ===================================================================
> RCS file: /cvs/src/sys/lib/libkern/arch/amd64/strchr.S,v
> retrieving revision 1.3
> diff -u -p -u -r1.3 strchr.S
> --- lib/libkern/arch/amd64/strchr.S   9 Dec 2014 15:13:57 -0000       1.3
> +++ lib/libkern/arch/amd64/strchr.S   20 Jun 2015 17:56:52 -0000
> @@ -102,7 +102,7 @@ ENTRY(strchr)
>  /* Source misaligned: read aligned word and make low bytes invalid */
>  /* I (dsl) think a _ALIGN_TEXT here will slow things down! */
>  20:
> -     xor     %rcx,%rcx
> +     xor     %ecx,%ecx
>       sub     %dil,%cl        /* Convert low address values 1..7 ... */
>       sbb     %rsi,%rsi       /* carry was set, so %rsi now ~0u! */
>       and     $7,%cl          /* ... to 7..1 */
> Index: lib/libkern/arch/amd64/strrchr.S
> ===================================================================
> RCS file: /cvs/src/sys/lib/libkern/arch/amd64/strrchr.S,v
> retrieving revision 1.3
> diff -u -p -u -r1.3 strrchr.S
> --- lib/libkern/arch/amd64/strrchr.S  9 Dec 2014 15:13:57 -0000       1.3
> +++ lib/libkern/arch/amd64/strrchr.S  20 Jun 2015 17:56:52 -0000
> @@ -14,7 +14,7 @@ ENTRY(strrchr)
>       movzbq  %sil,%rcx
>  
>       /* zero return value */
> -     xorq    %rax,%rax
> +     xorl    %eax,%eax
>  
>       /*
>        * Align to word boundary.
> 

Reply via email to