From 37acae846c4679f604965d17cb8c171cebaf62f6 Mon Sep 17 00:00:00 2001 From: Sergio Martin Date: Sun, 14 Jan 2024 09:17:06 +0100 Subject: [PATCH] Ensuring CPU run function starts at the beggining of a page --- meson.build | 6 +++++- source/core/Nes_Cpu.cpp | 9 ++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index b8fcaa9..b3772bc 100644 --- a/meson.build +++ b/meson.build @@ -4,6 +4,10 @@ project('quickerNES','c','cpp', default_options : ['cpp_std=c++20', 'default_library=shared', 'buildtype=release'] ) +# Getting page alignment +getConfCommand = run_command('getconf', 'PAGESIZE', check: true) +pageSize = getConfCommand.stdout().strip() + # quickerNES Core sources quickerNESCoreSrc = [ @@ -41,7 +45,7 @@ quickerNESCoreSrc = [ # quickerNES Core Configuration quickerNESCoreDependency = declare_dependency( - compile_args : [ '-Wfatal-errors', '-Wall', '-Werror', '-Wno-multichar' ], + compile_args : [ '-Wfatal-errors', '-Wall', '-Werror', '-Wno-multichar', '-D_PAGE_SIZE="' + pageSize + '"'], include_directories : include_directories(['source', 'source/core', 'extern']), sources : [ quickerNESCoreSrc, 'extern/metrohash128/metrohash128.cpp' ] ) diff --git a/source/core/Nes_Cpu.cpp b/source/core/Nes_Cpu.cpp index 242bd89..4149d37 100644 --- a/source/core/Nes_Cpu.cpp +++ b/source/core/Nes_Cpu.cpp @@ -231,11 +231,8 @@ constexpr uint8_t clock_table [256] = { 3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7 // F }; -#pragma GCC push_options -#pragma GCC optimize ("align-functions=1024") - - -Nes_Cpu::result_t Nes_Cpu::run ( nes_time_t end ) +__attribute__((optimize("align-functions=" _PAGE_SIZE))) + Nes_Cpu::result_t Nes_Cpu::run ( nes_time_t end ) { set_end_time_( end ); clock_count = 0; @@ -1180,5 +1177,3 @@ end: return result; } - - #pragma GCC pop_options \ No newline at end of file