From: Paul Cercueil Date: Tue, 15 Apr 2025 11:18:05 +0000 (+0200) Subject: cdrom: Align read buffers to 64 bytes X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20a88ae9db9732e9e6b02316cba5b9c45d73764a;p=pcsx_rearmed.git cdrom: Align read buffers to 64 bytes Align the address and size of read buffers to 64 bytes, which should be bigger or equal than the size of the cache lines on most systems. This allows hardware CD-ROM implementations to perform reads using DMA, which generally have tight requirements on alignment. Signed-off-by: Paul Cercueil --- diff --git a/libpcsxcore/cdrom-async.c b/libpcsxcore/cdrom-async.c index 84395e23..c2b64501 100644 --- a/libpcsxcore/cdrom-async.c +++ b/libpcsxcore/cdrom-async.c @@ -10,6 +10,7 @@ * GNU General Public License for more details. * ***************************************************************************/ +#include #include #include #include "system.h" @@ -104,12 +105,15 @@ static struct { u32 buf_cnt, thread_exit, do_prefetch, prefetch_failed, have_subchannel; u32 total_lba, prefetch_lba; int check_eject_delay; - u8 buf_local[CD_FRAMESIZE_RAW]; // single sector cache, not touched by the thread + + // single sector cache, not touched by the thread + alignas(64) u8 buf_local[CD_FRAMESIZE_RAW_ALIGNED]; } acdrom; static void lbacache_do(u32 lba) { - unsigned char msf[3], buf[CD_FRAMESIZE_RAW], buf_sub[SUB_FRAMESIZE]; + alignas(64) unsigned char buf[CD_FRAMESIZE_RAW_ALIGNED]; + unsigned char msf[3], buf_sub[SUB_FRAMESIZE]; u32 i = lba % acdrom.buf_cnt; int ret; diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index e52f74b8..df958bab 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -21,6 +21,7 @@ * Handles all CD-ROM registers and functions. */ +#include #include #include "cdrom.h" #include "cdrom-async.h" @@ -124,7 +125,7 @@ static struct { u8 AttenuatorLeftToLeftT, AttenuatorLeftToRightT; u8 AttenuatorRightToRightT, AttenuatorRightToLeftT; } cdr; -static s16 read_buf[CD_FRAMESIZE_RAW/2]; +alignas(64) static s16 read_buf[CD_FRAMESIZE_RAW_ALIGNED / 2]; struct SubQ { char res0[12]; diff --git a/libpcsxcore/cdrom.h b/libpcsxcore/cdrom.h index b8682b03..b762738c 100644 --- a/libpcsxcore/cdrom.h +++ b/libpcsxcore/cdrom.h @@ -41,6 +41,10 @@ extern "C" { #define CD_FRAMESIZE_RAW 2352 #define DATA_SIZE (CD_FRAMESIZE_RAW - 12) +/* CD_FRAMESIZE_RAW aligned to a cache line for DMA buffers + * (assuming a cache line of max. 64 bytes) */ +#define CD_FRAMESIZE_RAW_ALIGNED 2368 + #define SUB_FRAMESIZE 96 #define MSF2SECT(m, s, f) (((m) * 60 + (s) - 2) * 75 + (f))