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 1tpBCF-001WEj-Hn for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Mar 2025 19:11:23 +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 1tpBCE-00Ef8H-8R for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Mar 2025 19:11:22 +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 1tpBCD-00Ef87-UO for pgsql-hackers@lists.postgresql.org; Mon, 03 Mar 2025 19:11:21 +0000 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tpBCA-000lEo-1t for pgsql-hackers@lists.postgresql.org; Mon, 03 Mar 2025 19:11:21 +0000 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-3d2b3811513so17841195ab.1 for ; Mon, 03 Mar 2025 11:11:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741029078; x=1741633878; 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=hnIr53ycLO09x/MG+YmBrPOXfz9bpYo5BZd6w1rov5I=; b=ltb9Rg+zkrlDtV8/zdWpfZdht4+Bn3W81DwZVpRbmFGktXmByA7Ey2NxZhIqzuNC5W +c7+qWcDdL/nYx0/v9jHLpxPhECM4NWaOIYvuGq4DtxBtsi1JKBtKvYYZwVvZZzL9q2l SbqsTa5eERRN0y7c2wBqW1v4pTTdyttAe96clPoZXLwq+xTrJw5TofqQOg76C2Q2V/sR KrMf7srxfvrIyiPHGiyT+Y1Z99K334ytdR1IpdqmzCC5+2z1o1tCw7OQ4mSWWZpISPoY LGj148ems4BlDgKRbJK3JPJh4/SFhYboIesF2Pzwq1RNO2rjqeqg919rvutiEuD2go0c aDUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741029078; x=1741633878; 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=hnIr53ycLO09x/MG+YmBrPOXfz9bpYo5BZd6w1rov5I=; b=uvqk8QIIIcPoSN3kvr48BIEp90Wf/38Q095H6sMWYtE/fiz6PH4mJUu+XbpLmNb8qx 4VeqDfKnhQQPHFwyopwNCAcJQcs+xTkSSTcBYO0CFQOfK5hhCdR72AhXKaCOk8nd0K7N 1Mxlyshpk0p6wCX4TupT/Xh6GIC98d53vE0Kv4jclLd8ubj1hpqk6ZQBKflL0+bvF/Ke WWmkTYMp66XWNxKlcBpRbNQYzOxccsJ7aqZ77jZ6mYvLgV02lcs2v20wiZF5mOXEDobG e71Difi6GML5oTnFISdcVDXbJIDgx4Bq0B65kyAHBudUyqbOlZZSBI6i0CByrztTuPR4 1b9g== X-Forwarded-Encrypted: i=1; AJvYcCXbXLU7jtG1o0sLf8VdaF4BwMmlXWQ7qyIwJqAEiVu4dD2TKFYbqqmeicpRvX87mU9uE0U3lXHqGubm77mS@lists.postgresql.org X-Gm-Message-State: AOJu0YyCRePzlrDdgm4H0Dx222wEQAUEgNrOf24eek7W+ydzQWA1Atcj SQGodicI5Dhm/EYMjJs3j4YjaVRECktSu4FojiSTTAsPldSCgpd4 X-Gm-Gg: ASbGncvjshjXX0jwwv+BzQYt1WqPgaOuhnepE6Cp/rtDMExHdjImnEPyUadEm0VJd3/ YDaqSKre554H2Ep/zWAaULyYCkVB7awOrrmomLugRqhYUn0es9ic1hqPeL/4SGWo5vdVxOwDbpl DtWBZ69sDDv8uWPKnAbf5Ekb3nv8PP7jarc6vQpl25/KHDkzBJ1tXoQEjXwRvAbPmlt4ktIFWLb /FXP0xEdMgG94suvZWgEP/+RZy2VNiYKQaNCznTI9ToFl69vqQEMAKUrjbHKObjsDUhWqTD572R 6PB9OVOMgwZfz1AHG9F0tquw6PNBNxYQOgflA4LFubmrMP0qbpCu/wQigZp/Ml0hlCSrFchDyRe z3ncMjTM7NJj9C6jGfmQtq/NVfhlJkDBGoCk= X-Google-Smtp-Source: AGHT+IE3I0fnjKIs/yWqLfOVv4ypiYrfKPR+2ksoBoxh7sNIGl1Hq5S/4lWoqsJmv+8X9q9UKjNUhg== X-Received: by 2002:a92:d1cb:0:b0:3d3:f15e:8e23 with SMTP id e9e14a558f8ab-3d41dc72c72mr3971075ab.10.1741029078158; Mon, 03 Mar 2025 11:11:18 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3d3deecae4dsm25339685ab.45.2025.03.03.11.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Mar 2025 11:11:17 -0800 (PST) Date: Mon, 3 Mar 2025 13:11:15 -0600 From: Nathan Bossart To: John Naylor Cc: "Devulapalli, Raghuveer" , "pgsql-hackers@lists.postgresql.org" , "Shankaran, Akash" Subject: Re: Improve CRC32C performance on SSE4.2 Message-ID: References: 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 Fri, Feb 28, 2025 at 07:11:29PM +0700, John Naylor wrote: > 0002: For SSE4.2 builds, arrange so that constant input uses an > inlined path so that the compiler can emit unrolled loops anywhere. > This is particularly important for the WAL insertion lock, so this is > possibly committable on its own just for that. Nice. > 0004: the PCLMUL path for SSE4.2 builds. This uses a function pointer > for long-ish input and the same above inlined path for short input > (whether constant or not). So it gets the best of both worlds. I spent some time staring at pg_crc32.h with all these patches applied, and IIUC it leads to the following behavior: * For compiled-in SSE 4.2 builds, we branch based on the length. For smaller inputs, we are using an inlined version of the SSE 4.2 code. For larger inputs, we call a function pointer so that we can potentially use the PCLMUL version. This could potentially lead to a small regression for machines with SSE 4.2 but not PCLMUL, but that may be uncommon enough at this point to not worry aobut. * For runtime-check SSE 4.2 builds, we choose slicing-by-8, SSE 4.2, or SSE 4.2 with PCLMUL, and we always use a function pointer. The main question I have is whether we can simplify this by always using a runtime check and by inlining slicing-by-8 for small inputs. That would be dependent on the performance of slicing-by-8 and SSE 4.2 being comparable for small inputs. Overall, I wish we could avoid splitting things into separate files and adding more header file gymnastics, but maybe there isn't much better we can do without overhauling the CPU feature detection code. -- nathan