All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>,
	peer.adelt@hni.uni-paderborn.de,
	Richard Henderson <rth@twiddle.net>,
	"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
	Cleber Rosa <crosa@redhat.com>
Subject: Re: [Qemu-devel] [RFC PATCH 05/11] decodetree: Force Python to print unsigned values
Date: Mon, 12 Nov 2018 19:41:14 -0200	[thread overview]
Message-ID: <20181112214114.GV12503@habkost.net> (raw)
In-Reply-To: <CAAdtpL4234FKt685azMs_iWYNGzvhp8Mo6dJsah_Sq=JWJUaJA@mail.gmail.com>

On Mon, Nov 12, 2018 at 07:52:28PM +0100, Philippe Mathieu-Daudé wrote:
> On Mon, Nov 12, 2018 at 6:03 PM Eduardo Habkost <ehabkost@redhat.com> wrote:
> > On Mon, Nov 12, 2018 at 12:36:16AM +0100, Philippe Mathieu-Daudé wrote:
> > > Python internal representation is signed, so unsigned values
> > > bigger than 31-bit are interpreted as signed (and printed with
> > > a '-' signed).
> > > Mask out to force unsigned values.
> >
> > I don't understand this commit description. Python surely
> > supports integers larger than 2^31, and its internal
> > representation shouldn't matter at all:
> >
> >   >>> '0x{0:08x}'.format(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
> >   '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
> >
> > Can you explain how the code ends up with a negative value in the
> > `self.thismask` or `b` variables?  If `self.subs` contains
> > negative values, this is likely to break other parts of the code.
> 
> I guess I misunderstood the error, thus the description is invalid.
> 
> >
> > >
> > > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> > > ---
> > > TODO: display error encountered:
> > >
> > >    case 0x-1:
> > >        ....
> >
> > How can I reproduce it?
> 
> $ scripts/decodetree.py /dev/null
> 
>     switch (insn & 0x-0000001) {
>     }
> 
> main() ->
>   build_tree(patterns, 0, outermask = 0) ->
>        innermask = ~outermask # = -1
>       Tree(fullmask, innermask = -1) ->
>         __init__(self, fm, tm = -1) ->
>           self.thismask = tm # -1
>   t.output_code(4, False, 0, 0) ->
>     sh = is_contiguous(self.thismask) # -1
>         output(ind, 'switch (', str_switch(self.thismask), ') {\n')
> 
>         with:
> 
>             def str_switch(b):
>                 return 'insn & 0x{0:08x}'.format(b)
> 
> So the fix is rather:
> 
> -- >8 --
> diff --git a/scripts/decodetree.py b/scripts/decodetree.py
> @@ -916,7 +916,7 @@ class Tree:
> 
> def build_tree(pats, outerbits, outermask):
>      # Find the intersection of all remaining fixedmask.
> -    innermask = ~outermask
> +    innermask = ~outermask & insnmask
>      for i in pats:
>          innermask &= i.fixedmask

Nice.  Thanks for the explanation.

This really seems to be the only place in the code where the bit
operations may generate a negative number.  All remaining usage
of the ~ operator in the code is already inside & expressions
that will ensure the result is positive.

To the alternative fix above:

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

-- 
Eduardo

  parent reply	other threads:[~2018-11-12 21:41 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-11 23:36 [Qemu-devel] [RFC PATCH 00/11] decodetree: Add tokens to ease checking ISA flags Philippe Mathieu-Daudé
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 01/11] MAINTAINERS: Add scripts/decodetree.py to the TCG section Philippe Mathieu-Daudé
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 02/11] decodetree: Add multiple include guard Philippe Mathieu-Daudé
2018-11-12 22:30   ` Eduardo Habkost
2018-11-12 23:30     ` Philippe Mathieu-Daudé
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 03/11] target/mips: Move the !ISA_MIPS32R6 check out of decode_opc_special2_legacy Philippe Mathieu-Daudé
2018-11-12  8:16   ` Richard Henderson
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 04/11] target/mips: Avoid access to CPUMIPSState from decode* functions Philippe Mathieu-Daudé
2018-11-12  8:17   ` Richard Henderson
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 05/11] decodetree: Force Python to print unsigned values Philippe Mathieu-Daudé
2018-11-12  8:20   ` Richard Henderson
2018-11-12  8:57     ` Philippe Mathieu-Daudé
2018-11-12 17:03   ` Eduardo Habkost
2018-11-12 18:52     ` Philippe Mathieu-Daudé
2018-11-12 18:56       ` Philippe Mathieu-Daudé
2018-11-12 19:01       ` Richard Henderson
2018-11-12 21:41       ` Eduardo Habkost [this message]
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 06/11] scripts/decodetree: Allow empty specifications Philippe Mathieu-Daudé
2018-11-12  8:21   ` Richard Henderson
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 07/11] scripts/decodetree: Add add_func_check() Philippe Mathieu-Daudé
2018-11-12  8:31   ` Richard Henderson
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 08/11] target/mips: Add a decodetree stub Philippe Mathieu-Daudé
2018-11-12  5:37   ` Aleksandar Markovic
2018-11-12  8:58     ` Richard Henderson
2018-11-12 10:04       ` Aleksandar Markovic
2018-11-12 10:55         ` Richard Henderson
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 09/11] target/mips: Port SYNCI to decodetree Philippe Mathieu-Daudé
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 10/11] scripts/decodetree: Add add_cond_check() Philippe Mathieu-Daudé
2018-11-11 23:36 ` [Qemu-devel] [RFC PATCH 11/11] target/mips: Port MIPS64 DCL[Z/O] to decodetree Philippe Mathieu-Daudé
2018-11-12  9:14   ` Richard Henderson
2018-11-12  9:17     ` Philippe Mathieu-Daudé

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=20181112214114.GV12503@habkost.net \
    --to=ehabkost@redhat.com \
    --cc=crosa@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=peer.adelt@hni.uni-paderborn.de \
    --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 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.