shithub: snippets

ref: d9ff373a3ca08c97227c031a8d43bd7b1eae16cb
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