Re: [PATCH] 498+ days uptime

H. Peter Anvin (hpa@transmeta.com)
25 Aug 1998 23:10:10 GMT


Followup to: <19980825141946.A2198@tantalophile.demon.co.uk>
By author: Jamie Lokier <lkd@tantalophile.demon.co.uk>
In newsgroup: linux.dev.kernel
>
> Incrementing a 64-bit value on i386 is fast and simple. It's arithmetic
> done in GCC, especially with temporaries that you have to worry about.
>
> The instruction sequence is:
>
> incl counter
> adcl $0,counter+4
>
> This could be made into a kernel macro. Because the carry is so rare,
> you could safely use a lock prefix before the incl and put this in a
> macro called atomic_count or something.
>

This is wrong: INC doesn't update CF; one of the many quirks of the
x86 architecture. You need:

addl $1,counter
adcl $0,counter+4

-hpa

-- 
    PGP: 2047/2A960705 BA 03 D3 2C 14 A8 A8 BD  1E DF FE 69 EE 35 BD 74
    See http://www.zytor.com/~hpa/ for web page and full PGP public key
        I am Bahá'í -- ask me about it or see http://www.bahai.org/
   "To love another person is to see the face of God." -- Les Misérables

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html