Skip to content

Commit 2c81d24

Browse files
authored
Make codebase more CPU-agnostic + MacOS disclaimer (#559)
1 parent 445b0af commit 2c81d24

26 files changed

+410
-266
lines changed

dependencies/ih264d/CMakeLists.txt

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
project ("ih264d")
44

5-
set(LIBAVCDEC_X86_INCLUDES "common/x86" "decoder/x86")
6-
7-
include_directories("common/" "decoder/" ${LIBAVCDEC_X86_INCLUDES})
8-
95
add_library (ih264d
106
"common/ih264_buf_mgr.c"
117
"common/ih264_buf_mgr.h"
@@ -53,21 +49,6 @@ add_library (ih264d
5349
"common/ih264_weighted_pred.h"
5450
"common/ithread.c"
5551
"common/ithread.h"
56-
"common/x86/ih264_chroma_intra_pred_filters_ssse3.c"
57-
"common/x86/ih264_deblk_chroma_ssse3.c"
58-
"common/x86/ih264_deblk_luma_ssse3.c"
59-
"common/x86/ih264_ihadamard_scaling_sse42.c"
60-
"common/x86/ih264_ihadamard_scaling_ssse3.c"
61-
"common/x86/ih264_inter_pred_filters_ssse3.c"
62-
"common/x86/ih264_iquant_itrans_recon_dc_ssse3.c"
63-
"common/x86/ih264_iquant_itrans_recon_sse42.c"
64-
"common/x86/ih264_iquant_itrans_recon_ssse3.c"
65-
"common/x86/ih264_luma_intra_pred_filters_ssse3.c"
66-
"common/x86/ih264_mem_fns_ssse3.c"
67-
"common/x86/ih264_padding_ssse3.c"
68-
"common/x86/ih264_platform_macros.h"
69-
"common/x86/ih264_resi_trans_quant_sse42.c"
70-
"common/x86/ih264_weighted_pred_sse42.c"
7152
"decoder/ih264d.h"
7253
"decoder/ih264d_api.c"
7354
"decoder/ih264d_bitstrm.c"
@@ -134,10 +115,71 @@ add_library (ih264d
134115
"decoder/ih264d_vui.h"
135116
"decoder/iv.h"
136117
"decoder/ivd.h"
118+
)
119+
120+
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
121+
set(LIBAVCDEC_X86_INCLUDES "common/x86" "decoder/x86")
122+
include_directories("common/" "decoder/" ${LIBAVCDEC_X86_INCLUDES})
123+
target_sources(ih264d PRIVATE
124+
"common/x86/ih264_chroma_intra_pred_filters_ssse3.c"
125+
"common/x86/ih264_deblk_chroma_ssse3.c"
126+
"common/x86/ih264_deblk_luma_ssse3.c"
127+
"common/x86/ih264_ihadamard_scaling_sse42.c"
128+
"common/x86/ih264_ihadamard_scaling_ssse3.c"
129+
"common/x86/ih264_inter_pred_filters_ssse3.c"
130+
"common/x86/ih264_iquant_itrans_recon_dc_ssse3.c"
131+
"common/x86/ih264_iquant_itrans_recon_sse42.c"
132+
"common/x86/ih264_iquant_itrans_recon_ssse3.c"
133+
"common/x86/ih264_luma_intra_pred_filters_ssse3.c"
134+
"common/x86/ih264_mem_fns_ssse3.c"
135+
"common/x86/ih264_padding_ssse3.c"
136+
"common/x86/ih264_platform_macros.h"
137+
"common/x86/ih264_resi_trans_quant_sse42.c"
138+
"common/x86/ih264_weighted_pred_sse42.c"
137139
"decoder/x86/ih264d_function_selector.c"
138140
"decoder/x86/ih264d_function_selector_sse42.c"
139141
"decoder/x86/ih264d_function_selector_ssse3.c"
140142
)
143+
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
144+
enable_language( C CXX ASM )
145+
set(LIBAVCDEC_ARM_INCLUDES "common/armv8" "decoder/arm")
146+
include_directories("common/" "decoder/" ${LIBAVCDEC_ARM_INCLUDES})
147+
target_sources(ih264d PRIVATE
148+
"common/armv8/ih264_deblk_chroma_av8.s"
149+
"common/armv8/ih264_deblk_luma_av8.s"
150+
"common/armv8/ih264_default_weighted_pred_av8.s"
151+
"common/armv8/ih264_ihadamard_scaling_av8.s"
152+
"common/armv8/ih264_inter_pred_chroma_av8.s"
153+
"common/armv8/ih264_inter_pred_filters_luma_horz_av8.s"
154+
"common/armv8/ih264_inter_pred_filters_luma_vert_av8.s"
155+
"common/armv8/ih264_inter_pred_luma_copy_av8.s"
156+
"common/armv8/ih264_inter_pred_luma_horz_hpel_vert_hpel_av8.s"
157+
"common/armv8/ih264_inter_pred_luma_horz_hpel_vert_qpel_av8.s"
158+
"common/armv8/ih264_inter_pred_luma_horz_qpel_av8.s"
159+
"common/armv8/ih264_inter_pred_luma_horz_qpel_vert_hpel_av8.s"
160+
"common/armv8/ih264_inter_pred_luma_horz_qpel_vert_qpel_av8.s"
161+
"common/armv8/ih264_inter_pred_luma_vert_qpel_av8.s"
162+
"common/armv8/ih264_intra_pred_chroma_av8.s"
163+
"common/armv8/ih264_intra_pred_luma_16x16_av8.s"
164+
"common/armv8/ih264_intra_pred_luma_4x4_av8.s"
165+
"common/armv8/ih264_intra_pred_luma_8x8_av8.s"
166+
"common/armv8/ih264_iquant_itrans_recon_av8.s"
167+
"common/armv8/ih264_iquant_itrans_recon_dc_av8.s"
168+
"common/armv8/ih264_mem_fns_neon_av8.s"
169+
"common/armv8/ih264_neon_macros.s"
170+
"common/armv8/ih264_padding_neon_av8.s"
171+
"common/armv8/ih264_platform_macros.h"
172+
"common/armv8/ih264_resi_trans_quant_av8.s"
173+
"common/armv8/ih264_weighted_bi_pred_av8.s"
174+
"common/armv8/ih264_weighted_pred_av8.s"
175+
"decoder/arm/ih264d_function_selector_a9q.c"
176+
"decoder/arm/ih264d_function_selector_av8.c"
177+
"decoder/arm/ih264d_function_selector.c"
178+
)
179+
target_compile_options(ih264d PRIVATE -DARMV8)
180+
else()
181+
message(FATAL_ERROR "ih264d unknown architecture: ${CMAKE_SYSTEM_PROCESSOR}")
182+
endif()
141183

142184
if(MSVC)
143185
set_property(TARGET ih264d PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

src/Cafe/GamePatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void hleExport_xcx_enterCriticalSection(PPCInterpreter_t* hCPU)
8383
osLib_returnFromFunction(hCPU, 0);
8484
return;
8585
}
86-
_mm_pause();
86+
_mm_pause();
8787
}
8888
PPCCore_switchToScheduler();
8989
}

src/Cafe/HW/Espresso/PPCState.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ extern uint64 ppcMainThreadDECCycleStart; // at which cycle the dec register was
203203
void PPCTimer_init();
204204
void PPCTimer_waitForInit();
205205
uint64 PPCTimer_getFromRDTSC();
206-
bool PPCTimer_hasInvariantRDTSCSupport();
207206

208207
uint64 PPCTimer_microsecondsToTsc(uint64 us);
209208
uint64 PPCTimer_tscToMicroseconds(uint64 us);

src/Cafe/HW/Espresso/PPCTimer.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#include "Cafe/HW/Espresso/Const.h"
2-
#include <immintrin.h>
32
#include "asm/x64util.h"
43
#include "config/ActiveSettings.h"
54
#include "util/helpers/fspinlock.h"
65
#include "util/highresolutiontimer/HighResolutionTimer.h"
6+
#include "Common/cpu_features.h"
7+
8+
#if defined(ARCH_X86_64)
9+
#include <immintrin.h>
10+
#pragma intrinsic(__rdtsc)
11+
#endif
712

813
uint64 _rdtscLastMeasure = 0;
914
uint64 _rdtscFrequency = 0;
@@ -18,8 +23,6 @@ static_assert(sizeof(uint128_t) == 16);
1823

1924
uint128_t _rdtscAcc{};
2025

21-
#pragma intrinsic(__rdtsc)
22-
2326
uint64 muldiv64(uint64 a, uint64 b, uint64 d)
2427
{
2528
uint64 diva = a / d;
@@ -29,17 +32,12 @@ uint64 muldiv64(uint64 a, uint64 b, uint64 d)
2932
return diva * b + moda * divb + moda * modb / d;
3033
}
3134

32-
bool PPCTimer_hasInvariantRDTSCSupport()
33-
{
34-
uint32 cpuv[4];
35-
cpuid((int*)cpuv, 0x80000007);
36-
return ((cpuv[3] >> 8) & 1);
37-
}
38-
3935
uint64 PPCTimer_estimateRDTSCFrequency()
4036
{
41-
if (PPCTimer_hasInvariantRDTSCSupport() == false)
42-
forceLog_printf("Invariant TSC not supported");
37+
#if defined(ARCH_X86_64)
38+
if (!g_CPUFeatures.x86.invariant_tsc)
39+
cemuLog_log(LogType::Force, "Invariant TSC not supported");
40+
#endif
4341

4442
_mm_mfence();
4543
uint64 tscStart = __rdtsc();

src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
#include "Cafe/OS/libs/coreinit/coreinit_CodeGen.h"
99
#include "config/ActiveSettings.h"
1010
#include "config/LaunchSettings.h"
11-
12-
#include "util/helpers/fspinlock.h"
1311
#include "Common/ExceptionHandler/ExceptionHandler.h"
12+
#include "Common/cpu_features.h"
13+
#include "util/helpers/fspinlock.h"
1414
#include "util/helpers/helpers.h"
15-
1615
#include "util/MemMapper/MemMapper.h"
1716

1817
struct PPCInvalidationRange
@@ -461,6 +460,20 @@ void PPCRecompiler_invalidateRange(uint32 startAddr, uint32 endAddr)
461460
PPCRecompilerState.recompilerSpinlock.unlock();
462461
}
463462

463+
#if defined(ARCH_X86_64)
464+
void PPCRecompiler_initPlatform()
465+
{
466+
// mxcsr
467+
ppcRecompilerInstanceData->_x64XMM_mxCsr_ftzOn = 0x1F80 | 0x8000;
468+
ppcRecompilerInstanceData->_x64XMM_mxCsr_ftzOff = 0x1F80;
469+
}
470+
#else
471+
void PPCRecompiler_initPlatform()
472+
{
473+
474+
}
475+
#endif
476+
464477
void PPCRecompiler_init()
465478
{
466479
if (ActiveSettings::GetCPUMode() == CPUMode::SinglecoreInterpreter)
@@ -569,21 +582,9 @@ void PPCRecompiler_init()
569582
ppcRecompilerInstanceData->_psq_st_scale_ps0_ps1[(i + 32) * 2 + 1] = br;
570583
}
571584

572-
// mxcsr
573-
ppcRecompilerInstanceData->_x64XMM_mxCsr_ftzOn = 0x1F80 | 0x8000;
574-
ppcRecompilerInstanceData->_x64XMM_mxCsr_ftzOff = 0x1F80;
575-
576-
// query processor extensions
577-
int cpuInfo[4];
578-
cpuid(cpuInfo, 0x80000001);
579-
hasLZCNTSupport = ((cpuInfo[2] >> 5) & 1) != 0;
580-
cpuid(cpuInfo, 0x1);
581-
hasMOVBESupport = ((cpuInfo[2] >> 22) & 1) != 0;
582-
hasAVXSupport = ((cpuInfo[2] >> 28) & 1) != 0;
583-
cpuidex(cpuInfo, 0x7, 0);
584-
hasBMI2Support = ((cpuInfo[1] >> 8) & 1) != 0;
585-
586-
forceLog_printf("Recompiler initialized. CPU extensions: %s%s%s", hasLZCNTSupport ? "LZCNT " : "", hasMOVBESupport ? "MOVBE " : "", hasAVXSupport ? "AVX " : "");
585+
PPCRecompiler_initPlatform();
586+
587+
forceLog_printf("Recompiler initialized");
587588

588589
ppcRecompilerEnabled = true;
589590

src/Cafe/HW/Espresso/Recompiler/PPCRecompiler.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,6 @@ extern void ATTR_MS_ABI (*PPCRecompiler_leaveRecompilerCode_unvisited)();
384384

385385
#define PPC_REC_INVALID_FUNCTION ((PPCRecFunction_t*)-1)
386386

387-
// CPUID
388-
extern bool hasLZCNTSupport;
389-
extern bool hasMOVBESupport;
390-
extern bool hasBMI2Support;
391-
extern bool hasAVXSupport;
392-
393387
// todo - move some of the stuff above into PPCRecompilerInternal.h
394388

395389
// recompiler interface

0 commit comments

Comments
 (0)