Re: doubt on atomic increment operation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



what is the difference between incb %al and incb $i. According to my
> knowledge if you have  some thing like "i++" (in c) then it is translated in
> to movw $i %ebx, incw %ebx, movw %ebx $i. My question, when I explicitly
> give variable as operand to increment in assembly like "incb $i", then will
> that instruction execution cycle involves copying the contents from memory
> to register and increment and copy back to memory.

To the best I know, the answer is "no". The value will be directly
incremented in the target memory address

Thank you for the reply. If the value is incremented directly in the target memory address, then Is the execution cycle involves locking the memory bus of the target address and increments the value and releases the memory lock
Is the process of incrementing target memory address value directly is atomic? Or do we need to put lock instruction before "incb $i" kind instructions.

regards
Sri

On Sat, Sep 13, 2008 at 8:47 AM, Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:
Hi...

On Sat, Sep 13, 2008 at 1:28 PM, Sri Ram K Vemulpali
<vsriramksh@xxxxxxxxx> wrote:
> Hi all,
>
> what is the difference between incb %al and incb $i. According to my
> knowledge if you have  some thing like "i++" (in c) then it is translated in
> to movw $i %ebx, incw %ebx, movw %ebx $i. My question, when I explicitly
> give variable as operand to increment in assembly like "incb $i", then will
> that instruction execution cycle involves copying the contents from memory
> to register and increment and copy back to memory.

To the best I know, the answer is "no". The value will be directly
incremented in the target memory address

>Is this hidden
> and Assembler takes care of it when writing to image file (machine codes or
> elf).

Not sure about Linux assembler, but I remember that in gcc, if you
declare a variable as "volatile" and you do something like a++ then it
will be transformed like incw $a instead of movw $a %ebx, incw %ebx,
movw %ebx $a

>Another question: Is incb %al is atomic operation, I mean, Is
> instruction execution cycle is interrupted by an event or a process.
> Thank you.

yes it is atomic. The rule is:
a. it is atomic when you access data not bigger than processor data
bus (CMIIW if I use wrong term people). So, if your processor is 32
bit then accessing 8, 16 and 32 bit data will be done atomically...

AND....

b. it is naturally aligned e.g the address is multiple of data bus
width (only apply when you access memory cell directly...doesn't apply
when you access CPU register).

regards,

Mulyadi.


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux