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 1rkRdI-00CmWe-JB for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2024 16:39:13 +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 1rkRdH-007wNM-6A for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2024 16:39:11 +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 1rkRdG-007wNE-TP for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2024 16:39:11 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rkRdD-004Jhk-JA for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2024 16:39:10 +0000 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7c8b777ff8bso80340939f.0 for ; Wed, 13 Mar 2024 09:39:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710347948; x=1710952748; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=r8mV9RATm3bR0GdHsVIMeTJqNOgxlrRngBJNgY1C1Fs=; b=QeCgZyLw4JFFc6zwMd43RuXMXoaYi8iw5XIoE5pqTUhliah/T8rZWIVUxdm2xc8MrD h7RBhG1tddTK16Xzt6voc0oxL7QeX6WFyg15K/H/txX1/kQvLrrIkQ88LQsvnYzBoXSJ 0uC3iLLnHcD9Z074eQTDqd9eXY18ACtKfsucrpB1DN63aDBBJ+biNIigGYFiTbg5dM0u GVDxRzEzW5vuZzzseNrnhi+Oj9q2B/0HZ8VAozXSeTbM8LVLQibhPucMJmpcPfO4y1nn YDJNy2+HwKKR0txdLaV1wGH98/eCYT/Hc/olpiCmSs8wprQI1orrTTPWyCxRc4M4q9+A 2X5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710347948; x=1710952748; h=in-reply-to: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=r8mV9RATm3bR0GdHsVIMeTJqNOgxlrRngBJNgY1C1Fs=; b=C1OtRG+yf6Xl4Vxnb+e7HTbWAhWxzalDydmBZaD2G0lZc2PzAjEVSMbNPtDmslIjj8 o7JyzSw0mWhc3J/FR4gpAMMCikAy6Su1NenOmCH/7Np8CLSsgZJjiQWnEGAIPxAKlM9s snCe6SlRxZJHbMhzk51R2taFwJoILrJJe3obDCHbCO7+xlgonQBEiIH3q642y0oQELUQ zAIFdSrQxchqIg92TIr2imn9IKfKjq3vWXhipdCakhSGmpiASjgL9eiq8mew4Lzqqf2e Lk5Neh8CXIFM5ztrvgoVP7fTvYhPBE35yVYTpNwQD6AIkYEsHngUs3is3VkjX32paqB4 JDwQ== X-Forwarded-Encrypted: i=1; AJvYcCXsyBqgwa69MWixsHq3cd2ndT/TMOG1c28NPS2NmxYgU/aK4n3WE2PeYH5Yo5/SITLwxLiRxdDh+ZnGT9sGbTa4k/tdS7386WWPRJqPaFhjSTrg X-Gm-Message-State: AOJu0YzrbYcJy1Ns2U+z75rqFFs1rnW7bS3ns/DhszJCm4WGE9XO/nd8 AY5bSVI1jSxnsxC22BZ4jGp61UHfhjLeQYNGu/UfyY9c4iYw1A2N X-Google-Smtp-Source: AGHT+IEi65fAVSwhQHXudPPFc4RC8r6vPbY9SmF0Pj+cyreWW9rf/P6ImSr5QmbRSli7mCUUndhfgQ== X-Received: by 2002:a5e:8908:0:b0:7c8:965e:1dd4 with SMTP id k8-20020a5e8908000000b007c8965e1dd4mr619563ioj.7.1710347948080; Wed, 13 Mar 2024 09:39:08 -0700 (PDT) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id f24-20020a02a818000000b00476c165e60csm2878565jaj.30.2024.03.13.09.39.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:39:07 -0700 (PDT) Date: Wed, 13 Mar 2024 11:39:04 -0500 From: Nathan Bossart To: "Amonson, Paul D" Cc: Andres Freund , Alvaro Herrera , "Shankaran, Akash" , Noah Misch , Tom Lane , Matthias van de Meent , "pgsql-hackers@lists.postgresql.org" Subject: Re: Popcount optimization using AVX512 Message-ID: <20240313163904.GA2560056@nathanxps13> References: <20240301214457.GA3024365@nathanxps13> <20240304222118.GB3367383@nathanxps13> <20240305163730.GA3479896@nathanxps13> <20240307173318.GA455851@nathanxps13> <20240307213600.GA563369@nathanxps13> <20240312013436.GA1787866@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240312013436.GA1787866@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk A couple of thoughts on v7-0001: +extern int pg_popcount32_slow(uint32 word); +extern int pg_popcount64_slow(uint64 word); +/* In pg_popcnt_*_accel source file. */ +extern int pg_popcount32_fast(uint32 word); +extern int pg_popcount64_fast(uint64 word); Can these prototypes be moved to a header file (maybe pg_bitutils.h)? It looks like these are defined twice in the patch, and while I'm not positive that it's against project policy to declare extern function prototypes in .c files, it appears to be pretty rare. + 'pg_popcnt_choose.c', + 'pg_popcnt_x86_64_accel.c', I think we want these to be architecture-specific, i.e., only built for x86_64 if the compiler knows how to use the relevant instructions. There is a good chance that we'll want to add similar support for other systems. The CRC32C files are probably a good reference point for how to do this. +#ifdef TRY_POPCNT_FAST IIUC this macro can be set if either 1) the popcntq test in the autoconf/meson scripts passes or 2) we're building with MSVC on x86_64. I wonder if it would be better to move the MSVC/x86_64 check to the autoconf/meson scripts so that we could avoid surrounding large portions of the popcount code with this macro. This might even be a necessary step towards building these files in an architecture-specific fashion. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com