From 2b66e756dafdef26d8356ab9d46555e94719dcff Mon Sep 17 00:00:00 2001 From: rogerman Date: Thu, 19 Jan 2023 14:18:58 -0800 Subject: [PATCH] Add support for page-aligned variables/arrays. - Better account for UltraSPARC's unique memory page size. - malloc_alignedCacheLine() no longer returns 16-byte aligned memory if the architecture is neither 32-bit or 64-bit. Now, the function only returns 64-byte alignment for 64-bit architectures OR 32-byte alignment for 32-bit architectures. --- desmume/src/common.cpp | 16 +++------------- desmume/src/types.h | 9 ++++++++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/desmume/src/common.cpp b/desmume/src/common.cpp index 413effdc5..f7f12ee5c 100644 --- a/desmume/src/common.cpp +++ b/desmume/src/common.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2008-2017 DeSmuME team + Copyright (C) 2008-2023 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -105,22 +105,12 @@ void* malloc_aligned64(size_t length) void* malloc_alignedCacheLine(size_t length) { -#if defined(HOST_32) - return malloc_aligned32(length); -#elif defined(HOST_64) - return malloc_aligned64(length); -#else - return malloc_aligned16(length); -#endif + return malloc_aligned(length, CACHE_ALIGN_SIZE); } void* malloc_alignedPage(size_t length) { - // WARNING! - // - // This may fail for SPARC users, which have a page size - // of 8KB instead of the more typical 4KB. - return malloc_aligned(length, 4096); + return malloc_aligned(length, PAGE_ALIGN_SIZE); } void free_aligned(void *ptr) diff --git a/desmume/src/types.h b/desmume/src/types.h index 34a6c669f..b52e0f6e2 100644 --- a/desmume/src/types.h +++ b/desmume/src/types.h @@ -1,6 +1,6 @@ /* Copyright (C) 2005 Guillaume Duhamel - Copyright (C) 2008-2022 DeSmuME team + Copyright (C) 2008-2023 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -165,8 +165,15 @@ #define CACHE_ALIGN_SIZE 32 #endif +#if defined(__sparc_v9__) || defined(__sparcv9) + #define PAGE_ALIGN_SIZE 8192 // UltraSPARC architecture uses 8 KB pages. +#else + #define PAGE_ALIGN_SIZE 4096 // Most architectures use 4 KB pages. +#endif + //use this for example when you want a byte value to be better-aligned #define CACHE_ALIGN DS_ALIGN(CACHE_ALIGN_SIZE) +#define PAGE_ALIGN DS_ALIGN(PAGE_ALIGN_SIZE) #define FAST_ALIGN DS_ALIGN(4) //---------------------------------------------