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 1sYuoA-00F3wY-LD for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jul 2024 21:55:02 +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 1sYuo8-00E4I3-T2 for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jul 2024 21:55:00 +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 1sYuo8-00E4Hv-JL for pgsql-hackers@lists.postgresql.org; Tue, 30 Jul 2024 21:55:00 +0000 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sYuo5-002GuV-VT for pgsql-hackers@lists.postgresql.org; Tue, 30 Jul 2024 21:54:59 +0000 Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-397cdb4bf11so10487715ab.2 for ; Tue, 30 Jul 2024 14:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722376497; x=1722981297; 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=EEPT0BUi44QDGPqJFl4r3/s/LdznFOxKU5FqEOKZgE4=; b=FRho7m+AuHxtnn6NNNrhyjCqj8vijdVMMXD3HrckqPVPb+YE2pc6kdhBovhEPlwvBY hWIullo5E9VRCvDyNwwqTv60IOKL6c3pQQ/ax8Ta8RXWuxxNDH1Am9g/wdqMD931G5ti v0WG7ao09yCxTSFWElREbuZ9U01SBDzvSlhUdHZWbmz1VBuHfs30U9wJy/mnaUoJxE0q g4mF42VIpnshl3lVL0eju8wPJlTQdP1l0CcVs/ghFGcVUUmWT3FN+q7r8bMiFr+doMSp 0EgsIAU8Y+s1z7P6/178y9w3ImvRJcuJ3YeqgQY3K/GokXmf4+Ky6LcZuZfufp9lCoWy VSSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722376497; x=1722981297; 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=EEPT0BUi44QDGPqJFl4r3/s/LdznFOxKU5FqEOKZgE4=; b=Uir+2CA/3wjPcZhZaloWNIXog+kQcQjOrBhaPFlpS8RAd86jLAzZZJGM3pCUxGDM7R 3eFq+lzqhLRZxc+tf3vAXZJarda03Agaacrl/iiPjvpvgh2YUcMe43dIc5ORmPotTDPj BJ+cHFu/l1XbxZq1Kg+eY3Krtq4WMYkFgnE2rxp2hYfiUfiq5PIUMcVMhtx/3jPGQlgP cHPh8LlOP777c6wSK1IVOL22I2Fk6p13howj7l54Hk1/Ynbcglyu/Dv15C+IsPLMzv9C mJQpW4oGMTvZuj3nlShCCEnKYmdhDzyBeshYGKXe/u1/tWxMp0FQH/NxVWEeBsBVyQzP Pnyw== X-Forwarded-Encrypted: i=1; AJvYcCVjsQdwQ1OZCxviaS2XcSv3GLB/+nq1Q3lE/zWpFW1PS9tzKNwC+nbXpfOqmzX3YP/yONrYX9VW9HUTxuSpA/FrLhZwNMZoMIt8p1DJfazZi1Tf X-Gm-Message-State: AOJu0Yw8H/V2T9BUo7zLYcR/m2asUnNu+KSqQ6xenktMLQwjAKTwssFv Ydqqfn1PCZ9GVIwYBF9Ct4U+tWdVe2y7wh7OAAYuzowm6iTJmxlC X-Google-Smtp-Source: AGHT+IElLWxanWR1TJIKgAzeHH/n19WzU1fPJBuE4Fga6F0NOK84a9/a6eE1vYYHfLHqoG2S3Bte8Q== X-Received: by 2002:a92:c56e:0:b0:398:623a:2f49 with SMTP id e9e14a558f8ab-39aec41a2b5mr139146875ab.27.1722376497271; Tue, 30 Jul 2024 14:54:57 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-39af4e47e6esm25954815ab.56.2024.07.30.14.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jul 2024 14:54:56 -0700 (PDT) Date: Tue, 30 Jul 2024 16:54:54 -0500 From: Nathan Bossart To: Andres Freund Cc: "Devulapalli, Raghuveer" , "Shankaran, Akash" , Tom Lane , David Rowley , Ants Aasma , Alvaro Herrera , "Amonson, Paul D" , Noah Misch , Matthias van de Meent , "pgsql-hackers@lists.postgresql.org" Subject: Re: Popcount optimization using AVX512 Message-ID: References: <20240418195346.GA3506520@nathanxps13> <20240418210158.GA3776258@nathanxps13> <20240418215902.GA3830246@nathanxps13> <20240418221358.GA3927188@nathanxps13> <20240423160207.GA841237@nathanxps13> <20240730210701.oyn2wr4zduu2efrg@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jul 30, 2024 at 04:32:07PM -0500, Nathan Bossart wrote: > On Tue, Jul 30, 2024 at 02:07:01PM -0700, Andres Freund wrote: >> Afaict we could just check for predefined preprocessor macros: >> >> echo|time gcc -c -mxsave -mavx512vpopcntdq -mavx512bw -xc -dM -E - -o -|grep -E '__XSAVE__|__AVX512BW__|__AVX512VPOPCNTDQ__' >> #define __AVX512BW__ 1 >> #define __AVX512VPOPCNTDQ__ 1 >> #define __XSAVE__ 1 >> 0.00user 0.00system 0:00.00elapsed 100%CPU (0avgtext+0avgdata 13292maxresident)k >> >> echo|time gcc -c -march=nehalem -xc -dM -E - -o -|grep -E '__XSAVE__|__AVX512BW__|__AVX512VPOPCNTDQ__' >> 0.00user 0.00system 0:00.00elapsed 100%CPU (0avgtext+0avgdata 10972maxresident)k > > Seems promising. I can't think of a reason that wouldn't work. > >> Now, a reasonable counter-argument would be that only some of these macros are >> defined for msvc ([1]). However, as it turns out, the test is broken >> today, as msvc doesn't error out when using an intrinsic that's not >> "available" by the target architecture, it seems to assume that the caller did >> a cpuid check ahead of time. Hm. Upon further inspection, I see that MSVC appears to be missing __XSAVE__ and __AVX512VPOPCNTDQ__, which is unfortunate. Still, I think the worst case scenario is that the CPUID check fails and we don't use AVX-512 instructions. AFAICT we aren't adding new function pointers in any builds that don't already have them, just compiling some extra unused code. -- nathan