On 30/09/2018 00:23, Laszlo Ersek wrote:
> (This patch is identical to the last one, except for the
> InternalSyncCompareExchange16() -> InternalSyncCompareExchange32() and
> "cmpxchgw" -> "cmpxchgl" replacements.)
> 
> The CMPXCHG instruction has the following operands:
> - AX (implicit, CompareValue):    input and output
> - destination operand (*Value):   input and output
> - source operand (ExchangeValue): input
> 
> The IA32 version of InternalSyncCompareExchange32() correctly marks
> CompareValue as input/output, but it marks (*Value) only as input.
> 
> The X64 version of InternalSyncCompareExchange32() attempts to mark both
> CompareValue and (*Value) as input/output, but it doesn't use the
> appropriate constraints for either operand.
> 
> Fix these issues. Furthermore, prefer the short "+" constraint for I/O
> operands over the <output-operand-number> constraint that can be applied
> to the input instances of I/O operands.
> 
> Cc: Liming Gao <[email protected]>
> Cc: Michael D Kinney <[email protected]>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1208
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Laszlo Ersek <[email protected]>

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>

> ---
>  MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c |  9 ++++-----
>  MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c  | 10 ++++------
>  2 files changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c 
> b/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c
> index bd98a5aebfe7..44188e265af2 100644
> --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c
> +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c
> @@ -155,11 +155,10 @@ InternalSyncCompareExchange32 (
>  {
>    __asm__ __volatile__ (
>      "lock                 \n\t"
> -    "cmpxchgl    %1, %2   \n\t"
> -    : "=a" (CompareValue)       // %0
> -    : "q"  (ExchangeValue),     // %1
> -      "m"  (*Value),            // %2
> -      "0"  (CompareValue)       // %3
> +    "cmpxchgl    %2, %1   \n\t"
> +    : "+a" (CompareValue),      // %0
> +      "+m" (*Value)             // %1
> +    : "q"  (ExchangeValue)      // %2
>      : "memory",
>        "cc"
>      );
> diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c 
> b/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c
> index 4338fb8e65e8..a85cf0265c8b 100644
> --- a/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c
> +++ b/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c
> @@ -155,12 +155,10 @@ InternalSyncCompareExchange32 (
>  {
>    __asm__ __volatile__ (
>      "lock                 \n\t"
> -    "cmpxchgl    %3, %1   \n\t"
> -    : "=a" (CompareValue),      // %0
> -      "=m" (*Value)             // %1
> -    : "a"  (CompareValue),      // %2
> -      "r"  (ExchangeValue),     // %3
> -      "m"  (*Value)             // %4
> +    "cmpxchgl    %2, %1   \n\t"
> +    : "+a" (CompareValue),      // %0
> +      "+m" (*Value)             // %1
> +    : "r"  (ExchangeValue)      // %2
>      : "memory",
>        "cc"
>      );
> 
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to