Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r0F1g-004SOE-Qk for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Nov 2023 05:53:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r0F1f-005A3C-2R for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Nov 2023 05:53:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r0F1e-005A2f-I8 for pgsql-hackers@lists.postgresql.org; Tue, 07 Nov 2023 05:53:22 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r0F1b-004LsW-NE for pgsql-hackers@lists.postgresql.org; Tue, 07 Nov 2023 05:53:21 +0000 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-d865854ef96so5410256276.2 for ; Mon, 06 Nov 2023 21:53:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1699336399; x=1699941199; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ktLQ9p4/n/2e66Is3vGvbKHXSo0OvIW+A1y7jC6p7WM=; b=ItE8AHYfKZ7+6JdSIe/xKTOdftXsQpvG/1SDX6PnSD6Fo7ya22wGrRlJPVsmlr/P8G 5+MsjTqG2ra0O9AtmR755dbRMcNjZvfJe3HNVYP5Mp8drQL25hR04EfSX4sNXpHG9+iv ePBkeC2Ix0AjfdUzFKeU5TBTlZCqgjMVCP7n4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699336399; x=1699941199; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ktLQ9p4/n/2e66Is3vGvbKHXSo0OvIW+A1y7jC6p7WM=; b=ZnQQVzarhbJjrLv8Btlqv+lGq7hfJwB/qL2dC2o53xAuf5NEoEQ+qYCV/tt9M9hkVh 6sDRCyXnbyG4mImgF6QdjeCYLI48cKFV7pCpyzuE0ntCXxITLOZY3UnzndNoID1xXjEG VYJfxSPPGUGKert/KmRYPggA6vOxGJDwLvVBvIFduum89tqoxPUcyrzUi11AsSCgBefo LHaf7W5G6cybsRawP1Xje+fQYp1m7VGANDdjesCZwLRQjsa8LLHrA/ogc3py11JIBY4/ CYgqu7kuZBuNq+fUfy4l3JCkZFGX7xeUIMnKvNQH5Fs9Ive+g1kvocz6EBUgPOqFpEML lwRA== X-Gm-Message-State: AOJu0Yx/BJWSRbjW4j0LZKlsE1w42HH8nZvEiI9VlqXdvHzJg2+bPyhc e4Pk3sOViH7BIczVdNp9uMLYUw== X-Google-Smtp-Source: AGHT+IGRRFgSIXDgTz7ER7vT1qjCo3C70cyuWxCNYje0UeBzNLatvVQGA+T9W/sf2U7iPtStYDFv7A== X-Received: by 2002:a05:6902:1209:b0:da0:52e4:b5aa with SMTP id s9-20020a056902120900b00da052e4b5aamr36383678ybu.8.1699336398810; Mon, 06 Nov 2023 21:53:18 -0800 (PST) Received: from rfd.leadboat.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id d131-20020a25e689000000b00da394177f34sm4814326ybh.21.2023.11.06.21.53.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2023 21:53:18 -0800 (PST) Date: Mon, 6 Nov 2023 21:53:15 -0800 From: Noah Misch To: Nathan Bossart Cc: Tom Lane , Matthias van de Meent , "Amonson, Paul D" , "pgsql-hackers@lists.postgresql.org" , "Shankaran, Akash" Subject: Re: Popcount optimization using AVX512 Message-ID: <20231107055315.8e@rfd.leadboat.com> References: <20231107022240.GA729644@nathanxps13> <36329.1699325578@sss.pgh.pa.us> <20231107031501.61@rfd.leadboat.com> <20231107035926.GD729644@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231107035926.GD729644@nathanxps13> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Nov 06, 2023 at 09:59:26PM -0600, Nathan Bossart wrote: > On Mon, Nov 06, 2023 at 07:15:01PM -0800, Noah Misch wrote: > > On Mon, Nov 06, 2023 at 09:52:58PM -0500, Tom Lane wrote: > >> Nathan Bossart writes: > >> > Like I said, I don't have any proposals yet, but assuming we do want to > >> > support newer intrinsics, either open-coded or via auto-vectorization, I > >> > suspect we'll need to gather consensus for a new policy/strategy. > >> > >> Yeah. The function-pointer solution kind of sucks, because for the > >> sort of operation we're considering here, adding a call and return > >> is probably order-of-100% overhead. Worse, it adds similar overhead > >> for everyone who doesn't get the benefit of the optimization. > > > > The glibc/gcc "ifunc" mechanism was designed to solve this problem of choosing > > a function implementation based on the runtime CPU, without incurring function > > pointer overhead. I would not attempt to use AVX512 on non-glibc systems, and > > I would use ifunc to select the desired popcount implementation on glibc: > > https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Function-Attributes.html > > Thanks, that seems promising for the function pointer cases. I'll plan on > trying to convert one of the existing ones to use it. BTW it looks like > LLVM has something similar [0]. > > IIUC this unfortunately wouldn't help for cases where we wanted to keep > stuff inlined, such as is_valid_ascii() and the functions in pg_lfind.h, > unless we applied it to the calling functions, but that doesn't ѕound > particularly maintainable. Agreed, it doesn't solve inline cases. If the gains are big enough, we should move toward packages containing N CPU-specialized copies of the postgres binary, with bin/postgres just exec'ing the right one.