shithub: snippets

ref: fe3ec1a9c6b65cc8ed46e360aeffe1cdc65af71b
dir: /atomics9_amd64.s/

View raw version
TEXT atomic_fetch_add(SB), 1, $0
afap:
	MOVL	(RARG), AX	/* exp */
	MOVL	AX, CX
	MOVL	AX, BX
	ADDL	d+8(FP), BX	/* new */
	LOCK; CMPXCHGL BX, (RARG)
	JNZ	afap
	MOVL	CX, AX
	RET

TEXT atomic_fetch_sub(SB), 1, $0
afsp:
	MOVL	(RARG), AX	/* exp */
	MOVL	AX, CX
	MOVL	AX, BX
	SUBL	d+8(FP), BX	/* new */
	LOCK; CMPXCHGL BX, (RARG)
	JNZ	afsp
	MOVL	CX, AX
	RET

TEXT atomic_fetch_and(SB), 1, $0
afandp:
	MOVL	(RARG), AX	/* exp */
	MOVL	AX, CX
	MOVL	AX, BX
	ANDL	d+8(FP), BX	/* new */
	LOCK; CMPXCHGL BX, (RARG)
	JNZ	afandp
	MOVL	CX, AX
	RET

TEXT atomic_fetch_or(SB), 1, $0
aforp:
	MOVL	(RARG), AX	/* exp */
	MOVL	AX, CX
	MOVL	AX, BX
	ORL		d+8(FP), BX	/* new */
	LOCK; CMPXCHGL BX, (RARG)
	JNZ	aforp
	MOVL	CX, AX
	RET

TEXT atomic_fetch_xor(SB), 1, $0
afxorp:
	MOVL	(RARG), AX	/* exp */
	MOVL	AX, CX
	MOVL	AX, BX
	XORL	d+8(FP), BX	/* new */
	LOCK; CMPXCHGL BX, (RARG)
	JNZ	afxorp
	MOVL	CX, AX
	RET

TEXT atomic_exchange(SB), 1, $0
afexp:
	MOVL	(RARG), AX	/* exp */
	MOVL	AX, CX
	LOCK; CMPXCHGL AX, (RARG)
	JNZ	afexp
	MOVL	CX, AX
	RET