]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c
be19219c2dd6d4ac2416da4546d301c4e93fecd1
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
13 Performs an atomic increment of an 32-bit unsigned integer.
15 Performs an atomic increment of the 32-bit unsigned integer specified by
16 Value and returns the incremented value. The increment operation must be
17 performed using MP safe mechanisms.
19 @param Value A pointer to the 32-bit value to increment.
21 @return The incremented value.
26 InternalSyncIncrement (
27 IN
volatile UINT32
*Value
32 __asm__
__volatile__ (
37 : "=&a" (Result
), // %0
39 : // no inputs that aren't also outputs
49 Performs an atomic decrement of an 32-bit unsigned integer.
51 Performs an atomic decrement of the 32-bit unsigned integer specified by
52 Value and returns the decremented value. The decrement operation must be
53 performed using MP safe mechanisms.
55 @param Value A pointer to the 32-bit value to decrement.
57 @return The decremented value.
62 InternalSyncDecrement (
63 IN
volatile UINT32
*Value
68 __asm__
__volatile__ (
69 "movl $-1, %%eax \n\t"
73 : "=&a" (Result
), // %0
75 : // no inputs that aren't also outputs
85 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
87 Performs an atomic compare exchange operation on the 16-bit unsigned integer
88 specified by Value. If Value is equal to CompareValue, then Value is set to
89 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
90 then Value is returned. The compare exchange operation must be performed using
94 @param Value A pointer to the 16-bit value for the compare exchange
96 @param CompareValue 16-bit value used in compare operation.
97 @param ExchangeValue 16-bit value used in exchange operation.
99 @return The original *Value before exchange.
104 InternalSyncCompareExchange16 (
105 IN OUT
volatile UINT16
*Value
,
106 IN UINT16 CompareValue
,
107 IN UINT16 ExchangeValue
110 __asm__
__volatile__ (
112 "cmpxchgw %2, %1 \n\t"
113 : "+a" (CompareValue
), // %0
115 : "r" (ExchangeValue
) // %2
125 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
127 Performs an atomic compare exchange operation on the 32-bit unsigned integer
128 specified by Value. If Value is equal to CompareValue, then Value is set to
129 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
130 then Value is returned. The compare exchange operation must be performed using
134 @param Value A pointer to the 32-bit value for the compare exchange
136 @param CompareValue 32-bit value used in compare operation.
137 @param ExchangeValue 32-bit value used in exchange operation.
139 @return The original *Value before exchange.
144 InternalSyncCompareExchange32 (
145 IN OUT
volatile UINT32
*Value
,
146 IN UINT32 CompareValue
,
147 IN UINT32 ExchangeValue
150 __asm__
__volatile__ (
152 "cmpxchgl %2, %1 \n\t"
153 : "+a" (CompareValue
), // %0
155 : "r" (ExchangeValue
) // %2
165 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
167 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
168 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
169 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
170 The compare exchange operation must be performed using MP safe mechanisms.
173 @param Value A pointer to the 64-bit value for the compare exchange
175 @param CompareValue 64-bit value used in compare operation.
176 @param ExchangeValue 64-bit value used in exchange operation.
178 @return The original *Value before exchange.
183 InternalSyncCompareExchange64 (
184 IN OUT
volatile UINT64
*Value
,
185 IN UINT64 CompareValue
,
186 IN UINT64 ExchangeValue
189 __asm__
__volatile__ (
191 "cmpxchgq %2, %1 \n\t"
192 : "+a" (CompareValue
), // %0
194 : "r" (ExchangeValue
) // %2