public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Pedro Falcato" <pedro.falcato@gmail.com>
To: devel@edk2.groups.io, gaoliming@byosoft.com.cn
Cc: "Michael D Kinney" <michael.d.kinney@intel.com>,
	"Zhiguang Liu" <zhiguang.liu@intel.com>,
	"Marvin Häuser" <mhaeuser@posteo.de>
Subject: Re: [edk2-devel] [PATCH v2 1/1] MdePkg/Base.h: Simply alignment expressions
Date: Tue, 16 May 2023 03:22:17 +0100	[thread overview]
Message-ID: <CAKbZUD21UR+rQwPODcwmmFTnThr-jvUssiYrCq7P6DDFvGeHBg@mail.gmail.com> (raw)
In-Reply-To: <001c01d98798$42f4f9b0$c8deed10$@byosoft.com.cn>

On Tue, May 16, 2023 at 2:46 AM gaoliming via groups.io
<gaoliming=byosoft.com.cn@groups.io> wrote:
>
> Pedro:
>
> > -----邮件原件-----
> > 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Pedro Falcato
> > 发送时间: 2023年5月15日 23:15
> > 收件人: devel@edk2.groups.io
> > 抄送: Pedro Falcato <pedro.falcato@gmail.com>; Michael D Kinney
> > <michael.d.kinney@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>;
> > Zhiguang Liu <zhiguang.liu@intel.com>; Marvin Häuser
> > <mhaeuser@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

  reply	other threads:[~2023-05-16  2:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15 15:14 [PATCH v2 1/1] MdePkg/Base.h: Simply alignment expressions Pedro Falcato
2023-05-16  1:46 ` 回复: [edk2-devel] " gaoliming
2023-05-16  2:22   ` Pedro Falcato [this message]
2023-05-16  7:18     ` Marvin Häuser
2023-05-16  9:08       ` Marvin Häuser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKbZUD21UR+rQwPODcwmmFTnThr-jvUssiYrCq7P6DDFvGeHBg@mail.gmail.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox