public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ranier Vilela <[email protected]>
To: Heikki Linnakangas <[email protected]>
Cc: Bertrand Drouvot <[email protected]>
Cc: Peter Eisentraut <[email protected]>
Cc: [email protected]
Subject: Re: define pg_structiszero(addr, s, r)
Date: Mon, 28 Oct 2024 12:02:48 -0300
Message-ID: <CAEudQAq_D5edSnAy2y0Viuk9Y53LTR=FOu8240SSDWmSm_ToAA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<ZusioyiXTyKpOP/[email protected]>
	<[email protected]>

Em seg., 28 de out. de 2024 às 11:33, Heikki Linnakangas <[email protected]>
escreveu:

> On 18/09/2024 21:57, Bertrand Drouvot wrote:
> > On Wed, Sep 18, 2024 at 10:03:21AM +0200, Peter Eisentraut wrote:
> >> On 18.09.24 06:16, Bertrand Drouvot wrote:
> >>> +#define pg_structiszero(addr, s, r)
>                                       \
> >>> +   do {
>                                                       \
> >>> +           /* We assume this initializes to zeroes */
>                       \
> >>> +           static const s all_zeroes;
>                                       \
> >>> +           r = (memcmp(addr, &all_zeroes, sizeof(all_zeroes)) == 0);
>      \
> >>> +   } while (0)
>
> Not new with this patch, but do we guarantee padding bytes to be zeros?
>
> How about this instead:
>
> static inline bool
> pg_is_all_zeros(const char *p, size_t len)
> {
>    for (size_t i = 0; i < len; i++)
>    {
>      if (p[i] != 0)
>          return false;
>    }
>    return true;
> }
>
> It seems to me that this way is more optimized.

static inline bool
is_all_zeros(const char *p, size_t len)
{
  for (size_t i = len; i >= 0; i--)
  {
    if (p[i] != 0)
        return false;
  }
  return true;
}

main:
        sub     rsp, 24
        lea     rdx, [rsp + 12]
        lea     rcx, [rsp + 16]
        lea     rdi, [rip + .L.str]
        lea     rsi, [rsp + 8]
        xor     eax, eax
        call    __isoc99_scanf@PLT
        lea     rdi, [rip + .L.str.1]
        xor     esi, esi
        xor     eax, eax
        call    printf@PLT
        xor     eax, eax
        add     rsp, 24
        ret

best regards,
Ranier Vilela


view thread (9+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: define pg_structiszero(addr, s, r)
  In-Reply-To: <CAEudQAq_D5edSnAy2y0Viuk9Y53LTR=FOu8240SSDWmSm_ToAA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox