RE: [PATCH v8 01/12] bswap: add 64 bit endianness helper get_be64
- From
Ben Peart <ben.peart@microsoft.com>
- Date
- Sep 23, 2017, 23:31 UTC
- Message-ID
- <MWHPR21MB047887A575D5DFFB213092A1F4640@MWHPR21MB0478.namprd21.prod.outlook.com>
- In-Reply-To
- <20170922233707.25414-1-martin.agren@gmail.com>
Thanks,
Ben
Show 31 quoted lines
> -----Original Message-----
> From: Martin Ågren [mailto:martin.agren@gmail.com]
> Sent: Friday, September 22, 2017 7:37 PM
> To: Ben Peart <Ben.Peart@microsoft.com>
> Cc: David Turner <David.Turner@twosigma.com>; Ævar Arnfjörð Bjarmason
> <avarab@gmail.com>; Christian Couder <christian.couder@gmail.com>;
> git@vger.kernel.org; Junio C Hamano <gitster@pobox.com>; Johannes
> Schindelin <johannes.schindelin@gmx.de>; Nguyễn Thái Ngọc Duy
> <pclouds@gmail.com>; Jeff King <peff@peff.net>
> Subject: Re: [PATCH v8 01/12] bswap: add 64 bit endianness helper get_be64
>
> On 22 September 2017 at 18:35, Ben Peart <benpeart@microsoft.com>
> wrote:
> > Add a new get_be64 macro to enable 64 bit endian conversions on memory
> > that may or may not be aligned.
>
> I needed this to compile and pass the tests with NO_UNALIGNED_LOADS.
>
> Martin
>
> diff --git a/compat/bswap.h b/compat/bswap.h index 6b22c4621..9dc79bdf5
> 100644
> --- a/compat/bswap.h
> +++ b/compat/bswap.h
> @@ -183,8 +183,8 @@ static inline uint32_t get_be32(const void *ptr) static
> inline uint64_t get_be64(const void *ptr) {
> const unsigned char *p = ptr;
> - return (uint64_t)get_be32(p[0]) << 32 |
> - (uint64_t)get_be32(p[4]) << 0;
> + return (uint64_t)get_be32(p + 0) << 32 |
> + (uint64_t)get_be32(p + 4) << 0;This is surprising. Every other function in the file uses the p[x] syntax. Just for consistency, is there a way to stick to that syntax but still make it work correctly? Is there a typecast that can make it work?
Show 5 quoted lines
> } > > static inline void put_be32(void *ptr, uint32_t value) > -- > 2.14.1.727.g9ddaf86