]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c
1976720ac63650e8ae15303003f7ac1164ba619c
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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Performs an atomic increment of an 32-bit unsigned integer.
21 Performs an atomic increment of the 32-bit unsigned integer specified by
22 Value and returns the incremented value. The increment operation must be
23 performed using MP safe mechanisms.
25 @param Value A pointer to the 32-bit value to increment.
27 @return The incremented value.
32 InternalSyncIncrement (
33 IN
volatile UINT32
*Value
38 __asm__
__volatile__ (
43 : "=a" (Result
), // %0
45 : // no inputs that aren't also outputs
55 Performs an atomic decrement of an 32-bit unsigned integer.
57 Performs an atomic decrement of the 32-bit unsigned integer specified by
58 Value and returns the decremented value. The decrement operation must be
59 performed using MP safe mechanisms.
61 @param Value A pointer to the 32-bit value to decrement.
63 @return The decremented value.
68 InternalSyncDecrement (
69 IN
volatile UINT32
*Value
74 __asm__
__volatile__ (
75 "movl $-1, %%eax \n\t"
79 : "=a" (Result
), // %0
81 : // no inputs that aren't also outputs
91 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
93 Performs an atomic compare exchange operation on the 16-bit unsigned integer
94 specified by Value. If Value is equal to CompareValue, then Value is set to
95 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
96 then Value is returned. The compare exchange operation must be performed using
100 @param Value A pointer to the 16-bit value for the compare exchange
102 @param CompareValue 16-bit value used in compare operation.
103 @param ExchangeValue 16-bit value used in exchange operation.
105 @return The original *Value before exchange.
110 InternalSyncCompareExchange16 (
111 IN OUT
volatile UINT16
*Value
,
112 IN UINT16 CompareValue
,
113 IN UINT16 ExchangeValue
116 __asm__
__volatile__ (
118 "cmpxchgw %1, %2 \n\t"
119 : "=a" (CompareValue
) // %0
120 : "q" (ExchangeValue
), // %1
122 "0" (CompareValue
) // %3
132 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
134 Performs an atomic compare exchange operation on the 32-bit unsigned integer
135 specified by Value. If Value is equal to CompareValue, then Value is set to
136 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
137 then Value is returned. The compare exchange operation must be performed using
141 @param Value A pointer to the 32-bit value for the compare exchange
143 @param CompareValue 32-bit value used in compare operation.
144 @param ExchangeValue 32-bit value used in exchange operation.
146 @return The original *Value before exchange.
151 InternalSyncCompareExchange32 (
152 IN OUT
volatile UINT32
*Value
,
153 IN UINT32 CompareValue
,
154 IN UINT32 ExchangeValue
157 __asm__
__volatile__ (
159 "cmpxchgl %1, %2 \n\t"
160 : "=a" (CompareValue
) // %0
161 : "q" (ExchangeValue
), // %1
163 "0" (CompareValue
) // %3
173 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
175 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
176 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
177 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
178 The compare exchange operation must be performed using MP safe mechanisms.
181 @param Value A pointer to the 64-bit value for the compare exchange
183 @param CompareValue 64-bit value used in compare operation.
184 @param ExchangeValue 64-bit value used in exchange operation.
186 @return The original *Value before exchange.
191 InternalSyncCompareExchange64 (
192 IN OUT
volatile UINT64
*Value
,
193 IN UINT64 CompareValue
,
194 IN UINT64 ExchangeValue
197 __asm__
__volatile__ (
201 "cmpxchg8b (%1) \n\t"
203 : "+A" (CompareValue
) // %0
205 "r" ((UINT32
) ExchangeValue
), // %2
206 "c" ((UINT32
) (ExchangeValue
>> 32)) // %3