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

贡献者指南