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 1rqFIn-00BMje-Mi for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Mar 2024 16:42: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 1rqFIm-0032Nr-GP for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Mar 2024 16:42:00 +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 1rqFIm-0032Nj-4C for pgsql-hackers@lists.postgresql.org; Fri, 29 Mar 2024 16:42:00 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rqFIj-007Jtf-1V for pgsql-hackers@lists.postgresql.org; Fri, 29 Mar 2024 16:41:59 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3666affcb59so8293785ab.2 for ; Fri, 29 Mar 2024 09:41:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711730515; x=1712335315; 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=sFXkpLKxI/DDhVo8EFcq9SikI99dk0e49dn+qSQMdG0=; b=jK4qLKgZdvtX0tf0DvLKmBHfHYGteRzmzsFj40VUl7oCWVMpY4qVBI7lcSuDCz685V vbo+ye0KI+3lM9zWFrDHl73jEGAUNiziUnD5vjjAvhYbttG1CvSXPNfyyPduFS9ylv8a AzXiO0mYelJmFoCrBphxUweseN/3vFo+GyTqMyXOAeQi9y0Bi5BmSqhByx/VXdRgynKB IoGQEfy4lL/H90vJWY8am1UidhOxbyxhdGBsPGSH7V0Xjpzd99O6zZOneFwOUnuKhjWl wryEpbV4FU1DpuwEWCJYQBTm2FCot8PkbczcUd6RlM1dquj9LZEphEqBJx71hAtKu7Q4 Q9cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711730515; x=1712335315; 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=sFXkpLKxI/DDhVo8EFcq9SikI99dk0e49dn+qSQMdG0=; b=Q9jhC7CBVrfuDlyXW52mqe3SP1uIte+ZQJpD9ymdxK6VqOCijqlKMHxNa4Iz8C85fI iRlGsU7W9WsBCN4CBuPKSNUl6+J1XKeTtzFWn5XGC38bhSMo8X/ZIA8hyoUnkRkLLJl8 Ya6lXfMYiYS0FrRutGvLKWMhi6rWGBo/h5OTrE/PUW9SuiIvTvlRB0OgdOKOxXuf1UJ5 rT27lGlX/6UshJSv92dvOpAxdAFySSv/F66INPXid9/Au9CUVN/qAo6u5Fz5RhItA3Fr f4syAY5UD1NJX+EVSYh1KuXgrkgEt/yEU13W6uzcWRHf6iKJMLOiD9n7rMp8V8XibcdE S4Aw== X-Forwarded-Encrypted: i=1; AJvYcCVqzhycJrvva+ifI88FD2wNcOoCAgX7ti3VGQt8KylGG1IrXoWvumRWpFe+5IM8tMuZipClzFHu2gMeurL/YUa2NfGTIKIxnCY5lSR6pg9i613X X-Gm-Message-State: AOJu0YwaoaIdInRZrI06OtxXNNrKGSfVSHisTm1bbjKDRrvj4pXFR0Ns 8SbNyeD2pth3DuQHRXNJQvCjl8evQ09X0mEf+YB++hRMu1VrKeZ8 X-Google-Smtp-Source: AGHT+IFmfYTbQ3OsGASyC/99X6i1JxyEqpa/FpCyutv/3sDf/QVDwOFMbZr0KjvsSul2OxaqTRZ6XQ== X-Received: by 2002:a05:6e02:1a8a:b0:368:608f:35f4 with SMTP id k10-20020a056e021a8a00b00368608f35f4mr3440510ilv.12.1711730515296; Fri, 29 Mar 2024 09:41:55 -0700 (PDT) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id b6-20020a92ce06000000b003689b15b6efsm1182881ilo.15.2024.03.29.09.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 09:41:54 -0700 (PDT) Date: Fri, 29 Mar 2024 11:41:53 -0500 From: Nathan Bossart To: Tom Lane Cc: "Amonson, Paul D" , David Rowley , Andres Freund , Alvaro Herrera , "Shankaran, Akash" , Noah Misch , Matthias van de Meent , "pgsql-hackers@lists.postgresql.org" Subject: Re: Popcount optimization using AVX512 Message-ID: <20240329164153.GC1106154@nathanxps13> References: <20240325200551.GB2924132@nathanxps13> <20240327220010.GA231058@nathanxps13> <20240328213854.GA916732@nathanxps13> <20240329153515.GA1046039@nathanxps13> <20240329161642.GA1106154@nathanxps13> <6504.1711729814@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6504.1711729814@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Mar 29, 2024 at 12:30:14PM -0400, Tom Lane wrote: > Nathan Bossart writes: >>> I see google web references to the xgetbv instruction as far back as 2009 >>> for Intel 64 bit HW and 2010 for AMD 64bit HW, maybe you could test for >>> _xgetbv() MSVC built-in. How far back do you need to go? > >> Hm. It seems unlikely that a compiler would understand AVX512 intrinsics >> and not XGETBV then. I guess the other question is whether CPUID >> indicating AVX512 is enabled implies the availability of XGETBV on the CPU. >> If that's not safe, we might need to add another CPUID test. > > Some quick googling says that (1) XGETBV predates AVX and (2) if you > are worried about old CPUs, you should check CPUID to verify whether > XGETBV exists before trying to use it. I did not look for the > bit-level details on how to do that. That extra CPUID check should translate to exactly one additional line of code, so I think I'm inclined to just add it. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com