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 1tpWCs-0071cf-IL for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Mar 2025 17:37:26 +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 1tpWCq-003X68-Hg for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Mar 2025 17:37:24 +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 1tpWBk-003Qph-2V for pgsql-hackers@lists.postgresql.org; Tue, 04 Mar 2025 17:36:16 +0000 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tpWBg-000wGJ-1W for pgsql-hackers@lists.postgresql.org; Tue, 04 Mar 2025 17:36:15 +0000 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-85ad9632156so177915939f.1 for ; Tue, 04 Mar 2025 09:36:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741109772; x=1741714572; 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=dFkGJjfUjZxQpVlPlDLbioT9nqXVsM5m3bNLKL+Em/A=; b=aw8/Du5BT75uzi/iYjUI9SP6f995kvbj/9ElIeyNu6fQNyts1DkP7nH2eYfvSRGrHp vqA7INIVHiMuBY6SYIvObtecE9B8hIDKpd9c9Dxqf0BzQefODdXHpbKS0hbrgHqe5Doz nU8X85EtBKJlMK0gQtPkGMabYj0gq39cGF/QTUW4DAKQEeTwRGUBl0nLpY6Brwjn6T+m 1VvY3Q/CQ8BXm6EyULMcVjUvD56tW7g1tgIyPoF5RiW/7jd7ZD6hnEKxWEKpoAHdmWtd fQRDttB/DoxU35ZGwNsn3/ty9MSvRKZ1DrFy9pjCkI15V7DekNU7TOn9qJK8nT5h07oz UDfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741109772; x=1741714572; 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=dFkGJjfUjZxQpVlPlDLbioT9nqXVsM5m3bNLKL+Em/A=; b=tlmIM2RKhDyA0xrO6Yg44nyGi6T3i+PSd0Q438q4Ff2hQ9NBpcmwgBfhMSwlBNjOM0 Q8kuPfAjw+g9Rxa7wKDpNw5Aq7ocQJ2ZT3lELIUMgmJcW6K0Q2xLy3ng2GzLPexXCaQv aGKADOP8/PsWza6V8jDJJXfe6JTOt1RqqucnTP3GgqbinhCu6xyhkGA5swAQLWS7CqKx OG3M+SuWEsOOY2B68XHdDaMkf12AvEGvzOuefGn/mjRrgMWjEDzi8PrcQD/byefzrmRk OLotsHBevsJKxKwhJIk65vWwuo5YMrjlJRbJsWvzElB6kkUCrpTWmcEb6MbffEZY7Bxx PPkA== X-Forwarded-Encrypted: i=1; AJvYcCUzIXS5SOTVH3auQL8eNeBHyA0dsx38qy7dRGZAldU3YYy+SLl+zkSf6F6ADZ5SBXxpcCFlpJ/frv5UtcuQ@lists.postgresql.org X-Gm-Message-State: AOJu0YyZRd4J5swTK4s7CzPcFJn52bjpmzk4fattc//EUHGZoF3nkOB6 U724JpLUiK/pxRTufz2g7w+bfsAGGJd/jf36RL41THiOHGMARnPchj5Vdw== X-Gm-Gg: ASbGncstgIRk78Ig9VSj6kXh9HmWCiVBHxejLepf94QCJ8OlVOSWHBmjWNvFStBJGUx 49LcmFyZu1jQDhGVGBiOV3++FCrRAKsXneJe5c039DU+acZveMzeQckQRoSI0nj30XNunZ5Bf5x xYRAIoAMdDgVtfyDe5fs9LsASTmBDQma15F4ck722LE5ZMkXcCpRqyd677H9wPFOnUnBNiEXT2t /D2xqJlc3qqx0peNkAkPDO1JkKCRCj0MDotJmT5YhHrU6fwbSghGlKmChFZUSUd6OOE+4mzHpeo R85fOTGH6c+X482yMrPwuaF+yvAlMUTSJwEE5uKbi4Fkf6mScIEqGI1mKgyX6lQf4hNhYvZlmpU QZLo3NVTCvhA6LTD9nU4C/bgRG9O/Y8ACmbo= X-Google-Smtp-Source: AGHT+IEd7VzD7DblYWkQUV19HX6Cl8AVmXZHBDj61MzPydU/3wDr6XteHjflyrcUota781/TH20DBQ== X-Received: by 2002:a05:6e02:1567:b0:3d0:4c9c:965f with SMTP id e9e14a558f8ab-3d3e6fae4f7mr191143805ab.20.1741109772064; Tue, 04 Mar 2025 09:36:12 -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-3d3dee5d8b1sm33603735ab.13.2025.03.04.09.36.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 09:36:11 -0800 (PST) Date: Tue, 4 Mar 2025 11:36:09 -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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Mar 04, 2025 at 12:09:09PM +0700, John Naylor wrote: > On Tue, Mar 4, 2025 at 2:11 AM Nathan Bossart wrote: >> 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. > > Note also upthread I mentioned we may have to go to 512-bit pclmul, > since Zen 2 regresses on 128-bit. :-( Ah, okay. You mean the AVX-512 version [0]? And are you thinking we'd use the same strategy for the compiled-in-SSE4.2 builds, i.e., inline the SSE4.2 version for small inputs and use a function pointer for larger ones? > I actually haven't seen any measurable difference with direct calls > versus indirect, but it could very well be that the microbenchmark is > hiding that since it's doing something unnatural by calling things a > bunch of times in a loop. I want to try changing the benchmark to base > the address it's computing on some bits from the crc from the last > loop iteration. I think that would make it more latency-sensitive. We > could also make it do an additional constant 20-byte input every time > to make it resemble WAL more closely. Looking back on some old benchmarks for small-ish inputs [0], the difference does seem within the noise range. I suppose these functions might be expensive enough to make the function pointer overhead negligible. IME there's a big difference when a function pointer is used for an instruction or two [2], but even relatively small inputs to the CRC-32C functions might require several instructions. >> 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. > > Slicing-by-8 needs one lookup and one XOR per byte of input, and other > overheads, so I think it would still be very slow. That's my suspicion, too. [0] https://postgr.es/m/BL1PR11MB530401FA7E9B1CA432CF9DC3DC192%40BL1PR11MB5304.namprd11.prod.outlook.com [1] https://postgr.es/m/20231031033601.GA68409%40nathanxps13 [2] https://postgr.es/m/CAApHDvqyMNGVgwpaOPtENdq5uEMR%3DvSkRJEgG1S%2BX7Vtk1-EnA%40mail.gmail.com -- nathan