Compare commits

..

1 Commits

Author SHA1 Message Date
lizzie d14c1f13d8 [cmake] Add M1 to BUILD_PRESET, more proper tuning
Signed-off-by: lizzie <lizzie@eden-emu.dev>
2026-10-08 17:01:11 +00:00
3 changed files with 60 additions and 45 deletions
+20 -25
View File
@@ -322,47 +322,42 @@ endif()
# Build/optimization presets
if (CXX_GCC OR CXX_CLANG)
if (ARCHITECTURE_x86_64)
# GCC/clang will -mtune=generic by default
if ("${YUZU_BUILD_PRESET}" STREQUAL "native")
add_compile_options(
$<$<COMPILE_LANGUAGE:C,CXX>:-march=native>
$<$<COMPILE_LANGUAGE:C,CXX>:-mtune=native>)
elseif (ARCHITECTURE_x86_64)
# See https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
# Generic supports Pentium Pro instruction set and above
# TODO: if a value is unknown, pass that as march and mtune
set(YUZU_BUILD_PRESET "custom" CACHE STRING "Build preset to use. One of: custom, generic, v3, zen2, zen4, native")
if (${YUZU_BUILD_PRESET} STREQUAL "generic")
set(march x86-64)
set(mtune generic)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-march=x86-64>)
elseif (${YUZU_BUILD_PRESET} STREQUAL "v3")
set(march x86-64-v3)
set(mtune generic)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-march=x86-64-v3>)
elseif (${YUZU_BUILD_PRESET} STREQUAL "zen2")
set(march znver2)
set(mtune znver2)
add_compile_options(
$<$<COMPILE_LANGUAGE:C,CXX>:-march=znver2>
$<$<COMPILE_LANGUAGE:C,CXX>:-mtune=znver4>)
elseif (${YUZU_BUILD_PRESET} STREQUAL "zen4")
set(march znver4)
set(mtune znver4)
add_compile_options(
$<$<COMPILE_LANGUAGE:C,CXX>:-march=znver4>
$<$<COMPILE_LANGUAGE:C,CXX>:-mtune=znver4>)
endif()
elseif(ARCHITECTURE_arm64)
# See https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html
set(YUZU_BUILD_PRESET "custom" CACHE STRING "Build preset to use. One of: custom, generic, optimized, armv9, native")
set(mtune generic)
set(YUZU_BUILD_PRESET "custom" CACHE STRING "Build preset to use. One of: custom, generic, optimized, armv9, m1, native")
if (${YUZU_BUILD_PRESET} STREQUAL "generic")
set(march armv8-a)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-march=armv8-a>)
elseif (${YUZU_BUILD_PRESET} STREQUAL "optimized")
set(march armv8.2-a+lse+rcpc)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-march=armv8.2-a+lse+rcpc>)
elseif (${YUZU_BUILD_PRESET} STREQUAL "armv9")
set(march armv9-a)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-march=armv9-a>)
elseif (${YUZU_BUILD_PRESET} STREQUAL "m1")
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-mcpu=apple-m1>)
endif()
endif()
if ("${YUZU_BUILD_PRESET}" STREQUAL "native")
set(march native)
set(mtune native)
endif()
if (DEFINED march AND DEFINED mtune)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${march} -mtune=${mtune}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${march} -mtune=${mtune}")
endif()
endif()
# Configure C++ standard
@@ -7,27 +7,34 @@
*/
#include <cstring>
#include <cassert>
#include "common/assert.h"
#include "dynarmic/backend/x64/block_of_code.h"
#include "dynarmic/backend/x64/constant_pool.h"
namespace Dynarmic::Backend::X64 {
ConstantPool::ConstantPool(BlockOfCode& code, size_t size) noexcept {
auto const align_size = 64; //always align to cacheline
code.EnsureMemoryCommitted(2 * align_size + size);
ConstantPool::ConstantPool(BlockOfCode& code, size_t size)
: insertion_point(0)
{
code.EnsureMemoryCommitted(align_size + size);
code.int3();
code.align(align_size);
pool = std::span<u128>(static_cast<u128*>(code.AllocateFromCodeSpace(size)), size / sizeof(u128));
pool = std::span<ConstantT>(reinterpret_cast<ConstantT*>(code.AllocateFromCodeSpace(size)), size / align_size);
}
Xbyak::Address ConstantPool::GetConstant(BlockOfCode& code, const Xbyak::AddressFrame& frame, u64 lo, u64 hi) noexcept {
// offset grows iff new constant is added
auto const key = std::make_pair(lo, hi);
auto const val = u32(constant_info.size());
auto const [it, _] = constant_info.insert({key, val});
// if it != constant_info.end(): assume(pool[it->second] == c);
pool[it->second] = u128{lo, hi};
return frame[code.rip + std::addressof(pool[it->second])];
Xbyak::Address ConstantPool::GetConstant(BlockOfCode& code, const Xbyak::AddressFrame& frame, u64 lower, u64 upper) {
const auto constant = ConstantT(lower, upper);
auto it = constant_info.find(constant);
if (it == constant_info.end()) {
ASSERT(insertion_point < pool.size());
ConstantT& target_constant = pool[insertion_point];
target_constant = constant;
it = constant_info.insert({constant, &target_constant}).first;
++insertion_point;
}
return frame[code.rip + it->second];
}
} // namespace Dynarmic::Backend::X64
@@ -12,7 +12,6 @@
#include <cstddef>
#include <span>
#include <utility>
#include <boost/functional/hash.hpp>
#include "common/common_types.h"
#include "common/container/unordered_map.h"
@@ -22,17 +21,31 @@ namespace Dynarmic::Backend::X64 {
class BlockOfCode;
/// @brief ConstantPool allocates a block of memory from BlockOfCode.
/// ConstantPool allocates a block of memory from BlockOfCode.
/// It places constants into this block of memory, returning the address
/// of the memory location where the constant is placed. If the constant
/// already exists, its memory location is reused.
class ConstantPool final {
public:
ConstantPool(BlockOfCode& code, size_t size) noexcept;
Xbyak::Address GetConstant(BlockOfCode& code, const Xbyak::AddressFrame& frame, u64 lower, u64 upper = 0) noexcept;
// key = identity hash, value = offset from pool.data()
::Common::unordered_map<std::pair<u64, u64>, u32, boost::hash<std::pair<u64, u64>>> constant_info;
std::span<u128> pool;
ConstantPool(BlockOfCode& code, size_t size);
Xbyak::Address GetConstant(BlockOfCode& code, const Xbyak::AddressFrame& frame, u64 lower, u64 upper = 0);
private:
static constexpr size_t align_size = 16; // bytes
using ConstantT = std::pair<u64, u64>;
static_assert(sizeof(ConstantT) == align_size);
struct ConstantHash {
std::size_t operator()(const ConstantT& constant) const noexcept {
return constant.first ^ std::rotl<u64>(constant.second, 1);
}
};
::Common::unordered_map<ConstantT, void*, ConstantHash> constant_info;
std::span<ConstantT> pool;
std::size_t insertion_point;
};
} // namespace Dynarmic::Backend::X64