]>
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 - 2009, 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.
20 Performs an atomic increment of an 32-bit unsigned integer.
22 Performs an atomic increment of the 32-bit unsigned integer specified by
23 Value and returns the incremented value. The increment operation must be
24 performed using MP safe mechanisms. The state of the return value is not
25 guaranteed to be MP safe.
27 @param Value A pointer to the 32-bit value to increment.
29 @return The incremented value.
34 InternalSyncIncrement (
35 IN
volatile UINT32
*Value
40 __asm__
__volatile__ (
44 : "=a" (Result
), // %0
57 Performs an atomic decrement of an 32-bit unsigned integer.
59 Performs an atomic decrement of the 32-bit unsigned integer specified by
60 Value and returns the decremented value. The decrement operation must be
61 performed using MP safe mechanisms. The state of the return value is not
62 guaranteed to be MP safe.
64 @param Value A pointer to the 32-bit value to decrement.
66 @return The decremented value.
71 InternalSyncDecrement (
72 IN
volatile UINT32
*Value
77 __asm__
__volatile__ (
81 : "=a" (Result
), // %0
93 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
95 Performs an atomic compare exchange operation on the 32-bit unsigned integer
96 specified by Value. If Value is equal to CompareValue, then Value is set to
97 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
98 then Value is returned. The compare exchange operation must be performed using
102 @param Value A pointer to the 32-bit value for the compare exchange
104 @param CompareValue 32-bit value used in compare operation.
105 @param ExchangeValue 32-bit value used in exchange operation.
107 @return The original *Value before exchange.
112 InternalSyncCompareExchange32 (
113 IN OUT
volatile UINT32
*Value
,
114 IN UINT32 CompareValue
,
115 IN UINT32 ExchangeValue
118 // GCC 4.1 and forward supports atomic builtins
119 #if ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)))
121 return __sync_val_compare_and_swap (Value
, CompareValue
, ExchangeValue
);
125 __asm__
__volatile__ (
128 : "=a" (CompareValue
), // %0
130 : "a" (CompareValue
), // %2
131 "r" (ExchangeValue
), // %3
144 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
146 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
147 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
148 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
149 The compare exchange operation must be performed using MP safe mechanisms.
152 @param Value A pointer to the 64-bit value for the compare exchange
154 @param CompareValue 64-bit value used in compare operation.
155 @param ExchangeValue 64-bit value used in exchange operation.
157 @return The original *Value before exchange.
162 InternalSyncCompareExchange64 (
163 IN OUT
volatile UINT64
*Value
,
164 IN UINT64 CompareValue
,
165 IN UINT64 ExchangeValue
168 // GCC 4.1 and forward supports atomic builtins
169 #if ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)))
171 return __sync_val_compare_and_swap (Value
, CompareValue
, ExchangeValue
);
175 __asm__
__volatile__ (
178 : "=a" (CompareValue
), // %0
180 : "a" (CompareValue
), // %2
181 "r" (ExchangeValue
), // %3