diff options
Diffstat (limited to 'MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c')
-rw-r--r-- | MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c | 92 |
1 files changed, 36 insertions, 56 deletions
diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c b/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c index 5b1635a98043..ee9d6a4a32fc 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c +++ b/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c @@ -1,28 +1,20 @@ /** @file GCC inline implementation of BaseSynchronizationLib processor specific functions. - - Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> - Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php. - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ - /** Performs an atomic increment of an 32-bit unsigned integer. Performs an atomic increment of the 32-bit unsigned integer specified by Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. @param Value A pointer to the 32-bit value to increment. @@ -38,17 +30,18 @@ InternalSyncIncrement ( UINT32 Result; __asm__ __volatile__ ( + "movl $1, %%eax \n\t" "lock \n\t" - "incl %2 \n\t" - "mov %2, %%eax " - : "=a" (Result), // %0 - "=m" (*Value) // %1 - : "m" (*Value) // %2 + "xadd %%eax, %1 \n\t" + "inc %%eax \n\t" + : "=&a" (Result), // %0 + "+m" (*Value) // %1 + : // no inputs that aren't also outputs : "memory", "cc" ); - - return Result; + + return Result; } @@ -57,8 +50,7 @@ InternalSyncIncrement ( Performs an atomic decrement of the 32-bit unsigned integer specified by Value and returns the decremented value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. @param Value A pointer to the 32-bit value to decrement. @@ -72,18 +64,19 @@ InternalSyncDecrement ( ) { UINT32 Result; - + __asm__ __volatile__ ( - "lock \n\t" - "decl %2 \n\t" - "mov %2, %%eax " - : "=a" (Result), // %0 - "=m" (*Value) // %1 - : "m" (*Value) // %2 + "movl $-1, %%eax \n\t" + "lock \n\t" + "xadd %%eax, %1 \n\t" + "dec %%eax \n\t" + : "=&a" (Result), // %0 + "+m" (*Value) // %1 + : // no inputs that aren't also outputs : "memory", "cc" ); - + return Result; } @@ -114,16 +107,12 @@ InternalSyncCompareExchange16 ( IN UINT16 ExchangeValue ) { - - __asm__ __volatile__ ( "lock \n\t" - "cmpxchgw %3, %1 " - : "=a" (CompareValue), - "=m" (*Value) - : "a" (CompareValue), - "r" (ExchangeValue), - "m" (*Value) + "cmpxchgw %2, %1 \n\t" + : "+a" (CompareValue), // %0 + "+m" (*Value) // %1 + : "r" (ExchangeValue) // %2 : "memory", "cc" ); @@ -158,20 +147,16 @@ InternalSyncCompareExchange32 ( IN UINT32 ExchangeValue ) { - - __asm__ __volatile__ ( "lock \n\t" - "cmpxchgl %3, %1 " - : "=a" (CompareValue), // %0 - "=m" (*Value) // %1 - : "a" (CompareValue), // %2 - "r" (ExchangeValue), // %3 - "m" (*Value) + "cmpxchgl %2, %1 \n\t" + : "+a" (CompareValue), // %0 + "+m" (*Value) // %1 + : "r" (ExchangeValue) // %2 : "memory", "cc" ); - + return CompareValue; } @@ -201,20 +186,15 @@ InternalSyncCompareExchange64 ( IN UINT64 ExchangeValue ) { - __asm__ __volatile__ ( "lock \n\t" - "cmpxchgq %3, %1 " - : "=a" (CompareValue), // %0 - "=m" (*Value) // %1 - : "a" (CompareValue), // %2 - "r" (ExchangeValue), // %3 - "m" (*Value) + "cmpxchgq %2, %1 \n\t" + : "+a" (CompareValue), // %0 + "+m" (*Value) // %1 + : "r" (ExchangeValue) // %2 : "memory", "cc" ); - + return CompareValue; } - - |