All of lore.kernel.org
 help / color / mirror / Atom feed
* Can anyone explain "movl %eax %eax"?
@ 2011-02-09 22:24 Jidong Xiao
  2011-02-09 22:32 ` H. Peter Anvin
  0 siblings, 1 reply; 5+ messages in thread
From: Jidong Xiao @ 2011-02-09 22:24 UTC (permalink / raw)
  To: linux-kernel

Hi,

In the kernel source, I see in a couple of places, there is "movl %eax
%eax". Is this used for alignment purpose?

For example, in the following piece of code we can see "movl %eax,%eax".

407 ENTRY(ia32_syscall)
408         CFI_STARTPROC32 simple
409         CFI_SIGNAL_FRAME
410         CFI_DEF_CFA     rsp,SS+8-RIP
411         /*CFI_REL_OFFSET        ss,SS-RIP*/
412         CFI_REL_OFFSET  rsp,RSP-RIP
413         /*CFI_REL_OFFSET        rflags,EFLAGS-RIP*/
414         /*CFI_REL_OFFSET        cs,CS-RIP*/
415         CFI_REL_OFFSET  rip,RIP-RIP
416         PARAVIRT_ADJUST_EXCEPTION_FRAME
417         SWAPGS
418         /*
419          * No need to follow this irqs on/off section: the syscall
420          * disabled irqs and here we enable it straight after entry:
421          */
422         ENABLE_INTERRUPTS(CLBR_NONE)
423         movl %eax,%eax
424         pushq %rax
425         CFI_ADJUST_CFA_OFFSET 8
426         cld
427         /* note the registers are not zero extended to the sf.
428            this could be a problem. */
429         SAVE_ARGS 0,0,1
430         GET_THREAD_INFO(%r10)
431         orl   $TS_COMPAT,TI_status(%r10)
432         testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
433         jnz ia32_tracesys
434         cmpq $(IA32_NR_syscalls-1),%rax
435         ja ia32_badsys
436 ia32_do_call:
437         IA32_ARG_FIXUP
438         call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
439 ia32_sysret:
440         movq %rax,RAX-ARGOFFSET(%rsp)
441 ia32_ret_from_sys_call:
442         CLEAR_RREGS -ARGOFFSET
443         jmp int_ret_from_sys_call


Regards
Jidong

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Can anyone explain "movl %eax %eax"?
  2011-02-09 22:24 Can anyone explain "movl %eax %eax"? Jidong Xiao
@ 2011-02-09 22:32 ` H. Peter Anvin
  2011-02-09 23:02   ` Jidong Xiao
  0 siblings, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2011-02-09 22:32 UTC (permalink / raw)
  To: Jidong Xiao; +Cc: linux-kernel

On 02/09/2011 02:24 PM, Jidong Xiao wrote:
> Hi,
> 
> In the kernel source, I see in a couple of places, there is "movl %eax
> %eax". Is this used for alignment purpose?
> 
> For example, in the following piece of code we can see "movl %eax,%eax".
> 

In x86-64, a dword (long) operation clears the upper 32 bits of the
target register, so "movl %eax,%eax" clears the upper 32 bits of %rax.

	-hpa


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Can anyone explain "movl %eax %eax"?
  2011-02-09 22:32 ` H. Peter Anvin
@ 2011-02-09 23:02   ` Jidong Xiao
  2011-02-09 23:05     ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Jidong Xiao @ 2011-02-09 23:02 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel

Oh, I see. Thank you. So similarly, the operation "xorl %eax,%eax" is
used for the same reason, right? I see that appears in more files.

Regards
Jidong

On Wed, Feb 9, 2011 at 5:32 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 02/09/2011 02:24 PM, Jidong Xiao wrote:
>> Hi,
>>
>> In the kernel source, I see in a couple of places, there is "movl %eax
>> %eax". Is this used for alignment purpose?
>>
>> For example, in the following piece of code we can see "movl %eax,%eax".
>>
>
> In x86-64, a dword (long) operation clears the upper 32 bits of the
> target register, so "movl %eax,%eax" clears the upper 32 bits of %rax.
>
>        -hpa
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Can anyone explain "movl %eax %eax"?
  2011-02-09 23:02   ` Jidong Xiao
@ 2011-02-09 23:05     ` David Miller
  2011-02-10  1:32       ` Jidong Xiao
  0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2011-02-09 23:05 UTC (permalink / raw)
  To: jidong.xiao; +Cc: hpa, linux-kernel

From: Jidong Xiao <jidong.xiao@gmail.com>
Date: Wed, 9 Feb 2011 18:02:09 -0500

> Oh, I see. Thank you. So similarly, the operation "xorl %eax,%eax" is
> used for the same reason, right? I see that appears in more files.

The xorl clears the entire register.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Can anyone explain "movl %eax %eax"?
  2011-02-09 23:05     ` David Miller
@ 2011-02-10  1:32       ` Jidong Xiao
  0 siblings, 0 replies; 5+ messages in thread
From: Jidong Xiao @ 2011-02-10  1:32 UTC (permalink / raw)
  To: David Miller; +Cc: hpa, linux-kernel

Thank you David and Peter.

And I found more information in the following website, other people
who are not very clear can have a look at this document:

http://www.x86-64.org/documentation/assembly.html

======================
Implicit zero extend

Results of 32-bit operations are implicitly zero extended to 64-bit
values. This differs from 16 and 8 bit operations, that don't affect
the upper part of registers. This can be used for code size
optimisations in some cases, such as:

  movl $1, %eax                 # one byte shorter movq $1, %rax
  xorq %rax, %rax		# three byte equivalent of mov $0,%rax
  andl $5, %eax			# equivalent for andq $5, %eax
======================

Regards
Jidong

On Wed, Feb 9, 2011 at 6:05 PM, David Miller <davem@davemloft.net> wrote:
> From: Jidong Xiao <jidong.xiao@gmail.com>
> Date: Wed, 9 Feb 2011 18:02:09 -0500
>
>> Oh, I see. Thank you. So similarly, the operation "xorl %eax,%eax" is
>> used for the same reason, right? I see that appears in more files.
>
> The xorl clears the entire register.
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-02-10  1:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-09 22:24 Can anyone explain "movl %eax %eax"? Jidong Xiao
2011-02-09 22:32 ` H. Peter Anvin
2011-02-09 23:02   ` Jidong Xiao
2011-02-09 23:05     ` David Miller
2011-02-10  1:32       ` Jidong Xiao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.