All of lore.kernel.org
 help / color / mirror / Atom feed
From: BALATON Zoltan <balaton@eik.bme.hu>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: luoyonggang@gmail.com, "Emilio G . Cota" <cota@braap.org>,
	qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: Re: About hardfloat in ppc
Date: Thu, 30 Apr 2020 22:17:45 +0200 (CEST)	[thread overview]
Message-ID: <alpine.BSF.2.22.395.2004302158330.13881@zero.eik.bme.hu> (raw)
In-Reply-To: <87d07okdfh.fsf@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 5540 bytes --]

On Thu, 30 Apr 2020, Alex Bennée wrote:
> BALATON Zoltan <balaton@eik.bme.hu> writes:
>> On Tue, 28 Apr 2020, Alex Bennée wrote:
>>> 罗勇刚(Yonggang Luo) <luoyonggang@gmail.com> writes:
>>>> I am confusing why only  inexact  are set then we can use hard-float.
>>>
>>> The inexact behaviour of the host hardware may be different from the
>>> guest architecture we are trying to emulate and the host hardware may
>>> not be configurable to emulate the guest mode.
>>>
>>> Have a look in softfloat.c and see all the places where
>>> float_flag_inexact is set. Can you convince yourself that the host
>>> hardware will do the same?
>>
>> Can you convince me that it won't? This all seems to be guessing
>> without evidence so I think what we need first is some tests to prove
>> it either way. Such tests could then also be used at runtime to decide
>> if the host and guest FPU are compatible enough to enable hardfloat.
>> Are such tests available somewhere or what would need to be done to
>> implement them?
>
> I seem to recall it comes down to the various approaches that FPUs can
> take when dealing with tiny numbers when rounding. Emilio did the
> original work so I've CC'd him. The original paper is referenced in the
> hardfloat commentary:
>
> Guo, Yu-Chuan, et al. "Translating the ARM Neon and VFP instructions in a
> binary translator." Software: Practice and Experience 46.12 (2016):1591-1615.
>
> which is worth a read if you can get hold of it.
>
> Running tests on start up is not without precedent. We have a
> softfloat_init which checks for a broken FMA implementation. However I'd
> caution about adding too many checks in there.

Sure the runtime check should be quick so likely the approach would be to 
write detailed tests to profile different FPU implementations then only 
include one quick check to tell at runtime if we're running on a known 
good host. Maybe if someone knows the different FPUs can tell this without 
tests but I don't know and finding out from docs seems more work than 
determining it empirically by testing. Does someone have some hints on 
what operations should be tested to check for different inexact handling 
in different FPUs?

>> This may not solve the problem with PPC target with non-cumulative
>> status bits but could improve hardfloat performance at least for some
>> host-guest combinations. To see if it worth the effort we should run
>> such test on common combinations (say x86_64. ARM and PPC hosts with
>> at least these guests).
>
> We already enable hardfloat for all hosts apart from PPC and FAST_MATHS.

Only if inexact is set which may be common but still not using softfloat 
ar all if host's implementation is good for guest could be even faster.

>>>> And PPC always clearing inexact  flag before calling to soft-float
>>>> funcitons. so we can not
>>>> optimize it with hard-float.
>>>> I need some resouces about ineact flag and why always clearing inexcat in
>>>> PPC FP simualtion.
>>>
>>> Because that is the behaviour of the PPC floating point unit. The
>>> inexact flag will represent the last operation done.
>>
>> More precisely additional to the usual cumulative (or sticky) bits
>> there are two non-sticky bits for inexact and rounded (latter of which
>> is not emulated) that currently need clearing FP status before every
>> FP op.
>
> Thanks for the clarification.
>
>> I wonder if we can know when the guest reads these and rerun
>> the last FP op in softfloat to compute them only if these are read,
>> then it's enough to remember the last FP op. This could be relatively
>> simple and may be used even if we don't detect accessing the bits
>> within FPSCR just accessing the FPSCR as likely most guest code does
>> not check that and any cross-platform code won't check PPC specific
>> non-sticky bits so I'd exepect most guest code to be fine with
>> hardfloat.
>
> You could go further if you know nothing in a block can fault you can
> skip the calculation overhead of the per-op flags for all but the last
> op in the block.

I think that's an additional optimisation that could be done once the 
simple case of just rerunning last op if flags are accessed works. Just to 
keep complexity low first then try more complex solution. (Although I'm 
not planning to try to do this so whatever complexity can be handled by 
whom will implement it is fine but less complexity means less bugs so I'd 
go for simple first.)

>> Although what about FP exceptions? We also need to revert
>> to softfloat it FP exceptions are enabled so maybe using host FP
>> exception for managing status bits could be the way to go to let
>> hardware manage this and we don't need to implement everything in
>> software.
>
> Well for all apart from inexact handling (which would fault as soon as
> set) all other exception types are detected before we pass them to
> hardfloat anyway. Given the range of NaN types we would have to post
> process and hardfloat operation anyway to give the right NaN.

Is checking for those exceptions beforehand really needed? Wouldn't it be 
easier to install an exception handler and let the hardware do those 
checks? It this is again done because of FPU implemenation differences but 
inexact is determined by looking at the FP status (that's why it's cleared 
on PPC) then that means that we always use the hosts inexact semantics and 
don't emulate guest correctly anyway, so we can skip the tests above. Then 
why can't we install an exception handler and set guest bits whenever 
that's raised?

Regards,
BALATON Zoltan

      reply	other threads:[~2020-04-30 20:22 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27  6:39 About hardfloat in ppc 罗勇刚(Yonggang Luo)
2020-04-27  9:42 ` Alex Bennée
2020-04-27 10:34   ` BALATON Zoltan
2020-04-27 11:10     ` Alex Bennée
2020-04-27 21:18       ` 罗勇刚(Yonggang Luo)
2020-04-28  8:36         ` Alex Bennée
2020-04-28 14:29           ` 罗勇刚(Yonggang Luo)
2020-04-29 10:17           ` R: " Dino Papararo
2020-04-29 10:31             ` Dino Papararo
2020-04-29 11:57             ` Alex Bennée
2020-04-29 12:33               ` 罗勇刚(Yonggang Luo)
2020-04-29 13:38                 ` Alex Bennée
2020-04-29 14:31               ` R: " Dino Papararo
2020-04-29 14:49                 ` Peter Maydell
2020-04-29 18:25                 ` R: " Alex Bennée
2020-04-30  0:20                   ` 罗勇刚(Yonggang Luo)
2020-04-30  2:18                     ` Richard Henderson
2020-04-30  7:26                       ` 罗勇刚(Yonggang Luo)
2020-04-30  8:11                         ` Alex Bennée
2020-04-30  8:13                       ` 罗勇刚(Yonggang Luo)
2020-04-30 15:35                         ` BALATON Zoltan
2020-04-30 16:34                           ` R: " Dino Papararo
2020-05-01  1:59                             ` Programmingkid
2020-05-01  2:21                               ` 罗勇刚(Yonggang Luo)
2020-05-01 11:58                                 ` BALATON Zoltan
2020-05-01 12:04                                   ` 罗勇刚(Yonggang Luo)
2020-05-01 13:10                                     ` Alex Bennée
2020-05-01 13:39                                       ` BALATON Zoltan
2020-05-01 14:01                                         ` Alex Bennée
2020-05-01 14:18                                       ` Richard Henderson
2020-05-01 16:25                                         ` 罗勇刚(Yonggang Luo)
2020-05-01 19:33                                           ` Alex Bennée
2020-05-01 16:29                                         ` 罗勇刚(Yonggang Luo)
2020-05-01 16:51                                           ` Richard Henderson
2020-05-01 17:49                                             ` 罗勇刚(Yonggang Luo)
2020-05-01 20:35                                               ` Richard Henderson
2020-04-29 23:12               ` R: " 罗勇刚(Yonggang Luo)
2020-04-30 15:16           ` BALATON Zoltan
2020-04-30 18:59             ` Alex Bennée
2020-04-30 20:17               ` BALATON Zoltan [this message]

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-all 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=alpine.BSF.2.22.395.2004302158330.13881@zero.eik.bme.hu \
    --to=balaton@eik.bme.hu \
    --cc=alex.bennee@linaro.org \
    --cc=cota@braap.org \
    --cc=luoyonggang@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.