From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from walk.intel-email.com (walk.intel-email.com [101.227.64.242]) by mx.groups.io with SMTP id smtpd.web11.10955.1684201607682947834 for ; Mon, 15 May 2023 18:46:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@byosoft.com.cn header.s=cloud-union header.b=KE8KwS3W; spf=pass (domain: byosoft.com.cn, ip: 101.227.64.242, mailfrom: gaoliming@byosoft.com.cn) Received: from walk.intel-email.com (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id 7088ECD1F737 for ; Tue, 16 May 2023 09:46:44 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=byosoft.com.cn; s=cloud-union; t=1684201604; bh=/3aXqrDIwuaWF5eNyGlf3nRvLAj2A64PhZfObF9zug4=; h=From:To:Cc:References:In-Reply-To:Subject:Date; b=KE8KwS3WzLFvR+yL2ykNaf91hsAwc7YEVOT0NvKlms5s25fwRM4XzWjmKCGM6kfP2 tLi36+NzkaRGzWp63ZYF1wfLFmXZhFYeZhBIpw1QGL54SydpvtjlCTb4OEZfoOlXYu MIRT6swYe/cDBvecPRZavEyS0mZufS3bt2b+h1/o= Received: from localhost (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id 6C40ECD1F708 for ; Tue, 16 May 2023 09:46:44 +0800 (CST) Received: from walk.intel-email.com (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id 3A339CD1F64A for ; Tue, 16 May 2023 09:46:44 +0800 (CST) Authentication-Results: walk.intel-email.com; none Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by walk.intel-email.com (Postfix) with SMTP id C5A0DCD1F663 for ; Tue, 16 May 2023 09:46:41 +0800 (CST) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Tue, 16 May 2023 09:46:38 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: , Cc: "'Michael D Kinney'" , "'Zhiguang Liu'" , =?UTF-8?Q?'Marvin_H=C3=A4user'?= References: <20230515151437.179924-1-pedro.falcato@gmail.com> In-Reply-To: <20230515151437.179924-1-pedro.falcato@gmail.com> Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0gW1BBVENIIHYyIDEvMV0gTWRlUGtnL0Jhc2UuaDogU2ltcGx5IGFsaWdubWVudCBleHByZXNzaW9ucw==?= Date: Tue, 16 May 2023 09:46:41 +0800 Message-ID: <001c01d98798$42f4f9b0$c8deed10$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQDQ7VCZSOS31f/mc2yT0OUKS8i1CbFtUxVw Sender: "gaoliming" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Pedro: > -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6----- > =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io = =E4=BB=A3=E8=A1=A8 Pedro Falcato > =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2023=E5=B9=B45=E6=9C=8815=E6=97=A5 = 23:15 > =E6=94=B6=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io > =E6=8A=84=E9=80=81: Pedro Falcato ; Michael D Ki= nney > ; Liming Gao ; > Zhiguang Liu ; Marvin H=C3=A4user > > =E4=B8=BB=E9=A2=98: [edk2-devel] [PATCH v2 1/1] MdePkg/Base.h: Simply ali= gnment > expressions >=20 > Simplify ALIGN_VALUE and ALIGN_VALUE_ADDEND into simpler expressions. >=20 > ALIGN_VALUE can simply be a (value + (align - 1)) & ~align > expression, which works for any power of 2 alignment and generates > smaller code sequences. For instance: > ALIGN_VALUE(15, 16) =3D (15 + 15) & ~16 =3D 16 > ALIGN_VALUE(16, 16) =3D (16 + 15) & ~16 =3D 16 >=20 > Old codegen: > movq %rdi, %rax > negq %rax > andl $15, %eax > addq %rdi, %rax >=20 > New codegen: > leaq 15(%rdi), %rax > andq $-16, %rax >=20 > ALIGN_VALUE_ADDEND can simply use a bitwise NOT of Value to get the > addend for alignment, as, for instance: > ~15 & (16 - 1) =3D 1 > 15 + 1 =3D 16 >=20 > ~15 & (16 - 1) =3D 1 Its value should be zero, not 1. I also verify the updated ALIGN_VALUE_ADDE= ND.=20 Its value is incorrect. Please double check.=20 Thanks Liming > This change does not necessarily affect the end result, as the GCC and > clang compilers were already able to see through things and optimize > them into optimal instruction sequences, in the ALIGN_VALUE_ADDEND case. >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: Marvin H=C3=A4user > Signed-off-by: Pedro Falcato > --- >=20 > v2: > Addressed concerns expressed on Discord by Marvin > - Added missing parens around Alignment in ALIGN_VALUE > - Replaced -1 with -1U, as in the other macros. >=20 > MdePkg/Include/Base.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h > index 6597e441a6e2..422f80aff53d 100644 > --- a/MdePkg/Include/Base.h > +++ b/MdePkg/Include/Base.h > @@ -931,7 +931,7 @@ STATIC_ASSERT (ALIGNOF > (__VERIFY_INT32_ENUM_SIZE) =3D=3D sizeof (__VERIFY_INT32_ENUM >=20 > @return Addend to round Value up to alignment boundary Alignment. > **/ > -#define ALIGN_VALUE_ADDEND(Value, Alignment) (((Alignment) - (Value)) > & ((Alignment) - 1U)) > +#define ALIGN_VALUE_ADDEND(Value, Alignment) ((~(Value)) & > ((Alignment) - 1U)) >=20 > /** > Rounds a value up to the next boundary using a specified alignment. > @@ -945,7 +945,7 @@ STATIC_ASSERT (ALIGNOF > (__VERIFY_INT32_ENUM_SIZE) =3D=3D sizeof (__VERIFY_INT32_ENUM > @return A value up to the next boundary. >=20 > **/ > -#define ALIGN_VALUE(Value, Alignment) ((Value) + > ALIGN_VALUE_ADDEND (Value, Alignment)) > +#define ALIGN_VALUE(Value, Alignment) (((Value) + ((Alignment) - 1U)) & > ~(Alignment)) >=20 > /** > Adjust a pointer by adding the minimum offset required for it to be al= igned > on > -- > 2.40.1 >=20 >=20 >=20 >=20 >=20