9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] ainc() 386/amd64 differences
@ 2014-05-14 20:34 erik quanstrom
  2014-05-14 20:57 ` Charles Forsyth
  0 siblings, 1 reply; 4+ messages in thread
From: erik quanstrom @ 2014-05-14 20:34 UTC (permalink / raw)
  To: 9fans

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



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

end of thread, other threads:[~2014-05-14 21:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-14 20:34 [9fans] ainc() 386/amd64 differences erik quanstrom
2014-05-14 20:57 ` Charles Forsyth
2014-05-14 21:26   ` erik quanstrom
2014-05-14 21:46     ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).