Skip to content

Conversation

@dashsantosh-mcw
Copy link
Contributor

Adds -march=native flag to automatically detect CPU features during build time to generate code optimized specifically for that device's CPU architecture

Tested on:

  • Windows 10+ (via MinGW)
  • macOS 10.13+
  • Ubuntu Linux

@marcosfrm
Copy link
Contributor

By doing this, we'll be altering the official builds to use the instruction set specific to the processor running on the CI, correct? This compiler flag should only be used when HandBrake is configured with --cpu=native.

ifeq ($(HOST.machine),$(filter $(HOST.machine),i686 x86_64))
GCC.args.cpu.native += -march=native
endif

We might consider increasing the minimum requirement for the ARM64 version to -march=armv8.1-a, following Windows 11 24H2's requirement, but the impact on performance of this change needs to be measured.

@sr55
Copy link
Contributor

sr55 commented Oct 14, 2024

Just a note that all of our build servers for HandBrake on Windows are x86_64 so we won't get any benefit in official releases for build time optimisations that rely on being built on a specific platform.

@marcosfrm
Copy link
Contributor

Right. It does not even work with Clang:

  : Sanity check compile stderr:
  : clang: error: unsupported argument 'native' to option '-march='

@dashsantosh-mcw
Copy link
Contributor Author

By doing this, we'll be altering the official builds to use the instruction set specific to the processor running on the CI, correct?

I see. That is right. I'll put it under the --cpu=native flag if that's alright.

Just a note that all of our build servers for HandBrake on Windows are x86_64 so we won't get any benefit in official releases for build time optimisations that rely on being built on a specific platform.

That being the case, is it possible to add a build workflow, where we could pass -mcpu=oryon-1 which would make the build optimized for the latest Oryon CPUs, rather than having generic windows ARM builds?

Right. It does not even work with Clang:

I am using latest llvm-mingw 19.1.2 and it compiles fine without any issue. But its a ucrt aarch64 build. Let me check with the msvcrt x86_64 build as well

@galad87
Copy link
Contributor

galad87 commented Oct 16, 2024

This is not doable, because the result might run only on the machine it was built on. For example if the build machine has SVE, the compiler might use SVE instructions, and that will crash on every other machine that has no SVE.

You could set it to Windows for ARM baseline, if the compiler is not already setting it properly.

@marcosfrm
Copy link
Contributor

I think setting -march=armv8.1-a is doable, it's just a slight upgrade from the default armv8-a. ARMv8.1 is the minimum needed for Windows 11 24H2. Only a few ARM64 CPUs used on PCs can't handle this instruction set (essentially the Snapdragon 835), but those chips are so weak that HandBrake won't be much use on them anyway.

@bradleysepos
Copy link
Contributor

Since HandBrake 1.6.0 you can build with --cpu=native but this only works for x86_64 because clang does not support it on arm.

See:

That PR thread has a bunch of discussion about custom CFLAGS and LTO things that also might be of use to you.

Anyway, it is technically impossible for us to ship native builds. We have to target a general spec in order for the build to be usable across a wide range of machines for the given macro architecture. I do not believe we intend to ship more narrowly targeted builds at all, but we can discuss this.

Of course, anyone can create a native build for their own machine. Some people native + LTO to be beneficial on the order of 1-4%, but it probably only makes sense to create a custom personal build like this if one plans to transcode thousands of videos.

@github-actions
Copy link

Hello,

Warning

This pull request appears to be inactive and will be automatically closed within 10 days if no further activity is detected.
If you wish this issue to remain open, please request the stale label to be removed and an appropriate label assigned.

Thank You,
The HandBrake Bot

@github-actions github-actions bot added the Stale label Jan 15, 2025
@github-actions
Copy link

Hello,

Note

This pull request has now been closed due to inactivity.
If you believe this is in error, please leave a comment and we can re-open it.

Thank You,
The HandBrake Bot

@github-actions github-actions bot closed this Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

5 participants