public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: "Ni, Ruiyu" <ruiyu.ni@intel.com>,
	"Tian, Feng" <feng.tian@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	"afish@apple.com" <afish@apple.com>,
	"Gao, Liming" <liming.gao@intel.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>
Subject: Re: [PATCH v4 3/5] MdeModulePkg: implement generic PCI I/O driver for non-discoverable devices
Date: Mon, 5 Dec 2016 09:35:33 +0000	[thread overview]
Message-ID: <20161205093533.GE27069@bivouac.eciton.net> (raw)
In-Reply-To: <CAKv+Gu86me0nAijVZbDB-ASzS2joWtQaX7d5O4BdXHHErGR+Bw@mail.gmail.com>

On Fri, Dec 02, 2016 at 06:42:58PM +0000, Ard Biesheuvel wrote:
> >> > The point is that there is nothing clever here for the compiler to do:
> >> > casting a 64-bit int to a 32-bit int is an operation that discards the
> >> > top 32 bits - but the behaviour is entirely defined.
> >> >
> >> > In fact, all architectures other than IA32/ARM use the Math64.c
> >> > implementation of RShiftU64, which simply does the shift.
> >> > And ARM does it only for GCC. I'm not sure why, I can't imagine a GCC
> >> > version that would do anything more complicated than
> >> > ---
> >> > 00000000 <shift>:
> >> >   0:    e1a000c1    asr    r0, r1, #1
> >> >   4:    e12fff1e    bx    lr
> >> > ---
> >> > (and that's with -march=armv4t onwards)
> >>
> >> That's a 32-bit operand. Shifting a 64-bit value will result in a
> >> call to a compiler intrinsic, which is kind of the point of Riuyu's
> >> remark
> >
> > No, it's not.
> > As stated, that is the output from compiling:
> >
> > unsigned int shift(long long val)
> > {
> >   return (val >> 33);
> > }
> >
> > Unless you are claiming long long is 32-bit on ARM.
> >
> > Although I did mess up and make it signed :)
> > When fixed, the code generation is identical but with an lsr instead.
> >
> > The compiler just operates directly on the top 32-bits (in r1), since
> > the ones in r0 are irrelevant to the result.
> 
> OK, but that does mean it is performing optimization up to some point.
> So right shifts of 64-bit quantities by 32 bits or more will be
> 'optimized' by GCC into something that does not rely on the
> intrinsics. But this is not universally true for all toolchains

And I'm OK with a statement of "we can't do this because version X of
toolchain Y does not support it". But I am much less happy for people
to introduce workarounds in functional code because of an issue that
may no longer be relevant for any toolchains actually in use (or even
supported by BaseTools).

At which point can we know this problem goes away and we can program
in regular C instead, if we decide to obsolete some extremely outdated
toolchains?

> (and variable shifts are probably treated differently as well)

It has no effect on intrinsics being required or not, it simply requires
some more stack shuffling. But yes, that removes all options for
compiler shortcuts.

> > Change the shift to 31 and the compiler doesn't do anything cute, so
> > the code is slightly more obvious:
> > ---
> > 00000000 <shift>:
> >    0:    e1a00fa0       lsr     r0, r0, #31
> >    4:    e1800081       orr     r0, r0, r1, lsl #1
> >    8:    e12fff1e       bx      lr
> > ---
> >
> > But even if there were intrinsics generated, shouldn't we support the
> > intrinsic instead of massaging the C code and hope we can prevent it
> > from being generated.
> 
> This is exactly the issue at hand: EDK2 typically does *not* rely on
> such intrinsics, even if we were forced to add them for ARM because
> GCC cannot be instructed to inhibit such calls.
> 
> Actually, I do not agree with the EDK2 position, i.e., I think there
> is no issue relying on routines that are typically provided by the C
> runtime. But this is MdeModulePkg, so it is not up to us.

Indeed it is not.
But this does not sound like a topic we want per-package rules on.

Regards,

Leif


  reply	other threads:[~2016-12-05  9:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-25 15:42 [PATCH v4 0/5] MdeModulePkg: add support for non-discoverable devices Ard Biesheuvel
2016-11-25 15:42 ` [PATCH v4 1/5] MdeModulePkg: introduce non-discoverable device protocol Ard Biesheuvel
2016-11-28  1:57   ` Ni, Ruiyu
2016-11-25 15:42 ` [PATCH v4 2/5] MdeModulePkg: introduce helper library to register non-discoverable devices Ard Biesheuvel
2016-11-28  1:58   ` Ni, Ruiyu
2016-11-25 15:42 ` [PATCH v4 3/5] MdeModulePkg: implement generic PCI I/O driver for " Ard Biesheuvel
2016-11-28  1:56   ` Ni, Ruiyu
2016-11-30 14:06     ` Leif Lindholm
2016-12-02 10:09       ` Leif Lindholm
2016-12-02 12:54       ` Ni, Ruiyu
2016-12-02 14:40         ` Leif Lindholm
2016-12-02 15:07           ` Ard Biesheuvel
2016-12-02 15:56             ` Leif Lindholm
2016-12-02 18:42               ` Ard Biesheuvel
2016-12-05  9:35                 ` Leif Lindholm [this message]
2016-11-25 15:42 ` [PATCH v4 4/5] MdeModulePkg/NonDiscoverablePciDeviceDxe: add support for non-coherent DMA Ard Biesheuvel
2016-11-28  2:25   ` Ni, Ruiyu
2016-11-25 15:42 ` [PATCH v4 5/5] Omap35xxPkg/PciEmulation: port to new non-discoverable device infrastructure Ard Biesheuvel
2016-11-27 10:18 ` [PATCH v4 0/5] MdeModulePkg: add support for non-discoverable devices Marcin Wojtas

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=20161205093533.GE27069@bivouac.eciton.net \
    --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