3 * reactos/ntoskrnl/ex/i386/interlck.c
15 #define LOCK "lock ; "
20 #elif defined(_MSC_VER)
35 INTERLOCKED_RESULT FASTCALL
36 Exfi386InterlockedIncrementLong(IN PLONG Addend
);
38 __asm__("\n\t.global @Exfi386InterlockedIncrementLong@4\n\t"
39 "@Exfi386InterlockedIncrementLong@4:\n\t"
43 "andl $0xC000, %eax\n\t"
46 #elif defined(_MSC_VER)
52 INTERLOCKED_RESULT FASTCALL
53 Exfi386InterlockedIncrementLong(IN PLONG Addend
)
55 __asm LOCK add dword ptr
[ecx
], 1
62 #error Unknown compiler for inline assembler
71 INTERLOCKED_RESULT FASTCALL
72 Exfi386InterlockedDecrementLong(IN PLONG Addend
);
74 __asm__("\n\t.global @Exfi386InterlockedDecrementLong@4\n\t"
75 "@Exfi386InterlockedDecrementLong@4:\n\t"
79 "andl $0xC000, %eax\n\t"
82 #elif defined(_MSC_VER)
88 INTERLOCKED_RESULT FASTCALL
89 Exfi386InterlockedDecrementLong(IN PLONG Addend
)
91 __asm LOCK sub dword ptr
[ecx
], 1
98 #error Unknown compiler for inline assembler
102 #if defined(__GNUC__)
108 Exfi386InterlockedExchangeUlong(IN PULONG Target
,
111 __asm__("\n\t.global @Exfi386InterlockedExchangeUlong@8\n\t"
112 "@Exfi386InterlockedExchangeUlong@8:\n\t"
114 "xchgl %edx,(%ecx)\n\t"
118 #elif defined(_MSC_VER)
125 Exfi386InterlockedExchangeUlong(IN PULONG Target
,
128 __asm LOCK xchg
[ecx
], edx
134 #error Unknown compiler for inline assembler
138 #if defined(__GNUC__)
140 INTERLOCKED_RESULT STDCALL
141 Exi386InterlockedIncrementLong(IN PLONG Addend
);
143 __asm__("\n\t.global _Exi386InterlockedIncrementLong@4\n\t"
144 "_Exi386InterlockedIncrementLong@4:\n\t"
145 "movl 4(%esp),%eax\n\t"
149 "andl $0xC000, %eax\n\t"
152 #elif defined(_MSC_VER)
155 INTERLOCKED_RESULT STDCALL
156 Exi386InterlockedIncrementLong(IN PLONG Addend
)
158 __asm mov eax
, Addend
159 __asm LOCK add dword ptr
[eax
], 1
161 __asm
and eax
, 0xC000
166 #error Unknown compiler for inline assembler
170 #if defined(__GNUC__)
172 INTERLOCKED_RESULT STDCALL
173 Exi386InterlockedDecrementLong(IN PLONG Addend
);
175 __asm__("\n\t.global _Exi386InterlockedDecrementLong@4\n\t"
176 "_Exi386InterlockedDecrementLong@4:\n\t"
177 "movl 4(%esp),%eax\n\t"
181 "andl $0xC000, %eax\n\t"
184 #elif defined(_MSC_VER)
187 INTERLOCKED_RESULT STDCALL
188 Exi386InterlockedDecrementLong(IN PLONG Addend
)
190 __asm mov eax
, Addend
191 __asm LOCK sub dword ptr
[eax
], 1
193 __asm
and eax
, 0xC000
198 #error Unknown compiler for inline assembler
202 #if defined(__GNUC__)
205 Exi386InterlockedExchangeUlong(IN PULONG Target
,
208 __asm__("\n\t.global _Exi386InterlockedExchangeUlong@8\n\t"
209 "_Exi386InterlockedExchangeUlong@8:\n\t"
210 "movl 4(%esp),%edx\n\t"
211 "movl 8(%esp),%eax\n\t"
213 "xchgl %eax,(%edx)\n\t"
216 #elif defined(_MSC_VER)
220 Exi386InterlockedExchangeUlong(IN PULONG Target
,
224 __asm mov eax
, Target
225 __asm LOCK xchg
[edx
], eax
230 #error Unknown compiler for inline assembler
235 /**********************************************************************
236 * FASTCALL: @InterlockedIncrement@4
237 * STDCALL : _InterlockedIncrement@4
239 #if defined(__GNUC__)
244 InterlockedIncrement(PLONG Addend
);
246 * FUNCTION: Increments a caller supplied variable of type LONG as an
249 * Addend = Points to a variable whose value is to be increment
250 * RETURNS: The incremented value
253 __asm__("\n\t.global @InterlockedIncrement@4\n\t"
254 "@InterlockedIncrement@4:\n\t"
257 "xaddl %eax,(%ecx)\n\t"
261 #elif defined(_MSC_VER)
267 InterlockedIncrement(PLONG Addend
)
270 __asm LOCK xadd
[ecx
], eax
276 #error Unknown compiler for inline assembler
280 /**********************************************************************
281 * FASTCALL: @InterlockedDecrement@4
282 * STDCALL : _InterlockedDecrement@4
284 #if defined(__GNUC__)
289 InterlockedDecrement(PLONG Addend
);
291 __asm__("\n\t.global @InterlockedDecrement@4\n\t"
292 "@InterlockedDecrement@4:\n\t"
295 "xaddl %eax,(%ecx)\n\t"
299 #elif defined(_MSC_VER)
306 InterlockedDecrement(PLONG Addend
)
309 __asm LOCK xadd
[ecx
], eax
315 #error Unknown compiler for inline assembler
319 /**********************************************************************
320 * FASTCALL: @InterlockedExchange@8
321 * STDCALL : _InterlockedExchange@8
324 #if defined(__GNUC__)
329 InterlockedExchange(PLONG Target
,
332 __asm__("\n\t.global @InterlockedExchange@8\n\t"
333 "@InterlockedExchange@8:\n\t"
335 "xchgl %edx,(%ecx)\n\t"
339 #elif defined(_MSC_VER)
345 InterlockedExchange(PLONG Target
,
348 __asm LOCK xchg
[ecx
], edx
354 #error Unknown compiler for inline assembler
357 /**********************************************************************
358 * FASTCALL: @InterlockedExchangeAdd@8
359 * STDCALL: _InterlockedExchangeAdd@8
361 #if defined(__GNUC__)
366 InterlockedExchangeAdd(PLONG Addend
,
369 __asm__("\n\t.global @InterlockedExchangeAdd@8\n\t"
370 "@InterlockedExchangeAdd@8:\n\t"
372 "xaddl %edx,(%ecx)\n\t"
376 #elif defined(_MSC_VER)
382 InterlockedExchangeAdd(PLONG Addend
,
385 __asm LOCK xadd
[ecx
], edx
391 #error Unknown compiler for inline assembler
395 /**********************************************************************
396 * FASTCALL: @InterlockedCompareExchange@12
397 * STDCALL: _InterlockedCompareExchange@12
399 #if defined(__GNUC__)
402 InterlockedCompareExchange(PLONG Destination
,
406 __asm__("\n\t.global @InterlockedCompareExchange@12\n\t"
407 "@InterlockedCompareExchange@12:\n\t"
408 "movl 4(%esp),%eax\n\t"
410 "cmpxchg %edx,(%ecx)\n\t"
413 #elif defined(_MSC_VER)
417 InterlockedCompareExchange(PLONG Destination
,
421 __asm mov eax
, Comperand
422 __asm LOCK cmpxchg
[ecx
], edx
427 #error Unknown compiler for inline assembler
430 /**********************************************************************
431 * FASTCALL: @InterlockedCompareExchange64@8
433 #if defined(__GNUC__)
435 ExfpInterlockedExchange64(LONGLONG
volatile * Destination
,
438 __asm__("\n\t.global @ExfpInterlockedExchange64@8\n\t"
439 "@ExfpInterlockedExchange64@8:\n\t"
443 "movl (%edx),%ebx\n\t"
444 "movl 4(%edx),%ecx\n\t"
446 "movl (%esi),%eax\n\t"
447 "movl 4(%esi),%edx\n\t"
449 "cmpxchg8b (%esi)\n\t"
456 #error Unknown compiler for inline assembler
459 /**********************************************************************
460 * FASTCALL: @ExfInterlockedCompareExchange@12
462 #if defined(__GNUC__)
464 ExfInterlockedCompareExchange64(LONGLONG
volatile * Destination
,
466 PLONGLONG Comperand
);
468 __asm__("\n\t.global @ExfInterlockedCompareExchange64@12\n\t"
469 "@ExfInterlockedCompareExchange64@12:\n\t"
473 "movl (%edx),%ebx\n\t"
474 "movl 4(%edx),%ecx\n\t"
475 "movl 12(%esp),%edx\n\t"
476 "movl (%edx),%eax\n\t"
477 "movl 4(%edx),%edx\n\t"
479 "cmpxchg8b (%esi)\n\t"
485 #error Unknown compiler for inline assembler