From: Johannes Sixt <j.sixt@viscovery.net>
To: Jeff King <peff@peff.net>, Erik Faye-Lund <kusmabite@gmail.com>
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Jonathan Nieder" <jrnieder@gmail.com>,
"Brian Gernhardt" <brian@gernhardtsoftware.com>,
"Duy Nguyen" <pclouds@gmail.com>, "David Kastrup" <dak@gnu.org>,
"Vicent Martí" <tanoku@gmail.com>,
"Git Mailing List" <git@vger.kernel.org>
Subject: Re: pack bitmap woes on Windows
Date: Thu, 13 Feb 2014 09:07:05 +0100 [thread overview]
Message-ID: <52FC7D29.5070900@viscovery.net> (raw)
In-Reply-To: <20140212164828.GA24484@sigill.intra.peff.net>
Am 2/12/2014 17:48, schrieb Jeff King:
> On Wed, Feb 12, 2014 at 03:49:24PM +0100, Erik Faye-Lund wrote:
>
>> It seems the author of a201c20b41a2f0725977bcb89a2a66135d776ba2
>> assumes __BYTE_ORDER was guaranteed to always be defined, probably
>> fooled by the following check:
>>
>> #if !defined(__BYTE_ORDER)
>> # error "Cannot determine endianness"
>> #endif
>>
>> However, that check is only performed if we're NOT building with GCC
>> on x86/x64 nor MSVC (which I don't think defined __BYTE_ORDER either)
>>
>> The following would make __BYTE_ORDER a guarantee, and show that MinGW
>> does not define it:
>
> Yes, that is the problem. Sorry, this got brought up earlier[1], but the
> discussion went on and I did not notice that Brian's patch did not get
> applied.
>
> After re-reading the discussion, I think the patch below is the best
> solution. Can you confirm that it fixes the problem for you?
Yes, it fixes the problem! t5310-pack-bitmaps passes all tests with the patch.
Thanks,
-- Hannes
>
> -Peff
>
> [1] http://thread.gmane.org/gmane.comp.version-control.git/241278
>
> -- >8 --
> Subject: ewah: unconditionally ntohll ewah data
>
> Commit a201c20 tried to optimize out a loop like:
>
> for (i = 0; i < len; i++)
> data[i] = ntohll(data[i]);
>
> in the big-endian case, because we know that ntohll is a
> noop, and we do not need to pay the cost of the loop at all.
> However, it mistakenly assumed that __BYTE_ORDER was always
> defined, whereas it may not be on systems which do not
> define it by default, and where we did not need to define it
> to set up the ntohll macro. This includes OS X and Windows.
>
> We could muck with the ordering in compat/bswap.h to make
> sure it is defined unconditionally, but it is simpler to
> still to just execute the loop unconditionally. That avoids
> the application code knowing anything about these magic
> macros, and lets it depend only on having ntohll defined.
>
> And since the resulting loop looks like (on a big-endian
> system):
>
> for (i = 0; i < len; i++)
> data[i] = data[i];
>
> any decent compiler can probably optimize it out.
>
> Original report and analysis by Brian Gernhardt.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> ewah/ewah_io.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/ewah/ewah_io.c b/ewah/ewah_io.c
> index 4a7fae6..f7f700e 100644
> --- a/ewah/ewah_io.c
> +++ b/ewah/ewah_io.c
> @@ -113,6 +113,7 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
> int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
> {
> uint8_t *ptr = map;
> + size_t i;
>
> self->bit_size = get_be32(ptr);
> ptr += sizeof(uint32_t);
> @@ -135,13 +136,8 @@ int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
> memcpy(self->buffer, ptr, self->buffer_size * sizeof(uint64_t));
> ptr += self->buffer_size * sizeof(uint64_t);
>
> -#if __BYTE_ORDER != __BIG_ENDIAN
> - {
> - size_t i;
> - for (i = 0; i < self->buffer_size; ++i)
> - self->buffer[i] = ntohll(self->buffer[i]);
> - }
> -#endif
> + for (i = 0; i < self->buffer_size; ++i)
> + self->buffer[i] = ntohll(self->buffer[i]);
>
> self->rlw = self->buffer + get_be32(ptr);
>
>
prev parent reply other threads:[~2014-02-13 8:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-12 7:27 pack bitmap woes on Windows Johannes Sixt
2014-02-12 11:56 ` Erik Faye-Lund
2014-02-12 12:44 ` Johannes Sixt
2014-02-12 12:55 ` David Kastrup
2014-02-12 13:05 ` Johannes Sixt
2014-02-12 13:23 ` David Kastrup
2014-02-12 14:09 ` Duy Nguyen
2014-02-12 14:22 ` Erik Faye-Lund
2014-02-12 14:49 ` Erik Faye-Lund
2014-02-12 16:48 ` Jeff King
2014-02-13 8:07 ` Johannes Sixt [this message]
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=52FC7D29.5070900@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=brian@gernhardtsoftware.com \
--cc=dak@gnu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=kusmabite@gmail.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=tanoku@gmail.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 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).