RobRich999 / Chromium_Clang

Chromium browser compiled with the Clang/LLVM compiler.
172 stars 12 forks source link

Rust arch params. #30

Closed Alex313031 closed 2 years ago

Alex313031 commented 2 years ago

Hello. My rust lines in the main compiler build.gn all have copt level = 3 but they also have arch specific lines afterwards. However the difference is that mine has sse4,avx,aes, while yours just have avx or avx2

See this line (yours) > rustflags += [ "-Copt-level=3", "-Ctarget-feature=+avx", ]

versus mine > rustflags += [ "-Ccodegen-units=1", "-Copt-level=3", "-Ctarget-feature=+sse4,+aes,+avx", ]

By using mine, will this cause it to use sse4 in places where it would otherwise use avx? Should I make it have just avx and aes?

Also, regarding aes, I know we added it as a workaround for windows, but I think you should add it for all platforms (what Im doing), since it makes sense because any CPU with avx will also have aes, and compiling with aes allows speedup for certain things that use it, namely libaes which can explicitly use this compiler option if present (kinda like how, for example, libffmpeg has specific code to use avx intrinsics only if it detects that it is compiling for it). I imagine this will speed up parts of chromium that use libaes, for example encrypt/decrypt of AES encrypted certificates.

RobRich999 commented 2 years ago

AVX is a superset of SSE4, so there is no need to specify SSE4 or any other lower SIMD instruction set.

Hardware AES has been supported since Westmere and Bulldozer, so it should be fine to enable it as well for AVX and higher builds.

I did pull back rust targets optimized for size to -Os from the previous -O3 config, as I doubt we have PGO profiling for any rust code at this time, so we might as well do some manual tuning of code bloat.

if (optimize_for_size) { rustflags = [ "-Copt-level=s", "-Ctarget-feature=+avx,+aes", ]

Additionally, you might try passing in VEAS when enabliing AES with AVX or higher SIMD. It can promote some AES instructions to AVX registers. That should be -mvaes for cflags and +vaes for rust flags. YMMV.

RobRich999 commented 2 years ago

The -mvaes flags built okay here.

"-mavx", "-maes", "-mvaes",

"-Ctarget-feature=+avx,+aes,+vaes",

RobRich999 commented 2 years ago

BTW, ffmpeg does CPU dispatch. Many Chromium components supporting instructions sets above the compiler config baseline do similar. The CPU features are detected at code runtime instead of compile time. ;) For example, if certain ffmpeg functions detect AVX2 support is available when run, those functions will use AVX2 even if building for Chromium's default baseline of SSE3.

https://en.wikipedia.org/wiki/Dynamic_dispatch

Actually generating AVX/AVX2 instructions is (usually) nice, but another part of the reason we want to up the baseline to AVX (or higher) is to mitigate mixed SSE/AVX transition penalties. Even if SSE instructions continue to be generated at compile time, they will be VEX encoded if AVX/AVX2 support is specified as the baseline.

https://en.wikipedia.org/wiki/VEX_prefix https://john-h-k.github.io/VexTransitionPenalties.html