all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Mark Oteiza <mvoteiza@udel.edu>
Cc: 22689@debbugs.gnu.org
Subject: bug#22689: [PATCH] Add logcount
Date: Sat, 30 Sep 2017 14:42:51 +0300	[thread overview]
Message-ID: <83mv5c4dl0.fsf@gnu.org> (raw)
In-Reply-To: <20170929174134.e6uxcr63dtyvd6f4@logos.localdomain> (message from Mark Oteiza on Fri, 29 Sep 2017 13:41:34 -0400)

> Date: Fri, 29 Sep 2017 13:41:34 -0400
> From: Mark Oteiza <mvoteiza@udel.edu>
> 
> I made an attempt implementing this:

Thanks.  I'm not an expert on these ops, but otherwise the code looks
OK to me, modulo the minor comments below.

This will eventually need a NEWS entry and some docs in the ELisp
manual.

> +#if defined (__POPCNT__) && defined (__GNUC__) && (__GNUC__> 4 || (__GNUC__== 4 && __GNUC_MINOR__> 1))
> +#define HAVE_BUILTIN_POPCOUNTLL
> +#endif

Where does __POPCNT__ definition come from?  I don't see it in my
GCC's "gcc -dM" output.

As for the rest of the condition, I think you should use GNUC_PREREQ,
like this:

 #if GNUC_PREREQ (4, 1, 0)


> +static uint64_t
> +bitcount64 (uint64_t b)
> +{
> +  b -= (b >> 1) & 0x5555555555555555;
> +  b = (b & 0x3333333333333333) + ((b >> 2) & 0x3333333333333333);
> +  b = (b + (b >> 4)) & 0x0f0f0f0f0f0f0f0f;
> +  return (b * 0x0101010101010101) >> 56;

Shouldn't these constants have a ULL suffix, to make sure they are not
truncated to a 32-bit int?

> +#else  /* HAVE_BUILTIN_POPCOUNTLL */
> +  if (XINT (value) <= UINT_MAX)
> +    XSETINT (res, bitcount32 (XUINT (value)));
> +  else if (XINT (value) <= ULONG_MAX)
> +    XSETINT (res, bitcount64 (XUINT (value)));

The comparisons against Uxxx_MAX seem to assume that VALUE is
unsigned, but that's not guaranteed, right?





  reply	other threads:[~2017-09-30 11:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-15 23:18 bug#22689: 25.1.50; implement logcount Mark Oteiza
2017-09-29 17:41 ` bug#22689: [PATCH] Add logcount Mark Oteiza
2017-09-30 11:42   ` Eli Zaretskii [this message]
2017-09-30 13:16     ` Mark Oteiza
2017-09-30 13:59       ` Eli Zaretskii
2017-09-30 14:55         ` Mark Oteiza
2017-09-30 15:38           ` Eli Zaretskii
2017-09-30 16:03             ` Mark Oteiza
2017-09-30 16:17               ` Eli Zaretskii
2017-09-30 17:07                 ` Mark Oteiza
2017-09-30 17:53                   ` Eli Zaretskii
2017-09-30 18:18                     ` Mark Oteiza
2017-09-30 16:50           ` Benjamin Riefenstahl
2017-09-30 16:59             ` Mark Oteiza
2017-09-30 22:48 ` Paul Eggert
2017-09-30 23:22   ` Mark Oteiza

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=83mv5c4dl0.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=22689@debbugs.gnu.org \
    --cc=mvoteiza@udel.edu \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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.