All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bruno Piazera Larsen <bruno.larsen@eldorado.org.br>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: farosas@linux.ibm.com, luis.pires@eldorado.org.br,
	lucas.araujo@eldorado.org.br, fernando.valle@eldorado.org.br,
	qemu-ppc@nongnu.org, matheus.ferst@eldorado.org.br,
	david@gibson.dropbear.id.au
Subject: Re: [PATCH 07/11] target/ppc: added KVM fallback to fpscr manipulation
Date: Thu, 13 May 2021 13:36:53 -0300	[thread overview]
Message-ID: <c2fc1562-9d97-0d6f-5d24-632c2a9006dd@eldorado.org.br> (raw)
In-Reply-To: <a9ac8b35-faae-167d-ff78-4b7ddd8f75c9@linaro.org>

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


On 12/05/2021 15:20, Richard Henderson wrote:
> On 5/12/21 9:08 AM, Bruno Larsen (billionai) wrote:
>> diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
>> index 104a308abb..a8a720eb48 100644
>> --- a/target/ppc/kvm.c
>> +++ b/target/ppc/kvm.c
>> @@ -2947,3 +2947,17 @@ bool kvm_arch_cpu_check_are_resettable(void)
>>   {
>>       return true;
>>   }
>> +
>> +void kvmppc_store_fpscr(CPUPPCState *env, uint64_t arg, uint32_t mask)
>> +{
>> +    CPUState *cs = env_cpu(env);
>> +    struct kvm_one_reg reg;
>> +    int ret;
>> +    reg.id = KVM_REG_PPC_FPSCR;
>> +    reg.addr = (uintptr_t) &env->fpscr;
>> +    ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &reg);
>> +    if (ret < 0)
>> +    {
>> +        fprintf(stderr, "Unable to set FPSCR to KVM: %s", 
>> strerror(errno));
>> +    }
>> +}
>
> This is all unnecessary.  All you need to do is store to env->fpscr 
> and the value will be synced back with kvm_put_fp.
>
> I'll note that some of the trouble you may be having with extracting 
> helper_store_fpscr to a ppc_store_fpscr function is due to an existing 
> bug in the tcg code:
>
> Storing to fpscr should *never* raise an exception -- see MTFSF, 
> MTFSB0, MTFSB1.  Thus the mucking about with cs->exception_index and 
> env->error_code is incorrect.
>
> In addition, the masking is being done weirdly and could use a 
> complete overhaul.
>
> This could all be rewritten as
>
> -- %< -- cpu.h
>
>  /* Invalid operation exception summary */
> - #define fpscr_ix ((env->fpscr) & ((1 << FPSCR_VXSNAN) ...
> + #define FPSCR_IX  ((1 << FPSCR_VXSNAN) | ...)
>
> -- %< -- cpu.c
>
> // move fpscr_set_rounding_mode here
>
> void ppc_store_fpscr(CPUPPCState *env, target_ulong val)
> {
>     /* Recompute exception summary state. */
>     val &= ~(FP_VX | FP_FEX);
>     if (val & FPSCR_IX) {
>         val |= FP_VX;
>     }
>     if ((val >> FPSCR_XX) & (val >> FPSCR_XE) & 0x1f) {
>         val |= FP_FEX;
>     }
>     env->fpscr = val;
>     if (tcg_enabled()) {
>         fpscr_set_rounding_mode(env);
>     }
> }
>
> -- %< -- fpu_helper.c
>
> void helper_store_fpscr(CPUPPCState *env, target_ulong val,
>                         uint32_t nibbles)
> {
>     target_ulong mask = 0;
>
>     /* TODO: Push this expansion back to translation time. */
>     for (int i = 0; i < sizeof(target_ulong) * 2; ++i) {
>         if (nibbles & (1 << i)) {
>             mask |= (target_ulong)0xf << (4 * i);
>         }
>     }
>
>     val = (val & mask) | (env->fpscr & ~mask);
>     ppc_store_fpscr(env, val);
> }
That expansion can't be moved to translation time, because gdbstub would 
also need that code in a variety of functions, so better to keep it in 
that central location,
>
> void helper_fpscr_clrbit(CPUPPCState *env, uint32_t bit)
> {
>     uint32_t mask = 1u << bit;
>     if (env->fpscr & mask) {
>         ppc_store_fpscr(env, env->fpscr & ~mask);
>     }
> }
>
> void helper_fpscr_setbit(CPUPPCState *env, uint32_t bit)
> {
>     uint32_t mask = 1u << bit;
>     if (!(env->fpscr & mask)) {
>         ppc_store_fpscr(env, env->fpscr | mask);
>     }
> }
>
> There are a couple of other uses of fpscr_set_rounding_mode, where the 
> softfloat value is changed temporarily (do_fri, VSX_ROUND). These 
> should simply save the previous softfloat value (using 
> get_float_rounding_mode) around the operation instead of re-computing 
> from fpscr.
>
> Which leaves us with exactly one use of fpscr_set_rounding_mode, which 
> can then be moved to cpu.c next to ppc_store_fpscr.
>
>
> r~

I was implementing this solution, but ran into a problem: We needed 
store_fpscr for gdbstub.c, that's the original reason we made that new 
function to begin with. This solution, although it improves the handling 
of fpscr, doesn't fix the original problem.

What I think we can do is put the logic that is in helper_store_fpscr 
into store_fpscr, move it to cpu.c, and have the helper call the 
non-helper function. That way we conserve helper_* as TCG-specific and 
have the overhaul.

Toughts?

-- 
Bruno Piazera Larsen
Instituto de Pesquisas ELDORADO 
<https://www.eldorado.org.br/?utm_campaign=assinatura_de_e-mail&utm_medium=email&utm_source=RD+Station>
Departamento Computação Embarcada
Analista de Software Trainee
Aviso Legal - Disclaimer <https://www.eldorado.org.br/disclaimer.html>

[-- Attachment #2: Type: text/html, Size: 6846 bytes --]

  parent reply	other threads:[~2021-05-13 16:44 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 14:08 [RFC PATCH 00/11] target/ppc: add support to disable-tcg Bruno Larsen (billionai)
2021-05-12 14:08 ` [PATCH 01/11] target/ppc: created ppc_{store, get}_vscr for generic vscr usage Bruno Larsen (billionai)
2021-05-12 16:48   ` [PATCH 01/11] target/ppc: created ppc_{store,get}_vscr " Richard Henderson
2021-05-13  3:48   ` David Gibson
2021-05-12 14:08 ` [PATCH 02/11] target/ppc: moved ppc_store_sdr1 to cpu.c Bruno Larsen (billionai)
2021-05-12 16:54   ` Richard Henderson
2021-05-13  3:50   ` David Gibson
2021-05-31 18:17     ` Bruno Piazera Larsen
2021-06-07  3:50       ` David Gibson
2021-05-12 14:08 ` [PATCH 03/11] target/ppc: moved ppc_cpu_dump_state to cpu_init.c Bruno Larsen (billionai)
2021-05-12 16:58   ` Richard Henderson
2021-05-12 17:00     ` Richard Henderson
2021-05-13  3:51   ` David Gibson
2021-05-12 14:08 ` [PATCH 04/11] target/ppc: moved ppc_store_msr into gdbstub.c Bruno Larsen (billionai)
2021-05-12 17:05   ` Richard Henderson
2021-05-13  3:52     ` David Gibson
2021-05-12 14:08 ` [PATCH 05/11] target/ppc: moved ppc_store_lpcr to cpu.c Bruno Larsen (billionai)
2021-05-12 17:07   ` Richard Henderson
2021-05-13  3:53   ` David Gibson
2021-05-12 14:08 ` [PATCH 06/11] target/ppc: updated vscr manipulation in machine.c Bruno Larsen (billionai)
2021-05-12 17:08   ` Richard Henderson
2021-05-13  3:54     ` David Gibson
2021-05-12 14:08 ` [PATCH 07/11] target/ppc: added KVM fallback to fpscr manipulation Bruno Larsen (billionai)
2021-05-12 18:20   ` Richard Henderson
2021-05-12 19:15     ` Bruno Piazera Larsen
2021-05-13 16:36     ` Bruno Piazera Larsen [this message]
2021-05-13 22:45       ` Richard Henderson
2021-05-14 11:12         ` Bruno Piazera Larsen
2021-05-12 14:08 ` [RFC PATCH 08/11] target/ppc: wrapped some TCG only logic with ifdefs Bruno Larsen (billionai)
2021-05-12 18:33   ` Richard Henderson
2021-05-12 18:57     ` Bruno Piazera Larsen
2021-05-14 13:29       ` Bruno Piazera Larsen
2021-05-14 14:44         ` Richard Henderson
2021-05-14 16:22           ` Bruno Piazera Larsen
2021-05-17  4:10             ` David Gibson
2021-05-17 16:07               ` Richard Henderson
2021-05-17  4:00           ` David Gibson
2021-05-24 18:01     ` Bruno Piazera Larsen
2021-05-24 20:03       ` Richard Henderson
2021-05-12 14:08 ` [PATCH 09/11] include/exec: added functions to the stubs in exec-all.h Bruno Larsen (billionai)
2021-05-12 18:34   ` Richard Henderson
2021-05-13 14:03     ` Lucas Mateus Martins Araujo e Castro
2021-05-13 23:44       ` Richard Henderson
2021-05-17  3:58         ` David Gibson
2021-05-17 16:59           ` Lucas Mateus Martins Araujo e Castro
2021-05-17 18:02             ` Richard Henderson
2021-05-18 18:45               ` Bruno Piazera Larsen
2021-05-24  3:18             ` David Gibson
2021-05-17  3:55       ` David Gibson
2021-05-17 11:07         ` Bruno Piazera Larsen
2021-05-24  3:15           ` David Gibson
2021-05-12 14:08 ` [RFC PATCH 10/11] target/ppc: created tcg-stub.c file Bruno Larsen (billionai)
2021-05-12 18:39   ` Richard Henderson
2021-05-12 19:09     ` Bruno Piazera Larsen
2021-05-14 18:07     ` Bruno Piazera Larsen
2021-05-13  3:59   ` David Gibson
2021-05-13 12:56     ` Bruno Piazera Larsen
2021-05-17  3:53       ` David Gibson
2021-05-12 14:08 ` [PATCH 11/11] target/ppc: updated meson.build to support disable-tcg Bruno Larsen (billionai)

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=c2fc1562-9d97-0d6f-5d24-632c2a9006dd@eldorado.org.br \
    --to=bruno.larsen@eldorado.org.br \
    --cc=david@gibson.dropbear.id.au \
    --cc=farosas@linux.ibm.com \
    --cc=fernando.valle@eldorado.org.br \
    --cc=lucas.araujo@eldorado.org.br \
    --cc=luis.pires@eldorado.org.br \
    --cc=matheus.ferst@eldorado.org.br \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=richard.henderson@linaro.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.