Skip to content

crc: avoid VPTERNLOGQ on Hygon in crc32_iscsi_by16_10#403

Closed
MaodiMa wants to merge 1 commit intointel:masterfrom
MaodiMa:crc32c_avx512_vpternlogq
Closed

crc: avoid VPTERNLOGQ on Hygon in crc32_iscsi_by16_10#403
MaodiMa wants to merge 1 commit intointel:masterfrom
MaodiMa:crc32c_avx512_vpternlogq

Conversation

@MaodiMa
Copy link
Copy Markdown
Contributor

@MaodiMa MaodiMa commented Mar 26, 2026

Disable VPTERNLOGQ instruction in crc32_iscsi_by16_10 on Hygon CPU.

Using VPTERNLOGQ in this case leads to an uarch bottleneck on current Hygon CPU and does not perform ideally. So we would like to use VPXORQ instead. This will leads to ~53.5% speedup according to make perf :

original bandwidth (MB/s) opt speedup
Hygon 49643.52 76193.92 53.5%

Modification only takes effect on Hygon CPU, based on the result of cpuinfo check.

Comment thread crc/crc32_iscsi_by16_10.asm Outdated
vpclmulqdq zmm1, zmm0, zmm16, 0x10
vpclmulqdq zmm0, zmm0, zmm16, 0x01
vpternlogq zmm0, zmm1, [arg2+16*0], 0x96
TERNARY_XOR zmm0, zmm1, [arg2+16*0]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works but it is code intrusive and I think it would be better to do it through macro only

vpternlogq %1, %2, %3, 0x96
%endif
%endmacro

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about having a macro like this? this should not need more code changes

%ifdef NO_VPTERNLOGQ
%macro vpternlogq 4
%if %4 == 0x96
vpxorq %1, %1, %2
vpxorq %1, %1, %3
%endif
%endmacro
%endif

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with it from the perspective of code changes. Defining vpternlogq as a macro seems to be a bit misleading, but it is okay since this is an edge case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I added the other path to prevent the macro from being empty.

Disable VPTERNLOGQ based on platform check, as it reduces IPC on
Hygon CPUs.

Signed-off-by: Maodi Ma <mamaodi@hygon.cn>
@MaodiMa MaodiMa force-pushed the crc32c_avx512_vpternlogq branch from 08e634f to 4514062 Compare April 3, 2026 07:14
@pablodelara
Copy link
Copy Markdown
Contributor

This is now merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants