From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark Oteiza Newsgroups: gmane.emacs.bugs Subject: bug#22689: [PATCH] Add logcount Date: Sat, 30 Sep 2017 09:16:36 -0400 Message-ID: <20170930131636.xe22lbwlea7yqelh@logos.localdomain> References: <87h9h9pnof.fsf@udel.edu> <20170929174134.e6uxcr63dtyvd6f4@logos.localdomain> <83mv5c4dl0.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1506777435 4296 195.159.176.226 (30 Sep 2017 13:17:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 30 Sep 2017 13:17:15 +0000 (UTC) User-Agent: NeoMutt/20170912-48-0df7d3-dirty Cc: 22689@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Sep 30 15:17:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyHdk-0000Pj-TZ for geb-bug-gnu-emacs@m.gmane.org; Sat, 30 Sep 2017 15:17:09 +0200 Original-Received: from localhost ([::1]:39306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dyHdq-0000Be-MV for geb-bug-gnu-emacs@m.gmane.org; Sat, 30 Sep 2017 09:17:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dyHdg-0000AH-UI for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2017 09:17:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dyHde-0005DB-A8 for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2017 09:17:04 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59696) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dyHde-0005D5-5G for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2017 09:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dyHdd-0002zE-Vl for bug-gnu-emacs@gnu.org; Sat, 30 Sep 2017 09:17:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark Oteiza Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Sep 2017 13:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22689 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22689-submit@debbugs.gnu.org id=B22689.150677740511456 (code B ref 22689); Sat, 30 Sep 2017 13:17:01 +0000 Original-Received: (at 22689) by debbugs.gnu.org; 30 Sep 2017 13:16:45 +0000 Original-Received: from localhost ([127.0.0.1]:40144 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyHdN-0002yg-5s for submit@debbugs.gnu.org; Sat, 30 Sep 2017 09:16:45 -0400 Original-Received: from mail-qk0-f171.google.com ([209.85.220.171]:49069) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyHdL-0002yS-MP for 22689@debbugs.gnu.org; Sat, 30 Sep 2017 09:16:44 -0400 Original-Received: by mail-qk0-f171.google.com with SMTP id a128so1877978qkc.5 for <22689@debbugs.gnu.org>; Sat, 30 Sep 2017 06:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=udel-edu.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Y865DXghJthutX1oQmCnU2GlvsXA1+brF9SrvWrsTsI=; b=u46OtmU/hoEAyR0wAAuNkz2PWqFGeKEivHaeA45pg6BX9LYhMJu84P/tI82Ew9zdmz F7T6Oe56Vs8w6M28OtTdK+YX+lL9lo4Xow4B0UI68a+yatKgXMh6OzktiKzlORgMMMsO FcDRbizqqpZBAxIBl1l4w5iQsQTRSjVEweJreM94DZnSC0m5Ymp3YoqhArBKmxqyTNLL J+DkUGuU1MVSNLiVsnW+XbIhl+e+S26IOQK371m1QXM9qg9mwwWX5voV7BAvsK5JcQ8r ChPgHjnFoKAWgz+VLPnPxg5TvH0RDzMf6eXMCqJGOUPoHf5rSHOVBaxD1Z8RDhazuEBN j+AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Y865DXghJthutX1oQmCnU2GlvsXA1+brF9SrvWrsTsI=; b=ivNbeELa2+JQHs4ba91bDpAft86dirZVgXfHgTAAOUbt10mcB1VvOK6v6m4eo4h3Fc ipFBrEsSkZ85N+WIYIFgPN2ioFhGnhSYvWWBJWl3BbzYUIcpx4KM0Yq+pmTmrO/kdoP9 ynx5z62L6WuXeR9BbGlf4WgVm6KIt79MwzI0wILwyYVhtffO7wHxg79UAondEKuZnG4m jB72cRD+A0KuU3UEL6aWPqWO/PfMjZicmo/UA8YKTrFADYFlCHxuzo4ptnboSWzcUA6y lWWidFasvt18ilWMubmqzHDCJnRZXsFvC6ClFBhlulPRJ4bTT9oMXOHiDzpkGE9ApwW3 ZALg== X-Gm-Message-State: AMCzsaXho5yd9YC+OyM3Xc+5XHa1lmju/LBZTUqPfsAzbdqHQ9x1DDJ5 sHNQ30jj9snHebgAhp7X4TKMcg== X-Google-Smtp-Source: AOwi7QDEdfYeMNJ5hNnR5rVglaKMNs2IpCfhuWIajHN/eNL6F6roRhiUgjVMA22rI9Bk7//lRVuOKQ== X-Received: by 10.55.112.7 with SMTP id l7mr7596874qkc.38.1506777398137; Sat, 30 Sep 2017 06:16:38 -0700 (PDT) Original-Received: from logos.localdomain (pool-173-67-36-61.bltmmd.fios.verizon.net. [173.67.36.61]) by smtp.gmail.com with ESMTPSA id d140sm4038117qkc.41.2017.09.30.06.16.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Sep 2017 06:16:37 -0700 (PDT) Content-Disposition: inline In-Reply-To: <83mv5c4dl0.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:137679 Archived-At: On 30/09/17 at 02:42pm, Eli Zaretskii wrote: > > +#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) I guess it comes from nowhere, that condition and the two helper functions come from here https://rosettacode.org/wiki/Population_count#C > > +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? Probably, I don't know--I'm out of my comfort zone here. > > +#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? True. Should I instead be doing XINT (value) <= xxx_MAX && XINT (value) >= xxx_MIN or might there be a better check? For negative values popcount typically counts ones of the two's complement