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 1r0DFZ-004D1T-6k for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Nov 2023 03:59:37 +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 1r0DFW-004HV6-FQ for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Nov 2023 03:59:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r0DFW-004HTY-4g for pgsql-hackers@lists.postgresql.org; Tue, 07 Nov 2023 03:59:34 +0000 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r0DFT-0056vG-7u for pgsql-hackers@lists.postgresql.org; Tue, 07 Nov 2023 03:59:33 +0000 Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-7a694a365d9so224878639f.0 for ; Mon, 06 Nov 2023 19:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699329568; x=1699934368; darn=lists.postgresql.org; h=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=pxZ+D1CNrAYzVWlGCXDMlztjyMvSxeJVlt26BV6mSYQ=; b=HDfDE8alh7owJOCGjirMpeMwbS7c4AoLksEDLl8t/2vS4jlhoipxvv5Az/mLvY1Jwj ZxNKpMyALbtWbIp+4noKgKUgDbqWqFjXm3I6T1gOR+6bGDeGVgVK0eXSJ9mJfEqIlNyO zu/SsGduR/Qh4TA6CF0UyU21gEKUA5h5aveafzR9OdL6wSDC5AgF89rWuhO4rF4sjEno u4ZqznNo8UiuOB2IvN5yBBiMTgdCbgAMDkmtwE9zrTvEF/Wx2pCUXD7pxu/Rs7+RiGEg 93zOuFH14kF9zNHYvDZjeW7vMlJEq+hu/LQtOnEj+cUvSEMyjhLs7k3imLgL29SYOwSN Bu9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699329568; x=1699934368; h=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=pxZ+D1CNrAYzVWlGCXDMlztjyMvSxeJVlt26BV6mSYQ=; b=ZQn2vRcCMeWALduRPSwnClc4Vn5IUe4XLxzSx7OilpMF92lFEjIU/+yCDPt8epT69s ijGxT1oVSDpbza24YJPftO4pc5safiJ0vSRXvwBkA14UUw4+E+EdOcahJ/EGwju+ITAF RrDD+P84ywb+qrzZLn1vyc/bkBqtNSLq7RrfAQkhXj0v24wDVlaDFvhNxVRPUWrkaD8f fck3wYuHA993xtEAj2IE7t7iOOM1fwTr19SjSYxUSdC3FftpIs45oeIBRmzSPlYxUlu+ vNMx7SmpqunjWxuF8pRGmSK4F3Vkq0WQZxT+oyRa6xp6BCdIQnRMlh0geypmtfIQ+9Yh cF8g== X-Gm-Message-State: AOJu0YwOG5kPNZC+jN/N38iQcIXQgGBY3rJ8oNx17r5sEgneVlaiJ3kL k4QRywW66AcXVSd2hPmt4BQ= X-Google-Smtp-Source: AGHT+IHBoRPvLtdb/Xlt1ArFcd/1plOGBktqBNV8AfigcqthSomng9Rgux3rSzxzx9546CWK/qKhIw== X-Received: by 2002:a05:6602:154a:b0:7a6:8255:78b3 with SMTP id h10-20020a056602154a00b007a6825578b3mr46277208iow.7.1699329568114; Mon, 06 Nov 2023 19:59:28 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id v3-20020a5d9483000000b0079fcb62c5dcsm2630922ioj.45.2023.11.06.19.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 19:59:27 -0800 (PST) Date: Mon, 6 Nov 2023 21:59:26 -0600 From: Nathan Bossart To: Noah Misch 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: <20231107035926.GD729644@nathanxps13> References: <20231107022240.GA729644@nathanxps13> <36329.1699325578@sss.pgh.pa.us> <20231107031501.61@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231107031501.61@rfd.leadboat.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. [0] https://llvm.org/docs/LangRef.html#ifuncs -- Nathan Bossart Amazon Web Services: https://aws.amazon.com