Skip to content

Commit 07a060b

Browse files
JoelLinngibbed
authored andcommitted
[Kernel] Solve ambiguity in RegisterExport()
- Remove overload for exports with `void` return type - Use `if constexpr (std::is_void<R>::value)` to differentiate
1 parent d40dfa1 commit 07a060b

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

src/xenia/kernel/util/shim_utils.h

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <cstring>
1414
#include <string>
15+
#include <type_traits>
1516

1617
#include "third_party/fmt/include/fmt/format.h"
1718
#include "xenia/base/byte_order.h"
@@ -531,52 +532,25 @@ xe::cpu::Export* RegisterExport(R (*fn)(Ps&...), const char* name,
531532
cvars::log_high_frequency_kernel_calls)) {
532533
PrintKernelCall(export_entry, params);
533534
}
534-
auto result =
535-
KernelTrampoline(FN, std::forward<std::tuple<Ps...>>(params),
536-
std::make_index_sequence<sizeof...(Ps)>());
537-
result.Store(ppc_context);
538-
if (export_entry->tags &
539-
(xe::cpu::ExportTag::kLog | xe::cpu::ExportTag::kLogResult)) {
540-
// TODO(benvanik): log result.
535+
if constexpr (std::is_void<R>::value) {
536+
KernelTrampoline(FN, std::forward<std::tuple<Ps...>>(params),
537+
std::make_index_sequence<sizeof...(Ps)>());
538+
} else {
539+
auto result =
540+
KernelTrampoline(FN, std::forward<std::tuple<Ps...>>(params),
541+
std::make_index_sequence<sizeof...(Ps)>());
542+
result.Store(ppc_context);
543+
if (export_entry->tags &
544+
(xe::cpu::ExportTag::kLog | xe::cpu::ExportTag::kLogResult)) {
545+
// TODO(benvanik): log result.
546+
}
541547
}
542548
}
543549
};
544550
export_entry->function_data.trampoline = &X::Trampoline;
545551
return export_entry;
546552
}
547553

548-
template <KernelModuleId MODULE, uint16_t ORDINAL, typename... Ps>
549-
xe::cpu::Export* RegisterExport(void (*fn)(Ps&...), const char* name,
550-
xe::cpu::ExportTag::type tags) {
551-
static const auto export_entry = new cpu::Export(
552-
ORDINAL, xe::cpu::Export::Type::kFunction, name,
553-
tags | xe::cpu::ExportTag::kImplemented | xe::cpu::ExportTag::kLog);
554-
static void (*FN)(Ps & ...) = fn;
555-
struct X {
556-
static void Trampoline(PPCContext* ppc_context) {
557-
++export_entry->function_data.call_count;
558-
Param::Init init = {
559-
ppc_context,
560-
0,
561-
};
562-
// Using braces initializer instead of make_tuple because braces
563-
// enforce execution order across compilers.
564-
// The make_tuple order is undefined per the C++ standard and
565-
// cause inconsitencies between msvc and clang.
566-
std::tuple<Ps...> params = {Ps(init)...};
567-
if (export_entry->tags & xe::cpu::ExportTag::kLog &&
568-
(!(export_entry->tags & xe::cpu::ExportTag::kHighFrequency) ||
569-
cvars::log_high_frequency_kernel_calls)) {
570-
PrintKernelCall(export_entry, params);
571-
}
572-
KernelTrampoline(FN, std::forward<std::tuple<Ps...>>(params),
573-
std::make_index_sequence<sizeof...(Ps)>());
574-
}
575-
};
576-
export_entry->function_data.trampoline = &X::Trampoline;
577-
return export_entry;
578-
}
579-
580554
} // namespace shim
581555

582556
using xe::cpu::ExportTag;

0 commit comments

Comments
 (0)