[edk2-devel] [PATCH v2 1/1] MdePkg/Base.h: Simply alignment expressions

Pedro Falcato pedro.falcato at gmail.com
Tue May 16 02:22:17 UTC 2023


On Tue, May 16, 2023 at 2:46 AM gaoliming via groups.io
<gaoliming=byosoft.com.cn at groups.io> wrote:
>
> Pedro:
>
> > -----邮件原件-----
> > 发件人: devel at edk2.groups.io <devel at edk2.groups.io> 代表 Pedro Falcato
> > 发送时间: 2023年5月15日 23:15
> > 收件人: devel at edk2.groups.io
> > 抄送: Pedro Falcato <pedro.falcato at gmail.com>; Michael D Kinney
> > <michael.d.kinney at intel.com>; Liming Gao <gaoliming at byosoft.com.cn>;
> > Zhiguang Liu <zhiguang.liu at intel.com>; Marvin Häuser
> > <mhaeuser at posteo.de>
> > 主题: [edk2-devel] [PATCH v2 1/1] MdePkg/Base.h: Simply alignment
> > expressions
> >
> > Simplify ALIGN_VALUE and ALIGN_VALUE_ADDEND into simpler expressions.
> >
> > 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) = (15 + 15) & ~16 = 16
> >       ALIGN_VALUE(16, 16) = (16 + 15) & ~16 = 16
> >
> > Old codegen:
> >       movq    %rdi, %rax
> >       negq    %rax
> >       andl    $15, %eax
> >       addq    %rdi, %rax
> >
> > New codegen:
> >       leaq    15(%rdi), %rax
> >       andq    $-16, %rax
> >
> > ALIGN_VALUE_ADDEND can simply use a bitwise NOT of Value to get the
> > addend for alignment, as, for instance:
> >       ~15 & (16 - 1) = 1
> >       15 + 1 = 16
> >
>
> >       ~15 & (16 - 1) = 1
> Its value should be zero, not 1. I also verify the updated ALIGN_VALUE_ADDEND.
> Its value is incorrect. Please double check.

Hi Liming, you're 100% right. There was a mixup when we were
discussing this optimization, and I got the mental calculations wrong
there.
Two's complement is definitely what we want, as one's complement is
always off by one (from what we want).

So negation (-) works beautifully, as seen in the old codegen (we
figured this out from the compiler's output).

Sent a v3.

-- 
Pedro


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#104910): https://edk2.groups.io/g/devel/message/104910
Mute This Topic: https://groups.io/mt/98918981/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list