Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite2809e3

Browse files
committed
Inline CRC computation for small fixed-length input on x86
pg_crc32c.h now has a simplified copy of the loop in pg_crc32c_sse42.csuitable for inlining where possible.This may slightly reduce contention for the WAL insertion lock,but that hasn't been tested. The motivation for this change is avoidregressing for a future commit that will use a function pointer fornon-constant input in all x86 builds.While it's technically possible to make a similar change for Arm andLoongArch, there are some questions about how inlining should worksince those platforms prefer stricter alignment. There are also noimmediate plans to add additional implementations for them.Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>Reviewed-by: Raghuveer Devulapalli <raghuveer.devulapalli@intel.com>Discussion:https://postgr.es/m/CANWCAZZEiTzhZcuwTiJ2=opiNpAUn1vuDRu1N02z61AthwRZLA@mail.gmail.comDiscussion:https://postgr.es/m/CANWCAZYRhLHArpyfV4uRK-Rw9N5oV5HMkkKtBehcuTjNOMwCZg@mail.gmail.com
1 parent4694aed commite2809e3

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

‎src/include/port/pg_crc32c.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,42 @@ typedef uint32 pg_crc32c;
4343

4444
#if defined(USE_SSE42_CRC32C)
4545
/* Use Intel SSE4.2 instructions. */
46+
47+
#include<nmmintrin.h>
48+
4649
#defineCOMP_CRC32C(crc,data,len) \
47-
((crc) =pg_comp_crc32c_sse42((crc), (data), (len)))
50+
((crc) =pg_comp_crc32c_dispatch((crc), (data), (len)))
4851
#defineFIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF)
4952

5053
externpg_crc32cpg_comp_crc32c_sse42(pg_crc32ccrc,constvoid*data,size_tlen);
5154

55+
pg_attribute_no_sanitize_alignment()
56+
staticinline
57+
pg_crc32c
58+
pg_comp_crc32c_dispatch(pg_crc32ccrc,constvoid*data,size_tlen)
59+
{
60+
if (__builtin_constant_p(len)&&len<32)
61+
{
62+
constunsignedchar*p=data;
63+
64+
/*
65+
* For small constant inputs, inline the computation to avoid a
66+
* function call and allow the compiler to unroll loops.
67+
*/
68+
#ifSIZEOF_VOID_P >=8
69+
for (;len >=8;p+=8,len-=8)
70+
crc=_mm_crc32_u64(crc,*(constuint64*)p);
71+
#endif
72+
for (;len >=4;p+=4,len-=4)
73+
crc=_mm_crc32_u32(crc,*(constuint32*)p);
74+
for (;len>0;--len)
75+
crc=_mm_crc32_u8(crc,*p++);
76+
returncrc;
77+
}
78+
else
79+
returnpg_comp_crc32c_sse42(crc,data,len);
80+
}
81+
5282
#elif defined(USE_ARMV8_CRC32C)
5383
/* Use ARMv8 CRC Extension instructions. */
5484

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp