Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gpL56-0005zd-6H for pgsql-hackers@arkaria.postgresql.org; Thu, 31 Jan 2019 22:45:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gpL53-0006I1-4R for pgsql-hackers@arkaria.postgresql.org; Thu, 31 Jan 2019 22:45:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gpL52-000691-RT for pgsql-hackers@lists.postgresql.org; Thu, 31 Jan 2019 22:45:08 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gpL4z-0003ig-H0 for pgsql-hackers@lists.postgresql.org; Thu, 31 Jan 2019 22:45:07 +0000 Received: by mail-ed1-x541.google.com with SMTP id b14so3929060edt.6 for ; Thu, 31 Jan 2019 14:45:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=tAZXl25gmWKrZxXqa+DZIDfTiWjOlcE7MUDL/DAr0Kk=; b=UFLvIk9zWq/Wcpb9QZMl50zhiN5RPh0T0Wv+CmngRJh0G110s0Pdsbpl4MKGD+jngN z3LtSji4gsCwESJAFHWwT5CWjTzLeSb+8AuSXV4eqcj5FUmtvNwQEbnHCjP9nWeQqMBP OPK3Sil54mzu/C576ePkNy6UgjKR6/62ZjtsOOovLNCwqjdgAVTVEc2T6X8X2EcFk3Uc 1WVWGIeBgxhvN3LJ0t9cQ/P7ggRB+P/AXczMJ2ODkrLLr3CqEyrbgilz0cDQUrrlPqoC 6w9lbUrBuFFlAHTITIHEQnevScUHubMLNJqdmK2GZPptDrvk0KT4vSvBrgNC0PkXNsfB QWBQ== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=tAZXl25gmWKrZxXqa+DZIDfTiWjOlcE7MUDL/DAr0Kk=; b=GdBKw25DJo86FhkF1m/bO+z48ksj8qpjAd53OeOHSICKZTXdTRRV66oZ1CCflEYAME fhxcWVDxTZUrSOmxchN8+kwpzwK0YXPcYyqJrZVy4S6Vq0gEuBRKEncEeO87Ibam2rXr OoBbyiX+j0qLtlyYxfWZAsDz1hYFh55TmayuqKaDFimGQNhk0Iq+0eRhE2vSDJZWLVrE 0WbEsYZ63GqODAEef2E+TcmB5UPWiUhz1uRPhnG7qPmZQIwHU0hU5F3L3vXxQGuFZDMo g+mVxPC2ltVMCtGIV891UAxfjS3Y+dQDI24I3VJ9Iu38o6t7lHgxFlHTqf679kzEkFOW e4Hg== X-Gm-Message-State: AJcUukf/cM6+srHLGXivH6mordrjF5JYmgCkwSkTbGtiVg0LN5Mb7tb6 61p0HIJFYGI/3srgfoufK7mG8Q== X-Google-Smtp-Source: ALg8bN5es1UCfhqVU4lZPxUU8vx0P6DGl3ut6lZI4dv3ORV+X26+AXDS2on4OQFlMluBlZ1YvPHAEQ== X-Received: by 2002:a05:6402:1286:: with SMTP id w6mr37064624edv.53.1548974704233; Thu, 31 Jan 2019 14:45:04 -0800 (PST) Received: from alvin.alvh.no-ip.org ([212.76.254.98]) by smtp.gmail.com with ESMTPSA id m14sm1694342edc.27.2019.01.31.14.45.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Jan 2019 14:45:03 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id BCD0A85D; Thu, 31 Jan 2019 19:45:02 -0300 (-03) Date: Thu, 31 Jan 2019 19:45:02 -0300 From: Alvaro Herrera To: David Rowley Cc: PostgreSQL Hackers , Thomas Munro Subject: Re: Using POPCNT and other advanced bit manipulation instructions Message-ID: <201901312245.y4phq2m6f3gy@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716-1013-2c1e88 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I only have cosmetic suggestions for this patch. For one thing, I think the .c file should be in src/port and its header should be in src/include/port/, right beside the likes of pg_bswap.h and pg_crc32c.h. For another, I think the arrangement of all those "ifdef HAVE_THIS_OR_THAT" in the bitutils.c file is a bit hard to read. I'd lay them out like this: #ifdef HAVE__BUILTIN_CTZ int (*pg_rightmost_one32) (uint32 word) = pg_rightmost_one32_choose; #else int (*pg_rightmost_one32) (uint32 word) = pg_rightmost_one32_slow; #endif #ifdef HAVE__BUILTIN_CTZ /* * This gets called on the first call. It replaces the function pointer * so that subsequent calls are routed directly to the chosen implementation. */ static int pg_rightmost_one32_choose(uint32 word) { ... (You need declarations for the "choose" variants at the top of the file, but that seems okay.) Finally, the part in bitmapset.c is repetitive on the #ifdefs; I'd just put at the top of the file something like #if bms are 32 bits #define pg_rightmost_one(x) pg_rightmost_one32(x) #define pg_popcount(x) pg_popcount32(x) #elif they are 64 bits #define ... #else #error ... #endif This way, each place that uses the functions does not need the ifdefs. Other than those minor changes, I think we should just get this pushed and see what the buildfarm thinks. In the words of a famous PG hacker: if a platform ain't in the buildfarm, we don't support it. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services