atomicfunc_64.asm 4.2 KB
Newer Older
Michael Schmid committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
_TEXT	SEGMENT

_abort proto

define_not_implemented macro name
	public name
	name proc
		call _abort
		ret
	name endp
endm

; ---- and_assign -------------------------------------------------------------

define_and_assign macro name, size, value
	public name
	name proc
		lock and size ptr [rcx], value
		ret
	name endp
endm

define_and_assign embb_internal__atomic_and_assign_8_asm, qword, rdx
define_and_assign embb_internal__atomic_and_assign_4_asm, dword, edx
define_and_assign embb_internal__atomic_and_assign_2_asm, word, dx
define_and_assign embb_internal__atomic_and_assign_1_asm, byte, dl

; ---- compare_and_swap -------------------------------------------------------

define_compare_and_swap macro name, size, value, desired
	public name
	name proc
		mov desired, size ptr [rdx]
		lock cmpxchg size ptr [rcx], value
		mov size ptr [rdx], desired
		setz al
		movzx rax, al
		ret
	name endp
endm

define_compare_and_swap embb_internal__atomic_compare_and_swap_8_asm, qword, r8, rax
define_compare_and_swap embb_internal__atomic_compare_and_swap_4_asm, dword, r8d, eax
define_compare_and_swap embb_internal__atomic_compare_and_swap_2_asm, word, r8w, ax
define_compare_and_swap embb_internal__atomic_compare_and_swap_1_asm, byte, r8b, al

; ---- fetch_and_add ----------------------------------------------------------

define_fetch_and_add macro name, size, value, return
	public name
	name proc
		lock xadd size ptr [rcx], value
		mov return, value
		ret
	name endp
endm

define_fetch_and_add embb_internal__atomic_fetch_and_add_8_asm, qword, rdx, rax
define_fetch_and_add embb_internal__atomic_fetch_and_add_4_asm, dword, edx, eax
define_fetch_and_add embb_internal__atomic_fetch_and_add_2_asm, word, dx, ax
define_fetch_and_add embb_internal__atomic_fetch_and_add_1_asm, byte, dl, al

; ---- load -------------------------------------------------------------------

define_load macro name, size, return
	public name
	name proc
		mov return, size ptr [rcx]
		ret
	name endp
endm

define_load embb_internal__atomic_load_8_asm, qword, rax
define_load embb_internal__atomic_load_4_asm, dword, eax
define_load embb_internal__atomic_load_2_asm, word, ax
define_load embb_internal__atomic_load_1_asm, byte, al

; ---- memory_barrier ---------------------------------------------------------

define_memory_barrier macro name
	public name
	name proc
		mfence
		ret
	name endp
endm

define_memory_barrier embb_internal__atomic_memory_barrier_asm

; ---- or_assign --------------------------------------------------------------

define_or_assign macro name, size, value
	public name
	name proc
		lock or size ptr [rcx], value
		ret
	name endp
endm

define_or_assign embb_internal__atomic_or_assign_8_asm, qword, rdx
define_or_assign embb_internal__atomic_or_assign_4_asm, dword, edx
define_or_assign embb_internal__atomic_or_assign_2_asm, word, dx
define_or_assign embb_internal__atomic_or_assign_1_asm, byte, dl

; ---- store ------------------------------------------------------------------

define_store macro name, size, value
	public name
	name proc
		xchg size ptr [rcx], value
		ret
	name endp
endm

define_store embb_internal__atomic_store_8_asm, qword, rdx
define_store embb_internal__atomic_store_4_asm, dword, edx
define_store embb_internal__atomic_store_2_asm, word, dx
define_store embb_internal__atomic_store_1_asm, byte, dl

; ---- swap -------------------------------------------------------------------

define_swap macro name, size, value, return
	public name
	name proc
		lock xchg size ptr [rcx], value
		mov return, value
		ret
	name endp
endm

define_swap embb_internal__atomic_swap_8_asm, qword, rdx, rax
define_swap embb_internal__atomic_swap_4_asm, dword, edx, eax
define_swap embb_internal__atomic_swap_2_asm, word, dx, ax
define_swap embb_internal__atomic_swap_1_asm, byte, dl, al

; ---- xor_assign -------------------------------------------------------------

define_xor_assign macro name, size, value
	public name
	name proc
		lock xor size ptr [rcx], value
		ret
	name endp
endm

define_xor_assign embb_internal__atomic_xor_assign_8_asm, qword, rdx
define_xor_assign embb_internal__atomic_xor_assign_4_asm, dword, edx
define_xor_assign embb_internal__atomic_xor_assign_2_asm, word, dx
define_xor_assign embb_internal__atomic_xor_assign_1_asm, byte, dl

_TEXT	ENDS

END