dotnet/runtime

NativeAOT: Run-time simd checking

Open

#68,110 建立於 2022年4月16日

在 GitHub 查看
 (7 留言) (0 反應) (0 負責人)C# (5,445 fork)batch import
area-CodeGen-coreclrhelp wanted

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

Run-time simd checks can be beneficial in long-running cases (SpanHelpers.SequenceEqual for example)

Run-time simd checks can hurt performance because of redundant checks...

Could it be fixed? Eg;

void Method(){
    if(Avx2.IsSupported) avx2path();
    else softwarepath();
}
Method();
Method();
Method();

Can be transformed into:

if(Avx2.IsSupported){
    Method_avx2path();
    Method_avx2path();
    Method_avx2path();
} else {
    Method_softwarepath();
    Method_softwarepath();
    Method_softwarepath();
}

This could be done by inlining, but it won't work for the most part...

Compiler somehow should produce an unique codegen for every simd for every subsequent method:

void Start(){
    if(Avx2.IsSupported) ...;
    else ...;
    Continue();
}
void Continue(){
    End()
}
void End(){
    if(Avx2.IsSupported) ...;
    else ...;
}

Will produce

Start_Avx2
Start
Continue_Avx2
Continue
End_Avx2
End

But this unbiased codegeneration will cause dramatic size increase. Could PGO be possibly used to know where checks are actually useful?

category:cq theme:ready-to-run skill-level:expert cost:medium impact:small

貢獻者指南