atomicfunc_32.asm 4.32 KB
Newer Older
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
	.686p
	.xmm
	.model flat

_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 [ecx], value
		ret
	name endp
endm

define_not_implemented @embb_internal__atomic_and_assign_8_asm@8
define_and_assign @embb_internal__atomic_and_assign_4_asm@8, dword, edx
define_and_assign @embb_internal__atomic_and_assign_2_asm@8, word, dx
define_and_assign @embb_internal__atomic_and_assign_1_asm@8, byte, dl

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

define_compare_and_swap macro name, size, value, desired
	public name
	name proc
		push edx
		mov desired, size ptr [edx]
		mov value, size ptr [esp+8]
		lock cmpxchg size ptr [ecx], value
		pop edx
		mov size ptr [edx], desired
		setz al
		movzx eax, al
		ret 4
	name endp
endm

define_not_implemented @embb_internal__atomic_compare_and_swap_8_asm@12
define_compare_and_swap @embb_internal__atomic_compare_and_swap_4_asm@12, dword, edx, eax
define_compare_and_swap @embb_internal__atomic_compare_and_swap_2_asm@12, word, dx, ax
define_compare_and_swap @embb_internal__atomic_compare_and_swap_1_asm@12, byte, dl, al

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

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

define_not_implemented @embb_internal__atomic_fetch_and_add_8_asm@8
define_fetch_and_add @embb_internal__atomic_fetch_and_add_4_asm@8, dword, edx, eax
define_fetch_and_add @embb_internal__atomic_fetch_and_add_2_asm@8, word, dx, ax
define_fetch_and_add @embb_internal__atomic_fetch_and_add_1_asm@8, byte, dl, al

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

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

define_not_implemented @embb_internal__atomic_load_8_asm@4
define_load @embb_internal__atomic_load_4_asm@4, dword, eax
define_load @embb_internal__atomic_load_2_asm@4, word, ax
define_load @embb_internal__atomic_load_1_asm@4, 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@0

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

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

define_not_implemented @embb_internal__atomic_or_assign_8_asm@8
define_or_assign @embb_internal__atomic_or_assign_4_asm@8, dword, edx
define_or_assign @embb_internal__atomic_or_assign_2_asm@8, word, dx
define_or_assign @embb_internal__atomic_or_assign_1_asm@8, byte, dl

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

define_store macro name, size, value
	public name
	name proc
117
		xchg size ptr [ecx], value
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 154 155 156 157 158 159 160
		ret
	name endp
endm

define_not_implemented @embb_internal__atomic_store_8_asm@8
define_store @embb_internal__atomic_store_4_asm@8, dword, edx
define_store @embb_internal__atomic_store_2_asm@8, word, dx
define_store @embb_internal__atomic_store_1_asm@8, byte, dl

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

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

define_not_implemented @embb_internal__atomic_swap_8_asm@8
define_swap @embb_internal__atomic_swap_4_asm@8, dword, edx, eax
define_swap @embb_internal__atomic_swap_2_asm@8, word, dx, ax
define_swap @embb_internal__atomic_swap_1_asm@8, byte, dl, al

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

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

define_not_implemented @embb_internal__atomic_xor_assign_8_asm@8
define_xor_assign @embb_internal__atomic_xor_assign_4_asm@8, dword, edx
define_xor_assign @embb_internal__atomic_xor_assign_2_asm@8, word, dx
define_xor_assign @embb_internal__atomic_xor_assign_1_asm@8, byte, dl

_TEXT	ENDS

END