From: Jakub Jelinek <jakub@redhat.com>
To: Mark Wielaard <mark@klomp.org>
Cc: dwz@sourceware.org
Subject: Re: [PATCH] Add write_sleb129 and size_of_sleb128 for writing DW_FORM_implicit_const
Date: Tue, 29 Sep 2020 10:24:15 +0200 [thread overview]
Message-ID: <20200929082415.GW2176@tucnak> (raw)
In-Reply-To: <20200928073647.4629-1-mark@klomp.org>
On Mon, Sep 28, 2020 at 09:36:47AM +0200, Mark Wielaard wrote:
> We were writing out the DW_FORM_implicit_const value as uleb128,
> but it should be written out as sleb128 (as we already read it).
> I'll merge this into my experimental DW_FORM_implicit_const patch.
Besides s/129/128 in the title as mentioned by Florian:
> * dwz.c (write_sleb128): New macro.
> (size_of_sleb128): New function.
> ---
> dwz.c | 41 +++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 39 insertions(+), 2 deletions(-)
>
> diff --git a/dwz.c b/dwz.c
> index d730f98..e772954 100644
> --- a/dwz.c
> +++ b/dwz.c
> @@ -399,6 +399,25 @@ typedef struct
> } \
> while (0)
>
> +#define write_sleb128(ptr, val) \
> + do \
> + { \
> + int64_t valv = (val); \
> + bool more; \
> + do \
> + { \
> + unsigned char c = (valv & 0x7f); \
The parens above are unnecessary.
> + valv >>= 7; \
> + more = !((((valv == 0) && ((c & 0x40) == 0)) \
> + || ((valv == -1) && ((c & 0x40) != 0)))); \
And this has even more unnecessary parens.
Either
more = ((valv != 0 || (c & 0x40) != 0) \
&& (valv != -1 || (c & 0x40) == 0)); \
or perhaps
more = (valv + (uint64_t) 1 > 1 \
|| ((c ^ valv) & 0x40) != 0); \
?
> +/* Return number of bytes needed to encode VAL using
> + sleb128. */
> +static unsigned int
> +size_of_sleb128 (int64_t val)
> +{
> + unsigned int size = 0;
> + unsigned char b;
> + do
> + {
> + b = (val & 0x7f);
Ditto.
> + val >>= 7;
> + size++;
> + }
> + while (!(((val == 0) && ((b & 0x40) == 0))
> + || ((val == -1) && ((b & 0x40) != 0))));
Ditto.
Otherwise LGTM.
Jakub
next prev parent reply other threads:[~2020-09-29 8:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-28 7:36 Mark Wielaard
2020-09-29 8:24 ` Jakub Jelinek [this message]
2020-09-29 18:19 ` Mark Wielaard
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=20200929082415.GW2176@tucnak \
--to=jakub@redhat.com \
--cc=dwz@sourceware.org \
--cc=mark@klomp.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).