]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c
2 GCC inline implementation of BaseSynchronizationLib processor specific functions.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 Performs an atomic increment of an 32-bit unsigned integer.
13 Performs an atomic increment of the 32-bit unsigned integer specified by
14 Value and returns the incremented value. The increment operation must be
15 performed using MP safe mechanisms.
17 @param Value A pointer to the 32-bit value to increment.
19 @return The incremented value.
24 InternalSyncIncrement (
25 IN
volatile UINT32
*Value
30 __asm__
__volatile__ (
35 : "=&a" (Result
), // %0
37 : // no inputs that aren't also outputs
46 Performs an atomic decrement of an 32-bit unsigned integer.
48 Performs an atomic decrement of the 32-bit unsigned integer specified by
49 Value and returns the decremented value. The decrement operation must be
50 performed using MP safe mechanisms.
52 @param Value A pointer to the 32-bit value to decrement.
54 @return The decremented value.
59 InternalSyncDecrement (
60 IN
volatile UINT32
*Value
65 __asm__
__volatile__ (
66 "movl $-1, %%eax \n\t"
70 : "=&a" (Result
), // %0
72 : // no inputs that aren't also outputs
81 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
83 Performs an atomic compare exchange operation on the 16-bit unsigned integer
84 specified by Value. If Value is equal to CompareValue, then Value is set to
85 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
86 then Value is returned. The compare exchange operation must be performed using
90 @param Value A pointer to the 16-bit value for the compare exchange
92 @param CompareValue 16-bit value used in compare operation.
93 @param ExchangeValue 16-bit value used in exchange operation.
95 @return The original *Value before exchange.
100 InternalSyncCompareExchange16 (
101 IN OUT
volatile UINT16
*Value
,
102 IN UINT16 CompareValue
,
103 IN UINT16 ExchangeValue
106 __asm__
__volatile__ (
108 "cmpxchgw %2, %1 \n\t"
109 : "+a" (CompareValue
), // %0
111 : "r" (ExchangeValue
) // %2
120 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
122 Performs an atomic compare exchange operation on the 32-bit unsigned integer
123 specified by Value. If Value is equal to CompareValue, then Value is set to
124 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
125 then Value is returned. The compare exchange operation must be performed using
129 @param Value A pointer to the 32-bit value for the compare exchange
131 @param CompareValue 32-bit value used in compare operation.
132 @param ExchangeValue 32-bit value used in exchange operation.
134 @return The original *Value before exchange.
139 InternalSyncCompareExchange32 (
140 IN OUT
volatile UINT32
*Value
,
141 IN UINT32 CompareValue
,
142 IN UINT32 ExchangeValue
145 __asm__
__volatile__ (
147 "cmpxchgl %2, %1 \n\t"
148 : "+a" (CompareValue
), // %0
150 : "r" (ExchangeValue
) // %2
159 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
161 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
162 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
163 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
164 The compare exchange operation must be performed using MP safe mechanisms.
167 @param Value A pointer to the 64-bit value for the compare exchange
169 @param CompareValue 64-bit value used in compare operation.
170 @param ExchangeValue 64-bit value used in exchange operation.
172 @return The original *Value before exchange.
177 InternalSyncCompareExchange64 (
178 IN OUT
volatile UINT64
*Value
,
179 IN UINT64 CompareValue
,
180 IN UINT64 ExchangeValue
183 __asm__
__volatile__ (
185 "cmpxchgq %2, %1 \n\t"
186 : "+a" (CompareValue
), // %0
188 : "r" (ExchangeValue
) // %2