@@ -278,22 +278,24 @@ uint8_t PCSX::Memory::read8(uint32_t address) {
278
278
const auto pointer = (uint8_t *)m_readLUT[page];
279
279
const bool pioConnected = g_emulator->settings .get <Emulator::SettingPIOConnected>().value ;
280
280
281
- if (msanInitialized () && inMsanRange (address)) {
282
- switch (msanGetStatus (address, 1 )) {
283
- case MsanStatus::UNINITIALIZED:
284
- g_system->log (LogClass::CPU, _ (" 8-bit read from usable but uninitialized msan memory: %8.8lx\n " ), address);
285
- break ;
286
- case MsanStatus::UNUSABLE:
287
- g_system->log (LogClass::CPU, _ (" 8-bit read from unusable msan memory: %8.8lx\n " ), address);
288
- break ;
289
- case MsanStatus::OK:
290
- return m_msanRAM[address - c_msanStart];
291
- }
292
- g_system->pause ();
293
- return 0 ;
294
- } else if (pointer != nullptr ) {
281
+ if (pointer != nullptr ) {
282
+ if (msanInitialized () && inMsanRange (address)) [[unlikely]] {
283
+ switch (msanGetStatus (address, 1 )) {
284
+ case MsanStatus::UNINITIALIZED:
285
+ g_system->log (LogClass::CPU, _ (" 8-bit read from usable but uninitialized msan memory: %8.8lx\n " ), address);
286
+ break ;
287
+ case MsanStatus::UNUSABLE:
288
+ g_system->log (LogClass::CPU, _ (" 8-bit read from unusable msan memory: %8.8lx\n " ), address);
289
+ break ;
290
+ case MsanStatus::OK:
291
+ return m_msanRAM[address - c_msanStart];
292
+ }
293
+ g_system->pause ();
294
+ return 0 ;
295
+ }
296
+ [[likely]];
295
297
const uint32_t offset = address & 0xffff ;
296
- return *(pointer + offset);
298
+ return *(pointer + offset);
297
299
} else if (page == 0x1f80 || page == 0x9f80 || page == 0xbf80 ) {
298
300
if ((address & 0xffff ) < 0x400 ) {
299
301
return m_hard[address & 0x3ff ];
@@ -326,20 +328,22 @@ uint16_t PCSX::Memory::read16(uint32_t address) {
326
328
const auto pointer = (uint8_t *)m_readLUT[page];
327
329
const bool pioConnected = g_emulator->settings .get <Emulator::SettingPIOConnected>().value ;
328
330
329
- if (msanInitialized () && inMsanRange (address)) {
330
- switch (msanGetStatus (address, 2 )) {
331
- case MsanStatus::UNINITIALIZED:
332
- g_system->log (LogClass::CPU, _ (" 16-bit read from usable but uninitialized msan memory: %8.8lx\n " ), address);
333
- break ;
334
- case MsanStatus::UNUSABLE:
335
- g_system->log (LogClass::CPU, _ (" 16-bit read from unusable msan memory: %8.8lx\n " ), address);
336
- break ;
337
- case MsanStatus::OK:
338
- return *(uint16_t *)&m_msanRAM[address - c_msanStart];
331
+ if (pointer != nullptr ) {
332
+ if (msanInitialized () && inMsanRange (address)) {
333
+ switch (msanGetStatus (address, 2 )) {
334
+ case MsanStatus::UNINITIALIZED:
335
+ g_system->log (LogClass::CPU, _ (" 16-bit read from usable but uninitialized msan memory: %8.8lx\n " ), address);
336
+ break ;
337
+ case MsanStatus::UNUSABLE:
338
+ g_system->log (LogClass::CPU, _ (" 16-bit read from unusable msan memory: %8.8lx\n " ), address);
339
+ break ;
340
+ case MsanStatus::OK:
341
+ return SWAP_LEu16 (*(uint16_t *)&m_msanRAM[address - c_msanStart]);
342
+ }
343
+ g_system->pause ();
344
+ return 0 ;
339
345
}
340
- g_system->pause ();
341
- return 0 ;
342
- } else if (pointer != nullptr ) {
346
+ [[likely]];
343
347
const uint32_t offset = address & 0xffff ;
344
348
return SWAP_LEu16 (*(uint16_t *)(pointer + offset));
345
349
} else if (page == 0x1f80 || page == 0x9f80 || page == 0xbf80 ) {
@@ -371,20 +375,22 @@ uint32_t PCSX::Memory::read32(uint32_t address, ReadType readType) {
371
375
const auto pointer = (uint8_t *)m_readLUT[page];
372
376
const bool pioConnected = g_emulator->settings .get <Emulator::SettingPIOConnected>().value ;
373
377
374
- if (msanInitialized () && inMsanRange (address)) {
375
- switch (msanGetStatus (address, 4 )) {
376
- case MsanStatus::UNINITIALIZED:
377
- g_system->log (LogClass::CPU, _ (" 32-bit read from usable but uninitialized msan memory: %8.8lx\n " ), address);
378
- break ;
379
- case MsanStatus::UNUSABLE:
380
- g_system->log (LogClass::CPU, _ (" 32-bit read from unusable msan memory: %8.8lx\n " ), address);
381
- break ;
382
- case MsanStatus::OK:
383
- return *(uint32_t *)&m_msanRAM[address - c_msanStart];
378
+ if (pointer != nullptr ) {
379
+ if (msanInitialized () && inMsanRange (address)) {
380
+ switch (msanGetStatus (address, 4 )) {
381
+ case MsanStatus::UNINITIALIZED:
382
+ g_system->log (LogClass::CPU, _ (" 32-bit read from usable but uninitialized msan memory: %8.8lx\n " ), address);
383
+ break ;
384
+ case MsanStatus::UNUSABLE:
385
+ g_system->log (LogClass::CPU, _ (" 32-bit read from unusable msan memory: %8.8lx\n " ), address);
386
+ break ;
387
+ case MsanStatus::OK:
388
+ return SWAP_LEu32 (*(uint32_t *)&m_msanRAM[address - c_msanStart]);
389
+ }
390
+ g_system->pause ();
391
+ return 0 ;
384
392
}
385
- g_system->pause ();
386
- return 0 ;
387
- } else if (pointer != nullptr ) {
393
+ [[likely]];
388
394
const uint32_t offset = address & 0xffff ;
389
395
return SWAP_LEu32 (*(uint32_t *)(pointer + offset));
390
396
} else if (page == 0x1f80 || page == 0x9f80 || page == 0xbf80 ) {
@@ -492,14 +498,16 @@ void PCSX::Memory::write8(uint32_t address, uint32_t value) {
492
498
const auto pointer = (uint8_t *)m_writeLUT[page];
493
499
const bool pioConnected = g_emulator->settings .get <Emulator::SettingPIOConnected>().value ;
494
500
495
- if (msanInitialized () && inMsanRange (address)) {
496
- if (msanValidateWrite (address, 1 )) {
497
- m_msanRAM[address - c_msanStart] = value;
498
- } else {
499
- g_system->log (LogClass::CPU, _ (" 8-bit write to unusable msan memory: %8.8lx\n " ), address);
500
- g_system->pause ();
501
+ if (pointer != nullptr ) {
502
+ if (msanInitialized () && inMsanRange (address)) {
503
+ if (msanValidateWrite (address, 1 )) {
504
+ m_msanRAM[address - c_msanStart] = value;
505
+ } else {
506
+ g_system->log (LogClass::CPU, _ (" 8-bit write to unusable msan memory: %8.8lx\n " ), address);
507
+ g_system->pause ();
508
+ }
501
509
}
502
- } else if (pointer != nullptr ) {
510
+ [[likely]];
503
511
const uint32_t offset = address & 0xffff ;
504
512
*(pointer + offset) = static_cast <uint8_t >(value);
505
513
g_emulator->m_cpu ->Clear ((address & (~3 )), 1 );
@@ -527,14 +535,16 @@ void PCSX::Memory::write16(uint32_t address, uint32_t value) {
527
535
const auto pointer = (uint8_t *)m_writeLUT[page];
528
536
const bool pioConnected = g_emulator->settings .get <Emulator::SettingPIOConnected>().value ;
529
537
530
- if (msanInitialized () && inMsanRange (address)) {
531
- if (msanValidateWrite (address, 2 )) {
532
- *(uint16_t *)&m_msanRAM[address - c_msanStart] = SWAP_LEu16 (value);
533
- } else {
534
- g_system->log (LogClass::CPU, _ (" 16-bit write to unusable msan memory: %8.8lx\n " ), address);
535
- g_system->pause ();
538
+ if (pointer != nullptr ) {
539
+ if (msanInitialized () && inMsanRange (address)) {
540
+ if (msanValidateWrite (address, 2 )) {
541
+ *(uint16_t *)&m_msanRAM[address - c_msanStart] = SWAP_LEu16 (value);
542
+ } else {
543
+ g_system->log (LogClass::CPU, _ (" 16-bit write to unusable msan memory: %8.8lx\n " ), address);
544
+ g_system->pause ();
545
+ }
536
546
}
537
- } else if (pointer != nullptr ) {
547
+ [[likely]];
538
548
const uint32_t offset = address & 0xffff ;
539
549
*(uint16_t *)(pointer + offset) = SWAP_LEu16 (static_cast <uint16_t >(value));
540
550
g_emulator->m_cpu ->Clear ((address & (~3 )), 1 );
@@ -563,14 +573,16 @@ void PCSX::Memory::write32(uint32_t address, uint32_t value) {
563
573
const auto pointer = (uint8_t *)m_writeLUT[page];
564
574
const bool pioConnected = g_emulator->settings .get <Emulator::SettingPIOConnected>().value ;
565
575
566
- if (msanInitialized () && inMsanRange (address)) {
567
- if (msanValidateWrite (address, 4 )) {
568
- *(uint32_t *)&m_msanRAM[address - c_msanStart] = SWAP_LEu32 (value);
569
- } else {
570
- g_system->log (LogClass::CPU, _ (" 32-bit write to unusable msan memory: %8.8lx\n " ), address);
571
- g_system->pause ();
576
+ if (pointer != nullptr ) {
577
+ if (msanInitialized () && inMsanRange (address)) {
578
+ if (msanValidateWrite (address, 4 )) {
579
+ *(uint32_t *)&m_msanRAM[address - c_msanStart] = SWAP_LEu32 (value);
580
+ } else {
581
+ g_system->log (LogClass::CPU, _ (" 32-bit write to unusable msan memory: %8.8lx\n " ), address);
582
+ g_system->pause ();
583
+ }
572
584
}
573
- } else if (pointer != nullptr ) {
585
+ [[likely]];
574
586
const uint32_t offset = address & 0xffff ;
575
587
*(uint32_t *)(pointer + offset) = SWAP_LEu32 (value);
576
588
g_emulator->m_cpu ->Clear ((address & (~3 )), 1 );
@@ -923,19 +935,6 @@ uint32_t PCSX::Memory::msanRealloc(uint32_t ptr, uint32_t size) {
923
935
return newPtr + c_msanStart;
924
936
}
925
937
926
- PCSX::MsanStatus PCSX::Memory::msanGetStatus (uint32_t addr, uint32_t size) const {
927
- uint32_t msanAddr = addr - c_msanStart;
928
- if (!(m_msanUsableBitmap[msanAddr / 8 ] & (1 << msanAddr % 8 ))) {
929
- return PCSX::MsanStatus::UNUSABLE;
930
- }
931
- for (uint32_t checkAddr = msanAddr; checkAddr < msanAddr + size; checkAddr++) {
932
- if (!(m_msanWrittenBitmap[checkAddr / 8 ] & (1 << checkAddr % 8 ))) {
933
- return PCSX::MsanStatus::UNINITIALIZED;
934
- }
935
- }
936
- return PCSX::MsanStatus::OK;
937
- }
938
-
939
938
bool PCSX::Memory::msanValidateWrite (uint32_t addr, uint32_t size) {
940
939
uint32_t msanAddr = addr - c_msanStart;
941
940
if (!(m_msanUsableBitmap[msanAddr / 8 ] & (1 << msanAddr % 8 ))) {
@@ -944,6 +943,7 @@ bool PCSX::Memory::msanValidateWrite(uint32_t addr, uint32_t size) {
944
943
for (uint32_t checkAddr = msanAddr; checkAddr < msanAddr + size; checkAddr++) {
945
944
m_msanWrittenBitmap[checkAddr / 8 ] |= 1 << checkAddr % 8 ;
946
945
}
946
+ [[likely]];
947
947
return true ;
948
948
}
949
949
0 commit comments