for 386, libc has this definition for ainc

TEXT ainc(SB), $0       /* int ainc(int *); */
        MOVL    addr+0(FP), BX
ainclp:
        MOVL    (BX), AX
        MOVL    AX, CX
        INCL    CX
        LOCK
        BYTE    $0x0F; BYTE $0xB1; BYTE $0x0B   /* CMPXCHGL CX, (BX) */
        JNZ     ainclp
        MOVL    CX, AX
        RET

the amd64 kernel has had this definition (the pc kernel doesn't define ainc)

TEXT ainc(SB), 1, $-4
        MOVL    $1, AX
        LOCK; XADDL AX, (RARG)
        ADDL    $1, AX                          /* overflow if -ve or 0 */
        JGT     _return
_trap:
        XORQ    BX, BX
        MOVQ    (BX), BX                        /* over under sideways down */
_return:
        RET

these are substantially different in two ways.
- the first is not wait free.  the second may be wait free.
- the second is geared toward reference counting, and will
trap instead of wrapping.  it can't be used for generating
a unique sequence.

i'd like to see the amd64 kernel version replace incref, and
this version of ainc

TEXT ainc(SB), 1, $-4
TEXT ainc32(SB), 1, $-4
        MOVL    $1, AX
        LOCK; XADDL AX, (RARG)
        INCL    AX
        RET

what does the list think?

- erik

Reply via email to