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 1gufyO-0007PT-V1 for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Feb 2019 16:04:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gufyN-00049I-OF for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Feb 2019 16:04:19 +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 1gufyN-00049B-Gx for pgsql-hackers@lists.postgresql.org; Fri, 15 Feb 2019 16:04:19 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gufyK-00078U-Up for pgsql-hackers@lists.postgresql.org; Fri, 15 Feb 2019 16:04:19 +0000 Received: by mail-qk1-x742.google.com with SMTP id u188so5958037qkh.8 for ; Fri, 15 Feb 2019 08:04:16 -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=CyXun4RR0MFqgfkyMrFkH6oxXwe2IRdz61Cq+UGO1n8=; b=VfrFyjRtxF34D7lTg9oZwwH6FizV8zQFK7nZkVdHoelWnEICSMWA2DQET8Caz5iMyf lSGd51lRhdIYDysOAiC+AiDxcw8kFObhTZmkd7XOVxSbqTZkuJQzL4ChLWaFwg6H7mnQ gKuUO/2Hz1Cgv78OfzvnR5XTp3agUA0Uuo2LUK7oallBkWLnGztQDRpsd9f7F8Ab6LOi ABoL4FDmBCF5yRz06DZTS8oh1m4/mEu5bQhgTw15MlTeA+3VV9W/nmsbGQ3LUX+aFcXY 5mF1BzoM27DLrXekPUkyTtEI7Bl4EPM90kfiyJnYd1RqWq1odzfzdiDrAdwKVw4dM8va Mhhw== 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=CyXun4RR0MFqgfkyMrFkH6oxXwe2IRdz61Cq+UGO1n8=; b=S9qsvdsOIvKT/xePcoX2VYaww9mAnNFgOd8FaulDkQwpIDlL6aWxuhufadbFBisD3P K82xxxTWLkweLOmnaV+78M6KzfxGpAoMH9K4YsGPurVpmrCHhQdIkL72+9lDXyacx+B6 3kYbvlATRHN2gVRY6aarekrwk+t798czcGZlwo+XlgdfnuQj7jwxoyPTr1d8u4cO2voL L17RuD/05UYcAOrOjzk2qjNVZFU2c4C1hj3KsqDC1u5hzCKdl69JSMcRmGrEv4TqJ0LD hSLd+PciQ1bNLiB8Q5Pg07Kwqv3gBVvWYYAxmdQOJkuugyUrzUIpfWQMOabvzOgTez83 ubgQ== X-Gm-Message-State: AHQUAubDjDbyRVAQf0rngE/1HN1sEsS1qY63D8k3JsTGMSQPQiFplMhO 5tyiAvrbOUklJ1Zv8hq4oHHNX2mVshq7uw== X-Google-Smtp-Source: AHgI3IZwC3zTb8Z2t+1/fqL2VFMBbLDBH0wYzGrIxqLq3H0vhLkuj/G/FsGRv3OnqXVOAc0brDRM4w== X-Received: by 2002:a37:85c7:: with SMTP id h190mr7396973qkd.225.1550246655005; Fri, 15 Feb 2019 08:04:15 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id z8sm2998164qto.45.2019.02.15.08.04.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Feb 2019 08:04:14 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 3BD8412262E; Fri, 15 Feb 2019 13:04:12 -0300 (-03) Date: Fri, 15 Feb 2019 13:04:12 -0300 From: Alvaro Herrera To: Tom Lane Cc: Kyotaro HORIGUCHI , andres@anarazel.de, thomas.munro@enterprisedb.com, andrew@tao11.riddles.org.uk, david.rowley@2ndquadrant.com, pgsql-hackers@lists.postgresql.org Subject: Re: Using POPCNT and other advanced bit manipulation instructions Message-ID: <20190215160412.GA7354@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <986.1550243138@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Feb-15, Tom Lane wrote: > Alvaro Herrera writes: > > Ah, I understand it now: > > https://stackoverflow.com/questions/25683690/confusion-about-bsr-and-lzcnt/43443701#43443701 > > if you call LZCNT/TZCNT on a CPU that doesn't support it, it won't raise > > SIGILL or anything ... it'll just silently compute the wrong result. > > That's certainly not what I call a fallback! > > Yeah, that's pretty nasty; it means there's no backstop for whether > your choose function gets it right :-( Hopefully other tests will fail in some visible way, though. My fear is whether we have such systems in buildfarm. > Is POPCNT any better in this respect? I couldn't find how is POPCNT encoded. https://stackoverflow.com/a/28803917/242383 I did find these articles: http://danluu.com/assembly-intrinsics/ https://stackoverflow.com/questions/25078285/replacing-a-32-bit-loop-counter-with-64-bit-introduces-crazy-performance-deviati This suggests that this all a largely pointless exercise at least on Intel and GCC/Clang. It may be better on AMD ... but to get really better performance we'd need to be coding the popcnt calls in assembly rather than using the compiler intrinsics, even with -mpopcnt, because the intrinsics suck. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services