All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: BALATON Zoltan <balaton@eik.bme.hu>
Cc: Richard Henderson <richard.henderson@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Programmingkid <programmingkidx@gmail.com>,
	"qemu-ppc@nongnu.org" <qemu-ppc@nongnu.org>,
	Howard Spoelstra <hsp.cat7@gmail.com>,
	luigi burdo <intermediadc@hotmail.com>,
	Dino Papararo <skizzato73@msn.com>,
	Aleksandar Markovic <aleksandar.m.mail@gmail.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [RFC PATCH v2] target/ppc: Enable hardfloat for PPC
Date: Mon, 02 Mar 2020 17:10:30 +0000	[thread overview]
Message-ID: <87d09u8yyh.fsf@linaro.org> (raw)
In-Reply-To: <alpine.BSF.2.22.395.2003021218180.72848@zero.eik.bme.hu>


BALATON Zoltan <balaton@eik.bme.hu> writes:

> On Sun, 1 Mar 2020, Richard Henderson wrote:
>> On 3/1/20 4:13 PM, Programmingkid wrote:
>>> Ok, I was just looking at Intel's x87 chip documentation. It
>>> supports IEEE 754 floating point operations and exception flags.
>>> This leads me to this question. Would simply taking the host
>>> exception flags and using them to set the PowerPC's FPU's flag be
>>> an acceptable solution to this problem?
>
> In my understanding that's what is currently done, the problem with
> PPC as Richard said is the non-sticky versions of some of these bits
> which need clearing FP exception status before every FPU op which
> seems to be expensive and slower than using softfloat. So to use
> hardfloat we either accept that we can't emulate these bits with
> hardfloat or we need to do something else than clearing flags and
> checking after every FPU op.
>
> While not emulating these bits don't seem to matter for most clients
> and other PPC emulations got away with it, QEMU prefers accuracy over
> speed even for rarely used features.
>
>> No.
>>
>> The primary issue is the FPSCR.FI flag.  This is not an accumulative bit, per
>> ieee754, but per operation.
>>
>> The "hardfloat" option works (with other targets) only with ieee745
>> accumulative exceptions, when the most common of those exceptions, inexact, has
>> already been raised.  And thus need not be raised a second time.
>
> Why exactly it's done that way? What are the differences between IEEE
> FP implementations that prevents using hardfloat most of the time
> instead of only using it in some (although supposedly common) special
> cases?

There are a couple of wrinkles. As far as NaN and denormal behaviour
goes we have enough slack in the spec that different guests have
slightly different behaviour. See pickNaN and friends in the soft float
specialisation code. As a result we never try and hand off to hardfloat
for NaNs, Infs and Zeros. Luckily testing for those cases if a fairly
small part of the cost of the calculation.

Also things tend to get unstuck on changes to rounding modes.
Fortunately it doesn't seem to be supper common. 

You can read even more detail in the paper that originally prompted
Emilio's work:

  "supporting the neon and VFP instruction sets in an LLVM-based
   binary translator"
   https://www.thinkmind.org/download.php?articleid=icas_2015_5_20_20033

>> Per the PowerPC architecture, inexact must be recognized afresh for every
>> operation.  Which is cheap in hardware but expensive in software.
>>
>> And once you're done with FI, FR has been and continues to be emulated incorrectly.
>
> I think CPUs can also raise exceptions when they detect the condition
> in hardware so maybe we should install our FPU exception handler and
> set guest flags from that then we don't need to check and won't have
> problem with these bits either. Why is that not possible or isn't
> done?

One of my original patches did just this:

  Subject: [PATCH] fpu/softfloat: use hardware sqrt if we can (EXPERIMENT!)
  Date: Tue, 20 Feb 2018 21:01:37 +0000
  Message-Id: <20180220210137.18018-1-alex.bennee@linaro.org>

The two problems you run into are:

 - relying on a trap for inexact will be slow if you keep hitting it
 - reading host FPU flag registers turns out to be pretty expensive

> The softfloat code has a comment that working with exceptions is
> not pleasent but why? Isn't setting flags from a handler easier than
> checking separately for each op? If this is because of differences in
> how flags are handled by different targets we don't have to do that
> from the host FPU exception handler. That handler could only set a
> global flag on each exception that targets can be checked by targets
> and handle differences. This global flag then can include non-sticky
> versions if needed because clearing a global should be less expensive
> than clearing FPU status reg. But I don't really know, just guessing,
> somone who knows more about FPUs probably knows a better way.
>
> Regards,
> BALATON Zoltan


-- 
Alex Bennée


  parent reply	other threads:[~2020-03-02 17:11 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-18 17:10 [RFC PATCH v2] target/ppc: Enable hardfloat for PPC BALATON Zoltan
2020-02-18 17:38 ` BALATON Zoltan
2020-02-19  2:27 ` Programmingkid
2020-02-19 15:35   ` BALATON Zoltan
2020-02-19 18:28     ` Howard Spoelstra
2020-02-19 19:28       ` BALATON Zoltan
2020-02-20  5:43         ` Howard Spoelstra
2020-02-25  3:07     ` Programmingkid
2020-02-25 12:09       ` BALATON Zoltan
2020-02-26 10:46         ` Programmingkid
2020-02-26 11:28           ` BALATON Zoltan
2020-02-26 13:00             ` R: " luigi burdo
2020-02-26 13:08               ` Dino Papararo
2020-02-26 14:28                 ` Alex Bennée
2020-02-26 15:50                   ` Aleksandar Markovic
2020-02-26 17:04                     ` G 3
2020-02-26 17:27                       ` Aleksandar Markovic
2020-02-26 18:14                         ` R: " Dino Papararo
2020-02-26 18:51                           ` Aleksandar Markovic
2020-02-27  2:43                         ` Programmingkid
2020-02-27  7:16                           ` Aleksandar Markovic
2020-02-27 11:54                             ` BALATON Zoltan
2020-02-26 18:09                       ` R: " Alex Bennée
2020-03-02  0:13                         ` Programmingkid
2020-03-02  4:28                           ` Richard Henderson
2020-03-02 11:42                             ` BALATON Zoltan
2020-03-02 16:55                               ` Richard Henderson
2020-03-02 23:16                                 ` BALATON Zoltan
2020-03-03  0:11                                   ` Richard Henderson
     [not found]                                   ` <CAKyx-3Pt2qLPXWQjBwrHn-nxR-9e++TioGp4cKFC3adMN3rtiw@mail.gmail.com>
2020-03-04 18:43                                     ` Fwd: " G 3
2020-03-05 19:25                                       ` Richard Henderson
2020-03-02 17:10                               ` Alex Bennée [this message]
2020-03-02 23:01                                 ` BALATON Zoltan
2020-02-26 22:51                   ` R: " BALATON Zoltan
2020-02-20 20:13 ` Richard Henderson
2020-02-21 16:04   ` BALATON Zoltan
2020-02-21 16:11     ` Peter Maydell
2020-02-21 16:51       ` Aleksandar Markovic
2020-02-21 18:04       ` BALATON Zoltan
2020-02-21 18:26         ` Peter Maydell
2020-02-21 19:52           ` BALATON Zoltan
2020-02-26 12:28             ` Alex Bennée
2020-02-26 13:07               ` BALATON Zoltan
2020-04-10 13:50 ` 罗勇刚(Yonggang Luo)
2020-04-10 18:04   ` BALATON Zoltan

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=87d09u8yyh.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=aleksandar.m.mail@gmail.com \
    --cc=balaton@eik.bme.hu \
    --cc=david@gibson.dropbear.id.au \
    --cc=hsp.cat7@gmail.com \
    --cc=intermediadc@hotmail.com \
    --cc=programmingkidx@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=skizzato73@msn.com \
    /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.