qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chen Gang <chengang@emindsoft.com.cn>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, Chen Gang <gang.chen.5i5j@gmail.com>,
	ehabkost@redhat.com, rth@twiddle.net
Subject: Re: [PATCH] target: i386: Check float overflow about register stack
Date: Fri, 21 Feb 2020 22:09:11 +0800	[thread overview]
Message-ID: <900fd511-72f0-675d-4a7e-d228b2ade9c7@emindsoft.com.cn> (raw)
In-Reply-To: <a5533719-7ef1-938b-e52c-20711e65417f@redhat.com>

On 2020/2/21 下午4:58, Paolo Bonzini wrote:
> On 21/02/20 04:45, chengang@emindsoft.com.cn wrote:
>>  static inline void fpush(CPUX86State *env)
>>  {
>> -    env->fpstt = (env->fpstt - 1) & 7;
>> -    env->fptags[env->fpstt] = 0; /* validate stack entry */
>> +    set_fpstt(env, env->fpstt - 1, false, true);
> 
> On overflow fpstt is ~0, so this does:
> 
>     env->foverflow = true;
>     env->fpstt = 7;
>     env->fptags[7] = 0;      /* validate stack entry */
> 
> Is this correct?  You are going to set ST0 so the register should not be
> marked empty.
> 

Originally, I wanted to add foverflow to mark the stack overflow only,
and kept another things no touch.

But I think what you said above is correct, for me, if fpush/f[i]ld*_STO
are overflow, the env->fpstt, env->fpregs and env->fptags should be kept
no touch, and foverflow is set true, so there is no negative effect.

Welcome your idea.

>>  void helper_fdecstp(CPUX86State *env)
>>  {
>> -    env->fpstt = (env->fpstt - 1) & 7;
>> +    set_fpstt(env, env->fpstt - 1, false, false);
> 
> This is clearing env->foverflow.  But after 8 consecutive fdecstp or
> fincstp the result of FXAM should not change.
> 
>>      env->fpus &= ~0x4700;
>>  }
>>  
>>  void helper_fincstp(CPUX86State *env)
>>  {
>> -    env->fpstt = (env->fpstt + 1) & 7;
>> +    set_fpstt(env, env->fpstt + 1, true, false);
> 
> Same here.
> 

OK. thanks.

Now if foverflow is only for fpush/f[i]ld*_ST0, I guess fincstp/fdecstp
can clear foverflow. The env->fptags are only for fpop, which keep no
touch in fincstp/fdecstp.

> The actual bug is hinted in helper_fxam_ST0:
> 
>     /* XXX: test fptags too */
> 
> I think the correct fix should be something like
> 
> diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c
> index 99f28f267f..792a128a6d 100644
> --- a/target/i386/fpu_helper.c
> +++ b/target/i386/fpu_helper.c
> @@ -991,7 +991,11 @@ void helper_fxam_ST0(CPUX86State *env)
>          env->fpus |= 0x200; /* C1 <-- 1 */
>      }
> 
> -    /* XXX: test fptags too */
> +    if (env->fptags[env->fpstt]) {
> +        env->fpus |= 0x4100; /* Empty */
> +        return;
> +    }
> +

For fpop overflow, this fix is enough, but for me, we still need
foverflow to check fpush/fld*_ST0 overflow.

Don't you think we need check fpush/f[i]ld*_ST0 overflow?

Thanks




  reply	other threads:[~2020-02-21 14:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-21  3:45 [PATCH] target: i386: Check float overflow about register stack chengang
2020-02-21  8:58 ` Paolo Bonzini
2020-02-21 14:09   ` Chen Gang [this message]
2020-02-21 16:18     ` Paolo Bonzini
2020-02-22  2:10       ` Chen Gang
2020-02-22  2:27         ` Chen Gang
2020-02-22  7:37         ` Paolo Bonzini
2020-02-22 12:25           ` Chen Gang
2020-02-24 12:43             ` Paolo Bonzini
2020-02-25  1:22               ` Chen Gang

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=900fd511-72f0-675d-4a7e-d228b2ade9c7@emindsoft.com.cn \
    --to=chengang@emindsoft.com.cn \
    --cc=ehabkost@redhat.com \
    --cc=gang.chen.5i5j@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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;
as well as URLs for NNTP newsgroup(s).