Use SSE 4.2 as a baseline when compiling Godot

This lets the compiler do more optimizations, leading to increased
performance for demanding CPU tasks.
This commit is contained in:
Hugo Locurcio 2022-03-10 01:40:31 +01:00
parent b89c47bb85
commit be1f9a878b
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
2 changed files with 26 additions and 5 deletions

View File

@ -731,11 +731,25 @@ elif env.msvc:
) )
Exit(255) Exit(255)
# Default architecture flags. # Set x86 CPU instruction sets to use by the compiler's autovectorization.
if env["arch"] == "x86_32": if env["arch"] == "x86_64":
if env.msvc: # On 64-bit x86, enable SSE 4.2 and prior instruction sets (SSE3/SSSE3/SSE4/SSE4.1) to improve performance.
# This is supported on most CPUs released after 2009-2011 (Intel Nehalem, AMD Bulldozer).
# AVX and AVX2 aren't enabled because they aren't available on more recent low-end Intel CPUs.
if env.msvc and not methods.using_clang(env):
# https://stackoverflow.com/questions/64053597/how-do-i-enable-sse4-1-and-sse3-but-not-avx-in-msvc/69328426
env.Append(CCFLAGS=["/d2archSSE42"])
else:
# `-msse2` is implied when compiling for x86_64.
env.Append(CCFLAGS=["-msse4.2"])
elif env["arch"] == "x86_32":
# Be more conservative with instruction sets on 32-bit x86 to improve compatibility.
# SSE and SSE2 are present on all CPUs that support 64-bit, even if running a 32-bit OS.
if env.msvc and not methods.using_clang(env):
env.Append(CCFLAGS=["/arch:SSE2"]) env.Append(CCFLAGS=["/arch:SSE2"])
else: else:
# Use `-mfpmath=sse` to use SSE for floating-point math, which is more stable than x87.
# `-mstackrealign` is needed for it to work.
env.Append(CCFLAGS=["-msse2", "-mfpmath=sse", "-mstackrealign"]) env.Append(CCFLAGS=["-msse2", "-mfpmath=sse", "-mstackrealign"])
# Explicitly specify colored output. # Explicitly specify colored output.

View File

@ -80,9 +80,16 @@ if env["builtin_embree"]:
env_thirdparty.disable_warnings() env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
# Set x86 CPU instruction sets to use when building Embree's own intrinsics.
# Keep this in sync with Godot's main SConstruct file.
# This is only needed on MSVC, as GCC/Clang will set those defines automatically
# according to compiler instruction set flags.
if env["arch"] != "x86_64" or env.msvc: if env["arch"] != "x86_64" or env.msvc:
# Embree needs those, it will automatically use SSE2NEON in ARM # Embree needs those; it will automatically use SSE2NEON in ARM.
env_thirdparty.Append(CPPDEFINES=["__SSE2__", "__SSE__"]) env_thirdparty.Append(CPPDEFINES=["__SSE__", "__SSE2__"])
if env["arch"] == "x86_64" and env.msvc:
env_thirdparty.Append(CPPDEFINES=["__SSE3__", "__SSSE3__", "__SSE4_1__", "__SSE4_2__"])
if env["platform"] == "web": if env["platform"] == "web":
env_thirdparty.Append(CXXFLAGS=["-msimd128"]) env_thirdparty.Append(CXXFLAGS=["-msimd128"])