From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web08.2794.1663984640710905439 for ; Fri, 23 Sep 2022 18:57:21 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: loongson.cn, ip: 114.242.206.163, mailfrom: lichao@loongson.cn) Received: from lichao-PC (unknown [10.40.24.149]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxkOD5Yy5j5QIhAA--.58663S2; Sat, 24 Sep 2022 09:57:13 +0800 (CST) Date: Sat, 24 Sep 2022 09:57:13 +0800 From: "Chao Li" To: =?utf-8?Q?=22Kinney=2C_Michael_D=22?= Cc: "=?utf-8?Q?=22devel=40edk2.groups.io=22?=" , =?utf-8?Q?=22Gao=2C_Liming=22?= , =?utf-8?Q?=22Liu=2C_Zhiguang=22?= , Baoqi Zhang Message-ID: In-Reply-To: References: Subject: Re: [PATCH v2 28/34] MdePkg/BaseSynchronizationLib: LoongArch cache related code. X-Mailer: Mailspring MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxkOD5Yy5j5QIhAA--.58663S2 X-Coremail-Antispam: 1UD129KBjvJXoWxuw1fKw1UKF1xAry8try8AFb_yoWDJF15p3 yxtw4kKan2gw43G3WUJ395GFyDX397KryUGrsYyw18C3s0yr1kZrs5tr48KrW8Zw47Ww18 ZF15Kr4fuan8AFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBlb7Iv0xC_tr1lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I 8E87Iv6xkF7I0E14v26r4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG67k0 8I80eVWUJVW8JwAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl5I8CrVAKz4kIr2xC04v26ryj6r WUMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l7480Y4vEI4kI2Ix0rVAqx4xJMxkIecxEwVCm-w CF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r10 6r1rMI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64 vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_ Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0x vEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8mZX5UUUUU== X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQASCGMtod0D2QAcsv Content-Type: multipart/alternative; boundary="632e63f9_3f6e1140_19a0" --632e63f9_3f6e1140_19a0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Mike, Okay, I'll finish today, and manifest it in the V3. Thanks, Chao -------- On 9=E6=9C=88 23 2022, at 11:57 =E6=99=9A=E4=B8=8A, =22Kinney, Michael D=22= wrote: > Comments below. > > Recommend moving inline assembly to .S files too. > > -----Original Message----- > > =46rom: Chao Li > > Sent: Wednesday, September 14, 2022 2:42 AM > > To: devel=40edk2.groups.io > > Cc: Kinney, Michael D ; Gao, Liming ; Liu, Zhiguang ; > > Baoqi Zhang > > Subject: =5BPATCH v2 28/34=5D MdePkg/BaseSynchronizationLib: LoongArc= h cache related code. > > > > RE=46: https://bugzilla.tianocore.org/show=5Fbug.cgi=3Fid=3D4053 > > > > Support LoongArch cache related functions. > > > > Cc: Michael D Kinney > > Cc: Liming Gao > > Cc: Zhiguang Liu > > > > Signed-off-by: Chao Li > > Co-authored-by: Baoqi Zhang > > --- > > .../BaseSynchronizationLib.inf =7C 5 + > > .../LoongArch64/Synchronization.c =7C 246 ++++++++++++++++++ > > 2 files changed, 251 insertions(+) > > create mode 100644 MdePkg/Library/BaseSynchronizationLib/LoongArch64/= Synchronization.c > > > > diff --git a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizatio= nLib.inf > > b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf > > index 02ba12961a..10021f3352 100755 > > --- a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.in= f > > +++ b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.in= f > > =40=40 -4,6 +4,7 =40=40 > > =23 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved= .
> > > > =23 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserve= d.
> > > > =23 Copyright (c) 2020, Hewlett Packard Enterprise Development LP. Al= l rights reserved.
> > > > +=23 Copyright (c) 2022, Loongson Technology Corporation Limited. All= rights reserved.
> > > > =23 > > > > =23 SPDX-License-Identifier: BSD-2-Clause-Patent > > > > =23 > > > > =40=40 -82,6 +83,10 =40=40 > > Synchronization.c > > > > RiscV64/Synchronization.S > > > > > > > > +=5BSources.LOONGARCH64=5D > > > > + Synchronization.c > > > > + LoongArch64/Synchronization.c > > > > + > > > > =5BPackages=5D > > > > MdePkg/MdePkg.dec > > > > > > > > diff --git a/MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchr= onization.c > > b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c= > > new file mode 100644 > > index 0000000000..b7789f3212 > > --- /dev/null > > +++ b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronizati= on.c > > =40=40 -0,0 +1,246 =40=40 > > +/** =40file > > > > + LoongArch synchronization functions. > > > > + > > > > + Copyright (c) 2022, Loongson Technology Corporation Limited. All ri= ghts reserved.
> > > > + > > > > + SPDX-License-Identifier: BSD-2-Clause-Patent > > > > + > > > > +**/ > > > > + > > > > +=23include > > > > + > > > > +/** > > > > + Performs an atomic compare exchange operation on a 16-bit > > > > + unsigned integer. > > > > + > > > > + Performs an atomic compare exchange operation on the 16-bit > > > > + unsigned integer specified by Value. If Value is equal to > > > > + CompareValue, then Value is set to ExchangeValue and > > > > + CompareValue is returned. If Value is not equal to > > > > + CompareValue, then Value is returned. The compare exchange > > > > + operation must be performed using MP safe mechanisms. > > > > + > > > > + =40param=5Bin=5D Value A pointer to the 16-bit value for the > > > > + compare exchange operation. > > > > + =40param=5Bin=5D CompareValue 16-bit value used in compare operatio= n. > > > > + =40param=5Bin=5D ExchangeValue 16-bit value used in exchange operat= ion. > > > > + > > > > + =40return The original *Value before exchange. > > > > + > > > > +**/ > > > > +UINT16 > > > > +E=46IAPI > > > > +InternalSyncCompareExchange16 ( > > > > + IN volatile UINT16 *Value, > > > > + IN UINT16 CompareValue, > > > > + IN UINT16 ExchangeValue > > > > + ) > > > > +=7B > > > > + UINT32 RetValue; > > > > + UINT32 Temp; > > > > + UINT32 Shift; > > > > + UINT64 Mask; > > > > + UINT64 LocalCompareValue; > > > > + UINT64 LocalExchangeValue; > > > > + volatile UINT32 *Ptr32; > > > > + > > > > + /* Check that ptr is naturally aligned */ > > > > + ASSERT (=21((UINT64)Value & (sizeof (Value) - 1))); > > Recommend using macros in Base.h t check alignment. > > > > + > > > > + /* Mask inputs to the correct size. */ > > > > + Mask =3D (((=7E0UL) - (1UL << (0)) + 1) & (=7E0UL >> (64 - 1 - ((si= zeof (UINT16) * 8) - 1)))); > > This statement is hard to read. Especially with =7E0 and << 0. Base.h h= as MAX=5FUINT64 which may be better than =7E0. > > > > + LocalCompareValue =3D ((UINT64)CompareValue) & Mask; > > > > + LocalExchangeValue =3D ((UINT64)ExchangeValue) & Mask; > > > > + > > > > + /* > > > > + * Calculate a shift & mask that correspond to the value we wish to > > > > + * compare & exchange within the naturally aligned 4 byte integer > > > > + * that includes it. > > > > + */ > > > > + Shift =3D (UINT64)Value & 0x3; > > > > + Shift *=3D 8; /* BITS=5FPER=5FBYTE */ > > > > + LocalCompareValue <<=3D Shift; > > > > + LocalExchangeValue <<=3D Shift; > > > > + Mask <<=3D Shift; > > > > + > > > > + /* > > > > + * Calculate a pointer to the naturally aligned 4 byte integer that > > > > + * includes our byte of interest, and load its value. > > > > + */ > > > > + Ptr32 =3D (UINT32 *)((UINT64)Value & =7E0x3); > > > > + > > > > + =5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ( > > > > + =221: =5Cn=22 > > > > + =22ll.w %0, %3 =5Cn=22 > > > > + =22and %1, %0, %4 =5Cn=22 > > > > + =22bne %1, %5, 2f =5Cn=22 > > > > + =22andn %1, %0, %4 =5Cn=22 > > > > + =22or %1, %1, %6 =5Cn=22 > > > > + =22sc.w %1, %2 =5Cn=22 > > > > + =22beqz %1, 1b =5Cn=22 > > > > + =22b 3f =5Cn=22 > > > > + =222: =5Cn=22 > > > > + =22dbar 0 =5Cn=22 > > > > + =223: =5Cn=22 > > > > + : =22=3D&r=22 (RetValue), =22=3D&r=22 (Temp), =22=3D=22 =22ZC=22 (*= Ptr32) > > > > + : =22ZC=22 (*Ptr32), =22Jr=22 (Mask), =22Jr=22 (LocalCompareValue),= =22Jr=22 (LocalExchangeValue) > > > > + : =22memory=22 > > > > + ); > > Recommend removing inline assembly > > > > + > > > > + return (RetValue & Mask) >> Shift; > > > > +=7D > > > > + > > > > +/** > > > > + Performs an atomic compare exchange operation on a 32-bit > > > > + unsigned integer. > > > > + > > > > + Performs an atomic compare exchange operation on the 32-bit > > > > + unsigned integer specified by Value. If Value is equal to > > > > + CompareValue, then Value is set to ExchangeValue and > > > > + CompareValue is returned. If Value is not equal to > > > > + CompareValue, then Value is returned. The compare exchange > > > > + operation must be performed using MP safe mechanisms. > > > > + > > > > + =40param=5Bin=5D Value A pointer to the 32-bit value for the > > > > + compare exchange operation. > > > > + =40param=5Bin=5D CompareValue 32-bit value used in compare operatio= n. > > > > + =40param=5Bin=5D ExchangeValue 32-bit value used in exchange operat= ion. > > > > + > > > > + =40return The original *Value before exchange. > > > > + > > > > +**/ > > > > +UINT32 > > > > +E=46IAPI > > > > +InternalSyncCompareExchange32 ( > > > > + IN volatile UINT32 *Value, > > > > + IN UINT32 CompareValue, > > > > + IN UINT32 ExchangeValue > > > > + ) > > > > +=7B > > > > + UINT32 RetValue; > > > > + > > > > + =5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ( > > > > + =221: =5Cn=22 > > > > + =22ll.w %0, %2 =5Cn=22 > > > > + =22bne %0, %3, 2f =5Cn=22 > > > > + =22move %0, %4 =5Cn=22 > > > > + =22sc.w %0, %1 =5Cn=22 > > > > + =22beqz %0, 1b =5Cn=22 > > > > + =22b 3f =5Cn=22 > > > > + =222: =5Cn=22 > > > > + =22dbar 0 =5Cn=22 > > > > + =223: =5Cn=22 > > > > + : =22=3D&r=22 (RetValue), =22=3D=22 =22ZC=22 (*Value) > > > > + : =22ZC=22 (*Value), =22Jr=22 (CompareValue), =22Jr=22 (ExchangeVal= ue) > > > > + : =22memory=22 > > > > + ); > > Recommend removing inline assembly > > > > + return RetValue; > > > > +=7D > > > > + > > > > +/** > > > > + Performs an atomic compare exchange operation on a 64-bit unsigned = integer. > > > > + > > > > + Performs an atomic compare exchange operation on the 64-bit unsigne= d integer specified > > > > + by Value. If Value is equal to CompareValue, then Value is set to E= xchangeValue and > > > > + CompareValue is returned. If Value is not equal to CompareValue, th= en Value is returned. > > > > + The compare exchange operation must be performed using MP safe mech= anisms. > > > > + > > > > + =40param=5Bin=5D Value A pointer to the 64-bit value for the compar= e exchange > > > > + operation. > > > > + =40param=5Bin=5D CompareValue 64-bit value used in compare operatio= n. > > > > + =40param=5Bin=5D ExchangeValue 64-bit value used in exchange operat= ion. > > > > + > > > > + =40return The original *Value before exchange. > > > > + > > > > +**/ > > > > +UINT64 > > > > +E=46IAPI > > > > +InternalSyncCompareExchange64 ( > > > > + IN volatile UINT64 *Value, > > > > + IN UINT64 CompareValue, > > > > + IN UINT64 ExchangeValue > > > > + ) > > > > +=7B > > > > + UINT64 RetValue; > > > > + > > > > + =5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ( > > > > + =221: =5Cn=22 > > > > + =22ll.d %0, %2 =5Cn=22 > > > > + =22bne %0, %3, 2f =5Cn=22 > > > > + =22move %0, %4 =5Cn=22 > > > > + =22sc.d %0, %1 =5Cn=22 > > > > + =22beqz %0, 1b =5Cn=22 > > > > + =22b 3f =5Cn=22 > > > > + =222: =5Cn=22 > > > > + =22dbar 0 =5Cn=22 > > > > + =223: =5Cn=22 > > > > + : =22=3D&r=22 (RetValue), =22=3D=22 =22ZC=22 (*Value) > > > > + : =22ZC=22 (*Value), =22Jr=22 (CompareValue), =22Jr=22 (ExchangeVal= ue) > > > > + : =22memory=22 > > > > + ); > > > > + return RetValue; > > > > +=7D > > > > + > > > > +/** > > > > + Performs an atomic increment of an 32-bit unsigned integer. > > > > + > > > > + Performs an atomic increment of the 32-bit unsigned integer specifi= ed by > > > > + Value and returns the incremented value. The increment operation mu= st be > > > > + performed using MP safe mechanisms. The state of the return value i= s not > > > > + guaranteed to be MP safe. > > > > + > > > > + =40param=5Bin=5D Value A pointer to the 32-bit value to increment. > > > > + > > > > + =40return The incremented value. > > > > + > > > > +**/ > > > > +UINT32 > > > > +E=46IAPI > > > > +InternalSyncIncrement ( > > > > + IN volatile UINT32 *Value > > > > + ) > > > > +=7B > > > > + UINT32 Temp; > > > > + > > > > + Temp =3D *Value; > > > > + =5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ( > > > > + =22dbar 0 =5Cn=22 > > > > + =22amadd.w %1, %2, %0 =5Cn=22 > > > > + : =22+ZB=22 (*Value), =22=3D&r=22 (Temp) > > > > + : =22r=22 (1) > > > > + : =22memory=22 > > > > + ); > > > > + return *Value; > > > > +=7D > > > > + > > > > +/** > > > > + Performs an atomic decrement of an 32-bit unsigned integer. > > > > + > > > > + Performs an atomic decrement of the 32-bit unsigned integer specifi= ed by > > > > + Value and returns the decrement value. The decrement operation must= be > > > > + performed using MP safe mechanisms. The state of the return value i= s not > > > > + guaranteed to be MP safe. > > > > + > > > > + =40param=5Bin=5D Value A pointer to the 32-bit value to decrement. > > > > + > > > > + =40return The decrement value. > > > > + > > > > +**/ > > > > +UINT32 > > > > +E=46IAPI > > > > +InternalSyncDecrement ( > > > > + IN volatile UINT32 *Value > > > > + ) > > > > +=7B > > > > + UINT32 Temp; > > > > + > > > > + Temp =3D *Value; > > > > + =5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F ( > > > > + =22dbar 0 =5Cn=22 > > > > + =22amadd.w %1, %2, %0 =5Cn=22 > > > > + : =22+ZB=22 (*Value), =22=3D&r=22 (Temp) > > > > + : =22r=22 (-1) > > > > + : =22memory=22 > > > > + ); > > > > + return *Value; > > > > +=7D > > > > -- > > 2.27.0 > --632e63f9_3f6e1140_19a0 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Mike,
Okay, I'll finish today, and manifest it in the V3.<= /div>


Thanks,
Chao
--------

On 9=E6=9C=88= 23 2022, at 11:57 =E6=99=9A=E4=B8=8A, =22Kinney, Michael D=22 <michae= l.d.kinney=40intel.com> wrote:
Comments bel= ow.

Recommend moving inline assembly to .S files too.
=
> -----Original Message-----
> =46rom: Chao Li &= lt;lichao=40loongson.cn>
> Sent: Wednesday, September 14,= 2022 2:42 AM
> To: devel=40edk2.groups.io
> Cc= : Kinney, Michael D <michael.d.kinney=40intel.com>; Gao, Liming <= ;gaoliming=40byosoft.com.cn>; Liu, Zhiguang <zhiguang.liu=40intel.c= om>;
> Baoqi Zhang <zhangbaoqi=40loongson.cn>
=
> Subject: =5BPATCH v2 28/34=5D MdePkg/BaseSynchronizationLib: Lo= ongArch cache related code.
>
> RE=46: https://= bugzilla.tianocore.org/show=5Fbug.cgi=3Fid=3D4053
>
> Support LoongArch cache related functions.
>
> Cc: Michael D Kinney <michael.d.kinney=40intel.com>
> Cc: Liming Gao <gaoliming=40byosoft.com.cn>
> C= c: Zhiguang Liu <zhiguang.liu=40intel.com>
>
> Signed-off-by: Chao Li <lichao=40loongson.cn>
> = Co-authored-by: Baoqi Zhang <zhangbaoqi=40loongson.cn>
&g= t; ---
> .../BaseSynchronizationLib.inf =7C 5 +
&g= t; .../LoongArch64/Synchronization.c =7C 246 ++++++++++++++++++
> 2 files changed, 251 insertions(+)
> create mode 10064= 4 MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c
>
> diff --git a/MdePkg/Library/BaseSynchronizatio= nLib/BaseSynchronizationLib.inf
> b/MdePkg/Library/BaseSynch= ronizationLib/BaseSynchronizationLib.inf
> index 02ba12961a.= .10021f3352 100755
> --- a/MdePkg/Library/BaseSynchronizatio= nLib/BaseSynchronizationLib.inf
> +++ b/MdePkg/Library/BaseS= ynchronizationLib/BaseSynchronizationLib.inf
> =40=40 -4,6 += 4,7 =40=40
> =23 Copyright (c) 2007 - 2018, Intel Corporatio= n. All rights reserved.<BR>
>
> =23 Porti= ons copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR><= /div>
>
> =23 Copyright (c) 2020, Hewlett Packard Ent= erprise Development LP. All rights reserved.<BR>
>
> +=23 Copyright (c) 2022, Loongson Technology Corporation Limi= ted. All rights reserved.<BR>
>
> =23
>
> =23 SPDX-License-Identifier: BSD-2-Clause-Pate= nt
>
> =23
>
> =40=40= -82,6 +83,10 =40=40
> Synchronization.c
>
> RiscV64/Synchronization.S
>
>
<= div>>
> +=5BSources.LOONGARCH64=5D
>
> + Synchronization.c
>
> + LoongArch64/S= ynchronization.c
>
> +
>
> =5BPackages=5D
>
> MdePkg/MdePkg.dec
>
>
>
> diff --git a/MdeP= kg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c
> b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization= .c
> new file mode 100644
> index 0000000000..b= 7789f3212
> --- /dev/null
> +++ b/MdePkg/Librar= y/BaseSynchronizationLib/LoongArch64/Synchronization.c
> =40= =40 -0,0 +1,246 =40=40
> +/** =40file
>
> + LoongArch synchronization functions.
>
&= gt; +
>
> + Copyright (c) 2022, Loongson Techno= logy Corporation Limited. All rights reserved.<BR>
>
> +
>
> + SPDX-License-Identifier: = BSD-2-Clause-Patent
>
> +
>
<= div>> +**/
>
> +
>
&g= t; +=23include <Library/DebugLib.h>
>
> +=
>
> +/**
>
> + Perfo= rms an atomic compare exchange operation on a 16-bit
>
=
> + unsigned integer.
>
> +
&= gt;
> + Performs an atomic compare exchange operation on the= 16-bit
>
> + unsigned integer specified by Val= ue. If Value is equal to
>
> + CompareValue, th= en Value is set to ExchangeValue and
>
> + Comp= areValue is returned. If Value is not equal to
>
&= gt; + CompareValue, then Value is returned. The compare exchange
>
> + operation must be performed using MP safe mechani= sms.
>
> +
>
> + =40p= aram=5Bin=5D Value A pointer to the 16-bit value for the
>
> + compare exchange operation.
>
>= + =40param=5Bin=5D CompareValue 16-bit value used in compare operation.<= /div>
>
> + =40param=5Bin=5D ExchangeValue 16-bit val= ue used in exchange operation.
>
> +
= >
> + =40return The original *Value before exchange.
>
> +
>
> +**/
= >
> +UINT16
>
> +E=46IAPI
=
>
> +InternalSyncCompareExchange16 (
><= /div>
> + IN volatile UINT16 *Value,
>
>= + IN UINT16 CompareValue,
>
> + IN UINT16 Exch= angeValue
>
> + )
>
>= +=7B
>
> + UINT32 RetValue;
>
> + UINT32 Temp;
>
> + UINT32 Shift;<= /div>
>
> + UINT64 Mask;
>
>= ; + UINT64 LocalCompareValue;
>
> + UINT64 Loca= lExchangeValue;
>
> + volatile UINT32 *Ptr32;
>
> +
>
> + /* Check t= hat ptr is naturally aligned */
>
> + ASSERT (=21= ((UINT64)Value & (sizeof (Value) - 1)));

Recommend usin= g macros in Base.h t check alignment.
>
> +
>
> + /* Mask inputs to the correct size. */
=
>
> + Mask =3D (((=7E0UL) - (1UL << (0)) + 1) = & (=7E0UL >> (64 - 1 - ((sizeof (UINT16) * 8) - 1))));
This statement is hard to read. Especially with =7E0 and << 0= . Base.h has MAX=5FUINT64 which may be better than =7E0.

&g= t;
> + LocalCompareValue =3D ((UINT64)CompareValue) & Ma= sk;
>
> + LocalExchangeValue =3D ((UINT64)Excha= ngeValue) & Mask;
>
> +
>
> + /*
>
> + * Calculate a shift &= mask that correspond to the value we wish to
>
&g= t; + * compare & exchange within the naturally aligned 4 byte integer=
>
> + * that includes it.
>
=
> + */
>
> + Shift =3D (UINT64)Value &a= mp; 0x3;
>
> + Shift *=3D 8; /* BITS=5FPER=5FBY= TE */
>
> + LocalCompareValue <<=3D Shift= ;
>
> + LocalExchangeValue <<=3D Shift;
>
> + Mask <<=3D Shift;
>
> +
>
> + /*
>
> + * Calculate a pointer to the naturally aligned 4 byte integer tha= t
>
> + * includes our byte of interest, and lo= ad its value.
>
> + */
>
> + Ptr32 =3D (UINT32 *)((UINT64)Value & =7E0x3);
><= /div>
> +
>
> + =5F=5Fasm=5F=5F =5F=5Fvo= latile=5F=5F (
>
> + =221: =5Cn=22
&g= t;
> + =22ll.w %0, %3 =5Cn=22
>
> = + =22and %1, %0, %4 =5Cn=22
>
> + =22bne %1, %5= , 2f =5Cn=22
>
> + =22andn %1, %0, %4 =5Cn=22
>
> + =22or %1, %1, %6 =5Cn=22
>
> + =22sc.w %1, %2 =5Cn=22
>
> + =22= beqz %1, 1b =5Cn=22
>
> + =22b 3f =5Cn=22
=
>
> + =222: =5Cn=22
>
> + = =22dbar 0 =5Cn=22
>
> + =223: =5Cn=22
>
> + : =22=3D&r=22 (RetValue), =22=3D&r=22 (Tem= p), =22=3D=22 =22ZC=22 (*Ptr32)
>
> + : =22ZC=22= (*Ptr32), =22Jr=22 (Mask), =22Jr=22 (LocalCompareValue), =22Jr=22 (Local= ExchangeValue)
>
> + : =22memory=22
&= gt;
> + );

Recommend removing inline assembly<= /div>
>
> +
>
> + retur= n (RetValue & Mask) >> Shift;
>
> +=7D=
>
> +
>
> +/**
=
>
> + Performs an atomic compare exchange operation = on a 32-bit
>
> + unsigned integer.
&= gt;
> +
>
> + Performs an atomic c= ompare exchange operation on the 32-bit
>
> + u= nsigned integer specified by Value. If Value is equal to
>
> + CompareValue, then Value is set to ExchangeValue and
>
> + CompareValue is returned. If Value is not equ= al to
>
> + CompareValue, then Value is returne= d. The compare exchange
>
> + operation must be= performed using MP safe mechanisms.
>
> +
>
> + =40param=5Bin=5D Value A pointer to the 32-bi= t value for the
>
> + compare exchange operatio= n.
>
> + =40param=5Bin=5D CompareValue 32-bit v= alue used in compare operation.
>
> + =40param=5B= in=5D ExchangeValue 32-bit value used in exchange operation.
&g= t;
> +
>
> + =40return The origina= l *Value before exchange.
>
> +
><= /div>
> +**/
>
> +UINT32
><= /div>
> +E=46IAPI
>
> +InternalSyncCompa= reExchange32 (
>
> + IN volatile UINT32 *Value,=
>
> + IN UINT32 CompareValue,
>
> + IN UINT32 ExchangeValue
>
> + )=
>
> +=7B
>
> + UINT3= 2 RetValue;
>
> +
>
>= + =5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F (
>
> += =221: =5Cn=22
>
> + =22ll.w %0, %2 =5Cn=22
>
> + =22bne %0, %3, 2f =5Cn=22
>
> + =22move %0, %4 =5Cn=22
>
> + =22s= c.w %0, %1 =5Cn=22
>
> + =22beqz %0, 1b =5Cn=22=
>
> + =22b 3f =5Cn=22
>
> + =222: =5Cn=22
>
> + =22dbar 0 =5Cn=22
>
> + =223: =5Cn=22
>
>= ; + : =22=3D&r=22 (RetValue), =22=3D=22 =22ZC=22 (*Value)
&= gt;
> + : =22ZC=22 (*Value), =22Jr=22 (CompareValue), =22Jr=22= (ExchangeValue)
>
> + : =22memory=22
>
> + );

Recommend removing inline assembl= y

>
> + return RetValue;
>
> +=7D
>
> +
>
> +/**
>
> + Performs an atomic compare exc= hange operation on a 64-bit unsigned integer.
>
&g= t; +
>
> + Performs an atomic compare exchange = operation on the 64-bit unsigned integer specified
>
> + by Value. If Value is equal to CompareValue, then Value is set = to ExchangeValue and
>
> + CompareValue is retu= rned. If Value is not equal to CompareValue, then Value is returned.
>
> + The compare exchange operation must be perfor= med using MP safe mechanisms.
>
> +
&= gt;
> + =40param=5Bin=5D Value A pointer to the 64-bit value= for the compare exchange
>
> + operation.
>
> + =40param=5Bin=5D CompareValue 64-bit value us= ed in compare operation.
>
> + =40param=5Bin=5D= ExchangeValue 64-bit value used in exchange operation.
>
> +
>
> + =40return The original *Va= lue before exchange.
>
> +
>
=
> +**/
>
> +UINT64
>
=
> +E=46IAPI
>
> +InternalSyncCompareExc= hange64 (
>
> + IN volatile UINT64 *Value,
>
> + IN UINT64 CompareValue,
>
<= div>> + IN UINT64 ExchangeValue
>
> + )
>
> +=7B
>
> + UINT64 Ret= Value;
>
> +
>
> + =5F= =5Fasm=5F=5F =5F=5Fvolatile=5F=5F (
>
> + =221:= =5Cn=22
>
> + =22ll.d %0, %2 =5Cn=22
>
> + =22bne %0, %3, 2f =5Cn=22
>
> + =22move %0, %4 =5Cn=22
>
> + =22sc.d %0= , %1 =5Cn=22
>
> + =22beqz %0, 1b =5Cn=22
=
>
> + =22b 3f =5Cn=22
>
> = + =222: =5Cn=22
>
> + =22dbar 0 =5Cn=22
>
> + =223: =5Cn=22
>
> + : = =22=3D&r=22 (RetValue), =22=3D=22 =22ZC=22 (*Value)
>
> + : =22ZC=22 (*Value), =22Jr=22 (CompareValue), =22Jr=22 (Ex= changeValue)
>
> + : =22memory=22
>= ;
> + );
>
> + return RetValue;
>
> +=7D
>
> +
>
> +/**
>
> + Performs an at= omic increment of an 32-bit unsigned integer.
>
&g= t; +
>
> + Performs an atomic increment of the = 32-bit unsigned integer specified by
>
> + Valu= e 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.
>
> +
>
>= ; + =40param=5Bin=5D Value A pointer to the 32-bit value to increment.
>
> +
>
> + =40return T= he incremented value.
>
> +
>
> +**/
>
> +UINT32
>
> +E=46IAPI
>
> +InternalSyncIncrement= (
>
> + IN volatile UINT32 *Value
&g= t;
> + )
>
> +=7B
>
> + UINT32 Temp;
>
> +
&g= t;
> + Temp =3D *Value;
>
> + =5F=5F= asm=5F=5F =5F=5Fvolatile=5F=5F (
>
> + =22dbar = 0 =5Cn=22
>
> + =22amadd.w %1, %2, %0 =5Cn=22
>
> + : =22+ZB=22 (*Value), =22=3D&r=22 (Tem= p)
>
> + : =22r=22 (1)
>
> + : =22memory=22
>
> + );
><= /div>
> + return *Value;
>
> +=7D
<= div>>
> +
>
> +/**
&g= t;
> + Performs an atomic decrement of an 32-bit unsigned in= teger.
>
> +
>
> + Pe= rforms an atomic decrement of the 32-bit unsigned integer specified by
>
> + Value and returns the decrement value. The = decrement operation must be
>
> + performed usi= ng MP safe mechanisms. The state of the return value is not
>= ;
> + guaranteed to be MP safe.
>
>= ; +
>
> + =40param=5Bin=5D Value A pointer to t= he 32-bit value to decrement.
>
> +
&= gt;
> + =40return The decrement value.
>
<= div>> +
>
> +**/
>
&g= t; +UINT32
>
> +E=46IAPI
>
> +InternalSyncDecrement (
>
> + IN volat= ile UINT32 *Value
>
> + )
>
<= div>> +=7B
>
> + UINT32 Temp;
>=
> +
>
> + Temp =3D *Value;
<= div>>
> + =5F=5Fasm=5F=5F =5F=5Fvolatile=5F=5F (
>
> + =22dbar 0 =5Cn=22
>
> += =22amadd.w %1, %2, %0 =5Cn=22
>
> + : =22+ZB=22= (*Value), =22=3D&r=22 (Temp)
>
> + : =22r=22= (-1)
>
> + : =22memory=22
>
=
> + );
>
> + return *Value;
&= gt;
> +=7D
>
> --
> 2= .27.0
--632e63f9_3f6e1140_19a0--