More folding to vpternlogd?
@kendall1997 is already working on this.
Since May 29, 2025.
Assessment
This issue has not been assessed yet.
Description
Based on the description in https://github.com/dotnet/runtime/pull/91227, I thought each of the following might both compile down to a single vpternlogd:
static Vector512<int> Exp1(Vector512<int> a, Vector512<int> b, Vector512<int> c) =>
Vector512.ConditionalSelect(a, b & c, b | c);
static Vector512<int> Exp2(Vector512<int> a, Vector512<int> b, Vector512<int> c) =>
(a & (b & c)) | (~a & (b | c));
but they don't today. The first results in a vpternlogd, but it's the standard one for ConditionalSelect used to choose between the results, and it's thus still computing the and and or separately:
vmovups zmm0, zmmword ptr [r8]
vmovups zmm1, zmmword ptr [r9]
vpandd zmm2, zmm1, zmm0
vpord zmm0, zmm1, zmm0
vpternlogd zmm0, zmm2, zmmword ptr [rdx], -40
The second results in two vpternlogds that are then or'd together:
vmovups zmm0, zmmword ptr [rdx]
vmovups zmm1, zmmword ptr [r8]
vmovups zmm2, zmmword ptr [r9]
vmovaps zmm3, zmm0
vpternlogd zmm3, zmm2, zmm1, -128
vpternlogd zmm2, zmm1, zmm0, 84
vpord zmm0, zmm2, zmm3
rather than a single vpternlogd that handles the whole bitwise operation.
Is this just further opportunity? Or is there something preventing such optimization?
cc: @tannergooding, @EgorBo
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·